eslint 5.12.0 → 5.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/README.md +76 -143
  3. package/conf/eslint-all.js +3 -5
  4. package/conf/eslint-recommended.js +4 -268
  5. package/lib/built-in-rules-index.js +277 -0
  6. package/lib/cli-engine.js +6 -2
  7. package/lib/config/config-file.js +25 -2
  8. package/lib/config/config-initializer.js +150 -143
  9. package/lib/config/config-ops.js +30 -0
  10. package/lib/config/config-rule.js +2 -4
  11. package/lib/config/plugins.js +12 -4
  12. package/lib/config.js +1 -1
  13. package/lib/formatters/table.js +13 -4
  14. package/lib/formatters/tap.js +7 -4
  15. package/lib/linter.js +31 -31
  16. package/lib/load-rules.js +2 -5
  17. package/lib/rules/accessor-pairs.js +4 -2
  18. package/lib/rules/array-bracket-newline.js +4 -2
  19. package/lib/rules/array-callback-return.js +2 -1
  20. package/lib/rules/array-element-newline.js +4 -2
  21. package/lib/rules/arrow-body-style.js +1 -1
  22. package/lib/rules/arrow-parens.js +2 -1
  23. package/lib/rules/arrow-spacing.js +7 -6
  24. package/lib/rules/brace-style.js +2 -1
  25. package/lib/rules/camelcase.js +3 -2
  26. package/lib/rules/capitalized-comments.js +15 -14
  27. package/lib/rules/class-methods-use-this.js +1 -1
  28. package/lib/rules/comma-spacing.js +10 -4
  29. package/lib/rules/complexity.js +7 -9
  30. package/lib/rules/consistent-return.js +2 -1
  31. package/lib/rules/dot-notation.js +5 -3
  32. package/lib/rules/eqeqeq.js +2 -1
  33. package/lib/rules/for-direction.js +30 -17
  34. package/lib/rules/func-call-spacing.js +2 -1
  35. package/lib/rules/func-style.js +3 -2
  36. package/lib/rules/getter-return.js +2 -1
  37. package/lib/rules/global-require.js +5 -2
  38. package/lib/rules/guard-for-in.js +5 -2
  39. package/lib/rules/handle-callback-err.js +5 -2
  40. package/lib/rules/id-blacklist.js +4 -1
  41. package/lib/rules/id-length.js +9 -6
  42. package/lib/rules/id-match.js +11 -5
  43. package/lib/rules/implicit-arrow-linebreak.js +7 -3
  44. package/lib/rules/indent-legacy.js +11 -5
  45. package/lib/rules/indent.js +18 -9
  46. package/lib/rules/init-declarations.js +13 -13
  47. package/lib/rules/jsx-quotes.js +5 -2
  48. package/lib/rules/key-spacing.js +70 -35
  49. package/lib/rules/keyword-spacing.js +18 -12
  50. package/lib/rules/line-comment-position.js +15 -8
  51. package/lib/rules/linebreak-style.js +6 -6
  52. package/lib/rules/lines-around-comment.js +20 -16
  53. package/lib/rules/lines-around-directive.js +5 -2
  54. package/lib/rules/lines-between-class-members.js +8 -6
  55. package/lib/rules/max-depth.js +11 -9
  56. package/lib/rules/max-len.js +24 -13
  57. package/lib/rules/max-lines-per-function.js +17 -18
  58. package/lib/rules/max-lines.js +14 -10
  59. package/lib/rules/max-nested-callbacks.js +12 -11
  60. package/lib/rules/max-params.js +11 -9
  61. package/lib/rules/max-statements-per-line.js +8 -5
  62. package/lib/rules/max-statements.js +12 -11
  63. package/lib/rules/multiline-comment-style.js +18 -17
  64. package/lib/rules/multiline-ternary.js +8 -6
  65. package/lib/rules/new-cap.js +18 -11
  66. package/lib/rules/new-parens.js +5 -2
  67. package/lib/rules/newline-after-var.js +6 -8
  68. package/lib/rules/newline-before-return.js +5 -1
  69. package/lib/rules/newline-per-chained-call.js +7 -3
  70. package/lib/rules/no-async-promise-executor.js +5 -2
  71. package/lib/rules/no-bitwise.js +2 -1
  72. package/lib/rules/no-confusing-arrow.js +1 -1
  73. package/lib/rules/no-constant-condition.js +24 -2
  74. package/lib/rules/no-duplicate-imports.js +17 -11
  75. package/lib/rules/no-else-return.js +2 -1
  76. package/lib/rules/no-empty.js +2 -1
  77. package/lib/rules/no-eval.js +1 -1
  78. package/lib/rules/no-extra-parens.js +4 -4
  79. package/lib/rules/no-fallthrough.js +8 -4
  80. package/lib/rules/no-floating-decimal.js +7 -3
  81. package/lib/rules/no-implicit-coercion.js +9 -6
  82. package/lib/rules/no-irregular-whitespace.js +8 -4
  83. package/lib/rules/no-labels.js +6 -4
  84. package/lib/rules/no-magic-numbers.js +6 -3
  85. package/lib/rules/no-mixed-operators.js +5 -4
  86. package/lib/rules/no-mixed-requires.js +4 -2
  87. package/lib/rules/no-multi-spaces.js +2 -1
  88. package/lib/rules/no-param-reassign.js +1 -1
  89. package/lib/rules/no-plusplus.js +2 -1
  90. package/lib/rules/no-redeclare.js +2 -2
  91. package/lib/rules/no-self-assign.js +2 -1
  92. package/lib/rules/no-shadow-restricted-names.js +16 -2
  93. package/lib/rules/no-shadow.js +3 -3
  94. package/lib/rules/no-sync.js +2 -1
  95. package/lib/rules/no-tabs.js +2 -1
  96. package/lib/rules/no-trailing-spaces.js +5 -3
  97. package/lib/rules/no-undef.js +7 -3
  98. package/lib/rules/no-underscore-dangle.js +6 -3
  99. package/lib/rules/no-unexpected-multiline.js +14 -13
  100. package/lib/rules/no-unneeded-ternary.js +2 -1
  101. package/lib/rules/no-unsafe-negation.js +6 -3
  102. package/lib/rules/no-unused-expressions.js +6 -3
  103. package/lib/rules/no-unused-labels.js +7 -2
  104. package/lib/rules/no-unused-vars.js +8 -4
  105. package/lib/rules/no-use-before-define.js +3 -3
  106. package/lib/rules/no-useless-rename.js +3 -3
  107. package/lib/rules/object-curly-newline.js +6 -4
  108. package/lib/rules/object-property-newline.js +5 -3
  109. package/lib/rules/object-shorthand.js +9 -5
  110. package/lib/rules/one-var.js +24 -38
  111. package/lib/rules/operator-assignment.js +8 -4
  112. package/lib/rules/padded-blocks.js +32 -9
  113. package/lib/rules/prefer-arrow-callback.js +4 -2
  114. package/lib/rules/prefer-const.js +7 -4
  115. package/lib/rules/prefer-destructuring.js +70 -12
  116. package/lib/rules/prefer-promise-reject-errors.js +1 -1
  117. package/lib/rules/prefer-spread.js +2 -13
  118. package/lib/rules/quote-props.js +10 -5
  119. package/lib/rules/quotes.js +4 -2
  120. package/lib/rules/require-jsdoc.js +13 -7
  121. package/lib/rules/semi-spacing.js +6 -8
  122. package/lib/rules/semi.js +5 -4
  123. package/lib/rules/sort-imports.js +6 -3
  124. package/lib/rules/sort-keys.js +13 -5
  125. package/lib/rules/sort-vars.js +2 -1
  126. package/lib/rules/space-before-function-paren.js +6 -3
  127. package/lib/rules/space-infix-ops.js +2 -1
  128. package/lib/rules/space-unary-ops.js +20 -10
  129. package/lib/rules/spaced-comment.js +2 -1
  130. package/lib/rules/strict.js +34 -35
  131. package/lib/rules/switch-colon-spacing.js +11 -8
  132. package/lib/rules/symbol-description.js +6 -3
  133. package/lib/rules/template-curly-spacing.js +10 -10
  134. package/lib/rules/template-tag-spacing.js +7 -3
  135. package/lib/rules/unicode-bom.js +7 -3
  136. package/lib/rules/use-isnan.js +5 -2
  137. package/lib/rules/valid-jsdoc.js +40 -19
  138. package/lib/rules/valid-typeof.js +9 -4
  139. package/lib/rules/vars-on-top.js +6 -4
  140. package/lib/rules/wrap-iife.js +12 -6
  141. package/lib/rules/yield-star-spacing.js +17 -10
  142. package/lib/rules/yoda.js +9 -4
  143. package/lib/rules.js +4 -34
  144. package/lib/util/ajv.js +1 -0
  145. package/lib/util/config-comment-parser.js +7 -10
  146. package/package.json +20 -20
