Bug 1347884 - Enable eslint cyclomatic complexity rule at existing levels. r?jaws draft
authorMark Banner <standard8@mozilla.com>
Thu, 16 Mar 2017 11:04:39 +0000
changeset 499893 de8d1753883e06dffd0f99311f7eb9c4000537ad
parent 499512 ff04d410e74b69acfab17ef7e73e7397602d5a68
child 549506 be0522b5b8db2062fb82acf8861d361e535e4f45
push id49578
push userbmo:standard8@mozilla.com
push dateThu, 16 Mar 2017 11:05:41 +0000
reviewersjaws
bugs1347884
milestone55.0a1
Bug 1347884 - Enable eslint cyclomatic complexity rule at existing levels. r?jaws Enable the rule with the maximums set to avoid current failures, except for test_form_autocomplete which is very high (82). The levels are set per major area, with existing warnings being changed to errors. MozReview-Commit-ID: 37M6Ry0Mr1c
browser/components/.eslintrc.js
browser/components/migration/.eslintrc.js
browser/extensions/formautofill/.eslintrc.js
toolkit/.eslintrc.js
toolkit/components/narrate/.eslintrc.js
toolkit/components/satchel/test/test_form_autocomplete.html
toolkit/mozapps/extensions/.eslintrc.js
new file mode 100644
--- /dev/null
+++ b/browser/components/.eslintrc.js
@@ -0,0 +1,9 @@
+"use strict";
+
+module.exports = {
+  rules: {
+    // XXX Bug 1326071 - This should be reduced down - probably to 20 or to
+    // be removed & synced with the toolkit/.eslintrc.js value.
+    "complexity": ["error", {"max": 69}],
+  }
+};
--- a/browser/components/migration/.eslintrc.js
+++ b/browser/components/migration/.eslintrc.js
@@ -14,17 +14,17 @@ module.exports = { // eslint-disable-lin
   "env": { "browser": true },
 
   "rules": {
     "block-scoped-var": "error",
     // "brace-style": ["warn", "1tbs", {"allowSingleLine": true}],
     "comma-dangle": "off",
     "comma-spacing": ["warn", {"before": false, "after": true}],
     "comma-style": ["warn", "last"],
-    // "complexity": "warn",
+    "complexity": ["error", {"max": 21}],
     "consistent-return": "error",
     //"curly": "error",
     "dot-notation": "error",
     "eol-last": "error",
     "indent": ["warn", 2, {"SwitchCase": 1, "ArrayExpression": "first", "ObjectExpression": "first"}],
     // "key-spacing": ["warn", {"beforeColon": false, "afterColon": true}],
     "keyword-spacing": "warn",
     "max-nested-callbacks": ["error", 3],
@@ -74,9 +74,8 @@ module.exports = { // eslint-disable-lin
     "space-infix-ops": ["warn", {"int32Hint": true}],
     // "space-unary-ops": ["warn", { "words": true, "nonwords": false }],
     "strict": ["error", "global"],
     "use-isnan": "error",
     "valid-typeof": "error",
     "yoda": "error"
   }
 };
-
--- a/browser/extensions/formautofill/.eslintrc.js
+++ b/browser/extensions/formautofill/.eslintrc.js
@@ -104,17 +104,17 @@ module.exports = { // eslint-disable-lin
     // since only let and const are used, see "no-var").
     "block-scoped-var": "error",
 
     // Allow trailing commas for easy list extension.  Having them does not
     // impair readability, but also not required either.
     "comma-dangle": ["error", "always-multiline"],
 
     // Warn about cyclomatic complexity in functions.
-    "complexity": "warn",
+    "complexity": ["error", {"max": 20}],
 
     // Don't warn for inconsistent naming when capturing this (not so important
     // with auto-binding fat arrow functions).
     // "consistent-this": ["error", "self"],
 
     // Enforce dots on the next line with property name.
     "dot-location": ["error", "property"],
 
--- a/toolkit/.eslintrc.js
+++ b/toolkit/.eslintrc.js
@@ -17,16 +17,20 @@ module.exports = {
     "brace-style": ["error", "1tbs", { "allowSingleLine": true }],
 
     // No space before always a space after a comma
     "comma-spacing": ["error", {"before": false, "after": true}],
 
     // Commas at the end of the line not the start
     // "comma-style": "error",
 
+    // Warn about cyclomatic complexity in functions.
+    // XXX Bug 1326071 - This should be reduced down - probably to 20.
+    "complexity": ["error", {"max": 48}],
+
     // Don't require spaces around computed properties
     "computed-property-spacing": ["error", "never"],
 
     // Functions must always return something or nothing
     "consistent-return": "error",
 
     // Require braces around blocks that start a new line
     // Note that this rule is likely to be overridden on a per-directory basis
@@ -49,16 +53,20 @@ module.exports = {
     // "key-spacing": ["error", { "beforeColon": false, "afterColon": true, "mode": "minimum" }],
 
     // Require spaces before and after keywords
     "keyword-spacing": "error",
 
     // Unix linebreaks
     "linebreak-style": ["error", "unix"],
 
+    // Don't enforce the maximum depth that blocks can be nested. The complexity
+    // rule is a better rule to check this.
+    "max-depth": "off",
+
     // Always require parenthesis for new calls
     // "new-parens": "error",
 
     // Use [] instead of Array()
     // "no-array-constructor": "error",
 
     // Disallow assignment operators in conditional statements
     "no-cond-assign": "error",
--- a/toolkit/components/narrate/.eslintrc.js
+++ b/toolkit/components/narrate/.eslintrc.js
@@ -20,17 +20,17 @@ module.exports = { // eslint-disable-lin
     "mozilla/var-only-at-top-level": "warn",
 
     "block-scoped-var": "error",
     "brace-style": ["warn", "1tbs", {"allowSingleLine": false}],
     "camelcase": "warn",
     "comma-dangle": "off",
     "comma-spacing": ["warn", {"before": false, "after": true}],
     "comma-style": ["warn", "last"],
-    "complexity": "warn",
+    "complexity": ["error", {"max": 20}],
     "consistent-return": "error",
     "curly": "error",
     "dot-location": ["warn", "property"],
     "dot-notation": "error",
     "eol-last": "error",
     "generator-star-spacing": ["warn", "after"],
     "indent": ["warn", 2, {"SwitchCase": 1}],
     "key-spacing": ["warn", {"beforeColon": false, "afterColon": true}],
--- a/toolkit/components/satchel/test/test_form_autocomplete.html
+++ b/toolkit/components/satchel/test/test_form_autocomplete.html
@@ -229,17 +229,17 @@ registerPopupShownListener(popupShownLis
  *   - set expectingPopup to true, and the next test will occur when the autocomplete popup is shown
  *   - call waitForMenuChange(x) to run the next test when the autocomplete popup to have x items in it
  *   - addEntry calls runs the test when an entry has been added
  *   - some tests scroll the window. This is because the form fill controller happens to scroll
  *     the field into view near the end of the search, and there isn't any other good notification
  *     to listen to for when the search is complete.
  *   - some items still use setTimeout
  */
-function runTest() {
+function runTest() { // eslint-disable-line complexity
   testNum++;
 
   ok(true, "Starting test #" + testNum);
 
   switch (testNum) {
     case 1:
         // Make sure initial form is empty.
         checkForm("");
--- a/toolkit/mozapps/extensions/.eslintrc.js
+++ b/toolkit/mozapps/extensions/.eslintrc.js
@@ -1,10 +1,15 @@
 "use strict";
 
 module.exports = { // eslint-disable-line no-undef
   "rules": {
+    // Warn about cyclomatic complexity in functions.
+    // XXX Bug 1326071 - This should be reduced down - probably to 20 or to
+    // be removed & synced with the toolkit/.eslintrc.js value.
+    "complexity": ["error", {"max": 60}],
+
     // No using undeclared variables
     "no-undef": "error",
 
     "no-unused-vars": ["error", {"args": "none", "varsIgnorePattern": "^(Cc|Ci|Cr|Cu|EXPORTED_SYMBOLS)$"}],
   }
 };