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/options.js
CHANGED
@@ -50,7 +50,7 @@ const optionator = require("optionator");
|
|
50
50
|
* @property {boolean | undefined} reportUnusedDisableDirectives Adds reported errors for unused eslint-disable directives
|
51
51
|
* @property {string} [resolvePluginsRelativeTo] A folder where plugins should be resolved from, CWD by default
|
52
52
|
* @property {Object} [rule] Specify rules
|
53
|
-
* @property {string[]} [rulesdir]
|
53
|
+
* @property {string[]} [rulesdir] Load additional rules from this directory. Deprecated: Use rules from plugins
|
54
54
|
* @property {boolean} stdin Lint code provided on <STDIN>
|
55
55
|
* @property {string} [stdinFilename] Specify filename to process STDIN as
|
56
56
|
* @property {boolean} quiet Report errors only
|
@@ -118,11 +118,6 @@ module.exports = optionator({
|
|
118
118
|
{
|
119
119
|
heading: "Specifying rules and plugins"
|
120
120
|
},
|
121
|
-
{
|
122
|
-
option: "rulesdir",
|
123
|
-
type: "[path::String]",
|
124
|
-
description: "Use additional rules from this directory"
|
125
|
-
},
|
126
121
|
{
|
127
122
|
option: "plugin",
|
128
123
|
type: "[String]",
|
@@ -133,6 +128,11 @@ module.exports = optionator({
|
|
133
128
|
type: "Object",
|
134
129
|
description: "Specify rules"
|
135
130
|
},
|
131
|
+
{
|
132
|
+
option: "rulesdir",
|
133
|
+
type: "[path::String]",
|
134
|
+
description: "Load additional rules from this directory. Deprecated: Use rules from plugins"
|
135
|
+
},
|
136
136
|
{
|
137
137
|
heading: "Fixing problems"
|
138
138
|
},
|
@@ -216,6 +216,9 @@ function freezeDeeply(x) {
|
|
216
216
|
* @returns {string} The sanitized text.
|
217
217
|
*/
|
218
218
|
function sanitize(text) {
|
219
|
+
if (typeof text !== "string") {
|
220
|
+
return "";
|
221
|
+
}
|
219
222
|
return text.replace(
|
220
223
|
/[\u0000-\u0009\u000b-\u001a]/gu, // eslint-disable-line no-control-regex -- Escaping controls
|
221
224
|
c => `\\u${c.codePointAt(0).toString(16).padStart(4, "0")}`
|
@@ -691,6 +694,13 @@ class RuleTester {
|
|
691
694
|
* @private
|
692
695
|
*/
|
693
696
|
function testValidTemplate(item) {
|
697
|
+
const code = typeof item === "object" ? item.code : item;
|
698
|
+
|
699
|
+
assert.ok(typeof code === "string", "Test case must specify a string value for 'code'");
|
700
|
+
if (item.name) {
|
701
|
+
assert.ok(typeof item.name === "string", "Optional test case property 'name' must be a string");
|
702
|
+
}
|
703
|
+
|
694
704
|
const result = runRuleForItem(item);
|
695
705
|
const messages = result.messages;
|
696
706
|
|
@@ -731,6 +741,10 @@ class RuleTester {
|
|
731
741
|
* @private
|
732
742
|
*/
|
733
743
|
function testInvalidTemplate(item) {
|
744
|
+
assert.ok(typeof item.code === "string", "Test case must specify a string value for 'code'");
|
745
|
+
if (item.name) {
|
746
|
+
assert.ok(typeof item.name === "string", "Optional test case property 'name' must be a string");
|
747
|
+
}
|
734
748
|
assert.ok(item.errors || item.errors === 0,
|
735
749
|
`Did not specify errors for an invalid test of ${ruleName}`);
|
736
750
|
|
@@ -134,6 +134,7 @@ function isPropertyDescriptor(node) {
|
|
134
134
|
// Rule Definition
|
135
135
|
//------------------------------------------------------------------------------
|
136
136
|
|
137
|
+
/** @type {import('../shared/types').Rule} */
|
137
138
|
module.exports = {
|
138
139
|
meta: {
|
139
140
|
type: "suggestion",
|
@@ -8,6 +8,7 @@
|
|
8
8
|
// Rule Definition
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
|
+
/** @type {import('../shared/types').Rule} */
|
11
12
|
module.exports = {
|
12
13
|
meta: {
|
13
14
|
type: "suggestion",
|
@@ -112,6 +113,8 @@ module.exports = {
|
|
112
113
|
"SwitchStatement:exit": exitScope,
|
113
114
|
CatchClause: enterScope,
|
114
115
|
"CatchClause:exit": exitScope,
|
116
|
+
StaticBlock: enterScope,
|
117
|
+
"StaticBlock:exit": exitScope,
|
115
118
|
|
116
119
|
// Finds and reports references which are outside of valid scope.
|
117
120
|
VariableDeclaration: checkForVariables
|
@@ -11,6 +11,7 @@ const util = require("./utils/ast-utils");
|
|
11
11
|
// Rule Definition
|
12
12
|
//------------------------------------------------------------------------------
|
13
13
|
|
14
|
+
/** @type {import('../shared/types').Rule} */
|
14
15
|
module.exports = {
|
15
16
|
meta: {
|
16
17
|
type: "layout",
|
@@ -40,7 +41,7 @@ module.exports = {
|
|
40
41
|
|
41
42
|
/**
|
42
43
|
* Gets the open brace token from a given node.
|
43
|
-
* @param {ASTNode} node A BlockStatement/SwitchStatement node to get.
|
44
|
+
* @param {ASTNode} node A BlockStatement/StaticBlock/SwitchStatement node to get.
|
44
45
|
* @returns {Token} The token of the open brace.
|
45
46
|
*/
|
46
47
|
function getOpenBrace(node) {
|
@@ -50,6 +51,12 @@ module.exports = {
|
|
50
51
|
}
|
51
52
|
return sourceCode.getLastToken(node, 1);
|
52
53
|
}
|
54
|
+
|
55
|
+
if (node.type === "StaticBlock") {
|
56
|
+
return sourceCode.getFirstToken(node, { skip: 1 }); // skip the `static` token
|
57
|
+
}
|
58
|
+
|
59
|
+
// "BlockStatement"
|
53
60
|
return sourceCode.getFirstToken(node);
|
54
61
|
}
|
55
62
|
|
@@ -72,8 +79,8 @@ module.exports = {
|
|
72
79
|
}
|
73
80
|
|
74
81
|
/**
|
75
|
-
*
|
76
|
-
* @param {ASTNode} node A BlockStatement/SwitchStatement node to
|
82
|
+
* Checks and reports invalid spacing style inside braces.
|
83
|
+
* @param {ASTNode} node A BlockStatement/StaticBlock/SwitchStatement node to check.
|
77
84
|
* @returns {void}
|
78
85
|
*/
|
79
86
|
function checkSpacingInsideBraces(node) {
|
@@ -157,6 +164,7 @@ module.exports = {
|
|
157
164
|
|
158
165
|
return {
|
159
166
|
BlockStatement: checkSpacingInsideBraces,
|
167
|
+
StaticBlock: checkSpacingInsideBraces,
|
160
168
|
SwitchStatement: checkSpacingInsideBraces
|
161
169
|
};
|
162
170
|
}
|
package/lib/rules/brace-style.js
CHANGED
@@ -11,6 +11,7 @@ const astUtils = require("./utils/ast-utils");
|
|
11
11
|
// Rule Definition
|
12
12
|
//------------------------------------------------------------------------------
|
13
13
|
|
14
|
+
/** @type {import('../shared/types').Rule} */
|
14
15
|
module.exports = {
|
15
16
|
meta: {
|
16
17
|
type: "layout",
|
@@ -155,6 +156,12 @@ module.exports = {
|
|
155
156
|
validateCurlyPair(sourceCode.getFirstToken(node), sourceCode.getLastToken(node));
|
156
157
|
}
|
157
158
|
},
|
159
|
+
StaticBlock(node) {
|
160
|
+
validateCurlyPair(
|
161
|
+
sourceCode.getFirstToken(node, { skip: 1 }), // skip the `static` token
|
162
|
+
sourceCode.getLastToken(node)
|
163
|
+
);
|
164
|
+
},
|
158
165
|
ClassBody(node) {
|
159
166
|
validateCurlyPair(sourceCode.getFirstToken(node), sourceCode.getLastToken(node));
|
160
167
|
},
|
package/lib/rules/camelcase.js
CHANGED
@@ -99,6 +99,7 @@ function createRegExpForIgnorePatterns(normalizedOptions) {
|
|
99
99
|
// Rule Definition
|
100
100
|
//------------------------------------------------------------------------------
|
101
101
|
|
102
|
+
/** @type {import('../shared/types').Rule} */
|
102
103
|
module.exports = {
|
103
104
|
meta: {
|
104
105
|
type: "suggestion",
|
@@ -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: "suggestion",
|
@@ -161,8 +162,17 @@ module.exports = {
|
|
161
162
|
/*
|
162
163
|
* Class field value are implicit functions.
|
163
164
|
*/
|
164
|
-
"PropertyDefinition:exit": popContext,
|
165
165
|
"PropertyDefinition > *.key:exit": pushContext,
|
166
|
+
"PropertyDefinition:exit": popContext,
|
167
|
+
|
168
|
+
/*
|
169
|
+
* Class static blocks are implicit functions. They aren't required to use `this`,
|
170
|
+
* but we have to push context so that it captures any use of `this` in the static block
|
171
|
+
* separately from enclosing contexts, because static blocks have their own `this` and it
|
172
|
+
* shouldn't count as used `this` in enclosing contexts.
|
173
|
+
*/
|
174
|
+
StaticBlock: pushContext,
|
175
|
+
"StaticBlock:exit": popContext,
|
166
176
|
|
167
177
|
ThisExpression: markThisUsed,
|
168
178
|
Super: markThisUsed,
|
@@ -70,6 +70,7 @@ function normalizeOptions(optionValue, ecmaVersion) {
|
|
70
70
|
// Rule Definition
|
71
71
|
//------------------------------------------------------------------------------
|
72
72
|
|
73
|
+
/** @type {import('../shared/types').Rule} */
|
73
74
|
module.exports = {
|
74
75
|
meta: {
|
75
76
|
type: "layout",
|
package/lib/rules/comma-style.js
CHANGED
package/lib/rules/complexity.js
CHANGED
@@ -17,6 +17,7 @@ const { upperCaseFirst } = require("../shared/string-utils");
|
|
17
17
|
// Rule Definition
|
18
18
|
//------------------------------------------------------------------------------
|
19
19
|
|
20
|
+
/** @type {import('../shared/types').Rule} */
|
20
21
|
module.exports = {
|
21
22
|
meta: {
|
22
23
|
type: "suggestion",
|
@@ -124,20 +125,28 @@ module.exports = {
|
|
124
125
|
|
125
126
|
/*
|
126
127
|
* This rule only evaluates complexity of functions, so "program" is excluded.
|
127
|
-
* Class field initializers are implicit functions. Therefore,
|
128
|
-
* to the enclosing function's complexity, but their
|
128
|
+
* Class field initializers and class static blocks are implicit functions. Therefore,
|
129
|
+
* they shouldn't contribute to the enclosing function's complexity, but their
|
130
|
+
* own complexity should be evaluated.
|
129
131
|
*/
|
130
132
|
if (
|
131
133
|
codePath.origin !== "function" &&
|
132
|
-
codePath.origin !== "class-field-initializer"
|
134
|
+
codePath.origin !== "class-field-initializer" &&
|
135
|
+
codePath.origin !== "class-static-block"
|
133
136
|
) {
|
134
137
|
return;
|
135
138
|
}
|
136
139
|
|
137
140
|
if (complexity > THRESHOLD) {
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
+
let name;
|
142
|
+
|
143
|
+
if (codePath.origin === "class-field-initializer") {
|
144
|
+
name = "class field initializer";
|
145
|
+
} else if (codePath.origin === "class-static-block") {
|
146
|
+
name = "class static block";
|
147
|
+
} else {
|
148
|
+
name = astUtils.getFunctionNameWithKind(node);
|
149
|
+
}
|
141
150
|
|
142
151
|
context.report({
|
143
152
|
node,
|
@@ -116,6 +116,7 @@ function isPossibleConstructor(node) {
|
|
116
116
|
// Rule Definition
|
117
117
|
//------------------------------------------------------------------------------
|
118
118
|
|
119
|
+
/** @type {import('../shared/types').Rule} */
|
119
120
|
module.exports = {
|
120
121
|
meta: {
|
121
122
|
type: "problem",
|
package/lib/rules/curly.js
CHANGED
@@ -10,6 +10,7 @@ const DEFAULT_COMMENT_PATTERN = /^no default$/iu;
|
|
10
10
|
// Rule Definition
|
11
11
|
//------------------------------------------------------------------------------
|
12
12
|
|
13
|
+
/** @type {import('../shared/types').Rule} */
|
13
14
|
module.exports = {
|
14
15
|
meta: {
|
15
16
|
type: "suggestion",
|
@@ -20,6 +20,7 @@ const validIdentifier = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/u;
|
|
20
20
|
// `null` literal must be handled separately.
|
21
21
|
const literalTypesToCheck = new Set(["string", "boolean"]);
|
22
22
|
|
23
|
+
/** @type {import('../shared/types').Rule} */
|
23
24
|
module.exports = {
|
24
25
|
meta: {
|
25
26
|
type: "suggestion",
|
package/lib/rules/eol-last.js
CHANGED
package/lib/rules/eqeqeq.js
CHANGED
package/lib/rules/func-names.js
CHANGED
package/lib/rules/func-style.js
CHANGED
@@ -110,6 +110,7 @@ function isShorthandPropertyDefinition(node) {
|
|
110
110
|
// Rule Definition
|
111
111
|
//------------------------------------------------------------------------------
|
112
112
|
|
113
|
+
/** @type {import('../shared/types').Rule} */
|
113
114
|
module.exports = {
|
114
115
|
meta: {
|
115
116
|
deprecated: true,
|
package/lib/rules/id-denylist.js
CHANGED