From f80ae67c53c0a4bfc95741ed39d7f9e498eaf02b Mon Sep 17 00:00:00 2001 From: Oleg Gaidarenko Date: Tue, 10 May 2016 12:06:37 +0300 Subject: [PATCH] Build: Switch from jscs+jshint to eslint --- .eslintignore | 12 +++ .eslintrc | 145 ++++++++++++++++++++++++++++++++ .jscsrc | 10 --- .jshintrc | 14 --- .npmignore | 4 +- Gruntfile.js | 49 ++++------- build/.eslintrc | 7 ++ package.json | 3 +- src/.eslintrc | 15 ++++ src/.jshintrc | 30 ------- test/.eslintrc | 55 ++++++++++++ test/.jshintrc | 56 ------------ test/node_smoke_tests/.eslintrc | 7 ++ test/node_smoke_tests/.jshintrc | 14 --- 14 files changed, 261 insertions(+), 160 deletions(-) create mode 100644 .eslintignore create mode 100644 .eslintrc delete mode 100644 .jscsrc delete mode 100644 .jshintrc create mode 100644 build/.eslintrc create mode 100644 src/.eslintrc delete mode 100644 src/.jshintrc create mode 100644 test/.eslintrc delete mode 100644 test/.jshintrc create mode 100644 test/node_smoke_tests/.eslintrc delete mode 100644 test/node_smoke_tests/.jshintrc diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 000000000..adfbe3f4b --- /dev/null +++ b/.eslintignore @@ -0,0 +1,12 @@ +external +test/data/jquery-1.9.1.js +test/data/badcall.js +test/data/badjson.js +test/data/json_obj.js +test/data/readywaitasset.js +test/data/readywaitloader.js +test/data/support/csp.js +test/data/support/getComputedSupport.js +test/node_smoke_tests/lib/ensure_iterability.js +node_modules +dist diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 000000000..4bb05b235 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,145 @@ +{ + "env": {}, + "globals": {}, + "rules": { + "no-cond-assign": [ + "error", + "except-parens" + ], + "curly": [ + "error", + "all" + ], + "object-curly-spacing": [ + "error", + "always" + ], + "computed-property-spacing": [ + "error", + "always" + ], + "array-bracket-spacing": [ + "error", + "always" + ], + "eqeqeq": [ + "error", + "smart" + ], + + // Shows errors where jshint wouldn't (see jshint "expr" rule) + // clarifing this with eslint team + // "no-unused-expressions": "error", + "wrap-iife": [ + "error", + "inside" + ], + "no-caller": "error", + "quotes": [ + "error", + "double", + "avoid-escape" + ], + "no-undef": "error", + "no-unused-vars": "error", + "operator-linebreak": [ + "error", + "after" + ], + "comma-style": [ + "error", + "last" + ], + "camelcase": [ + "error", + { + "properties": "never" + } + ], + "dot-notation": [ + "error", + { + "allowPattern": "^[a-z]+(_[a-z]+)+$" + } + ], + "max-len": [ + "error", + { + "code": 100, + "ignoreComments": true + } + ], + "no-mixed-spaces-and-tabs": "error", + "no-trailing-spaces": "error", + "no-multi-str": "error", + "comma-dangle": [ + "error", + "never" + ], + "comma-spacing": [ + "error", + { + "before": false, + "after": true + } + ], + "space-before-blocks": [ + "error", + "always" + ], + "space-in-parens": [ + "error", + "always" + ], + "keyword-spacing": [ + 2 + ], + "semi": [ + "error", + "always" + ], + "semi-spacing": [ + "error", + { + // Because of the `for ( ; ...)` requirement + // "before": true, + "after": true + } + ], + "space-infix-ops": "error", + "eol-last": "error", + "lines-around-comment": [ + "error", + { + "beforeLineComment": true + } + ], + "linebreak-style": [ + "error", + "unix" + ], + "no-with": "error", + "brace-style": "error", + "space-before-function-paren": [ + "error", + "never" + ], + "no-loop-func": "error", + "no-spaced-func": "error", + "key-spacing": [ + "error", + { + "beforeColon": false, + "afterColon": true + } + ], + "space-unary-ops": [ + "error", + { + "words": false, + "nonwords": false + } + ], + "no-multiple-empty-lines": 2 + } +} diff --git a/.jscsrc b/.jscsrc deleted file mode 100644 index c6dc9ee69..000000000 --- a/.jscsrc +++ /dev/null @@ -1,10 +0,0 @@ -{ - "preset": "jquery", - - // remove after https://github.com/jscs-dev/node-jscs/issues/1685 - // and https://github.com/jscs-dev/node-jscs/issues/1686 - "requireCapitalizedComments": null, - - "excludeFiles": [ "external", - "test/node_smoke_tests/lib/ensure_iterability.js", "node_modules" ] -} diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 1445c7b18..000000000 --- a/.jshintrc +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boss": true, - "curly": true, - "eqeqeq": true, - "eqnull": true, - "expr": true, - "immed": true, - "noarg": true, - "quotmark": "double", - "undef": true, - "unused": true, - - "node": true -} diff --git a/.npmignore b/.npmignore index d51094952..322f560b7 100644 --- a/.npmignore +++ b/.npmignore @@ -1,5 +1,5 @@ -.jshintignore -.jshintrc +.eslintignore +.eslintrc /.editorconfig /.gitattributes diff --git a/Gruntfile.js b/Gruntfile.js index 3e81b6161..5f101050a 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -14,7 +14,6 @@ module.exports = function( grunt ) { var fs = require( "fs" ), gzip = require( "gzip-js" ), - srcHintOptions = readOptionalJSON( "src/.jshintrc" ), // Skip jsdom-related tests in Node.js 0.10 & 0.12 runJsdomTests = !/^v0/.test( process.version ); @@ -103,34 +102,14 @@ module.exports = function( grunt ) { src: [ "package.json" ] } }, - jshint: { - all: { - src: [ - "src/**/*.js", "Gruntfile.js", "test/**/*.js", "build/**/*.js" - ], - options: { - jshintrc: true - } - }, - dist: { - src: "dist/jquery.js", - options: srcHintOptions - } - }, - jscs: { - src: "src", - gruntfile: "Gruntfile.js", + eslint: { + options: { - // Check parts of tests that pass - test: [ - "test/data/testrunner.js", - "test/unit/animation.js", - "test/unit/basic.js", - "test/unit/support.js", - "test/unit/tween.js", - "test/unit/wrap.js" - ], - build: "build" + // See https://github.com/sindresorhus/grunt-eslint/issues/119 + quiet: true + }, + all: ".", + dev: [ "src/**/*.js", "Gruntfile.js", "test/**/*.js", "build/**/*.js" ] }, testswarm: { tests: [ @@ -164,7 +143,7 @@ module.exports = function( grunt ) { ] }, watch: { - files: [ "<%= jshint.all.src %>" ], + files: [ "<%= eslint.dev %>" ], tasks: [ "dev" ] }, uglify: { @@ -201,7 +180,7 @@ module.exports = function( grunt ) { // Integrate jQuery specific tasks grunt.loadTasks( "build/tasks" ); - grunt.registerTask( "lint", [ "jsonlint", "jshint", "jscs" ] ); + grunt.registerTask( "lint", [ "jsonlint" ] ); // Don't run Node-related tests in Node.js < 1.0.0 as they require an old // jsdom version that needs compiling, making it harder for people to compile @@ -213,9 +192,15 @@ module.exports = function( grunt ) { ) ); // Short list as a high frequency watch task - grunt.registerTask( "dev", [ "build:*:*", "lint", "uglify", "remove_map_comment", "dist:*" ] ); + grunt.registerTask( "dev", [ + "build:*:*", + "uglify", + "remove_map_comment", + "dist:*" + ] + ); grunt.registerTask( "default", [ "dev", "test_fast", "compare_size" ] ); - grunt.registerTask( "precommit_lint", [ "newer:jsonlint", "newer:jshint:all", "newer:jscs" ] ); + grunt.registerTask( "precommit_lint", [ "newer:jsonlint" ] ); }; diff --git a/build/.eslintrc b/build/.eslintrc new file mode 100644 index 000000000..11368d984 --- /dev/null +++ b/build/.eslintrc @@ -0,0 +1,7 @@ +{ + "env": { + "node": true + }, + "extends": "../.eslintrc", + "root": true +} diff --git a/package.json b/package.json index c6ae7165d..00b7d2e65 100644 --- a/package.json +++ b/package.json @@ -33,11 +33,10 @@ "grunt-babel": "6.0.0", "grunt-cli": "1.2.0", "grunt-compare-size": "0.4.2", - "grunt-contrib-jshint": "1.0.0", "grunt-contrib-uglify": "1.0.1", "grunt-contrib-watch": "1.0.0", + "grunt-eslint": "18.1.0", "grunt-git-authors": "3.2.0", - "grunt-jscs": "2.8.0", "grunt-jsonlint": "1.0.7", "grunt-newer": "1.2.0", "grunt-npmcopy": "0.1.0", diff --git a/src/.eslintrc b/src/.eslintrc new file mode 100644 index 000000000..ef090331f --- /dev/null +++ b/src/.eslintrc @@ -0,0 +1,15 @@ +{ + "env": { + "browser" + }, + "extends": "../.eslintrc", + "root": true, + "globals": { + "window": true, + "JSON": false, + "jQuery": true, + "define": true, + "module": true, + "noGlobal": true + } +} diff --git a/src/.jshintrc b/src/.jshintrc deleted file mode 100644 index c3506e70f..000000000 --- a/src/.jshintrc +++ /dev/null @@ -1,30 +0,0 @@ -{ - "boss": true, - "curly": true, - "eqeqeq": true, - "eqnull": true, - "expr": true, - "immed": true, - "noarg": true, - "quotmark": "double", - "strict": true, - "undef": true, - "unused": true, - - "sub": true, - - // Support: IE <=9 only, Android <=4.0 only - // The above browsers are failing a lot of tests in the ES5 - // test suite at http://test262.ecmascript.org. - "es3": true, - - "globals": { - "window": true, - "JSON": false, - - "jQuery": true, - "define": true, - "module": true, - "noGlobal": true - } -} diff --git a/test/.eslintrc b/test/.eslintrc new file mode 100644 index 000000000..439a07a6c --- /dev/null +++ b/test/.eslintrc @@ -0,0 +1,55 @@ +{ + "env": { + "browser": true + }, + "extends": "../.eslintrc", + "root": true, + "globals": { + "require": false, + "define": false, + "DOMParser": false, + "JSON": false, + "Promise": false, + "Symbol": false, + "QUnit": false, + "ajaxTest": false, + "testIframe": false, + "testIframeWithCallback": false, + "iframeCallback": true, + "createDashboardXML": false, + "createXMLFragment": false, + "moduleTeardown": false, + "testFoo": false, + "url": false, + "t": false, + "q": false, + "jQuery": true, + "sinon": true, + "amdDefined": true, + "fireNative": true, + "Globals": true, + "hasPHP": true, + "isLocal": true, + "supportjQuery": true, + "originaljQuery": true, + "$": true, + "original$": true, + "baseURL": true, + "externalHost": true + }, + "rules": { + // See https://github.com/eslint/eslint/issues/6125 + "no-unused-vars": "off", + + // Too much errors + "max-len": "off", + "brace-style": "off", + "key-spacing": "off", + "camelcase": "off", + "dot-notaion": "off", + + // Not a lot really too much, but waiting for autofix for these rules + "lines-around-comment": "off", + "dot-notation": "off" + } +} diff --git a/test/.jshintrc b/test/.jshintrc deleted file mode 100644 index 5516f8404..000000000 --- a/test/.jshintrc +++ /dev/null @@ -1,56 +0,0 @@ -{ - "boss": true, - "curly": true, - "eqeqeq": true, - "eqnull": true, - "expr": true, - "immed": true, - "noarg": true, - "quotmark": "double", - "undef": true, - "unused": true, - - "es3": true, - - "evil": true, - "sub": true, - - "browser": true, - "devel": true, - "wsh": true, - - "globals": { - "require": false, - "define": false, - "DOMParser": false, - "JSON": false, - "Promise": false, - "Symbol": false, - "QUnit": false, - "ajaxTest": false, - "testIframe": false, - "testIframeWithCallback": false, - "iframeCallback": true, - "createDashboardXML": false, - "createXMLFragment": false, - "moduleTeardown": false, - "testFoo": false, - "url": false, - "t": false, - "q": false, - - "jQuery": true, - "sinon": true, - "amdDefined": true, - "fireNative": true, - "Globals": true, - "hasPHP": true, - "isLocal": true, - "supportjQuery": true, - "originaljQuery": true, - "$": true, - "original$": true, - "baseURL": true, - "externalHost": true - } -} diff --git a/test/node_smoke_tests/.eslintrc b/test/node_smoke_tests/.eslintrc new file mode 100644 index 000000000..11368d984 --- /dev/null +++ b/test/node_smoke_tests/.eslintrc @@ -0,0 +1,7 @@ +{ + "env": { + "node": true + }, + "extends": "../.eslintrc", + "root": true +} diff --git a/test/node_smoke_tests/.jshintrc b/test/node_smoke_tests/.jshintrc deleted file mode 100644 index 1445c7b18..000000000 --- a/test/node_smoke_tests/.jshintrc +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boss": true, - "curly": true, - "eqeqeq": true, - "eqnull": true, - "expr": true, - "immed": true, - "noarg": true, - "quotmark": "double", - "undef": true, - "unused": true, - - "node": true -}