eslint 8.2.0 → 8.5.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 +7 -11
- package/conf/globals.js +144 -0
- 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 +11 -3
- 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/options.js +6 -6
- package/lib/rule-tester/rule-tester.js +14 -0
- 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 +24 -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 +1 -0
- package/lib/rules/keyword-spacing.js +2 -0
- 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 +1 -0
- 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 +1 -0
- package/lib/rules/no-unused-vars.js +1 -0
- package/lib/rules/no-use-before-define.js +33 -9
- 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-has-own.js +112 -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 +218 -1
- package/lib/rules/prefer-rest-params.js +1 -0
- package/lib/rules/prefer-spread.js +1 -0
- package/lib/rules/prefer-template.js +2 -1
- 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 +8 -8
package/lib/rules/id-match.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",
|
@@ -66,6 +67,8 @@ module.exports = {
|
|
66
67
|
onlyDeclarations = !!options.onlyDeclarations,
|
67
68
|
ignoreDestructuring = !!options.ignoreDestructuring;
|
68
69
|
|
70
|
+
let globalScope;
|
71
|
+
|
69
72
|
//--------------------------------------------------------------------------
|
70
73
|
// Helpers
|
71
74
|
//--------------------------------------------------------------------------
|
@@ -76,6 +79,19 @@ module.exports = {
|
|
76
79
|
const DECLARATION_TYPES = new Set(["FunctionDeclaration", "VariableDeclarator"]);
|
77
80
|
const IMPORT_TYPES = new Set(["ImportSpecifier", "ImportNamespaceSpecifier", "ImportDefaultSpecifier"]);
|
78
81
|
|
82
|
+
/**
|
83
|
+
* Checks whether the given node represents a reference to a global variable that is not declared in the source code.
|
84
|
+
* These identifiers will be allowed, as it is assumed that user has no control over the names of external global variables.
|
85
|
+
* @param {ASTNode} node `Identifier` node to check.
|
86
|
+
* @returns {boolean} `true` if the node is a reference to a global variable.
|
87
|
+
*/
|
88
|
+
function isReferenceToGlobalVariable(node) {
|
89
|
+
const variable = globalScope.set.get(node.name);
|
90
|
+
|
91
|
+
return variable && variable.defs.length === 0 &&
|
92
|
+
variable.references.some(ref => ref.identifier === node);
|
93
|
+
}
|
94
|
+
|
79
95
|
/**
|
80
96
|
* Checks if a string matches the provided pattern
|
81
97
|
* @param {string} name The string to check.
|
@@ -154,11 +170,19 @@ module.exports = {
|
|
154
170
|
|
155
171
|
return {
|
156
172
|
|
173
|
+
Program() {
|
174
|
+
globalScope = context.getScope();
|
175
|
+
},
|
176
|
+
|
157
177
|
Identifier(node) {
|
158
178
|
const name = node.name,
|
159
179
|
parent = node.parent,
|
160
180
|
effectiveParent = (parent.type === "MemberExpression") ? parent.parent : parent;
|
161
181
|
|
182
|
+
if (isReferenceToGlobalVariable(node)) {
|
183
|
+
return;
|
184
|
+
}
|
185
|
+
|
162
186
|
if (parent.type === "MemberExpression") {
|
163
187
|
|
164
188
|
if (!checkProperties) {
|
@@ -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
@@ -255,6 +255,7 @@ module.exports = new LazyLoadingRuleMap(Object.entries({
|
|
255
255
|
"prefer-exponentiation-operator": () => require("./prefer-exponentiation-operator"),
|
256
256
|
"prefer-named-capture-group": () => require("./prefer-named-capture-group"),
|
257
257
|
"prefer-numeric-literals": () => require("./prefer-numeric-literals"),
|
258
|
+
"prefer-object-has-own": () => require("./prefer-object-has-own"),
|
258
259
|
"prefer-object-spread": () => require("./prefer-object-spread"),
|
259
260
|
"prefer-promise-reject-errors": () => require("./prefer-promise-reject-errors"),
|
260
261
|
"prefer-reflect": () => require("./prefer-reflect"),
|
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",
|
@@ -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",
|
@@ -590,6 +591,7 @@ module.exports = {
|
|
590
591
|
ImportNamespaceSpecifier: checkSpacingForImportNamespaceSpecifier,
|
591
592
|
MethodDefinition: checkSpacingForProperty,
|
592
593
|
PropertyDefinition: checkSpacingForProperty,
|
594
|
+
StaticBlock: checkSpacingAroundFirstToken,
|
593
595
|
Property: checkSpacingForProperty,
|
594
596
|
|
595
597
|
// To avoid conflicts with `space-infix-ops`, e.g. `a > this.b`
|
@@ -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
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
package/lib/rules/no-caller.js
CHANGED
package/lib/rules/no-console.js
CHANGED