Skip to content

Commit

Permalink
Switch from JSHint to ESLint
Browse files Browse the repository at this point in the history
This switches us from JSHint to ESLint, improving the quality and
consistency of our code. (We also use ESLint elsewhere at Airtable.)

To break down this change:

* We made several cleanups before this commit to ease the transition.
  See [#95][1], [#96][2], [#97][3], [#98][4], [#99][5], [#101][6] (and a
  fix in [#107][7]), [#105][8], [#109][9], [#118][10], [#119][11],
  [#120][12]
* Installed `eslint`
* Add `.eslintrc.json` and `.eslintignore` (and a slightly-different
  `.eslintrc.json` in `test`)
* Remove JSHint. Involved uninstalling the package, removing it from the
  gruntfile, and removing `jshint ignore`s.
* Update the `lint` task in `package.json`
* Update `return` into `return void 0` for consistent returns in
  `callbackToPromise`
* Add one `// eslint-disable-line` comment in a single test file
* Run `eslint --fix .`, automatically fixing all of the remaining
  warnings and errors

[1]: #95
[2]: #96
[3]: #97
[4]: #98
[5]: #99
[6]: #101
[7]: #107
[8]: #105
[9]: #109
[10]: #118
[11]: #119
[12]: #120
  • Loading branch information
Evan Hahn committed Jul 9, 2019
1 parent 0621f51 commit 9861673
Show file tree
Hide file tree
Showing 23 changed files with 1,214 additions and 779 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/node_modules/
/build/airtable.browser.js
/test/test_files/airtable.browser.js
115 changes: 115 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{
"env": {
"browser": true,
"node": true
},
"globals": {
"Promise": true
},
"extends": [
"eslint:recommended"
],
"rules": {
"no-case-declarations": "warn",
"no-debugger": "warn",
"no-empty": "warn",
"no-extra-boolean-cast": "warn",
"no-extra-semi": "warn",
"no-redeclare": "warn",
"no-regex-spaces": "warn",
"no-self-assign": "warn",
"no-sparse-arrays": "warn",
"no-unreachable": "warn",
"no-console": "off",
"require-yield": "off",
"array-bracket-spacing": "warn",
"array-callback-return": "error",
"arrow-spacing": "warn",
"block-scoped-var": "error",
"block-spacing": "warn",
"comma-spacing": "warn",
"comma-style": "warn",
"computed-property-spacing": "warn",
"consistent-return": "error",
"consistent-this": ["warn", "that"],
"curly": "warn",
"default-case": "warn",
"dot-notation": ["warn", {"allowPattern": "[$_0-9]"}],
"eqeqeq": "error",
"func-call-spacing": "error",
"guard-for-in": "error",
"handle-callback-err": "error",
"key-spacing": "warn",
"keyword-spacing": "warn",
"linebreak-style": "warn",
"indent": ["warn", 4],
"new-parens": "warn",
"no-array-constructor": "error",
"no-caller": "error",
"no-catch-shadow": "error",
"no-confusing-arrow": "warn",
"no-constant-condition": "warn",
"no-div-regex": "warn",
"no-eq-null": "error",
"no-eval": "error",
"no-extend-native": "error",
"no-extra-bind": "warn",
"no-extra-label": "error",
"no-floating-decimal": "warn",
"no-global-assign": "warn",
"no-implicit-globals": "warn",
"no-implied-eval": "error",
"no-iterator": "error",
"no-labels": "error",
"no-label-var": "error",
"no-loop-func": "error",
"no-lone-blocks": "error",
"no-native-reassign": "error",
"no-mixed-operators": ["warn", {"groups": [["&&", "||"]]}],
"no-mixed-requires": "error",
"no-multi-spaces": "warn",
"no-multi-str": "warn",
"no-new-object": "warn",
"no-new-require": "error",
"no-new-wrappers": "warn",
"no-octal-escape": "error",
"no-path-concat": "error",
"no-proto": "error",
"no-script-url": "error",
"no-sequences": "error",
"no-self-compare": "error",
"no-shadow": "error",
"no-shadow-restricted-names": "error",
"no-spaced-func": "warn",
"no-template-curly-in-string": "error",
"no-throw-literal": "warn",
"no-undef": "error",
"no-undef-init": "warn",
"no-unneeded-ternary": "warn",
"no-unsafe-negation": "warn",
"no-unused-expressions": "error",
"no-unused-vars": "warn",
"no-useless-call": "warn",
"no-useless-computed-key": "warn",
"no-useless-concat": "warn",
"no-useless-constructor": "warn",
"no-undefined": "error",
"no-whitespace-before-property": "warn",
"no-with": "error",
"object-curly-spacing": "warn",
"one-var-declaration-per-line": "warn",
"quotes": ["warn", "single", "avoid-escape"],
"radix": "error",
"semi": "warn",
"semi-spacing": "warn",
"space-before-blocks": "warn",
"space-before-function-paren": [
"warn",
{"anonymous": "never", "named": "never", "asyncArrow": "always"}
],
"space-in-parens": "warn",
"space-unary-ops": "warn",
"spaced-comment": "warn",
"yoda": "warn"
}
}
34 changes: 1 addition & 33 deletions gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,6 @@ module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: pkg,
jshint: {
// define the files to lint
files: ['gruntfile.js', 'lib/**/!(class.js)*.js', 'test/*.test.js'],
// configure JSHint (documented at http://www.jshint.com/docs/)
options: {
// more options here if you want to override JSHint defaults
strict: true,
globalstrict: true,
globals: {
console: true,
module: true,
require: true,
process: true,
setTimeout: true,
jest: true,
describe: true,
beforeEach: true,
beforeAll: true,
afterAll: true,
it: true,
expect: true,
Promise: true,
__dirname: true
}
}
},
browserify: {
client: {
src: './lib/airtable.js',
Expand All @@ -44,18 +18,12 @@ module.exports = function(grunt) {
}]
],
preBundleCB: function(b) {
b.require('./lib/airtable.js', { expose: 'airtable' });
b.require('./lib/airtable.js', {expose: 'airtable'});
}
}
}
},
});

// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-jshint');

// Default task(s).
grunt.registerTask('default', ['jshint']);

grunt.loadNpmTasks('grunt-browserify');
};
2 changes: 1 addition & 1 deletion lib/airtable.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var Airtable = Class.extend({
}
});

Airtable.default_config = function () {
Airtable.default_config = function() {
return {
endpointUrl: process.env.AIRTABLE_ENDPOINT_URL || 'https://api.airtable.com',
apiVersion: '0.1.0',
Expand Down
2 changes: 1 addition & 1 deletion lib/airtable_error.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var AirtableError = Class.extend({
return [
this.message,
'(', this.error, ')',
this.statusCode ? '[Http code ' + this.statusCode + ']' : ''
this.statusCode ? '[Http code ' + this.statusCode + ']' : ''
].join('');
}
});
Expand Down
8 changes: 4 additions & 4 deletions lib/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,26 @@ var Base = Class.extend({
} else if (statusCode === 403) {
return new AirtableError('NOT_AUTHORIZED', 'You are not authorized to perform this operation', statusCode);
} else if (statusCode === 404) {
return (function(){
return (function() {
var message = (body && body.error && body.error.message) ? body.error.message : 'Could not find what you are looking for';
return new AirtableError('NOT_FOUND', message, statusCode);
})();
} else if (statusCode === 413) {
return new AirtableError('REQUEST_TOO_LARGE', 'Request body is too large', statusCode);
} else if (statusCode === 422) {
return (function(){
return (function() {
var type = (body && body.error && body.error.type) ? body.error.type : 'UNPROCESSABLE_ENTITY';
var message = (body && body.error && body.error.message) ? body.error.message : 'The operation cannot be processed';
return new AirtableError(type, message, statusCode);
})();
} else if (statusCode === 429) {
return new AirtableError('TOO_MANY_REQUESTS', 'You have made too many requests in a short period of time. Please retry your request later', statusCode);
}else if (statusCode === 500) {
} else if (statusCode === 500) {
return new AirtableError('SERVER_ERROR', 'Try again. If the problem persists, contact support.', statusCode);
} else if (statusCode === 503) {
return new AirtableError('SERVICE_UNAVAILABLE', 'The service is temporarily unavailable. Please retry shortly.', statusCode);
} else if (statusCode >= 400) {
return (function(){
return (function() {
var type = (body && body.error && body.error.type) ? body.error.type : 'UNEXPECTED_ERROR';
var message = (body && body.error && body.error.message) ? body.error.message : 'An unexpected error occurred';
return new AirtableError(type, message, statusCode);
Expand Down
2 changes: 1 addition & 1 deletion lib/callback_to_promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function callbackToPromise(fn, context, callbackArgIndex) {
var callbackArg = arguments[thisCallbackArgIndex];
if (typeof callbackArg === 'function') {
fn.apply(context, arguments);
return;
return void 0;
} else {
var args = [];
// If an explicit callbackArgIndex is set, but the function is called
Expand Down
2 changes: 1 addition & 1 deletion lib/class.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// jshint ignore: start
/* eslint-disable */

/* Simple JavaScript Inheritance
* By John Resig http://ejohn.org/
Expand Down
10 changes: 5 additions & 5 deletions lib/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ var Table = Class.extend({
throw new Error('Airtable: the parameter for `select` should be a plain object or undefined.');
}
},
_urlEncodedNameOrId: function(){
_urlEncodedNameOrId: function() {
return this.id || encodeURIComponent(this.name);
},
_createRecords: function(recordsData, optionalParameters, done) {
Expand All @@ -98,7 +98,7 @@ var Table = Class.extend({

var result;
if (isCreatingMultipleRecords) {
result = body.records.map(function (record) {
result = body.records.map(function(record) {
return new Record(that, record.id, record);
});
} else {
Expand All @@ -121,7 +121,7 @@ var Table = Class.extend({
this._base.runAction(method, '/' + this._urlEncodedNameOrId() + '/', {}, requestData, function(err, resp, body) {
if (err) { done(err); return; }

var result = body.records.map(function (record) {
var result = body.records.map(function(record) {
return new Record(that, record.id, record);
});
done(null, result);
Expand All @@ -144,7 +144,7 @@ var Table = Class.extend({
if (isArray(recordIdsOrId)) {
var that = this;
var queryParams = {records: recordIdsOrId};
this._base.runAction('delete', '/' + this._urlEncodedNameOrId(), queryParams, null, function (err, response, results) {
this._base.runAction('delete', '/' + this._urlEncodedNameOrId(), queryParams, null, function(err, response, results) {
if (err) {
done(err);
return;
Expand All @@ -171,7 +171,7 @@ var Table = Class.extend({
limit: limit, offset: offset
}, opts);

this._base.runAction('get', '/' + this._urlEncodedNameOrId() + '/', listRecordsParameters, null, function (err, response, results) {
this._base.runAction('get', '/' + this._urlEncodedNameOrId() + '/', listRecordsParameters, null, function(err, response, results) {
if (err) {
done(err);
return;
Expand Down
Loading

0 comments on commit 9861673

Please sign in to comment.