Bug 1358949 - Lower eslint cyclomatic complexity threshold in some directories. r?standard8
We can lower the eslint cyclomatic complexity threshold in some directories without adding eslint suppression comments in any .js source files. We need to specify the complexity rule in accessible/.eslintrc because it doesn't inherit the mozilla/recommended rules. eslint's default complexity threshold is 20.
Also bump the eslint-plugin-mozilla version because we modified the mozilla/recommended rules.
MozReview-Commit-ID: 57T4gAjPH7z
--- a/accessible/.eslintrc.js
+++ b/accessible/.eslintrc.js
@@ -8,10 +8,14 @@ module.exports = {
"Cc": true,
"Ci": true,
"Components": true,
"console": true,
"Cu": true,
"dump": true,
"Services": true,
"XPCOMUtils": true
+ },
+ "rules": {
+ // Warn about cyclomatic complexity in functions.
+ "complexity": ["error", 42],
}
};
--- a/accessible/tests/browser/.eslintrc.js
+++ b/accessible/tests/browser/.eslintrc.js
@@ -57,17 +57,17 @@ module.exports = { // eslint-disable-lin
"mozilla/var-only-at-top-level": "warn",
"block-scoped-var": "error",
"brace-style": ["error", "1tbs"],
"camelcase": "error",
"comma-dangle": ["error", "never"],
"comma-spacing": "error",
"comma-style": ["error", "last"],
- "complexity": ["error", 35],
+ "complexity": ["error", 20],
"consistent-this": "off",
"curly": ["error", "multi-line"],
"default-case": "off",
"dot-location": ["error", "property"],
"dot-notation": "error",
"eol-last": "error",
"eqeqeq": "off",
"func-names": "off",
--- a/browser/components/.eslintrc.js
+++ b/browser/components/.eslintrc.js
@@ -1,9 +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 mozilla/recommended value.
- "complexity": ["error", {"max": 69}],
+ "complexity": ["error", {"max": 61}],
}
};
--- a/mobile/android/.eslintrc
+++ b/mobile/android/.eslintrc
@@ -42,16 +42,21 @@ rules:
global-strict: 0 # Overridden by "strict"
no-underscore-dangle: 0 # We allow trailing underscores in names.
# We disable everything to get all files to pass w/o updating them.
# We'll re-enable one by one.
camelcase: 0
comma-dangle: 0
comma-spacing: 0
+
+ # XXX Bug 1358949 - This should be reduced down - probably to 20 or to
+ # be removed & synced with the mozilla/recommended value.
+ complexity: ["error", 31]
+
consistent-return: 0
curly: 0
dot-notation: 0
eqeqeq: 0
key-spacing: 0
new-cap: 0
no-caller: 0
no-constant-condition: 0
--- a/mobile/android/chrome/content/.eslintrc
+++ b/mobile/android/chrome/content/.eslintrc
@@ -12,12 +12,14 @@ globals:
MediaPlayerApp: false
RokuApp: false
SearchEngines: false
ConsoleAPI: true
Point: false
Rect: false
rules:
+ complexity: ["error", 20]
+
# Disabled stuff
no-console: 0 # TODO: Can we use console?
no-cond-assign: 0
no-fallthrough: 0
--- a/toolkit/.eslintrc.js
+++ b/toolkit/.eslintrc.js
@@ -3,11 +3,11 @@
module.exports = {
extends: [
"plugin:mozilla/recommended"
],
rules: {
// XXX Bug 1326071 - This should be reduced down - probably to 20 or to
// be removed & synced with the mozilla/recommended value.
- "complexity": ["error", {"max": 48}],
+ "complexity": ["error", {"max": 41}],
}
};
--- a/toolkit/components/passwordmgr/.eslintrc.js
+++ b/toolkit/components/passwordmgr/.eslintrc.js
@@ -10,16 +10,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",
+ // XXX Bug 1358949 - This should be reduced down - probably to 20 or to
+ // be removed & synced with the mozilla/recommended value.
+ "complexity": ["error", 43],
+
// Use [] instead of Array()
"no-array-constructor": "error",
// Use {} instead of new Object()
"no-new-object": "error",
// No using undeclared variables
"no-undef": "error",
--- a/toolkit/content/.eslintrc.js
+++ b/toolkit/content/.eslintrc.js
@@ -3,9 +3,15 @@
module.exports = {
"env": {
"mozilla/browser-window": true,
},
"plugins": [
"mozilla"
],
+
+ rules: {
+ // XXX Bug 1358949 - This should be reduced down - probably to 20 or to
+ // be removed & synced with the mozilla/recommended value.
+ "complexity": ["error", 48],
+ }
};
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js
@@ -40,17 +40,17 @@ module.exports = {
// 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 Get this down to 20?
- "complexity": ["error", {"max": 35}],
+ "complexity": ["error", {"max": 32}],
// 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
--- a/tools/lint/eslint/eslint-plugin-mozilla/package.json
+++ b/tools/lint/eslint/eslint-plugin-mozilla/package.json
@@ -1,11 +1,11 @@
{
"name": "eslint-plugin-mozilla",
- "version": "0.2.42",
+ "version": "0.2.43",
"description": "A collection of rules that help enforce JavaScript coding standard in the Mozilla project.",
"keywords": [
"eslint",
"eslintplugin",
"eslint-plugin",
"mozilla",
"firefox"
],