package/lib/linter.js CHANGED
@@ -70,30 +70,30 @@ const commentParser = new ConfigCommentParser();
70
70
  * @returns {void}
71
71
  */
72
72
  function addDeclaredGlobals(globalScope, configGlobals, commentDirectives) {
73
- Object.keys(configGlobals).forEach(name => {
74
- let variable = globalScope.set.get(name);
75
-
76
- if (!variable) {
77
- variable = new eslintScope.Variable(name, globalScope);
78
- variable.eslintExplicitGlobal = false;
79
- globalScope.variables.push(variable);
80
- globalScope.set.set(name, variable);
81
- }
82
- variable.writeable = configGlobals[name];
83
- });
84
-
85
- Object.keys(commentDirectives.enabledGlobals).forEach(name => {
86
- let variable = globalScope.set.get(name);
73
+ const mergedGlobalsInfo = Object.assign(
74
+ {},
75
+ lodash.mapValues(configGlobals, value => ({ sourceComment: null, value: ConfigOps.normalizeConfigGlobal(value) })),
76
+ lodash.mapValues(commentDirectives.enabledGlobals, ({ comment, value }) => ({ sourceComment: comment, value: ConfigOps.normalizeConfigGlobal(value) }))
77
+ );
87
78
 
88
- if (!variable) {
89
- variable = new eslintScope.Variable(name, globalScope);
90
- variable.eslintExplicitGlobal = true;
91
- variable.eslintExplicitGlobalComment = commentDirectives.enabledGlobals[name].comment;
92
- globalScope.variables.push(variable);
93
- globalScope.set.set(name, variable);
94
- }
95
- variable.writeable = commentDirectives.enabledGlobals[name].value;
96
- });
79
+ Object.keys(mergedGlobalsInfo)
80
+ .filter(name => mergedGlobalsInfo[name].value !== "off")
81
+ .forEach(name => {
82
+ let variable = globalScope.set.get(name);
83
+
84
+ if (!variable) {
85
+ variable = new eslintScope.Variable(name, globalScope);
86
+ if (mergedGlobalsInfo[name].sourceComment === null) {
87
+ variable.eslintExplicitGlobal = false;
88
+ } else {
89
+ variable.eslintExplicitGlobal = true;
90
+ variable.eslintExplicitGlobalComment = mergedGlobalsInfo[name].sourceComment;
91
+ }
92
+ globalScope.variables.push(variable);
93
+ globalScope.set.set(name, variable);
94
+ }
95
+ variable.writeable = (mergedGlobalsInfo[name].value === "writeable");
96
+ });
97
97
 
98
98
  // mark all exported variables as such
99
99
  Object.keys(commentDirectives.exportedVariables).forEach(name => {
@@ -191,12 +191,12 @@ function getDirectiveComments(filename, ast, ruleMapper) {
191
191
  } else if (comment.type === "Block") {
192
192
  switch (match[1]) {
193
193
  case "exported":
194
- Object.assign(exportedVariables, commentParser.parseBooleanConfig(directiveValue, comment));
194
+ Object.assign(exportedVariables, commentParser.parseStringConfig(directiveValue, comment));
195
195
  break;
196
196
 
197
197
  case "globals":
198
198
  case "global":
199
- Object.assign(enabledGlobals, commentParser.parseBooleanConfig(directiveValue, comment));
199
+ Object.assign(enabledGlobals, commentParser.parseStringConfig(directiveValue, comment));
200
200
  break;
201
201
 
202
202
  case "eslint-disable":
@@ -758,6 +758,7 @@ function runRules(sourceCode, configuredRules, ruleMapper, parserOptions, parser
758
758
 
759
759
  const lastSourceCodes = new WeakMap();
760
760
  const loadedParserMaps = new WeakMap();
761
+ const ruleMaps = new WeakMap();
761
762
 
762
763
  //------------------------------------------------------------------------------
763
764
  // Public Interface
@@ -772,9 +773,8 @@ module.exports = class Linter {
772
773
  constructor() {
773
774
  lastSourceCodes.set(this, null);
774
775
  loadedParserMaps.set(this, new Map());
776
+ ruleMaps.set(this, new Rules());
775
777
  this.version = pkg.version;
776
-
777
- this.rules = new Rules();
778
778
  this.environments = new Environments();
779
779
  }
780
780
 
@@ -873,7 +873,7 @@ module.exports = class Linter {
873
873
 
874
874
  const sourceCode = lastSourceCodes.get(this);
875
875
  const commentDirectives = options.allowInlineConfig
876
- ? getDirectiveComments(options.filename, sourceCode.ast, ruleId => this.rules.get(ruleId))
876
+ ? getDirectiveComments(options.filename, sourceCode.ast, ruleId => ruleMaps.get(this).get(ruleId))
877
877
  : { configuredRules: {}, enabledGlobals: {}, exportedVariables: {}, problems: [], disableDirectives: [] };
878
878
 
879
879
  // augment global scope with declared global variables
@@ -891,7 +891,7 @@ module.exports = class Linter {
891
891
  lintingProblems = runRules(
892
892
  sourceCode,
893
893
  configuredRules,
894
- ruleId => this.rules.get(ruleId),
894
+ ruleId => ruleMaps.get(this).get(ruleId),
895
895
  parserOptions,
896
896
  parserName,
897
897
  settings,
@@ -957,7 +957,7 @@ module.exports = class Linter {
957
957
  * @returns {void}
958
958
  */
959
959
  defineRule(ruleId, ruleModule) {
960
- this.rules.define(ruleId, ruleModule);
960
+ ruleMaps.get(this).define(ruleId, ruleModule);
961
961
  }
962
962
 
963
963
  /**
@@ -976,7 +976,7 @@ module.exports = class Linter {
976
976
  * @returns {Map} All loaded rules
977
977
  */
978
978
  getRules() {
979
- return this.rules.getAllLoadedRules();
979
+ return ruleMaps.get(this).getAllLoadedRules();
980
980
  }
981
981
 
982
982
  /**
package/lib/load-rules.js CHANGED
@@ -20,15 +20,12 @@ const rulesDirCache = {};
20
20
 
21
21
  /**
22
22
  * Load all rule modules from specified directory.
23
- * @param {string} [relativeRulesDir] Path to rules directory, may be relative. Defaults to `lib/rules`.
23
+ * @param {string} relativeRulesDir Path to rules directory, may be relative.
24
24
  * @param {string} cwd Current working directory
25
25
  * @returns {Object} Loaded rule modules by rule ids (file names).
26
26
  */
27
27
  module.exports = function(relativeRulesDir, cwd) {
28
-
29
- const rulesDir = relativeRulesDir
30
- ? path.resolve(cwd, relativeRulesDir)
31
- : path.join(__dirname, "rules");
28
+ const rulesDir = path.resolve(cwd, relativeRulesDir);
32
29
 
33
30
  // cache will help performance as IO operation are expensive
34
31
  if (rulesDirCache[rulesDir]) {
@@ -85,10 +85,12 @@ module.exports = {
85
85
  type: "object",
86
86
  properties: {
87
87
  getWithoutSet: {
88
- type: "boolean"
88
+ type: "boolean",
89
+ default: false
89
90
  },
90
91
  setWithoutGet: {
91
- type: "boolean"
92
+ type: "boolean",
93
+ default: true
92
94
  }
93
95
  },
94
96
  additionalProperties: false
@@ -34,11 +34,13 @@ module.exports = {
34
34
  type: "object",
35
35
  properties: {
36
36
  multiline: {
37
- type: "boolean"
37
+ type: "boolean",
38
+ default: true
38
39
  },
39
40
  minItems: {
40
41
  type: ["integer", "null"],
41
- minimum: 0
42
+ minimum: 0,
43
+ default: null
42
44
  }
43
45
  },
44
46
  additionalProperties: false
@@ -155,7 +155,8 @@ module.exports = {
155
155
  type: "object",
156
156
  properties: {
157
157
  allowImplicit: {
158
- type: "boolean"
158
+ type: "boolean",
159
+ default: false
159
160
  }
160
161
  },
161
162
  additionalProperties: false
@@ -34,11 +34,13 @@ module.exports = {
34
34
  type: "object",
35
35
  properties: {
36
36
  multiline: {
37
- type: "boolean"
37
+ type: "boolean",
38
+ default: false
38
39
  },
39
40
  minItems: {
40
41
  type: ["integer", "null"],
41
- minimum: 0
42
+ minimum: 0,
43
+ default: null
42
44
  }
43
45
  },
44
46
  additionalProperties: false
@@ -46,7 +46,7 @@ module.exports = {
46
46
  {
47
47
  type: "object",
48
48
  properties: {
49
- requireReturnForObjectLiteral: { type: "boolean" }
49
+ requireReturnForObjectLiteral: { type: "boolean", default: false }
50
50
  },
51
51
  additionalProperties: false
52
52
  }
@@ -35,7 +35,8 @@ module.exports = {
35
35
  type: "object",
36
36
  properties: {
37
37
  requireForBlockBody: {
38
- type: "boolean"
38
+ type: "boolean",
39
+ default: false
39
40
  }
40
41
  },
41
42
  additionalProperties: false
@@ -32,10 +32,12 @@ module.exports = {
32
32
  type: "object",
33
33
  properties: {
34
34
  before: {
35
- type: "boolean"
35
+ type: "boolean",
36
+ default: true
36
37
  },
37
38
  after: {
38
- type: "boolean"
39
+ type: "boolean",
40
+ default: true
39
41
  }
40
42
  },
41
43
  additionalProperties: false
@@ -54,11 +56,10 @@ module.exports = {
54
56
  create(context) {
55
57
 
56
58
  // merge rules with default
57
- const rule = { before: true, after: true },
58
- option = context.options[0] || {};
59
+ const rule = Object.assign({}, context.options[0]);
59
60
 
60
- rule.before = option.before !== false;
61
- rule.after = option.after !== false;
61
+ rule.before = rule.before !== false;
62
+ rule.after = rule.after !== false;
62
63
 
63
64
  const sourceCode = context.getSourceCode();
64
65
 
@@ -30,7 +30,8 @@ module.exports = {
30
30
  type: "object",
31
31
  properties: {
32
32
  allowSingleLine: {
33
- type: "boolean"
33
+ type: "boolean",
34
+ default: false
34
35
  }
35
36
  },
36
37
  additionalProperties: false
@@ -25,7 +25,8 @@ module.exports = {
25
25
  type: "object",
26
26
  properties: {
27
27
  ignoreDestructuring: {
28
- type: "boolean"
28
+ type: "boolean",
29
+ default: false
29
30
  },
30
31
  properties: {
31
32
  enum: ["always", "never"]
@@ -54,7 +55,7 @@ module.exports = {
54
55
 
55
56
  const options = context.options[0] || {};
56
57
  let properties = options.properties || "";
57
- const ignoreDestructuring = options.ignoreDestructuring || false;
58
+ const ignoreDestructuring = options.ignoreDestructuring;
58
59
  const allow = options.allow || [];
59
60
 
60
61
  if (properties !== "always" && properties !== "never") {
@@ -17,12 +17,7 @@ const astUtils = require("../util/ast-utils");
17
17
 
18
18
  const DEFAULT_IGNORE_PATTERN = astUtils.COMMENTS_IGNORE_PATTERN,
19
19
  WHITESPACE = /\s/g,
20
- MAYBE_URL = /^\s*[^:/?#\s]+:\/\/[^?#]/, // TODO: Combine w/ max-len pattern?
21
- DEFAULTS = {
22
- ignorePattern: null,
23
- ignoreInlineComments: false,
24
- ignoreConsecutiveComments: false
25
- };
20
+ MAYBE_URL = /^\s*[^:/?#\s]+:\/\/[^?#]/; // TODO: Combine w/ max-len pattern?
26
21
 
27
22
  /*
28
23
  * Base schema body for defining the basic capitalization rule, ignorePattern,
@@ -33,17 +28,27 @@ const SCHEMA_BODY = {
33
28
  type: "object",
34
29
  properties: {
35
30
  ignorePattern: {
36
- type: "string"
31
+ type: "string",
32
+ default: ""
37
33
  },
38
34
  ignoreInlineComments: {
39
- type: "boolean"
35
+ type: "boolean",
36
+ default: false
40
37
  },
41
38
  ignoreConsecutiveComments: {
42
- type: "boolean"
39
+ type: "boolean",
40
+ default: false
43
41
  }
44
42
  },
45
43
  additionalProperties: false
46
44
  };
45
+ const DEFAULTS = Object.keys(SCHEMA_BODY.properties).reduce(
46
+ (obj, current) => {
47
+ obj[current] = SCHEMA_BODY.properties[current].default;
48
+ return obj;
49
+ },
50
+ {}
51
+ );
47
52
 
48
53
  /**
49
54
  * Get normalized options for either block or line comments from the given
@@ -59,11 +64,7 @@ const SCHEMA_BODY = {
59
64
  * @param {string} which Either "line" or "block".
60
65
  * @returns {Object} The normalized options.
61
66
  */
62
- function getNormalizedOptions(rawOptions, which) {
63
- if (!rawOptions) {
64
- return Object.assign({}, DEFAULTS);
65
- }
66
-
67
+ function getNormalizedOptions(rawOptions = {}, which) {
67
68
  return Object.assign({}, DEFAULTS, rawOptions[which] || rawOptions);
68
69
  }
69
70
 
@@ -38,7 +38,7 @@ module.exports = {
38
38
  }
39
39
  },
40
40
  create(context) {
41
- const config = context.options[0] ? Object.assign({}, context.options[0]) : {};
41
+ const config = Object.assign({}, context.options[0]);
42
42
  const exceptMethods = new Set(config.exceptMethods || []);
43
43
 
44
44
  const stack = [];
@@ -28,10 +28,12 @@ module.exports = {
28
28
  type: "object",
29
29
  properties: {
30
30
  before: {
31
- type: "boolean"
31
+ type: "boolean",
32
+ default: false
32
33
  },
33
34
  after: {
34
- type: "boolean"
35
+ type: "boolean",
36
+ default: true
35
37
  }
36
38
  },
37
39
  additionalProperties: false
@@ -50,8 +52,8 @@ module.exports = {
50
52
  const tokensAndComments = sourceCode.tokensAndComments;
51
53
 
52
54
  const options = {
53
- before: context.options[0] ? !!context.options[0].before : false,
54
- after: context.options[0] ? !!context.options[0].after : true
55
+ before: context.options[0] ? context.options[0].before : false,
56
+ after: context.options[0] ? context.options[0].after : true
55
57
  };
56
58
 
57
59
  //--------------------------------------------------------------------------
@@ -118,6 +120,10 @@ module.exports = {
118
120
  report(reportItem, "before", tokens.left);
119
121
  }
120
122
 
123
+ if (tokens.right && astUtils.isClosingParenToken(tokens.right)) {
124
+ return;
125
+ }
126
+
121
127
  if (tokens.right && !options.after && tokens.right.type === "Line") {
122
128
  return;
123
129
  }
@@ -41,11 +41,13 @@ module.exports = {
41
41
  properties: {
42
42
  maximum: {
43
43
  type: "integer",
44
- minimum: 0
44
+ minimum: 0,
45
+ default: 20
45
46
  },
46
47
  max: {
47
48
  type: "integer",
48
- minimum: 0
49
+ minimum: 0,
50
+ default: 20
49
51
  }
50
52
  },
51
53
  additionalProperties: false
@@ -63,13 +65,9 @@ module.exports = {
63
65
  const option = context.options[0];
64
66
  let THRESHOLD = 20;
65
67
 
66
- if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "maximum") && typeof option.maximum === "number") {
67
- THRESHOLD = option.maximum;
68
- }
69
- if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "max") && typeof option.max === "number") {
70
- THRESHOLD = option.max;
71
- }
72
- if (typeof option === "number") {
68
+ if (typeof option === "object") {
69
+ THRESHOLD = option.maximum || option.max;
70
+ } else if (typeof option === "number") {
73
71
  THRESHOLD = option;
74
72
  }
75
73
 
@@ -66,7 +66,8 @@ module.exports = {
66
66
  type: "object",
67
67
  properties: {
68
68
  treatUndefinedAsUnspecified: {
69
- type: "boolean"
69
+ type: "boolean",
70
+ default: false
70
71
  }
71
72
  },
72
73
  additionalProperties: false
@@ -33,10 +33,12 @@ module.exports = {
33
33
  type: "object",
34
34
  properties: {
35
35
  allowKeywords: {
36
- type: "boolean"
36
+ type: "boolean",
37
+ default: true
37
38
  },
38
39
  allowPattern: {
39
- type: "string"
40
+ type: "string",
41
+ default: ""
40
42
  }
41
43
  },
42
44
  additionalProperties: false
@@ -53,7 +55,7 @@ module.exports = {
53
55
 
54
56
  create(context) {
55
57
  const options = context.options[0] || {};
56
- const allowKeywords = options.allowKeywords === void 0 || !!options.allowKeywords;
58
+ const allowKeywords = options.allowKeywords === void 0 || options.allowKeywords;
57
59
  const sourceCode = context.getSourceCode();
58
60
 
59
61
  let allowPattern;
@@ -38,7 +38,8 @@ module.exports = {
38
38
  type: "object",
39
39
  properties: {
40
40
  null: {
41
- enum: ["always", "never", "ignore"]
41
+ enum: ["always", "never", "ignore"],
42
+ default: "always"
42
43
  }
43
44
  },
44
45
  additionalProperties: false
@@ -42,6 +42,23 @@ module.exports = {
42
42
  });
43
43
  }
44
44
 
45
+ /**
46
+ * check the right side of the assignment
47
+ * @param {ASTNode} update UpdateExpression to check
48
+ * @param {int} dir expected direction that could either be turned around or invalidated
49
+ * @returns {int} return dir, the negated dir or zero if it's not clear for identifiers
50
+ */
51
+ function getRightDirection(update, dir) {
52
+ if (update.right.type === "UnaryExpression") {
53
+ if (update.right.operator === "-") {
54
+ return -dir;
55
+ }
56
+ } else if (update.right.type === "Identifier") {
57
+ return 0;
58
+ }
59
+ return dir;
60
+ }
61
+
45
62
  /**
46
63
  * check UpdateExpression add/sub the counter
47
64
  * @param {ASTNode} update UpdateExpression to check
@@ -69,10 +86,10 @@ module.exports = {
69
86
  function getAssignmentDirection(update, counter) {
70
87
  if (update.left.name === counter) {
71
88
  if (update.operator === "+=") {
72
- return 1;
89
+ return getRightDirection(update, 1);
73
90
  }
74
91
  if (update.operator === "-=") {
75
- return -1;
92
+ return getRightDirection(update, -1);
76
93
  }
77
94
  }
78
95
  return 0;
@@ -85,26 +102,22 @@ module.exports = {
85
102
  const operator = node.test.operator;
86
103
  const update = node.update;
87
104
 
88
- if (operator === "<" || operator === "<=") {
89
-
90
- // report error if update sub the counter (--, -=)
91
- if (update.type === "UpdateExpression" && getUpdateDirection(update, counter) < 0) {
92
- report(node);
93
- }
105
+ let wrongDirection;
94
106
 
95
- if (update.type === "AssignmentExpression" && getAssignmentDirection(update, counter) < 0) {
96
- report(node);
97
- }
107
+ if (operator === "<" || operator === "<=") {
108
+ wrongDirection = -1;
98
109
  } else if (operator === ">" || operator === ">=") {
110
+ wrongDirection = 1;
111
+ } else {
112
+ return;
113
+ }
99
114
 
100
- // report error if update add the counter (++, +=)
101
- if (update.type === "UpdateExpression" && getUpdateDirection(update, counter) > 0) {
102
- report(node);
103
- }
104
-
105
- if (update.type === "AssignmentExpression" && getAssignmentDirection(update, counter) > 0) {
115
+ if (update.type === "UpdateExpression") {
116
+ if (getUpdateDirection(update, counter) === wrongDirection) {
106
117
  report(node);
107
118
  }
119
+ } else if (update.type === "AssignmentExpression" && getAssignmentDirection(update, counter) === wrongDirection) {
120
+ report(node);
108
121
  }
109
122
  }
110
123
  }
@@ -50,7 +50,8 @@ module.exports = {
50
50
  type: "object",
51
51
  properties: {
52
52
  allowNewlines: {
53
- type: "boolean"
53
+ type: "boolean",
54
+ default: false
54
55
  }
55
56
  },
56
57
  additionalProperties: false
@@ -27,7 +27,8 @@ module.exports = {
27
27
  type: "object",
28
28
  properties: {
29
29
  allowArrowFunctions: {
30
- type: "boolean"
30
+ type: "boolean",
31
+ default: false
31
32
  }
32
33
  },
33
34
  additionalProperties: false
@@ -43,7 +44,7 @@ module.exports = {
43
44
  create(context) {
44
45
 
45
46
  const style = context.options[0],
46
- allowArrowFunctions = context.options[1] && context.options[1].allowArrowFunctions === true,
47
+ allowArrowFunctions = context.options[1] && context.options[1].allowArrowFunctions,
47
48
  enforceDeclarations = (style === "declaration"),
48
49
  stack = [];
49
50
 
@@ -60,7 +60,8 @@ module.exports = {
60
60
  type: "object",
61
61
  properties: {
62
62
  allowImplicit: {
63
- type: "boolean"
63
+ type: "boolean",
64
+ default: false
64
65
  }
65
66
  },
66
67
  additionalProperties: false
@@ -57,7 +57,10 @@ module.exports = {
57
57
  url: "https://eslint.org/docs/rules/global-require"
58
58
  },
59
59
 
60
- schema: []
60
+ schema: [],
61
+ messages: {
62
+ unexpected: "Unexpected require()."
63
+ }
61
64
  },
62
65
 
63
66
  create(context) {
@@ -69,7 +72,7 @@ module.exports = {
69
72
  const isGoodRequire = context.getAncestors().every(parent => ACCEPTABLE_PARENTS.indexOf(parent.type) > -1);
70
73
 
71
74
  if (!isGoodRequire) {
72
- context.report({ node, message: "Unexpected require()." });
75
+ context.report({ node, messageId: "unexpected" });
73
76
  }
74
77
  }
75
78
  }
@@ -20,7 +20,10 @@ module.exports = {
20
20
  url: "https://eslint.org/docs/rules/guard-for-in"
21
21
  },
22
22
 
23
- schema: []
23
+ schema: [],
24
+ messages: {
25
+ wrap: "The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype."
26
+ }
24
27
  },
25
28
 
26
29
  create(context) {
@@ -65,7 +68,7 @@ module.exports = {
65
68
  }
66
69
  }
67
70
 
68
- context.report({ node, message: "The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype." });
71
+ context.report({ node, messageId: "wrap" });
69
72
  }
70
73
  };
71
74
 
@@ -24,7 +24,10 @@ module.exports = {
24
24
  {
25
25
  type: "string"
26
26
  }
27
- ]
27
+ ],
28
+ messages: {
29
+ expected: "Expected error to be handled."
30
+ }
28
31
  },
29
32
 
30
33
  create(context) {
@@ -77,7 +80,7 @@ module.exports = {
77
80
 
78
81
  if (firstParameter && matchesConfiguredErrorName(firstParameter.name)) {
79
82
  if (firstParameter.references.length === 0) {
80
- context.report({ node, message: "Expected error to be handled." });
83
+ context.report({ node, messageId: "expected" });
81
84
  }
82
85
  }
83
86
  }