]> source.dussan.org Git - jquery.git/commitdiff
Build: ESLint setup improvements
authorMichał Gołębiowski <m.goleb@gmail.com>
Wed, 2 Nov 2016 23:51:34 +0000 (00:51 +0100)
committerMichał Gołębiowski <m.goleb@gmail.com>
Mon, 19 Dec 2016 01:07:03 +0000 (02:07 +0100)
1. Use the short name of the preset in the config.
2. Run ESLint first on non-minified files.
3. Explicitly specify environments in every config file (those settings cascade
which means we've been assuming a Node.js environment where we shouldn't have).

.eslintrc-browser.json [new file with mode: 0644]
.eslintrc-node.json [new file with mode: 0644]
.eslintrc.json
Gruntfile.js
dist/.eslintrc.json
src/.eslintrc.json
test/.eslintrc.json
test/node_smoke_tests/.eslintrc.json
test/promises_aplus_adapters/.eslintrc.json

diff --git a/.eslintrc-browser.json b/.eslintrc-browser.json
new file mode 100644 (file)
index 0000000..c704209
--- /dev/null
@@ -0,0 +1,31 @@
+{
+       "root": true,
+
+       "extends": "jquery",
+
+       // 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.
+       "parserOptions": {
+               "ecmaVersion": 3
+       },
+
+       // The browser env is not enabled on purpose so that code takes
+       // all browser-only globals from window instead of assuming
+       // they're available as globals. This makes it possible to use
+       // jQuery with tools like jsdom which provide a custom window
+       // implementation.
+       "env": {},
+
+       "globals": {
+               "window": true,
+               "jQuery": true,
+               "define": true,
+               "module": true,
+               "noGlobal": true
+       },
+
+       "rules": {
+               "strict": ["error", "function"]
+       }
+}
diff --git a/.eslintrc-node.json b/.eslintrc-node.json
new file mode 100644 (file)
index 0000000..904e7ba
--- /dev/null
@@ -0,0 +1,13 @@
+{
+       "root": true,
+
+       "extends": "jquery",
+
+       "parserOptions": {
+               "ecmaVersion": 5
+       },
+
+       "env": {
+               "node": true
+       }
+}
index 6dcb6353a48f180fc77fd2b3233b83959fa6aa7d..d2c977ca851d8ba124539a86f9a140e55318f87a 100644 (file)
@@ -1,7 +1,5 @@
 {
-       "extends": "eslint-config-jquery",
        "root": true,
-       "env": {
-               "node": true
-       }
+
+       "extends": "./.eslintrc-node.json"
 }
index 200424d35da81d5be682a366b3f89628be6c311b..fbb271630d44c4db0bbfe677734d499b536b7b74 100644 (file)
@@ -203,12 +203,21 @@ module.exports = function( grunt ) {
 
        grunt.registerTask( "lint", [
                "jsonlint",
-               runIfNewNode( "eslint" )
+
+               // Running the full eslint task without breaking it down to targets
+               // would run the dist target first which would point to errors in the built
+               // file, making it harder to fix them. We want to check the built file only
+               // if we already know the source files pass the linter.
+               runIfNewNode( "eslint:dev" ),
+               runIfNewNode( "eslint:dist" )
        ] );
 
        grunt.registerTask( "lint:newer", [
                "newer:jsonlint",
-               runIfNewNode( "newer:eslint" )
+
+               // Don't replace it with just the task; see the above comment.
+               runIfNewNode( "newer:eslint:dev" ),
+               runIfNewNode( "newer:eslint:dist" )
        ] );
 
        grunt.registerTask( "test:fast", runIfNewNode( "node_smoke_tests" ) );
index b99e682f401704dd77beb7a23323cb7b7fa9cb65..a15539adbc5a1a00e748061153111aa7065b0cbd 100644 (file)
@@ -1,5 +1,8 @@
 {
-       "extends": "../src/.eslintrc.json",
+       "root": true,
+
+       "extends": "../.eslintrc-browser.json",
+
        "rules": {
                // That is okay for the built version
                "no-multiple-empty-lines": "off",
index dbf16c58465fbb4b0947b0ff52c297c94be2ee71..3a4a3d2578a747f3d77f86b5c038aaf4abf3efb3 100644 (file)
@@ -1,18 +1,5 @@
 {
-       // 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.
-       "parserOptions": {
-               "ecmaVersion": 3
-       },
-       "globals": {
-               "window": true,
-               "jQuery": true,
-               "define": true,
-               "module": true,
-               "noGlobal": true
-       },
-       "rules": {
-               "strict": ["error", "function"]
-       }
+       "root": true,
+
+       "extends": "../.eslintrc-browser.json"
 }
index 744de89ec3adb42561cd273a42cb5b2886011234..8cc2adc9606becfb6769aa8154bde9f4e9003766 100644 (file)
@@ -1,13 +1,15 @@
 {
+       "root": true,
+
+       "extends": "../.eslintrc-browser.json",
+
        "env": {
+
+               // In source the browser env is not enabled but unit tests rely on them
+               // too much and we don't run them in non-browser environments anyway.
                "browser": 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.
-       "parserOptions": {
-               "ecmaVersion": 3
-       },
+
        "globals": {
                "require": false,
                "define": false,
                "baseURL": true,
                "externalHost": true
        },
+
        "rules": {
                // See https://github.com/eslint/eslint/issues/2342
                "no-unused-vars": "off",
 
-               // Too much errors
+               // Too many errors
                "max-len": "off",
                "brace-style": "off",
                "key-spacing": "off",
                "camelcase": "off",
+               "strict": "off",
 
-               // Not really too much - waiting autofix features for these rules
+               // Not really too many - waiting for autofix features for these rules
                "lines-around-comment": "off",
                "dot-notation": "off"
        }
index 0877d24afa9be565bfddad7f543e351979444da2..91ec5ba4e1a374fa9ec83d85f7bc68a29435ff5d 100644 (file)
@@ -1,7 +1,13 @@
 {
+       "root": true,
+
+       "extends": "../../.eslintrc-node.json",
+
+       "parserOptions": {
+               "ecmaVersion": 2015
+       },
+
        "env": {
                "es6": true
-       },
-       "extends" : "../../.eslintrc.json",
-       "root": true
+       }
 }
index d117757105285af79da3848f76c797ef5e4980d8..f961645e55f8558472fb8f366b453bca34a97a07 100644 (file)
@@ -1,4 +1,5 @@
 {
-       "extends": "../../.eslintrc.json",
-       "root": true
+       "root": true,
+
+       "extends": "../../.eslintrc-node.json"
 }