MDL-54944 eslint: Add rules from Policy decision
authorDan Poltawski <dan@moodle.com>
Tue, 28 Jun 2016 20:03:27 +0000 (21:03 +0100)
committerDan Poltawski <dan@moodle.com>
Thu, 7 Jul 2016 11:10:49 +0000 (12:10 +0100)
Also bump eslint to v2.13.1 and make the version explicit in
package.json

.eslintrc
Gruntfile.js
admin/tool/lp/amd/src/tree.js
lib/amd/src/tree.js
npm-shrinkwrap.json
package.json

index 03dc85a..02fc3a3 100644 (file)
--- a/.eslintrc
+++ b/.eslintrc
@@ -9,10 +9,10 @@
   },
   'rules': {
     // See http://eslint.org/docs/rules/ for all rules and explanations of all
-    // rules. Commented out rules with 'DEFINE POLICY' are rules Dan P has flagged
-    // for discussion and possible enable soon.
+    // rules.
+
     // === Possible Errors ===
-    // DEFINE POLICY: 'comma-dangle': ['off', 'always'],
+    'comma-dangle': 'off',
     'no-cond-assign': 'error',
     'no-console': 'error',
     'no-constant-condition': 'error',
@@ -21,7 +21,7 @@
     'no-dupe-args': 'error',
     'no-dupe-keys': 'error',
     'no-duplicate-case': 'error',
-    // Disabled for YUI rollups, enabled by grunt for AMD: 'no-empty': 'error',
+    'no-empty': 'warn',
     'no-empty-character-class': 'error',
     'no-ex-assign': 'error',
     'no-extra-boolean-cast': 'error',
 
     // === Best Practices ===
     // (these mostly match our jshint config)
+    'array-callback-return': 'warn',
+    'block-scoped-var': 'warn',
+    'complexity': 'warn',
+    'consistent-return': 'warn',
     'curly': 'error',
     'dot-notation': 'warn',
     'no-alert': 'warn',
     'no-caller': 'error',
     'no-case-declarations': 'error',
+    'no-div-regex': 'error',
     'no-empty-pattern': 'error',
     'no-empty-function': 'warn',
-    //DEFINE POLICY: 'no-eq-null': 'warn',
+    'no-eq-null': 'error',
     'no-eval': 'error',
-    //DEFINE POLICY: 'no-extra-bind': 'warn',
+    'no-extend-native': 'error',
+    'no-extra-bind': 'warn',
     'no-fallthrough': 'error',
-    //DEFINE POLICY: 'no-implicit-globals': 'warn',
+    'no-floating-decimal': 'warn',
+    // Disabled for YUI rollups, enabled by grunt for AMD: 'no-implicit-globals': 'warn',
     'no-implied-eval': 'error',
     'no-invalid-this': 'error',
     'no-iterator': 'error',
     'no-native-reassign': 'warn',
     'no-new-func': 'error',
     'no-new-wrappers': 'error',
-    // DEFINE POLICY: no-octal: "error"
-    // DEFINE POLICY: no-octal-escape: "error"
+    'no-octal': 'error',
+    'no-octal-escape': 'error',
     'no-proto': 'error',
     'no-redeclare': 'warn',
     'no-return-assign': 'error',
     'no-script-url': 'error',
     'no-self-assign': 'error',
     'no-self-compare': 'error',
+    'no-sequences': 'warn',
+    'no-throw-literal': 'warn',
     'no-unmodified-loop-condition': 'error',
     // Disabled for YUI rollups, enabled by grunt for AMD: 'no-unused-expressions': 'error',
     'no-unused-labels': 'error',
-    //DEFINE POLICY: 'no-useless-call': 'error',
+    'no-useless-call': 'warn',
     'no-useless-escape': 'warn',
-    //DEFINE POLICY: 'no-with': 'error',
+    'no-with': 'error',
     'wrap-iife': ['error', 'any'],
 
     // === Variables ===
     'no-delete-var': 'error',
     // Disabled for YUI rollups, enabled by grunt for AMD: 'no-undef': 'off',
-    //DEFINE POLICY: 'no-undef-init': 'error',
+    'no-undef-init': 'error',
     // Disabled for YUI rollups, enabled by grunt for AMD: 'no-unused-vars': 'error',
 
     // === Stylistic Issues ===
     'lines-around-comment': 'off',
     'max-len': ['error', 132],
     'max-lines': 'off',
-    // DEFINE POLICY: turn on some of these max values?
-    'max-depth': 'off',
-    'max-nested-callbacks': 'off',
+    'max-depth': 'warn',
+    'max-nested-callbacks': ['warn', 5],
     'max-params': 'off',
     'max-statements': 'off',
-    'max-statements-per-line': 'off',
+    'max-statements-per-line': ['warn', { max: 2 }],
     'new-cap': ['warn', { 'properties': false }],
     'new-parens': 'warn',
     'newline-after-var': 'off',
     'newline-before-return': 'off',
-    // REVIST POLICY: 'newline-per-chained-call': 'warn',
+    'newline-per-chained-call': 'off',
     'no-array-constructor': 'off',
     'no-bitwise': 'error',
     'no-continue': 'off',
     'no-ternary': 'off',
     'no-trailing-spaces': 'error',
     'no-underscore-dangle': 'off',
-    // DEFINE POLICY: 'no-unneeded-ternary': 'off',
+    'no-unneeded-ternary': 'off',
     'no-whitespace-before-property': 'warn',
-    // DEFINE POLICY: 'object-curly-newline': 'off,
-    // DEFINE POLICY: 'object-curly-spacing': 'off',
-    // DEFINE POLICY: 'object-property-newline': 'off',
+    'object-curly-newline': 'off',
+    'object-curly-spacing': 'warn',
+    'object-property-newline': 'off',
     'one-var': 'off',
-    // DEFINE POLICY: 'one-var-declaration-per-line': 'off',
+    'one-var-declaration-per-line': ['warn', 'initializations'],
     'operator-assignment': 'off',
     'operator-linebreak': 'off',
     'padded-blocks': 'off',
-    // DEFINE POLICY: 'quote-props': 'off',
+    'quote-props': ['warn', 'as-needed', {'unnecessary': false, 'keywords': true, 'numbers': true}],
     'quotes': 'off',
     'require-jsdoc': 'warn',
     'semi': 'error',
index 0b52cc8..5dd95e2 100644 (file)
@@ -104,13 +104,18 @@ module.exports = function(grunt) {
         eslint: {
             // Even though warnings dont stop the build we don't display warnings by default because
             // at this moment we've got too many core warnings.
-            options: { quiet: !grunt.option('show-lint-warnings') },
+            options: {quiet: !grunt.option('show-lint-warnings')},
             // Check AMD files. We add some stricter rules which we can't apply to the default configuration due
             // to YUI rollups.
             amd: {
               src: amdSrc,
               options: {
-                  rules: {'no-undef': 'error', 'no-unused-vars': 'error', 'no-empty': 'error', 'no-unused-expressions': 'error'}
+                  rules: {
+                    'no-undef': 'error',
+                    'no-unused-vars': 'error',
+                    'no-unused-expressions': 'error',
+                    'no-implicit-globals': 'error'
+                  }
               }
             },
             // Check YUI module source files.
index 179dcf6..70af4e3 100644 (file)
@@ -274,6 +274,8 @@ define(['jquery', 'core/url', 'core/log'], function($, url, log) {
      * @param {Event} e The event.
      * @return {Boolean}
      */
+     // This function should be simplified. In the meantime..
+    // eslint-disable-next-line complexity
     Tree.prototype.handleKeyDown = function(item, e) {
         var currentIndex = this.visibleItems.index(item);
         var newItem = null;
index c3fff8b..0938056 100644 (file)
@@ -343,6 +343,8 @@ define(['jquery'], function($) {
      * @param {Event} e The event.
      * @return {Boolean}
      */
+     // This function should be simplified. In the meantime..
+     // eslint-disable-next-line complexity
     Tree.prototype.handleKeyDown = function(item, e) {
         var currentIndex = this.getVisibleItems().index(item);
 
index 11749ac..8ad8f15 100644 (file)
@@ -8,7 +8,7 @@
     },
     "acorn": {
       "version": "3.2.0",
-      "from": "acorn@>=3.1.0 <4.0.0",
+      "from": "acorn@>=3.2.0 <4.0.0",
       "resolved": "https://registry.npmjs.org/acorn/-/acorn-3.2.0.tgz"
     },
     "acorn-jsx": {
       }
     },
     "array-union": {
-      "version": "1.0.1",
+      "version": "1.0.2",
       "from": "array-union@>=1.0.1 <2.0.0",
-      "resolved": "https://registry.npmjs.org/array-union/-/array-union-1.0.1.tgz"
+      "resolved": "https://registry.npmjs.org/array-union/-/array-union-1.0.2.tgz"
     },
     "array-uniq": {
-      "version": "1.0.2",
+      "version": "1.0.3",
       "from": "array-uniq@>=1.0.1 <2.0.0",
-      "resolved": "https://registry.npmjs.org/array-uniq/-/array-uniq-1.0.2.tgz"
+      "resolved": "https://registry.npmjs.org/array-uniq/-/array-uniq-1.0.3.tgz"
     },
     "arrify": {
       "version": "1.0.1",
       }
     },
     "bluebird": {
-      "version": "3.4.0",
+      "version": "3.4.1",
       "from": "bluebird@>=3.1.1 <4.0.0",
-      "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.4.0.tgz"
+      "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.4.1.tgz"
     },
     "boom": {
       "version": "2.10.1",
     },
     "concat-stream": {
       "version": "1.5.1",
-      "from": "concat-stream@>=1.4.1 <2.0.0",
+      "from": "concat-stream@>=1.4.6 <2.0.0",
       "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.5.1.tgz",
       "dependencies": {
         "readable-stream": {
       "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz"
     },
     "del": {
-      "version": "2.2.0",
+      "version": "2.2.1",
       "from": "del@>=2.0.2 <3.0.0",
-      "resolved": "https://registry.npmjs.org/del/-/del-2.2.0.tgz"
+      "resolved": "https://registry.npmjs.org/del/-/del-2.2.1.tgz"
     },
     "delayed-stream": {
       "version": "1.0.0",
       }
     },
     "eslint": {
-      "version": "2.12.0",
-      "from": "eslint@>=2.0.0 <3.0.0",
-      "resolved": "https://registry.npmjs.org/eslint/-/eslint-2.12.0.tgz",
+      "version": "2.13.1",
+      "from": "eslint@2.13.1",
+      "resolved": "https://registry.npmjs.org/eslint/-/eslint-2.13.1.tgz",
       "dependencies": {
         "ansi-styles": {
           "version": "2.2.1",
           "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.2.0.tgz"
         },
         "glob": {
-          "version": "7.0.3",
+          "version": "7.0.5",
           "from": "glob@>=7.0.3 <8.0.0",
-          "resolved": "https://registry.npmjs.org/glob/-/glob-7.0.3.tgz"
+          "resolved": "https://registry.npmjs.org/glob/-/glob-7.0.5.tgz"
         },
         "js-yaml": {
           "version": "3.6.1",
           "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.13.1.tgz"
         },
         "minimatch": {
-          "version": "3.0.0",
-          "from": "minimatch@3.0.0",
-          "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.0.tgz"
+          "version": "3.0.2",
+          "from": "minimatch@^3.0.2",
+          "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.2.tgz"
         },
         "progress": {
           "version": "1.1.8",
       }
     },
     "espree": {
-      "version": "3.1.4",
-      "from": "espree@3.1.4",
-      "resolved": "https://registry.npmjs.org/espree/-/espree-3.1.4.tgz"
+      "version": "3.1.6",
+      "from": "espree@>=3.1.6 <4.0.0",
+      "resolved": "https://registry.npmjs.org/espree/-/espree-3.1.6.tgz"
     },
     "esprima": {
       "version": "1.0.4",
         }
       }
     },
+    "fs.realpath": {
+      "version": "1.0.0",
+      "from": "fs.realpath@>=1.0.0 <2.0.0",
+      "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz"
+    },
     "gaze": {
       "version": "0.5.2",
       "from": "gaze@>=0.5.1 <0.6.0",
       "resolved": "https://registry.npmjs.org/globals/-/globals-9.8.0.tgz"
     },
     "globby": {
-      "version": "4.1.0",
-      "from": "globby@>=4.0.0 <5.0.0",
-      "resolved": "https://registry.npmjs.org/globby/-/globby-4.1.0.tgz",
+      "version": "5.0.0",
+      "from": "globby@>=5.0.0 <6.0.0",
+      "resolved": "https://registry.npmjs.org/globby/-/globby-5.0.0.tgz",
       "dependencies": {
         "glob": {
-          "version": "6.0.4",
-          "from": "glob@>=6.0.1 <7.0.0",
-          "resolved": "https://registry.npmjs.org/glob/-/glob-6.0.4.tgz"
+          "version": "7.0.5",
+          "from": "glob@^7.0.3",
+          "resolved": "https://registry.npmjs.org/glob/-/glob-7.0.5.tgz"
         },
         "minimatch": {
-          "version": "3.0.0",
-          "from": "minimatch@>=2.0.0 <3.0.0||>=3.0.0 <4.0.0",
-          "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.0.tgz"
+          "version": "3.0.2",
+          "from": "minimatch@>=3.0.2 <4.0.0",
+          "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.2.tgz"
         }
       }
     },
       "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.2.11.tgz"
     },
     "ignore": {
-      "version": "3.1.2",
+      "version": "3.1.3",
       "from": "ignore@>=3.1.2 <4.0.0",
-      "resolved": "https://registry.npmjs.org/ignore/-/ignore-3.1.2.tgz"
+      "resolved": "https://registry.npmjs.org/ignore/-/ignore-3.1.3.tgz"
     },
     "image-size": {
       "version": "0.3.5",
     },
     "inherits": {
       "version": "2.0.1",
-      "from": "inherits@>=2.0.0 <3.0.0",
+      "from": "inherits@>=2.0.1 <2.1.0",
       "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz"
     },
     "inquirer": {
     },
     "strip-json-comments": {
       "version": "1.0.4",
-      "from": "strip-json-comments@>=1.0.0 <1.1.0",
+      "from": "strip-json-comments@>=1.0.1 <1.1.0",
       "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-1.0.4.tgz"
     },
     "supports-color": {
index fa72459..eaada7d 100644 (file)
@@ -4,6 +4,7 @@
   "description": "Moodle",
   "devDependencies": {
     "async": "^1.5.2",
+    "eslint": "^2.13.1",
     "grunt": "0.4.5",
     "grunt-contrib-less": "1.1.0",
     "grunt-contrib-uglify": "0.11.0",