eslint 8.0.1 → 8.4.0
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.
- package/README.md +8 -12
- package/conf/globals.js +144 -0
- package/lib/cli-engine/cli-engine.js +10 -21
- package/lib/cli.js +1 -1
- package/lib/config/default-config.js +11 -2
- package/lib/config/flat-config-array.js +2 -2
- package/lib/config/flat-config-helpers.js +67 -0
- package/lib/config/flat-config-schema.js +13 -8
- package/lib/config/rule-validator.js +28 -27
- package/lib/eslint/eslint.js +13 -18
- package/lib/linter/code-path-analysis/code-path-analyzer.js +6 -1
- package/lib/linter/code-path-analysis/code-path.js +1 -1
- package/lib/linter/linter.js +457 -45
- package/lib/linter/node-event-generator.js +7 -0
- package/lib/options.js +6 -6
- package/lib/rule-tester/rule-tester.js +5 -2
- package/lib/rules/accessor-pairs.js +1 -0
- package/lib/rules/array-bracket-newline.js +1 -0
- package/lib/rules/array-bracket-spacing.js +1 -0
- package/lib/rules/array-callback-return.js +1 -0
- package/lib/rules/array-element-newline.js +1 -0
- package/lib/rules/arrow-body-style.js +1 -0
- package/lib/rules/arrow-parens.js +1 -0
- package/lib/rules/arrow-spacing.js +1 -0
- package/lib/rules/block-scoped-var.js +3 -0
- package/lib/rules/block-spacing.js +11 -3
- package/lib/rules/brace-style.js +7 -0
- package/lib/rules/callback-return.js +1 -0
- package/lib/rules/camelcase.js +1 -0
- package/lib/rules/capitalized-comments.js +1 -0
- package/lib/rules/class-methods-use-this.js +11 -1
- package/lib/rules/comma-dangle.js +1 -0
- package/lib/rules/comma-spacing.js +1 -0
- package/lib/rules/comma-style.js +1 -0
- package/lib/rules/complexity.js +15 -6
- package/lib/rules/computed-property-spacing.js +1 -0
- package/lib/rules/consistent-return.js +1 -0
- package/lib/rules/consistent-this.js +1 -0
- package/lib/rules/constructor-super.js +1 -0
- package/lib/rules/curly.js +1 -0
- package/lib/rules/default-case-last.js +1 -0
- package/lib/rules/default-case.js +1 -0
- package/lib/rules/default-param-last.js +1 -0
- package/lib/rules/dot-location.js +1 -0
- package/lib/rules/dot-notation.js +1 -0
- package/lib/rules/eol-last.js +1 -0
- package/lib/rules/eqeqeq.js +1 -0
- package/lib/rules/for-direction.js +1 -0
- package/lib/rules/func-call-spacing.js +1 -0
- package/lib/rules/func-name-matching.js +1 -0
- package/lib/rules/func-names.js +1 -0
- package/lib/rules/func-style.js +1 -0
- package/lib/rules/function-call-argument-newline.js +1 -0
- package/lib/rules/function-paren-newline.js +1 -0
- package/lib/rules/generator-star-spacing.js +1 -0
- package/lib/rules/getter-return.js +1 -0
- package/lib/rules/global-require.js +1 -0
- package/lib/rules/grouped-accessor-pairs.js +1 -0
- package/lib/rules/guard-for-in.js +1 -0
- package/lib/rules/handle-callback-err.js +1 -0
- package/lib/rules/id-blacklist.js +1 -0
- package/lib/rules/id-denylist.js +1 -0
- package/lib/rules/id-length.js +1 -0
- package/lib/rules/id-match.js +1 -0
- package/lib/rules/implicit-arrow-linebreak.js +1 -0
- package/lib/rules/indent-legacy.js +1 -0
- package/lib/rules/indent.js +22 -0
- package/lib/rules/index.js +1 -0
- package/lib/rules/init-declarations.js +1 -0
- package/lib/rules/jsx-quotes.js +1 -0
- package/lib/rules/key-spacing.js +15 -13
- package/lib/rules/keyword-spacing.js +16 -1
- package/lib/rules/line-comment-position.js +1 -0
- package/lib/rules/linebreak-style.js +1 -0
- package/lib/rules/lines-around-comment.js +55 -7
- package/lib/rules/lines-around-directive.js +1 -0
- package/lib/rules/lines-between-class-members.js +1 -0
- package/lib/rules/max-classes-per-file.js +1 -0
- package/lib/rules/max-depth.js +3 -0
- package/lib/rules/max-len.js +1 -0
- package/lib/rules/max-lines-per-function.js +21 -2
- package/lib/rules/max-lines.js +1 -0
- package/lib/rules/max-nested-callbacks.js +1 -0
- package/lib/rules/max-params.js +1 -0
- package/lib/rules/max-statements-per-line.js +1 -0
- package/lib/rules/max-statements.js +11 -0
- package/lib/rules/multiline-comment-style.js +1 -0
- package/lib/rules/multiline-ternary.js +1 -0
- package/lib/rules/new-cap.js +1 -0
- package/lib/rules/new-parens.js +1 -0
- package/lib/rules/newline-after-var.js +1 -0
- package/lib/rules/newline-before-return.js +1 -0
- package/lib/rules/newline-per-chained-call.js +1 -0
- package/lib/rules/no-alert.js +1 -0
- package/lib/rules/no-array-constructor.js +1 -0
- package/lib/rules/no-async-promise-executor.js +1 -0
- package/lib/rules/no-await-in-loop.js +1 -0
- package/lib/rules/no-bitwise.js +1 -0
- package/lib/rules/no-buffer-constructor.js +1 -0
- package/lib/rules/no-caller.js +1 -0
- package/lib/rules/no-case-declarations.js +1 -0
- package/lib/rules/no-catch-shadow.js +1 -0
- package/lib/rules/no-class-assign.js +1 -0
- package/lib/rules/no-compare-neg-zero.js +1 -0
- package/lib/rules/no-cond-assign.js +1 -0
- package/lib/rules/no-confusing-arrow.js +1 -0
- package/lib/rules/no-console.js +1 -0
- package/lib/rules/no-const-assign.js +1 -0
- package/lib/rules/no-constant-condition.js +4 -1
- package/lib/rules/no-constructor-return.js +1 -0
- package/lib/rules/no-continue.js +1 -0
- package/lib/rules/no-control-regex.js +1 -0
- package/lib/rules/no-debugger.js +1 -0
- package/lib/rules/no-delete-var.js +1 -0
- package/lib/rules/no-div-regex.js +1 -0
- package/lib/rules/no-dupe-args.js +1 -0
- package/lib/rules/no-dupe-class-members.js +1 -0
- package/lib/rules/no-dupe-else-if.js +1 -0
- package/lib/rules/no-dupe-keys.js +1 -0
- package/lib/rules/no-duplicate-case.js +1 -0
- package/lib/rules/no-duplicate-imports.js +1 -0
- package/lib/rules/no-else-return.js +1 -0
- package/lib/rules/no-empty-character-class.js +1 -0
- package/lib/rules/no-empty-function.js +1 -0
- package/lib/rules/no-empty-pattern.js +1 -0
- package/lib/rules/no-empty.js +1 -0
- package/lib/rules/no-eq-null.js +1 -0
- package/lib/rules/no-eval.js +3 -0
- package/lib/rules/no-ex-assign.js +1 -0
- package/lib/rules/no-extend-native.js +1 -0
- package/lib/rules/no-extra-bind.js +1 -0
- package/lib/rules/no-extra-boolean-cast.js +1 -0
- package/lib/rules/no-extra-label.js +1 -0
- package/lib/rules/no-extra-parens.js +1 -0
- package/lib/rules/no-extra-semi.js +2 -1
- package/lib/rules/no-fallthrough.js +1 -0
- package/lib/rules/no-floating-decimal.js +1 -0
- package/lib/rules/no-func-assign.js +1 -0
- package/lib/rules/no-global-assign.js +1 -0
- package/lib/rules/no-implicit-coercion.js +1 -0
- package/lib/rules/no-implicit-globals.js +1 -0
- package/lib/rules/no-implied-eval.js +1 -0
- package/lib/rules/no-import-assign.js +1 -0
- package/lib/rules/no-inline-comments.js +1 -0
- package/lib/rules/no-inner-declarations.js +27 -4
- package/lib/rules/no-invalid-regexp.js +1 -0
- package/lib/rules/no-invalid-this.js +5 -0
- package/lib/rules/no-irregular-whitespace.js +1 -0
- package/lib/rules/no-iterator.js +1 -0
- package/lib/rules/no-label-var.js +1 -0
- package/lib/rules/no-labels.js +1 -0
- package/lib/rules/no-lone-blocks.js +9 -2
- package/lib/rules/no-lonely-if.js +1 -0
- package/lib/rules/no-loop-func.js +1 -0
- package/lib/rules/no-loss-of-precision.js +1 -0
- package/lib/rules/no-magic-numbers.js +1 -0
- package/lib/rules/no-misleading-character-class.js +1 -0
- package/lib/rules/no-mixed-operators.js +1 -0
- package/lib/rules/no-mixed-requires.js +1 -0
- package/lib/rules/no-mixed-spaces-and-tabs.js +1 -0
- package/lib/rules/no-multi-assign.js +1 -0
- package/lib/rules/no-multi-spaces.js +1 -0
- package/lib/rules/no-multi-str.js +1 -0
- package/lib/rules/no-multiple-empty-lines.js +1 -0
- package/lib/rules/no-native-reassign.js +1 -0
- package/lib/rules/no-negated-condition.js +1 -0
- package/lib/rules/no-negated-in-lhs.js +1 -0
- package/lib/rules/no-nested-ternary.js +1 -0
- package/lib/rules/no-new-func.js +1 -0
- package/lib/rules/no-new-object.js +1 -0
- package/lib/rules/no-new-require.js +1 -0
- package/lib/rules/no-new-symbol.js +1 -0
- package/lib/rules/no-new-wrappers.js +1 -0
- package/lib/rules/no-new.js +1 -0
- package/lib/rules/no-nonoctal-decimal-escape.js +1 -0
- package/lib/rules/no-obj-calls.js +1 -0
- package/lib/rules/no-octal-escape.js +1 -0
- package/lib/rules/no-octal.js +1 -0
- package/lib/rules/no-param-reassign.js +1 -0
- package/lib/rules/no-path-concat.js +1 -0
- package/lib/rules/no-plusplus.js +1 -0
- package/lib/rules/no-process-env.js +1 -0
- package/lib/rules/no-process-exit.js +1 -0
- package/lib/rules/no-promise-executor-return.js +1 -0
- package/lib/rules/no-proto.js +1 -0
- package/lib/rules/no-prototype-builtins.js +1 -0
- package/lib/rules/no-redeclare.js +3 -0
- package/lib/rules/no-regex-spaces.js +1 -0
- package/lib/rules/no-restricted-exports.js +1 -0
- package/lib/rules/no-restricted-globals.js +1 -0
- package/lib/rules/no-restricted-imports.js +1 -0
- package/lib/rules/no-restricted-modules.js +1 -0
- package/lib/rules/no-restricted-properties.js +1 -0
- package/lib/rules/no-restricted-syntax.js +1 -0
- package/lib/rules/no-return-assign.js +1 -0
- package/lib/rules/no-return-await.js +1 -0
- package/lib/rules/no-script-url.js +1 -0
- package/lib/rules/no-self-assign.js +1 -0
- package/lib/rules/no-self-compare.js +1 -0
- package/lib/rules/no-sequences.js +1 -0
- package/lib/rules/no-setter-return.js +1 -0
- package/lib/rules/no-shadow-restricted-names.js +1 -0
- package/lib/rules/no-shadow.js +1 -0
- package/lib/rules/no-spaced-func.js +1 -0
- package/lib/rules/no-sparse-arrays.js +1 -0
- package/lib/rules/no-sync.js +1 -0
- package/lib/rules/no-tabs.js +1 -0
- package/lib/rules/no-template-curly-in-string.js +1 -0
- package/lib/rules/no-ternary.js +1 -0
- package/lib/rules/no-this-before-super.js +1 -0
- package/lib/rules/no-throw-literal.js +1 -0
- package/lib/rules/no-trailing-spaces.js +1 -0
- package/lib/rules/no-undef-init.js +1 -0
- package/lib/rules/no-undef.js +1 -0
- package/lib/rules/no-undefined.js +1 -0
- package/lib/rules/no-underscore-dangle.js +1 -0
- package/lib/rules/no-unexpected-multiline.js +1 -0
- package/lib/rules/no-unmodified-loop-condition.js +1 -0
- package/lib/rules/no-unneeded-ternary.js +1 -0
- package/lib/rules/no-unreachable-loop.js +1 -0
- package/lib/rules/no-unreachable.js +1 -0
- package/lib/rules/no-unsafe-finally.js +1 -0
- package/lib/rules/no-unsafe-negation.js +1 -0
- package/lib/rules/no-unsafe-optional-chaining.js +1 -0
- package/lib/rules/no-unused-expressions.js +7 -0
- package/lib/rules/no-unused-labels.js +1 -0
- package/lib/rules/no-unused-private-class-members.js +195 -0
- package/lib/rules/no-unused-vars.js +1 -0
- package/lib/rules/no-use-before-define.js +176 -74
- package/lib/rules/no-useless-backreference.js +1 -0
- package/lib/rules/no-useless-call.js +1 -0
- package/lib/rules/no-useless-catch.js +1 -0
- package/lib/rules/no-useless-computed-key.js +1 -0
- package/lib/rules/no-useless-concat.js +1 -0
- package/lib/rules/no-useless-constructor.js +1 -0
- package/lib/rules/no-useless-escape.js +1 -0
- package/lib/rules/no-useless-rename.js +1 -0
- package/lib/rules/no-useless-return.js +1 -0
- package/lib/rules/no-var.js +1 -0
- package/lib/rules/no-void.js +1 -0
- package/lib/rules/no-warning-comments.js +1 -0
- package/lib/rules/no-whitespace-before-property.js +1 -0
- package/lib/rules/no-with.js +1 -0
- package/lib/rules/nonblock-statement-body-position.js +1 -0
- package/lib/rules/object-curly-newline.js +1 -0
- package/lib/rules/object-curly-spacing.js +1 -0
- package/lib/rules/object-property-newline.js +1 -0
- package/lib/rules/object-shorthand.js +1 -0
- package/lib/rules/one-var-declaration-per-line.js +1 -0
- package/lib/rules/one-var.js +6 -1
- package/lib/rules/operator-assignment.js +1 -0
- package/lib/rules/operator-linebreak.js +1 -0
- package/lib/rules/padded-blocks.js +9 -0
- package/lib/rules/padding-line-between-statements.js +3 -0
- package/lib/rules/prefer-arrow-callback.js +1 -0
- package/lib/rules/prefer-const.js +2 -1
- package/lib/rules/prefer-destructuring.js +1 -0
- package/lib/rules/prefer-exponentiation-operator.js +1 -0
- package/lib/rules/prefer-named-capture-group.js +1 -0
- package/lib/rules/prefer-numeric-literals.js +1 -0
- package/lib/rules/prefer-object-spread.js +1 -0
- package/lib/rules/prefer-promise-reject-errors.js +1 -0
- package/lib/rules/prefer-reflect.js +1 -0
- package/lib/rules/prefer-regex-literals.js +1 -0
- package/lib/rules/prefer-rest-params.js +1 -0
- package/lib/rules/prefer-spread.js +1 -0
- package/lib/rules/prefer-template.js +1 -0
- package/lib/rules/quote-props.js +1 -0
- package/lib/rules/quotes.js +1 -0
- package/lib/rules/radix.js +1 -0
- package/lib/rules/require-atomic-updates.js +15 -2
- package/lib/rules/require-await.js +1 -0
- package/lib/rules/require-jsdoc.js +1 -0
- package/lib/rules/require-unicode-regexp.js +1 -0
- package/lib/rules/require-yield.js +1 -0
- package/lib/rules/rest-spread-spacing.js +1 -0
- package/lib/rules/semi-spacing.js +1 -0
- package/lib/rules/semi-style.js +9 -2
- package/lib/rules/semi.js +19 -9
- package/lib/rules/sort-imports.js +1 -0
- package/lib/rules/sort-keys.js +1 -0
- package/lib/rules/sort-vars.js +1 -0
- package/lib/rules/space-before-blocks.js +1 -0
- package/lib/rules/space-before-function-paren.js +1 -0
- package/lib/rules/space-in-parens.js +1 -0
- package/lib/rules/space-infix-ops.js +1 -0
- package/lib/rules/space-unary-ops.js +1 -0
- package/lib/rules/spaced-comment.js +1 -0
- package/lib/rules/strict.js +1 -0
- package/lib/rules/switch-colon-spacing.js +1 -0
- package/lib/rules/symbol-description.js +1 -0
- package/lib/rules/template-curly-spacing.js +1 -0
- package/lib/rules/template-tag-spacing.js +1 -0
- package/lib/rules/unicode-bom.js +1 -0
- package/lib/rules/use-isnan.js +1 -0
- package/lib/rules/utils/ast-utils.js +15 -3
- package/lib/rules/valid-jsdoc.js +1 -0
- package/lib/rules/valid-typeof.js +1 -0
- package/lib/rules/vars-on-top.js +26 -12
- package/lib/rules/wrap-iife.js +1 -0
- package/lib/rules/wrap-regex.js +1 -0
- package/lib/rules/yield-star-spacing.js +1 -0
- package/lib/rules/yoda.js +1 -0
- package/lib/shared/types.js +10 -0
- package/package.json +12 -12
package/lib/rules/no-with.js
CHANGED
@@ -144,6 +144,7 @@ function areLineBreaksRequired(node, options, first, last) {
|
|
144
144
|
// Rule Definition
|
145
145
|
//------------------------------------------------------------------------------
|
146
146
|
|
147
|
+
/** @type {import('../shared/types').Rule} */
|
147
148
|
module.exports = {
|
148
149
|
meta: {
|
149
150
|
type: "layout",
|
@@ -22,6 +22,7 @@ const astUtils = require("./utils/ast-utils");
|
|
22
22
|
//------------------------------------------------------------------------------
|
23
23
|
// Rule Definition
|
24
24
|
//------------------------------------------------------------------------------
|
25
|
+
/** @type {import('../shared/types').Rule} */
|
25
26
|
module.exports = {
|
26
27
|
meta: {
|
27
28
|
type: "suggestion",
|
package/lib/rules/one-var.js
CHANGED
@@ -28,6 +28,7 @@ function isInStatementList(node) {
|
|
28
28
|
// Rule Definition
|
29
29
|
//------------------------------------------------------------------------------
|
30
30
|
|
31
|
+
/** @type {import('../shared/types').Rule} */
|
31
32
|
module.exports = {
|
32
33
|
meta: {
|
33
34
|
type: "suggestion",
|
@@ -541,6 +542,8 @@ module.exports = {
|
|
541
542
|
FunctionDeclaration: startFunction,
|
542
543
|
FunctionExpression: startFunction,
|
543
544
|
ArrowFunctionExpression: startFunction,
|
545
|
+
StaticBlock: startFunction, // StaticBlock creates a new scope for `var` variables
|
546
|
+
|
544
547
|
BlockStatement: startBlock,
|
545
548
|
ForStatement: startBlock,
|
546
549
|
ForInStatement: startBlock,
|
@@ -552,10 +555,12 @@ module.exports = {
|
|
552
555
|
"ForInStatement:exit": endBlock,
|
553
556
|
"SwitchStatement:exit": endBlock,
|
554
557
|
"BlockStatement:exit": endBlock,
|
558
|
+
|
555
559
|
"Program:exit": endFunction,
|
556
560
|
"FunctionDeclaration:exit": endFunction,
|
557
561
|
"FunctionExpression:exit": endFunction,
|
558
|
-
"ArrowFunctionExpression:exit": endFunction
|
562
|
+
"ArrowFunctionExpression:exit": endFunction,
|
563
|
+
"StaticBlock:exit": endFunction
|
559
564
|
};
|
560
565
|
|
561
566
|
}
|
@@ -15,6 +15,7 @@ const astUtils = require("./utils/ast-utils");
|
|
15
15
|
// Rule Definition
|
16
16
|
//------------------------------------------------------------------------------
|
17
17
|
|
18
|
+
/** @type {import('../shared/types').Rule} */
|
18
19
|
module.exports = {
|
19
20
|
meta: {
|
20
21
|
type: "layout",
|
@@ -106,6 +107,12 @@ module.exports = {
|
|
106
107
|
if (node.type === "SwitchStatement") {
|
107
108
|
return sourceCode.getTokenBefore(node.cases[0]);
|
108
109
|
}
|
110
|
+
|
111
|
+
if (node.type === "StaticBlock") {
|
112
|
+
return sourceCode.getFirstToken(node, { skip: 1 }); // skip the `static` token
|
113
|
+
}
|
114
|
+
|
115
|
+
// `BlockStatement` or `ClassBody`
|
109
116
|
return sourceCode.getFirstToken(node);
|
110
117
|
}
|
111
118
|
|
@@ -172,6 +179,7 @@ module.exports = {
|
|
172
179
|
function requirePaddingFor(node) {
|
173
180
|
switch (node.type) {
|
174
181
|
case "BlockStatement":
|
182
|
+
case "StaticBlock":
|
175
183
|
return options.blocks;
|
176
184
|
case "SwitchStatement":
|
177
185
|
return options.switches;
|
@@ -282,6 +290,7 @@ module.exports = {
|
|
282
290
|
}
|
283
291
|
checkPadding(node);
|
284
292
|
};
|
293
|
+
rule.StaticBlock = rule.BlockStatement;
|
285
294
|
}
|
286
295
|
|
287
296
|
if (Object.prototype.hasOwnProperty.call(options, "classes")) {
|
@@ -425,6 +425,7 @@ const StatementTypes = {
|
|
425
425
|
// Rule Definition
|
426
426
|
//------------------------------------------------------------------------------
|
427
427
|
|
428
|
+
/** @type {import('../shared/types').Rule} */
|
428
429
|
module.exports = {
|
429
430
|
meta: {
|
430
431
|
type: "layout",
|
@@ -618,9 +619,11 @@ module.exports = {
|
|
618
619
|
Program: enterScope,
|
619
620
|
BlockStatement: enterScope,
|
620
621
|
SwitchStatement: enterScope,
|
622
|
+
StaticBlock: enterScope,
|
621
623
|
"Program:exit": exitScope,
|
622
624
|
"BlockStatement:exit": exitScope,
|
623
625
|
"SwitchStatement:exit": exitScope,
|
626
|
+
"StaticBlock:exit": exitScope,
|
624
627
|
|
625
628
|
":statement": verify,
|
626
629
|
|
@@ -145,6 +145,7 @@ function hasDuplicateParams(paramsList) {
|
|
145
145
|
// Rule Definition
|
146
146
|
//------------------------------------------------------------------------------
|
147
147
|
|
148
|
+
/** @type {import('../shared/types').Rule} */
|
148
149
|
module.exports = {
|
149
150
|
meta: {
|
150
151
|
type: "suggestion",
|
@@ -17,7 +17,7 @@ const astUtils = require("./utils/ast-utils");
|
|
17
17
|
//------------------------------------------------------------------------------
|
18
18
|
|
19
19
|
const PATTERN_TYPE = /^(?:.+?Pattern|RestElement|SpreadProperty|ExperimentalRestProperty|Property)$/u;
|
20
|
-
const DECLARATION_HOST_TYPE = /^(?:Program|BlockStatement|SwitchCase)$/u;
|
20
|
+
const DECLARATION_HOST_TYPE = /^(?:Program|BlockStatement|StaticBlock|SwitchCase)$/u;
|
21
21
|
const DESTRUCTURING_HOST_TYPE = /^(?:VariableDeclarator|AssignmentExpression)$/u;
|
22
22
|
|
23
23
|
/**
|
@@ -326,6 +326,7 @@ function findUp(node, type, shouldStop) {
|
|
326
326
|
// Rule Definition
|
327
327
|
//------------------------------------------------------------------------------
|
328
328
|
|
329
|
+
/** @type {import('../shared/types').Rule} */
|
329
330
|
module.exports = {
|
330
331
|
meta: {
|
331
332
|
type: "suggestion",
|
@@ -20,6 +20,7 @@ const PRECEDENCE_OF_ASSIGNMENT_EXPR = astUtils.getPrecedence({ type: "Assignment
|
|
20
20
|
// Rule Definition
|
21
21
|
//------------------------------------------------------------------------------
|
22
22
|
|
23
|
+
/** @type {import('../shared/types').Rule} */
|
23
24
|
module.exports = {
|
24
25
|
meta: {
|
25
26
|
type: "suggestion",
|
@@ -84,6 +84,7 @@ function parenthesizeIfShould(text, shouldParenthesize) {
|
|
84
84
|
// Rule Definition
|
85
85
|
//------------------------------------------------------------------------------
|
86
86
|
|
87
|
+
/** @type {import('../shared/types').Rule} */
|
87
88
|
module.exports = {
|
88
89
|
meta: {
|
89
90
|
type: "suggestion",
|
@@ -43,6 +43,7 @@ function isValidThisArg(expectedThis, thisArg, context) {
|
|
43
43
|
// Rule Definition
|
44
44
|
//------------------------------------------------------------------------------
|
45
45
|
|
46
|
+
/** @type {import('../shared/types').Rule} */
|
46
47
|
module.exports = {
|
47
48
|
meta: {
|
48
49
|
type: "suggestion",
|
@@ -122,6 +122,7 @@ function endsWithTemplateCurly(node) {
|
|
122
122
|
// Rule Definition
|
123
123
|
//------------------------------------------------------------------------------
|
124
124
|
|
125
|
+
/** @type {import('../shared/types').Rule} */
|
125
126
|
module.exports = {
|
126
127
|
meta: {
|
127
128
|
type: "suggestion",
|
package/lib/rules/quote-props.js
CHANGED
package/lib/rules/quotes.js
CHANGED
package/lib/rules/radix.js
CHANGED
@@ -165,6 +165,7 @@ class SegmentInfo {
|
|
165
165
|
// Rule Definition
|
166
166
|
//------------------------------------------------------------------------------
|
167
167
|
|
168
|
+
/** @type {import('../shared/types').Rule} */
|
168
169
|
module.exports = {
|
169
170
|
meta: {
|
170
171
|
type: "problem",
|
@@ -176,7 +177,17 @@ module.exports = {
|
|
176
177
|
},
|
177
178
|
|
178
179
|
fixable: null,
|
179
|
-
|
180
|
+
|
181
|
+
schema: [{
|
182
|
+
type: "object",
|
183
|
+
properties: {
|
184
|
+
allowProperties: {
|
185
|
+
type: "boolean",
|
186
|
+
default: false
|
187
|
+
}
|
188
|
+
},
|
189
|
+
additionalProperties: false
|
190
|
+
}],
|
180
191
|
|
181
192
|
messages: {
|
182
193
|
nonAtomicUpdate: "Possible race condition: `{{value}}` might be reassigned based on an outdated value of `{{value}}`.",
|
@@ -185,6 +196,8 @@ module.exports = {
|
|
185
196
|
},
|
186
197
|
|
187
198
|
create(context) {
|
199
|
+
const allowProperties = !!context.options[0] && context.options[0].allowProperties;
|
200
|
+
|
188
201
|
const sourceCode = context.getSourceCode();
|
189
202
|
const assignmentReferences = new Map();
|
190
203
|
const segmentInfo = new SegmentInfo();
|
@@ -284,7 +297,7 @@ module.exports = {
|
|
284
297
|
value: variable.name
|
285
298
|
}
|
286
299
|
});
|
287
|
-
} else {
|
300
|
+
} else if (!allowProperties) {
|
288
301
|
context.report({
|
289
302
|
node: node.parent,
|
290
303
|
messageId: "nonAtomicObjectUpdate",
|
package/lib/rules/semi-style.js
CHANGED
@@ -25,7 +25,8 @@ const SELECTOR = [
|
|
25
25
|
|
26
26
|
/**
|
27
27
|
* Get the child node list of a given node.
|
28
|
-
* This returns `
|
28
|
+
* This returns `BlockStatement#body`, `StaticBlock#body`, `Program#body`,
|
29
|
+
* `ClassBody#body`, or `SwitchCase#consequent`.
|
29
30
|
* This is used to check whether a node is the first/last child.
|
30
31
|
* @param {Node} node A node to get child node list.
|
31
32
|
* @returns {Node[]|null} The child node list.
|
@@ -33,7 +34,12 @@ const SELECTOR = [
|
|
33
34
|
function getChildren(node) {
|
34
35
|
const t = node.type;
|
35
36
|
|
36
|
-
if (
|
37
|
+
if (
|
38
|
+
t === "BlockStatement" ||
|
39
|
+
t === "StaticBlock" ||
|
40
|
+
t === "Program" ||
|
41
|
+
t === "ClassBody"
|
42
|
+
) {
|
37
43
|
return node.body;
|
38
44
|
}
|
39
45
|
if (t === "SwitchCase") {
|
@@ -61,6 +67,7 @@ function isLastChild(node) {
|
|
61
67
|
return nodeList !== null && nodeList[nodeList.length - 1] === node; // before `}` or etc.
|
62
68
|
}
|
63
69
|
|
70
|
+
/** @type {import('../shared/types').Rule} */
|
64
71
|
module.exports = {
|
65
72
|
meta: {
|
66
73
|
type: "layout",
|
package/lib/rules/semi.js
CHANGED
@@ -15,6 +15,7 @@ const astUtils = require("./utils/ast-utils");
|
|
15
15
|
// Rule Definition
|
16
16
|
//------------------------------------------------------------------------------
|
17
17
|
|
18
|
+
/** @type {import('../shared/types').Rule} */
|
18
19
|
module.exports = {
|
19
20
|
meta: {
|
20
21
|
type: "layout",
|
@@ -306,22 +307,31 @@ module.exports = {
|
|
306
307
|
}
|
307
308
|
|
308
309
|
/**
|
309
|
-
* Checks a node to see if it's in a one-liner block
|
310
|
+
* Checks a node to see if it's the last item in a one-liner block.
|
311
|
+
* Block is any `BlockStatement` or `StaticBlock` node. Block is a one-liner if its
|
312
|
+
* braces (and consequently everything between them) are on the same line.
|
310
313
|
* @param {ASTNode} node The node to check.
|
311
|
-
* @returns {boolean} whether the node is in a one-liner block
|
314
|
+
* @returns {boolean} whether the node is the last item in a one-liner block.
|
312
315
|
*/
|
313
|
-
function
|
316
|
+
function isLastInOneLinerBlock(node) {
|
314
317
|
const parent = node.parent;
|
315
318
|
const nextToken = sourceCode.getTokenAfter(node);
|
316
319
|
|
317
320
|
if (!nextToken || nextToken.value !== "}") {
|
318
321
|
return false;
|
319
322
|
}
|
320
|
-
|
321
|
-
|
322
|
-
parent.
|
323
|
-
|
324
|
-
|
323
|
+
|
324
|
+
if (parent.type === "BlockStatement") {
|
325
|
+
return parent.loc.start.line === parent.loc.end.line;
|
326
|
+
}
|
327
|
+
|
328
|
+
if (parent.type === "StaticBlock") {
|
329
|
+
const openingBrace = sourceCode.getFirstToken(parent, { skip: 1 }); // skip the `static` token
|
330
|
+
|
331
|
+
return openingBrace.loc.start.line === parent.loc.end.line;
|
332
|
+
}
|
333
|
+
|
334
|
+
return false;
|
325
335
|
}
|
326
336
|
|
327
337
|
/**
|
@@ -343,7 +353,7 @@ module.exports = {
|
|
343
353
|
report(node);
|
344
354
|
}
|
345
355
|
} else {
|
346
|
-
const oneLinerBlock = (exceptOneLine &&
|
356
|
+
const oneLinerBlock = (exceptOneLine && isLastInOneLinerBlock(node));
|
347
357
|
|
348
358
|
if (isSemi && oneLinerBlock) {
|
349
359
|
report(node, true);
|
package/lib/rules/sort-keys.js
CHANGED
package/lib/rules/sort-vars.js
CHANGED
@@ -146,6 +146,7 @@ function createNeverStylePattern(markers) {
|
|
146
146
|
// Rule Definition
|
147
147
|
//------------------------------------------------------------------------------
|
148
148
|
|
149
|
+
/** @type {import('../shared/types').Rule} */
|
149
150
|
module.exports = {
|
150
151
|
meta: {
|
151
152
|
type: "suggestion",
|
package/lib/rules/strict.js
CHANGED