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
@@ -57,7 +57,8 @@ module.exports = {
57
57
  type: "object",
58
58
  properties: {
59
59
  avoidQuotes: {
60
- type: "boolean"
60
+ type: "boolean",
61
+ default: false
61
62
  }
62
63
  },
63
64
  additionalProperties: false
@@ -76,13 +77,16 @@ module.exports = {
76
77
  type: "object",
77
78
  properties: {
78
79
  ignoreConstructors: {
79
- type: "boolean"
80
+ type: "boolean",
81
+ default: false
80
82
  },
81
83
  avoidQuotes: {
82
- type: "boolean"
84
+ type: "boolean",
85
+ default: false
83
86
  },
84
87
  avoidExplicitReturnArrows: {
85
- type: "boolean"
88
+ type: "boolean",
89
+ default: false
86
90
  }
87
91
  },
88
92
  additionalProperties: false
@@ -255,7 +259,7 @@ module.exports = {
255
259
  keyPrefix + keyText + sourceCode.text.slice(tokenBeforeParams.range[1], node.value.range[1])
256
260
  );
257
261
  }
258
- const arrowToken = sourceCode.getTokens(node.value).find(token => token.value === "=>");
262
+ const arrowToken = sourceCode.getTokenBefore(node.value.body, { filter: token => token.value === "=>" });
259
263
  const tokenBeforeArrow = sourceCode.getTokenBefore(arrowToken);
260
264
  const hasParensAroundParameters = tokenBeforeArrow.type === "Punctuator" && tokenBeforeArrow.value === ")";
261
265
  const oldParamText = sourceCode.text.slice(sourceCode.getFirstToken(node.value, node.value.async ? 1 : 0).range[0], tokenBeforeArrow.range[1]);
@@ -32,16 +32,20 @@ module.exports = {
32
32
  type: "object",
33
33
  properties: {
34
34
  separateRequires: {
35
- type: "boolean"
35
+ type: "boolean",
36
+ default: false
36
37
  },
37
38
  var: {
38
- enum: ["always", "never", "consecutive"]
39
+ enum: ["always", "never", "consecutive"],
40
+ default: "always"
39
41
  },
40
42
  let: {
41
- enum: ["always", "never", "consecutive"]
43
+ enum: ["always", "never", "consecutive"],
44
+ default: "always"
42
45
  },
43
46
  const: {
44
- enum: ["always", "never", "consecutive"]
47
+ enum: ["always", "never", "consecutive"],
48
+ default: "always"
45
49
  }
46
50
  },
47
51
  additionalProperties: false
@@ -76,42 +80,16 @@ module.exports = {
76
80
  options.let = { uninitialized: mode, initialized: mode };
77
81
  options.const = { uninitialized: mode, initialized: mode };
78
82
  } else if (typeof mode === "object") { // options configuration is an object
79
- if (Object.prototype.hasOwnProperty.call(mode, "separateRequires")) {
80
- options.separateRequires = !!mode.separateRequires;
81
- }
82
- if (Object.prototype.hasOwnProperty.call(mode, "var")) {
83
- options.var = { uninitialized: mode.var, initialized: mode.var };
84
- }
85
- if (Object.prototype.hasOwnProperty.call(mode, "let")) {
86
- options.let = { uninitialized: mode.let, initialized: mode.let };
87
- }
88
- if (Object.prototype.hasOwnProperty.call(mode, "const")) {
89
- options.const = { uninitialized: mode.const, initialized: mode.const };
90
- }
83
+ options.separateRequires = mode.separateRequires;
84
+ options.var = { uninitialized: mode.var, initialized: mode.var };
85
+ options.let = { uninitialized: mode.let, initialized: mode.let };
86
+ options.const = { uninitialized: mode.const, initialized: mode.const };
91
87
  if (Object.prototype.hasOwnProperty.call(mode, "uninitialized")) {
92
- if (!options.var) {
93
- options.var = {};
94
- }
95
- if (!options.let) {
96
- options.let = {};
97
- }
98
- if (!options.const) {
99
- options.const = {};
100
- }
101
88
  options.var.uninitialized = mode.uninitialized;
102
89
  options.let.uninitialized = mode.uninitialized;
103
90
  options.const.uninitialized = mode.uninitialized;
104
91
  }
105
92
  if (Object.prototype.hasOwnProperty.call(mode, "initialized")) {
106
- if (!options.var) {
107
- options.var = {};
108
- }
109
- if (!options.let) {
110
- options.let = {};
111
- }
112
- if (!options.const) {
113
- options.const = {};
114
- }
115
93
  options.var.initialized = mode.initialized;
116
94
  options.let.initialized = mode.initialized;
117
95
  options.const.initialized = mode.initialized;
@@ -257,7 +235,9 @@ module.exports = {
257
235
 
258
236
  if (currentOptions.uninitialized === MODE_ALWAYS && currentOptions.initialized === MODE_ALWAYS) {
259
237
  if (currentScope.uninitialized || currentScope.initialized) {
260
- return false;
238
+ if (!hasRequires) {
239
+ return false;
240
+ }
261
241
  }
262
242
  }
263
243
 
@@ -268,7 +248,9 @@ module.exports = {
268
248
  }
269
249
  if (declarationCounts.initialized > 0) {
270
250
  if (currentOptions.initialized === MODE_ALWAYS && currentScope.initialized) {
271
- return false;
251
+ if (!hasRequires) {
252
+ return false;
253
+ }
272
254
  }
273
255
  }
274
256
  if (currentScope.required && hasRequires) {
@@ -340,7 +322,11 @@ module.exports = {
340
322
  * y`
341
323
  * ^ afterComma
342
324
  */
343
- if (afterComma.loc.start.line > tokenAfterDeclarator.loc.end.line || afterComma.type === "Line" || afterComma.type === "Block") {
325
+ if (
326
+ afterComma.loc.start.line > tokenAfterDeclarator.loc.end.line ||
327
+ afterComma.type === "Line" ||
328
+ afterComma.type === "Block"
329
+ ) {
344
330
  let lastComment = afterComma;
345
331
 
346
332
  while (lastComment.type === "Line" || lastComment.type === "Block") {
@@ -349,7 +335,7 @@ module.exports = {
349
335
 
350
336
  return fixer.replaceTextRange(
351
337
  [tokenAfterDeclarator.range[0], lastComment.range[0]],
352
- `;\n${sourceCode.text.slice(tokenAfterDeclarator.range[1], lastComment.range[0])}\n${declaration.kind} `
338
+ `;${sourceCode.text.slice(tokenAfterDeclarator.range[1], lastComment.range[0])}${declaration.kind} `
353
339
  );
354
340
  }
355
341
 
@@ -104,7 +104,11 @@ module.exports = {
104
104
  }
105
105
  ],
106
106
 
107
- fixable: "code"
107
+ fixable: "code",
108
+ messages: {
109
+ replaced: "Assignment can be replaced with operator assignment.",
110
+ unexpected: "Unexpected operator assignment shorthand."
111
+ }
108
112
  },
109
113
 
110
114
  create(context) {
@@ -138,7 +142,7 @@ module.exports = {
138
142
  if (same(left, expr.left)) {
139
143
  context.report({
140
144
  node,
141
- message: "Assignment can be replaced with operator assignment.",
145
+ messageId: "replaced",
142
146
  fix(fixer) {
143
147
  if (canBeFixed(left)) {
144
148
  const equalsToken = getOperatorToken(node);
@@ -160,7 +164,7 @@ module.exports = {
160
164
  */
161
165
  context.report({
162
166
  node,
163
- message: "Assignment can be replaced with operator assignment."
167
+ messageId: "replaced"
164
168
  });
165
169
  }
166
170
  }
@@ -175,7 +179,7 @@ module.exports = {
175
179
  if (node.operator !== "=") {
176
180
  context.report({
177
181
  node,
178
- message: "Unexpected operator assignment shorthand.",
182
+ messageId: "unexpected",
179
183
  fix(fixer) {
180
184
  if (canBeFixed(node.left)) {
181
185
  const operatorToken = getOperatorToken(node);
@@ -5,6 +5,12 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ //------------------------------------------------------------------------------
9
+ // Requirements
10
+ //------------------------------------------------------------------------------
11
+
12
+ const astUtils = require("../util/ast-utils");
13
+
8
14
  //------------------------------------------------------------------------------
9
15
  // Rule Definition
10
16
  //------------------------------------------------------------------------------
@@ -45,32 +51,45 @@ module.exports = {
45
51
  minProperties: 1
46
52
  }
47
53
  ]
54
+ },
55
+ {
56
+ type: "object",
57
+ properties: {
58
+ allowSingleLineBlocks: {
59
+ type: "boolean"
60
+ }
61
+ }
48
62
  }
49
63
  ]
50
64
  },
51
65
 
52
66
  create(context) {
53
67
  const options = {};
54
- const config = context.options[0] || "always";
68
+ const typeOptions = context.options[0] || "always";
69
+ const exceptOptions = context.options[1] || {};
55
70
 
56
- if (typeof config === "string") {
57
- const shouldHavePadding = config === "always";
71
+ if (typeof typeOptions === "string") {
72
+ const shouldHavePadding = typeOptions === "always";
58
73
 
59
74
  options.blocks = shouldHavePadding;
60
75
  options.switches = shouldHavePadding;
61
76
  options.classes = shouldHavePadding;
62
77
  } else {
63
- if (Object.prototype.hasOwnProperty.call(config, "blocks")) {
64
- options.blocks = config.blocks === "always";
78
+ if (Object.prototype.hasOwnProperty.call(typeOptions, "blocks")) {
79
+ options.blocks = typeOptions.blocks === "always";
65
80
  }
66
- if (Object.prototype.hasOwnProperty.call(config, "switches")) {
67
- options.switches = config.switches === "always";
81
+ if (Object.prototype.hasOwnProperty.call(typeOptions, "switches")) {
82
+ options.switches = typeOptions.switches === "always";
68
83
  }
69
- if (Object.prototype.hasOwnProperty.call(config, "classes")) {
70
- options.classes = config.classes === "always";
84
+ if (Object.prototype.hasOwnProperty.call(typeOptions, "classes")) {
85
+ options.classes = typeOptions.classes === "always";
71
86
  }
72
87
  }
73
88
 
89
+ if (Object.prototype.hasOwnProperty.call(exceptOptions, "allowSingleLineBlocks")) {
90
+ options.allowSingleLineBlocks = exceptOptions.allowSingleLineBlocks === true;
91
+ }
92
+
74
93
  const ALWAYS_MESSAGE = "Block must be padded by blank lines.",
75
94
  NEVER_MESSAGE = "Block must not be padded by blank lines.";
76
95
 
@@ -177,6 +196,10 @@ module.exports = {
177
196
  blockHasTopPadding = isPaddingBetweenTokens(tokenBeforeFirst, firstBlockToken),
178
197
  blockHasBottomPadding = isPaddingBetweenTokens(lastBlockToken, tokenAfterLast);
179
198
 
199
+ if (options.allowSingleLineBlocks && astUtils.isTokenOnSameLine(tokenBeforeFirst, tokenAfterLast)) {
200
+ return;
201
+ }
202
+
180
203
  if (requirePaddingFor(node)) {
181
204
  if (!blockHasTopPadding) {
182
205
  context.report({
@@ -146,10 +146,12 @@ module.exports = {
146
146
  type: "object",
147
147
  properties: {
148
148
  allowNamedFunctions: {
149
- type: "boolean"
149
+ type: "boolean",
150
+ default: false
150
151
  },
151
152
  allowUnboundThis: {
152
- type: "boolean"
153
+ type: "boolean",
154
+ default: true
153
155
  }
154
156
  },
155
157
  additionalProperties: false
@@ -345,12 +345,15 @@ module.exports = {
345
345
  {
346
346
  type: "object",
347
347
  properties: {
348
- destructuring: { enum: ["any", "all"] },
349
- ignoreReadBeforeAssign: { type: "boolean" }
348
+ destructuring: { enum: ["any", "all"], default: "any" },
349
+ ignoreReadBeforeAssign: { type: "boolean", default: false }
350
350
  },
351
351
  additionalProperties: false
352
352
  }
353
- ]
353
+ ],
354
+ messages: {
355
+ useConst: "'{{name}}' is never reassigned. Use 'const' instead."
356
+ }
354
357
  },
355
358
 
356
359
  create(context) {
@@ -445,7 +448,7 @@ module.exports = {
445
448
  nodesToReport.forEach(node => {
446
449
  context.report({
447
450
  node,
448
- message: "'{{name}}' is never reassigned. Use 'const' instead.",
451
+ messageId: "useConst",
449
452
  data: node,
450
453
  fix: shouldFix ? fixer => fixer.replaceText(sourceCode.getFirstToken(varDeclParent), "const") : null
451
454
  });
@@ -19,6 +19,8 @@ module.exports = {
19
19
  url: "https://eslint.org/docs/rules/prefer-destructuring"
20
20
  },
21
21
 
22
+ fixable: "code",
23
+
22
24
  schema: [
23
25
  {
24
26
 
@@ -34,10 +36,12 @@ module.exports = {
34
36
  type: "object",
35
37
  properties: {
36
38
  array: {
37
- type: "boolean"
39
+ type: "boolean",
40
+ default: true
38
41
  },
39
42
  object: {
40
- type: "boolean"
43
+ type: "boolean",
44
+ default: true
41
45
  }
42
46
  },
43
47
  additionalProperties: false
@@ -46,10 +50,12 @@ module.exports = {
46
50
  type: "object",
47
51
  properties: {
48
52
  array: {
49
- type: "boolean"
53
+ type: "boolean",
54
+ default: true
50
55
  },
51
56
  object: {
52
- type: "boolean"
57
+ type: "boolean",
58
+ default: true
53
59
  }
54
60
  },
55
61
  additionalProperties: false
@@ -61,10 +67,12 @@ module.exports = {
61
67
  type: "object",
62
68
  properties: {
63
69
  array: {
64
- type: "boolean"
70
+ type: "boolean",
71
+ default: true
65
72
  },
66
73
  object: {
67
- type: "boolean"
74
+ type: "boolean",
75
+ default: true
68
76
  }
69
77
  },
70
78
  additionalProperties: false
@@ -75,7 +83,8 @@ module.exports = {
75
83
  type: "object",
76
84
  properties: {
77
85
  enforceForRenamedProperties: {
78
- type: "boolean"
86
+ type: "boolean",
87
+ default: false
79
88
  }
80
89
  },
81
90
  additionalProperties: false
@@ -130,10 +139,55 @@ module.exports = {
130
139
  *
131
140
  * @param {ASTNode} reportNode the node to report
132
141
  * @param {string} type the type of destructuring that should have been done
142
+ * @param {Function|null} fix the fix function or null to pass to context.report
133
143
  * @returns {void}
134
144
  */
135
- function report(reportNode, type) {
136
- context.report({ node: reportNode, message: "Use {{type}} destructuring.", data: { type } });
145
+ function report(reportNode, type, fix) {
146
+ context.report({
147
+ node: reportNode,
148
+ message: "Use {{type}} destructuring.",
149
+ data: { type },
150
+ fix
151
+ });
152
+ }
153
+
154
+ /**
155
+ * Determines if a node should be fixed into object destructuring
156
+ *
157
+ * The fixer only fixes the simplest case of object destructuring,
158
+ * like: `let x = a.x`;
159
+ *
160
+ * Assignment expression is not fixed.
161
+ * Array destructuring is not fixed.
162
+ * Renamed property is not fixed.
163
+ *
164
+ * @param {ASTNode} node the the node to evaluate
165
+ * @returns {boolean} whether or not the node should be fixed
166
+ */
167
+ function shouldFix(node) {
168
+ return node.type === "VariableDeclarator" &&
169
+ node.id.type === "Identifier" &&
170
+ node.init.type === "MemberExpression" &&
171
+ node.id.name === node.init.property.name;
172
+ }
173
+
174
+ /**
175
+ * Fix a node into object destructuring.
176
+ * This function only handles the simplest case of object destructuring,
177
+ * see {@link shouldFix}.
178
+ *
179
+ * @param {SourceCodeFixer} fixer the fixer object
180
+ * @param {ASTNode} node the node to be fixed.
181
+ * @returns {Object} a fix for the node
182
+ */
183
+ function fixIntoObjectDestructuring(fixer, node) {
184
+ const rightNode = node.init;
185
+ const sourceCode = context.getSourceCode();
186
+
187
+ return fixer.replaceText(
188
+ node,
189
+ `{${rightNode.property.name}} = ${sourceCode.getText(rightNode.object)}`
190
+ );
137
191
  }
138
192
 
139
193
  /**
@@ -155,13 +209,17 @@ module.exports = {
155
209
 
156
210
  if (isArrayIndexAccess(rightNode)) {
157
211
  if (shouldCheck(reportNode.type, "array")) {
158
- report(reportNode, "array");
212
+ report(reportNode, "array", null);
159
213
  }
160
214
  return;
161
215
  }
162
216
 
217
+ const fix = shouldFix(reportNode)
218
+ ? fixer => fixIntoObjectDestructuring(fixer, reportNode)
219
+ : null;
220
+
163
221
  if (shouldCheck(reportNode.type, "object") && enforceForRenamedProperties) {
164
- report(reportNode, "object");
222
+ report(reportNode, "object", fix);
165
223
  return;
166
224
  }
167
225
 
@@ -172,7 +230,7 @@ module.exports = {
172
230
  (property.type === "Literal" && leftNode.name === property.value) ||
173
231
  (property.type === "Identifier" && leftNode.name === property.name && !rightNode.computed)
174
232
  ) {
175
- report(reportNode, "object");
233
+ report(reportNode, "object", fix);
176
234
  }
177
235
  }
178
236
  }
@@ -27,7 +27,7 @@ module.exports = {
27
27
  {
28
28
  type: "object",
29
29
  properties: {
30
- allowEmptyReject: { type: "boolean" }
30
+ allowEmptyReject: { type: "boolean", default: false }
31
31
  },
32
32
  additionalProperties: false
33
33
  }
@@ -59,7 +59,7 @@ module.exports = {
59
59
  },
60
60
 
61
61
  schema: [],
62
- fixable: "code"
62
+ fixable: null
63
63
  },
64
64
 
65
65
  create(context) {
@@ -78,18 +78,7 @@ module.exports = {
78
78
  if (isValidThisArg(expectedThis, thisArg, sourceCode)) {
79
79
  context.report({
80
80
  node,
81
- message: "Use the spread operator instead of '.apply()'.",
82
- fix(fixer) {
83
- if (expectedThis && expectedThis.type !== "Identifier") {
84
-
85
- // Don't fix cases where the `this` value could be a computed expression.
86
- return null;
87
- }
88
-
89
- const propertyDot = sourceCode.getFirstTokenBetween(applied, node.callee.property, token => token.value === ".");
90
-
91
- return fixer.replaceTextRange([propertyDot.range[0], node.range[1]], `(...${sourceCode.getText(node.arguments[1])})`);
92
- }
81
+ message: "Use the spread operator instead of '.apply()'."
93
82
  });
94
83
  }
95
84
  }
@@ -32,7 +32,8 @@ module.exports = {
32
32
  type: "array",
33
33
  items: [
34
34
  {
35
- enum: ["always", "as-needed", "consistent", "consistent-as-needed"]
35
+ enum: ["always", "as-needed", "consistent", "consistent-as-needed"],
36
+ default: "always"
36
37
  }
37
38
  ],
38
39
  minItems: 0,
@@ -42,19 +43,23 @@ module.exports = {
42
43
  type: "array",
43
44
  items: [
44
45
  {
45
- enum: ["always", "as-needed", "consistent", "consistent-as-needed"]
46
+ enum: ["always", "as-needed", "consistent", "consistent-as-needed"],
47
+ default: "always"
46
48
  },
47
49
  {
48
50
  type: "object",
49
51
  properties: {
50
52
  keywords: {
51
- type: "boolean"
53
+ type: "boolean",
54
+ default: false
52
55
  },
53
56
  unnecessary: {
54
- type: "boolean"
57
+ type: "boolean",
58
+ default: true
55
59
  },
56
60
  numbers: {
57
- type: "boolean"
61
+ type: "boolean",
62
+ default: false
58
63
  }
59
64
  },
60
65
  additionalProperties: false
@@ -100,10 +100,12 @@ module.exports = {
100
100
  type: "object",
101
101
  properties: {
102
102
  avoidEscape: {
103
- type: "boolean"
103
+ type: "boolean",
104
+ default: false
104
105
  },
105
106
  allowTemplateLiterals: {
106
- type: "boolean"
107
+ type: "boolean",
108
+ default: false
107
109
  }
108
110
  },
109
111
  additionalProperties: false
@@ -23,22 +23,28 @@ module.exports = {
23
23
  type: "object",
24
24
  properties: {
25
25
  ClassDeclaration: {
26
- type: "boolean"
26
+ type: "boolean",
27
+ default: false
27
28
  },
28
29
  MethodDefinition: {
29
- type: "boolean"
30
+ type: "boolean",
31
+ default: false
30
32
  },
31
33
  FunctionDeclaration: {
32
- type: "boolean"
34
+ type: "boolean",
35
+ default: true
33
36
  },
34
37
  ArrowFunctionExpression: {
35
- type: "boolean"
38
+ type: "boolean",
39
+ default: false
36
40
  },
37
41
  FunctionExpression: {
38
- type: "boolean"
42
+ type: "boolean",
43
+ default: false
39
44
  }
40
45
  },
41
- additionalProperties: false
46
+ additionalProperties: false,
47
+ default: {}
42
48
  }
43
49
  },
44
50
  additionalProperties: false
@@ -58,7 +64,7 @@ module.exports = {
58
64
  ArrowFunctionExpression: false,
59
65
  FunctionExpression: false
60
66
  };
61
- const options = Object.assign(DEFAULT_OPTIONS, context.options[0] && context.options[0].require || {});
67
+ const options = Object.assign(DEFAULT_OPTIONS, context.options[0] && context.options[0].require);
62
68
 
63
69
  /**
64
70
  * Report the error message
@@ -29,10 +29,12 @@ module.exports = {
29
29
  type: "object",
30
30
  properties: {
31
31
  before: {
32
- type: "boolean"
32
+ type: "boolean",
33
+ default: false
33
34
  },
34
35
  after: {
35
- type: "boolean"
36
+ type: "boolean",
37
+ default: true
36
38
  }
37
39
  },
38
40
  additionalProperties: false
@@ -48,12 +50,8 @@ module.exports = {
48
50
  requireSpaceAfter = true;
49
51
 
50
52
  if (typeof config === "object") {
51
- if (Object.prototype.hasOwnProperty.call(config, "before")) {
52
- requireSpaceBefore = config.before;
53
- }
54
- if (Object.prototype.hasOwnProperty.call(config, "after")) {
55
- requireSpaceAfter = config.after;
56
- }
53
+ requireSpaceBefore = config.before;
54
+ requireSpaceAfter = config.after;
57
55
  }
58
56
 
59
57
  /**
package/lib/rules/semi.js CHANGED
@@ -40,7 +40,8 @@ module.exports = {
40
40
  type: "object",
41
41
  properties: {
42
42
  beforeStatementContinuationChars: {
43
- enum: ["always", "any", "never"]
43
+ enum: ["always", "any", "never"],
44
+ default: "any"
44
45
  }
45
46
  },
46
47
  additionalProperties: false
@@ -58,7 +59,7 @@ module.exports = {
58
59
  {
59
60
  type: "object",
60
61
  properties: {
61
- omitLastInOneLineBlock: { type: "boolean" }
62
+ omitLastInOneLineBlock: { type: "boolean", default: false }
62
63
  },
63
64
  additionalProperties: false
64
65
  }
@@ -75,8 +76,8 @@ module.exports = {
75
76
  const OPT_OUT_PATTERN = /^[-[(/+`]/; // One of [(/+-`
76
77
  const options = context.options[1];
77
78
  const never = context.options[0] === "never";
78
- const exceptOneLine = Boolean(options && options.omitLastInOneLineBlock);
79
- const beforeStatementContinuationChars = (options && options.beforeStatementContinuationChars) || "any";
79
+ const exceptOneLine = options && options.omitLastInOneLineBlock;
80
+ const beforeStatementContinuationChars = options && options.beforeStatementContinuationChars;
80
81
  const sourceCode = context.getSourceCode();
81
82
 
82
83
  //--------------------------------------------------------------------------