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
@@ -9,6 +9,7 @@ const { isCommentToken, isNotOpeningParenToken } = require("./utils/ast-utils");
|
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
// Rule Definition
|
11
11
|
//------------------------------------------------------------------------------
|
12
|
+
/** @type {import('../shared/types').Rule} */
|
12
13
|
module.exports = {
|
13
14
|
meta: {
|
14
15
|
type: "layout",
|
@@ -20,6 +20,7 @@ const astUtils = require("./utils/ast-utils");
|
|
20
20
|
//------------------------------------------------------------------------------
|
21
21
|
|
22
22
|
/* istanbul ignore next: this rule has known coverage issues, but it's deprecated and shouldn't be updated in the future anyway. */
|
23
|
+
/** @type {import('../shared/types').Rule} */
|
23
24
|
module.exports = {
|
24
25
|
meta: {
|
25
26
|
type: "layout",
|
package/lib/rules/indent.js
CHANGED
@@ -68,6 +68,7 @@ const KNOWN_NODES = new Set([
|
|
68
68
|
"ReturnStatement",
|
69
69
|
"SequenceExpression",
|
70
70
|
"SpreadElement",
|
71
|
+
"StaticBlock",
|
71
72
|
"Super",
|
72
73
|
"SwitchCase",
|
73
74
|
"SwitchStatement",
|
@@ -493,6 +494,7 @@ const ELEMENT_LIST_SCHEMA = {
|
|
493
494
|
]
|
494
495
|
};
|
495
496
|
|
497
|
+
/** @type {import('../shared/types').Rule} */
|
496
498
|
module.exports = {
|
497
499
|
meta: {
|
498
500
|
type: "layout",
|
@@ -583,6 +585,16 @@ module.exports = {
|
|
583
585
|
},
|
584
586
|
additionalProperties: false
|
585
587
|
},
|
588
|
+
StaticBlock: {
|
589
|
+
type: "object",
|
590
|
+
properties: {
|
591
|
+
body: {
|
592
|
+
type: "integer",
|
593
|
+
minimum: 0
|
594
|
+
}
|
595
|
+
},
|
596
|
+
additionalProperties: false
|
597
|
+
},
|
586
598
|
CallExpression: {
|
587
599
|
type: "object",
|
588
600
|
properties: {
|
@@ -646,6 +658,9 @@ module.exports = {
|
|
646
658
|
parameters: DEFAULT_PARAMETER_INDENT,
|
647
659
|
body: DEFAULT_FUNCTION_BODY_INDENT
|
648
660
|
},
|
661
|
+
StaticBlock: {
|
662
|
+
body: DEFAULT_FUNCTION_BODY_INDENT
|
663
|
+
},
|
649
664
|
CallExpression: {
|
650
665
|
arguments: DEFAULT_PARAMETER_INDENT
|
651
666
|
},
|
@@ -1397,6 +1412,13 @@ module.exports = {
|
|
1397
1412
|
}
|
1398
1413
|
},
|
1399
1414
|
|
1415
|
+
StaticBlock(node) {
|
1416
|
+
const openingCurly = sourceCode.getFirstToken(node, { skip: 1 }); // skip the `static` token
|
1417
|
+
const closingCurly = sourceCode.getLastToken(node);
|
1418
|
+
|
1419
|
+
addElementListIndent(node.body, openingCurly, closingCurly, options.StaticBlock.body);
|
1420
|
+
},
|
1421
|
+
|
1400
1422
|
SwitchStatement(node) {
|
1401
1423
|
const openingCurly = sourceCode.getTokenAfter(node.discriminant, astUtils.isOpeningBraceToken);
|
1402
1424
|
const closingCurly = sourceCode.getLastToken(node);
|
package/lib/rules/index.js
CHANGED
@@ -221,6 +221,7 @@ module.exports = new LazyLoadingRuleMap(Object.entries({
|
|
221
221
|
"no-unsafe-optional-chaining": () => require("./no-unsafe-optional-chaining"),
|
222
222
|
"no-unused-expressions": () => require("./no-unused-expressions"),
|
223
223
|
"no-unused-labels": () => require("./no-unused-labels"),
|
224
|
+
"no-unused-private-class-members": () => require("./no-unused-private-class-members"),
|
224
225
|
"no-unused-vars": () => require("./no-unused-vars"),
|
225
226
|
"no-use-before-define": () => require("./no-use-before-define"),
|
226
227
|
"no-useless-backreference": () => require("./no-useless-backreference"),
|
package/lib/rules/jsx-quotes.js
CHANGED
package/lib/rules/key-spacing.js
CHANGED
@@ -133,6 +133,7 @@ function initOptions(toOptions, fromOptions) {
|
|
133
133
|
// Rule Definition
|
134
134
|
//------------------------------------------------------------------------------
|
135
135
|
|
136
|
+
/** @type {import('../shared/types').Rule} */
|
136
137
|
module.exports = {
|
137
138
|
meta: {
|
138
139
|
type: "layout",
|
@@ -427,19 +428,7 @@ module.exports = {
|
|
427
428
|
* @returns {void}
|
428
429
|
*/
|
429
430
|
function report(property, side, whitespace, expected, mode) {
|
430
|
-
const diff = whitespace.length - expected
|
431
|
-
nextColon = getNextColon(property.key),
|
432
|
-
tokenBeforeColon = sourceCode.getTokenBefore(nextColon, { includeComments: true }),
|
433
|
-
tokenAfterColon = sourceCode.getTokenAfter(nextColon, { includeComments: true }),
|
434
|
-
isKeySide = side === "key",
|
435
|
-
isExtra = diff > 0,
|
436
|
-
diffAbs = Math.abs(diff),
|
437
|
-
spaces = Array(diffAbs + 1).join(" ");
|
438
|
-
|
439
|
-
const locStart = isKeySide ? tokenBeforeColon.loc.end : nextColon.loc.start;
|
440
|
-
const locEnd = isKeySide ? nextColon.loc.start : tokenAfterColon.loc.start;
|
441
|
-
const missingLoc = isKeySide ? tokenBeforeColon.loc : tokenAfterColon.loc;
|
442
|
-
const loc = isExtra ? { start: locStart, end: locEnd } : missingLoc;
|
431
|
+
const diff = whitespace.length - expected;
|
443
432
|
|
444
433
|
if ((
|
445
434
|
diff && mode === "strict" ||
|
@@ -447,6 +436,19 @@ module.exports = {
|
|
447
436
|
diff > 0 && !expected && mode === "minimum") &&
|
448
437
|
!(expected && containsLineTerminator(whitespace))
|
449
438
|
) {
|
439
|
+
const nextColon = getNextColon(property.key),
|
440
|
+
tokenBeforeColon = sourceCode.getTokenBefore(nextColon, { includeComments: true }),
|
441
|
+
tokenAfterColon = sourceCode.getTokenAfter(nextColon, { includeComments: true }),
|
442
|
+
isKeySide = side === "key",
|
443
|
+
isExtra = diff > 0,
|
444
|
+
diffAbs = Math.abs(diff),
|
445
|
+
spaces = Array(diffAbs + 1).join(" ");
|
446
|
+
|
447
|
+
const locStart = isKeySide ? tokenBeforeColon.loc.end : nextColon.loc.start;
|
448
|
+
const locEnd = isKeySide ? nextColon.loc.start : tokenAfterColon.loc.start;
|
449
|
+
const missingLoc = isKeySide ? tokenBeforeColon.loc : tokenAfterColon.loc;
|
450
|
+
const loc = isExtra ? { start: locStart, end: locEnd } : missingLoc;
|
451
|
+
|
450
452
|
let fix;
|
451
453
|
|
452
454
|
if (isExtra) {
|
@@ -61,6 +61,7 @@ function isCloseParenOfTemplate(token) {
|
|
61
61
|
// Rule Definition
|
62
62
|
//------------------------------------------------------------------------------
|
63
63
|
|
64
|
+
/** @type {import('../shared/types').Rule} */
|
64
65
|
module.exports = {
|
65
66
|
meta: {
|
66
67
|
type: "layout",
|
@@ -109,6 +110,8 @@ module.exports = {
|
|
109
110
|
create(context) {
|
110
111
|
const sourceCode = context.getSourceCode();
|
111
112
|
|
113
|
+
const tokensToIgnore = new WeakSet();
|
114
|
+
|
112
115
|
/**
|
113
116
|
* Reports a given token if there are not space(s) before the token.
|
114
117
|
* @param {Token} token A token to report.
|
@@ -121,6 +124,7 @@ module.exports = {
|
|
121
124
|
if (prevToken &&
|
122
125
|
(CHECK_TYPE.test(prevToken.type) || pattern.test(prevToken.value)) &&
|
123
126
|
!isOpenParenOfTemplate(prevToken) &&
|
127
|
+
!tokensToIgnore.has(prevToken) &&
|
124
128
|
astUtils.isTokenOnSameLine(prevToken, token) &&
|
125
129
|
!sourceCode.isSpaceBetweenTokens(prevToken, token)
|
126
130
|
) {
|
@@ -147,6 +151,7 @@ module.exports = {
|
|
147
151
|
if (prevToken &&
|
148
152
|
(CHECK_TYPE.test(prevToken.type) || pattern.test(prevToken.value)) &&
|
149
153
|
!isOpenParenOfTemplate(prevToken) &&
|
154
|
+
!tokensToIgnore.has(prevToken) &&
|
150
155
|
astUtils.isTokenOnSameLine(prevToken, token) &&
|
151
156
|
sourceCode.isSpaceBetweenTokens(prevToken, token)
|
152
157
|
) {
|
@@ -173,6 +178,7 @@ module.exports = {
|
|
173
178
|
if (nextToken &&
|
174
179
|
(CHECK_TYPE.test(nextToken.type) || pattern.test(nextToken.value)) &&
|
175
180
|
!isCloseParenOfTemplate(nextToken) &&
|
181
|
+
!tokensToIgnore.has(nextToken) &&
|
176
182
|
astUtils.isTokenOnSameLine(token, nextToken) &&
|
177
183
|
!sourceCode.isSpaceBetweenTokens(token, nextToken)
|
178
184
|
) {
|
@@ -199,6 +205,7 @@ module.exports = {
|
|
199
205
|
if (nextToken &&
|
200
206
|
(CHECK_TYPE.test(nextToken.type) || pattern.test(nextToken.value)) &&
|
201
207
|
!isCloseParenOfTemplate(nextToken) &&
|
208
|
+
!tokensToIgnore.has(nextToken) &&
|
202
209
|
astUtils.isTokenOnSameLine(token, nextToken) &&
|
203
210
|
sourceCode.isSpaceBetweenTokens(token, nextToken)
|
204
211
|
) {
|
@@ -584,7 +591,15 @@ module.exports = {
|
|
584
591
|
ImportNamespaceSpecifier: checkSpacingForImportNamespaceSpecifier,
|
585
592
|
MethodDefinition: checkSpacingForProperty,
|
586
593
|
PropertyDefinition: checkSpacingForProperty,
|
587
|
-
|
594
|
+
StaticBlock: checkSpacingAroundFirstToken,
|
595
|
+
Property: checkSpacingForProperty,
|
596
|
+
|
597
|
+
// To avoid conflicts with `space-infix-ops`, e.g. `a > this.b`
|
598
|
+
"BinaryExpression[operator='>']"(node) {
|
599
|
+
const operatorToken = sourceCode.getTokenBefore(node.right, astUtils.isNotOpeningParenToken);
|
600
|
+
|
601
|
+
tokensToIgnore.add(operatorToken);
|
602
|
+
}
|
588
603
|
};
|
589
604
|
}
|
590
605
|
};
|
@@ -49,6 +49,7 @@ function getCommentLineNums(comments) {
|
|
49
49
|
// Rule Definition
|
50
50
|
//------------------------------------------------------------------------------
|
51
51
|
|
52
|
+
/** @type {import('../shared/types').Rule} */
|
52
53
|
module.exports = {
|
53
54
|
meta: {
|
54
55
|
type: "layout",
|
@@ -185,10 +186,39 @@ module.exports = {
|
|
185
186
|
/**
|
186
187
|
* Returns the parent node that contains the given token.
|
187
188
|
* @param {token} token The token to check.
|
188
|
-
* @returns {ASTNode} The parent node that contains the given token.
|
189
|
+
* @returns {ASTNode|null} The parent node that contains the given token.
|
189
190
|
*/
|
190
191
|
function getParentNodeOfToken(token) {
|
191
|
-
|
192
|
+
const node = sourceCode.getNodeByRangeIndex(token.range[0]);
|
193
|
+
|
194
|
+
/*
|
195
|
+
* For the purpose of this rule, the comment token is in a `StaticBlock` node only
|
196
|
+
* if it's inside the braces of that `StaticBlock` node.
|
197
|
+
*
|
198
|
+
* Example where this function returns `null`:
|
199
|
+
*
|
200
|
+
* static
|
201
|
+
* // comment
|
202
|
+
* {
|
203
|
+
* }
|
204
|
+
*
|
205
|
+
* Example where this function returns `StaticBlock` node:
|
206
|
+
*
|
207
|
+
* static
|
208
|
+
* {
|
209
|
+
* // comment
|
210
|
+
* }
|
211
|
+
*
|
212
|
+
*/
|
213
|
+
if (node && node.type === "StaticBlock") {
|
214
|
+
const openingBrace = sourceCode.getFirstToken(node, { skip: 1 }); // skip the `static` token
|
215
|
+
|
216
|
+
return token.range[0] >= openingBrace.range[0]
|
217
|
+
? node
|
218
|
+
: null;
|
219
|
+
}
|
220
|
+
|
221
|
+
return node;
|
192
222
|
}
|
193
223
|
|
194
224
|
/**
|
@@ -200,8 +230,15 @@ module.exports = {
|
|
200
230
|
function isCommentAtParentStart(token, nodeType) {
|
201
231
|
const parent = getParentNodeOfToken(token);
|
202
232
|
|
203
|
-
|
204
|
-
|
233
|
+
if (parent && isParentNodeType(parent, nodeType)) {
|
234
|
+
const parentStartNodeOrToken = parent.type === "StaticBlock"
|
235
|
+
? sourceCode.getFirstToken(parent, { skip: 1 }) // opening brace of the static block
|
236
|
+
: parent;
|
237
|
+
|
238
|
+
return token.loc.start.line - parentStartNodeOrToken.loc.start.line === 1;
|
239
|
+
}
|
240
|
+
|
241
|
+
return false;
|
205
242
|
}
|
206
243
|
|
207
244
|
/**
|
@@ -213,7 +250,7 @@ module.exports = {
|
|
213
250
|
function isCommentAtParentEnd(token, nodeType) {
|
214
251
|
const parent = getParentNodeOfToken(token);
|
215
252
|
|
216
|
-
return parent && isParentNodeType(parent, nodeType) &&
|
253
|
+
return !!parent && isParentNodeType(parent, nodeType) &&
|
217
254
|
parent.loc.end.line - token.loc.end.line === 1;
|
218
255
|
}
|
219
256
|
|
@@ -223,7 +260,12 @@ module.exports = {
|
|
223
260
|
* @returns {boolean} True if the comment is at block start.
|
224
261
|
*/
|
225
262
|
function isCommentAtBlockStart(token) {
|
226
|
-
return
|
263
|
+
return (
|
264
|
+
isCommentAtParentStart(token, "ClassBody") ||
|
265
|
+
isCommentAtParentStart(token, "BlockStatement") ||
|
266
|
+
isCommentAtParentStart(token, "StaticBlock") ||
|
267
|
+
isCommentAtParentStart(token, "SwitchCase")
|
268
|
+
);
|
227
269
|
}
|
228
270
|
|
229
271
|
/**
|
@@ -232,7 +274,13 @@ module.exports = {
|
|
232
274
|
* @returns {boolean} True if the comment is at block end.
|
233
275
|
*/
|
234
276
|
function isCommentAtBlockEnd(token) {
|
235
|
-
return
|
277
|
+
return (
|
278
|
+
isCommentAtParentEnd(token, "ClassBody") ||
|
279
|
+
isCommentAtParentEnd(token, "BlockStatement") ||
|
280
|
+
isCommentAtParentEnd(token, "StaticBlock") ||
|
281
|
+
isCommentAtParentEnd(token, "SwitchCase") ||
|
282
|
+
isCommentAtParentEnd(token, "SwitchStatement")
|
283
|
+
);
|
236
284
|
}
|
237
285
|
|
238
286
|
/**
|
package/lib/rules/max-depth.js
CHANGED
@@ -9,6 +9,7 @@
|
|
9
9
|
// Rule Definition
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
+
/** @type {import('../shared/types').Rule} */
|
12
13
|
module.exports = {
|
13
14
|
meta: {
|
14
15
|
type: "suggestion",
|
@@ -118,6 +119,7 @@ module.exports = {
|
|
118
119
|
FunctionDeclaration: startFunction,
|
119
120
|
FunctionExpression: startFunction,
|
120
121
|
ArrowFunctionExpression: startFunction,
|
122
|
+
StaticBlock: startFunction,
|
121
123
|
|
122
124
|
IfStatement(node) {
|
123
125
|
if (node.parent.type !== "IfStatement") {
|
@@ -146,6 +148,7 @@ module.exports = {
|
|
146
148
|
"FunctionDeclaration:exit": endFunction,
|
147
149
|
"FunctionExpression:exit": endFunction,
|
148
150
|
"ArrowFunctionExpression:exit": endFunction,
|
151
|
+
"StaticBlock:exit": endFunction,
|
149
152
|
"Program:exit": endFunction
|
150
153
|
};
|
151
154
|
|
package/lib/rules/max-len.js
CHANGED
@@ -65,6 +65,7 @@ function getCommentLineNumbers(comments) {
|
|
65
65
|
// Rule Definition
|
66
66
|
//------------------------------------------------------------------------------
|
67
67
|
|
68
|
+
/** @type {import('../shared/types').Rule} */
|
68
69
|
module.exports = {
|
69
70
|
meta: {
|
70
71
|
type: "suggestion",
|
@@ -79,7 +80,7 @@ module.exports = {
|
|
79
80
|
OPTIONS_OR_INTEGER_SCHEMA
|
80
81
|
],
|
81
82
|
messages: {
|
82
|
-
exceed: "{{name}} has
|
83
|
+
exceed: "{{name}} has exceeded the limit of lines allowed by {{linesExceed}}. Maximum allowed number of lines per function is {{maxLines}}."
|
83
84
|
}
|
84
85
|
},
|
85
86
|
|
@@ -169,18 +170,26 @@ module.exports = {
|
|
169
170
|
return;
|
170
171
|
}
|
171
172
|
let lineCount = 0;
|
173
|
+
let comments = 0;
|
174
|
+
let blankLines = 0;
|
172
175
|
|
173
176
|
for (let i = node.loc.start.line - 1; i < node.loc.end.line; ++i) {
|
174
177
|
const line = lines[i];
|
175
178
|
|
176
179
|
if (skipComments) {
|
177
180
|
if (commentLineNumbers.has(i + 1) && isFullLineComment(line, i + 1, commentLineNumbers.get(i + 1))) {
|
181
|
+
if (lineCount <= maxLines) {
|
182
|
+
comments++;
|
183
|
+
}
|
178
184
|
continue;
|
179
185
|
}
|
180
186
|
}
|
181
187
|
|
182
188
|
if (skipBlankLines) {
|
183
189
|
if (line.match(/^\s*$/u)) {
|
190
|
+
if (lineCount <= maxLines) {
|
191
|
+
blankLines++;
|
192
|
+
}
|
184
193
|
continue;
|
185
194
|
}
|
186
195
|
}
|
@@ -190,11 +199,21 @@ module.exports = {
|
|
190
199
|
|
191
200
|
if (lineCount > maxLines) {
|
192
201
|
const name = upperCaseFirst(astUtils.getFunctionNameWithKind(funcNode));
|
202
|
+
const linesExceed = lineCount - maxLines;
|
203
|
+
|
204
|
+
const loc = {
|
205
|
+
start: {
|
206
|
+
line: node.loc.start.line + maxLines + (comments + blankLines),
|
207
|
+
column: 0
|
208
|
+
},
|
209
|
+
end: node.loc.end
|
210
|
+
};
|
193
211
|
|
194
212
|
context.report({
|
195
213
|
node,
|
214
|
+
loc,
|
196
215
|
messageId: "exceed",
|
197
|
-
data: { name,
|
216
|
+
data: { name, linesExceed, maxLines }
|
198
217
|
});
|
199
218
|
}
|
200
219
|
}
|
package/lib/rules/max-lines.js
CHANGED
package/lib/rules/max-params.js
CHANGED
@@ -16,6 +16,7 @@ const { upperCaseFirst } = require("../shared/string-utils");
|
|
16
16
|
// Rule Definition
|
17
17
|
//------------------------------------------------------------------------------
|
18
18
|
|
19
|
+
/** @type {import('../shared/types').Rule} */
|
19
20
|
module.exports = {
|
20
21
|
meta: {
|
21
22
|
type: "suggestion",
|
@@ -16,6 +16,7 @@ const { upperCaseFirst } = require("../shared/string-utils");
|
|
16
16
|
// Rule Definition
|
17
17
|
//------------------------------------------------------------------------------
|
18
18
|
|
19
|
+
/** @type {import('../shared/types').Rule} */
|
19
20
|
module.exports = {
|
20
21
|
meta: {
|
21
22
|
type: "suggestion",
|
@@ -123,6 +124,14 @@ module.exports = {
|
|
123
124
|
function endFunction(node) {
|
124
125
|
const count = functionStack.pop();
|
125
126
|
|
127
|
+
/*
|
128
|
+
* This rule does not apply to class static blocks, but we have to track them so
|
129
|
+
* that stataments in them do not count as statements in the enclosing function.
|
130
|
+
*/
|
131
|
+
if (node.type === "StaticBlock") {
|
132
|
+
return;
|
133
|
+
}
|
134
|
+
|
126
135
|
if (ignoreTopLevelFunctions && functionStack.length === 0) {
|
127
136
|
topLevelFunctions.push({ node, count });
|
128
137
|
} else {
|
@@ -148,12 +157,14 @@ module.exports = {
|
|
148
157
|
FunctionDeclaration: startFunction,
|
149
158
|
FunctionExpression: startFunction,
|
150
159
|
ArrowFunctionExpression: startFunction,
|
160
|
+
StaticBlock: startFunction,
|
151
161
|
|
152
162
|
BlockStatement: countStatements,
|
153
163
|
|
154
164
|
"FunctionDeclaration:exit": endFunction,
|
155
165
|
"FunctionExpression:exit": endFunction,
|
156
166
|
"ArrowFunctionExpression:exit": endFunction,
|
167
|
+
"StaticBlock:exit": endFunction,
|
157
168
|
|
158
169
|
"Program:exit"() {
|
159
170
|
if (topLevelFunctions.length === 1) {
|
package/lib/rules/new-cap.js
CHANGED
package/lib/rules/new-parens.js
CHANGED
package/lib/rules/no-alert.js
CHANGED
@@ -82,6 +82,7 @@ function isGlobalThisReferenceOrGlobalWindow(scope, node) {
|
|
82
82
|
// Rule Definition
|
83
83
|
//------------------------------------------------------------------------------
|
84
84
|
|
85
|
+
/** @type {import('../shared/types').Rule} */
|
85
86
|
module.exports = {
|
86
87
|
meta: {
|
87
88
|
type: "suggestion",
|
package/lib/rules/no-bitwise.js
CHANGED