oxlint-plugin-eslint 1.52.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/LICENSE +22 -0
- package/README.md +36 -0
- package/common/ast-utils.cjs +5843 -0
- package/common/chunk.cjs +9 -0
- package/common/eslint-utils.cjs +1633 -0
- package/common/fix-tracker.cjs +89 -0
- package/common/ignore.cjs +123 -0
- package/common/keywords.cjs +15 -0
- package/common/regexpp.cjs +1720 -0
- package/common/regular-expressions.cjs +40 -0
- package/common/string-utils.cjs +39 -0
- package/index.js +7477 -0
- package/package.json +34 -0
- package/rules/accessor-pairs.cjs +233 -0
- package/rules/array-bracket-newline.cjs +172 -0
- package/rules/array-bracket-spacing.cjs +184 -0
- package/rules/array-callback-return.cjs +262 -0
- package/rules/array-element-newline.cjs +178 -0
- package/rules/arrow-body-style.cjs +135 -0
- package/rules/arrow-parens.cjs +130 -0
- package/rules/arrow-spacing.cjs +129 -0
- package/rules/block-scoped-var.cjs +101 -0
- package/rules/block-spacing.cjs +125 -0
- package/rules/brace-style.cjs +141 -0
- package/rules/callback-return.cjs +117 -0
- package/rules/camelcase.cjs +194 -0
- package/rules/capitalized-comments.cjs +168 -0
- package/rules/class-methods-use-this.cjs +155 -0
- package/rules/comma-dangle.cjs +274 -0
- package/rules/comma-spacing.cjs +111 -0
- package/rules/comma-style.cjs +180 -0
- package/rules/complexity.cjs +100 -0
- package/rules/computed-property-spacing.cjs +155 -0
- package/rules/consistent-return.cjs +113 -0
- package/rules/consistent-this.cjs +109 -0
- package/rules/constructor-super.cjs +207 -0
- package/rules/curly.cjs +173 -0
- package/rules/default-case-last.cjs +36 -0
- package/rules/default-case.cjs +50 -0
- package/rules/default-param-last.cjs +61 -0
- package/rules/dot-location.cjs +87 -0
- package/rules/dot-notation.cjs +77 -0
- package/rules/eol-last.cjs +91 -0
- package/rules/eqeqeq.cjs +127 -0
- package/rules/for-direction.cjs +94 -0
- package/rules/func-call-spacing.cjs +127 -0
- package/rules/func-name-matching.cjs +138 -0
- package/rules/func-names.cjs +121 -0
- package/rules/func-style.cjs +103 -0
- package/rules/function-call-argument-newline.cjs +109 -0
- package/rules/function-paren-newline.cjs +173 -0
- package/rules/generator-star-spacing.cjs +174 -0
- package/rules/getter-return.cjs +129 -0
- package/rules/global-require.cjs +84 -0
- package/rules/grouped-accessor-pairs.cjs +146 -0
- package/rules/guard-for-in.cjs +39 -0
- package/rules/handle-callback-err.cjs +86 -0
- package/rules/id-blacklist.cjs +135 -0
- package/rules/id-denylist.cjs +126 -0
- package/rules/id-length.cjs +119 -0
- package/rules/id-match.cjs +139 -0
- package/rules/implicit-arrow-linebreak.cjs +76 -0
- package/rules/indent-legacy.cjs +520 -0
- package/rules/indent.cjs +842 -0
- package/rules/init-declarations.cjs +88 -0
- package/rules/jsx-quotes.cjs +84 -0
- package/rules/key-spacing.cjs +399 -0
- package/rules/keyword-spacing.cjs +464 -0
- package/rules/line-comment-position.cjs +75 -0
- package/rules/linebreak-style.cjs +89 -0
- package/rules/lines-around-comment.cjs +290 -0
- package/rules/lines-around-directive.cjs +129 -0
- package/rules/lines-between-class-members.cjs +212 -0
- package/rules/logical-assignment-operators.cjs +305 -0
- package/rules/max-classes-per-file.cjs +61 -0
- package/rules/max-depth.cjs +117 -0
- package/rules/max-len.cjs +256 -0
- package/rules/max-lines-per-function.cjs +116 -0
- package/rules/max-lines.cjs +109 -0
- package/rules/max-nested-callbacks.cjs +78 -0
- package/rules/max-params.cjs +78 -0
- package/rules/max-statements-per-line.cjs +147 -0
- package/rules/max-statements.cjs +119 -0
- package/rules/multiline-comment-style.cjs +319 -0
- package/rules/multiline-ternary.cjs +106 -0
- package/rules/new-cap.cjs +139 -0
- package/rules/new-parens.cjs +70 -0
- package/rules/newline-after-var.cjs +159 -0
- package/rules/newline-before-return.cjs +128 -0
- package/rules/newline-per-chained-call.cjs +100 -0
- package/rules/no-alert.cjs +84 -0
- package/rules/no-array-constructor.cjs +91 -0
- package/rules/no-async-promise-executor.cjs +33 -0
- package/rules/no-await-in-loop.cjs +75 -0
- package/rules/no-bitwise.cjs +106 -0
- package/rules/no-buffer-constructor.cjs +51 -0
- package/rules/no-caller.cjs +34 -0
- package/rules/no-case-declarations.cjs +56 -0
- package/rules/no-catch-shadow.cjs +57 -0
- package/rules/no-class-assign.cjs +55 -0
- package/rules/no-compare-neg-zero.cjs +52 -0
- package/rules/no-cond-assign.cjs +104 -0
- package/rules/no-confusing-arrow.cjs +87 -0
- package/rules/no-console.cjs +138 -0
- package/rules/no-const-assign.cjs +50 -0
- package/rules/no-constant-binary-expression.cjs +284 -0
- package/rules/no-constant-condition.cjs +119 -0
- package/rules/no-constructor-return.cjs +43 -0
- package/rules/no-continue.cjs +33 -0
- package/rules/no-control-regex.cjs +74 -0
- package/rules/no-debugger.cjs +33 -0
- package/rules/no-delete-var.cjs +32 -0
- package/rules/no-div-regex.cjs +39 -0
- package/rules/no-dupe-args.cjs +61 -0
- package/rules/no-dupe-class-members.cjs +77 -0
- package/rules/no-dupe-else-if.cjs +74 -0
- package/rules/no-dupe-keys.cjs +88 -0
- package/rules/no-duplicate-case.cjs +49 -0
- package/rules/no-duplicate-imports.cjs +166 -0
- package/rules/no-else-return.cjs +182 -0
- package/rules/no-empty-character-class.cjs +47 -0
- package/rules/no-empty-function.cjs +141 -0
- package/rules/no-empty-pattern.cjs +50 -0
- package/rules/no-empty-static-block.cjs +50 -0
- package/rules/no-empty.cjs +78 -0
- package/rules/no-eq-null.cjs +34 -0
- package/rules/no-eval.cjs +165 -0
- package/rules/no-ex-assign.cjs +45 -0
- package/rules/no-extend-native.cjs +103 -0
- package/rules/no-extra-bind.cjs +127 -0
- package/rules/no-extra-boolean-cast.cjs +159 -0
- package/rules/no-extra-label.cjs +116 -0
- package/rules/no-extra-parens.cjs +665 -0
- package/rules/no-extra-semi.cjs +103 -0
- package/rules/no-fallthrough.cjs +136 -0
- package/rules/no-floating-decimal.cjs +66 -0
- package/rules/no-func-assign.cjs +63 -0
- package/rules/no-global-assign.cjs +62 -0
- package/rules/no-implicit-coercion.cjs +219 -0
- package/rules/no-implicit-globals.cjs +77 -0
- package/rules/no-implied-eval.cjs +87 -0
- package/rules/no-import-assign.cjs +123 -0
- package/rules/no-inline-comments.cjs +57 -0
- package/rules/no-inner-declarations.cjs +82 -0
- package/rules/no-invalid-regexp.cjs +130 -0
- package/rules/no-invalid-this.cjs +90 -0
- package/rules/no-irregular-whitespace.cjs +157 -0
- package/rules/no-iterator.cjs +34 -0
- package/rules/no-label-var.cjs +46 -0
- package/rules/no-labels.cjs +106 -0
- package/rules/no-lone-blocks.cjs +75 -0
- package/rules/no-lonely-if.cjs +42 -0
- package/rules/no-loop-func.cjs +143 -0
- package/rules/no-loss-of-precision.cjs +160 -0
- package/rules/no-magic-numbers.cjs +222 -0
- package/rules/no-misleading-character-class.cjs +500 -0
- package/rules/no-mixed-operators.cjs +197 -0
- package/rules/no-mixed-requires.cjs +117 -0
- package/rules/no-mixed-spaces-and-tabs.cjs +87 -0
- package/rules/no-multi-assign.cjs +38 -0
- package/rules/no-multi-spaces.cjs +95 -0
- package/rules/no-multi-str.cjs +44 -0
- package/rules/no-multiple-empty-lines.cjs +112 -0
- package/rules/no-native-reassign.cjs +72 -0
- package/rules/no-negated-condition.cjs +77 -0
- package/rules/no-negated-in-lhs.cjs +43 -0
- package/rules/no-nested-ternary.cjs +33 -0
- package/rules/no-new-func.cjs +50 -0
- package/rules/no-new-native-nonconstructor.cjs +42 -0
- package/rules/no-new-object.cjs +47 -0
- package/rules/no-new-require.cjs +50 -0
- package/rules/no-new-symbol.cjs +48 -0
- package/rules/no-new-wrappers.cjs +44 -0
- package/rules/no-new.cjs +33 -0
- package/rules/no-nonoctal-decimal-escape.cjs +80 -0
- package/rules/no-obj-calls.cjs +64 -0
- package/rules/no-object-constructor.cjs +69 -0
- package/rules/no-octal-escape.cjs +35 -0
- package/rules/no-octal.cjs +32 -0
- package/rules/no-param-reassign.cjs +135 -0
- package/rules/no-path-concat.cjs +52 -0
- package/rules/no-plusplus.cjs +64 -0
- package/rules/no-process-env.cjs +51 -0
- package/rules/no-process-exit.cjs +50 -0
- package/rules/no-promise-executor-return.cjs +131 -0
- package/rules/no-proto.cjs +34 -0
- package/rules/no-prototype-builtins.cjs +85 -0
- package/rules/no-redeclare.cjs +103 -0
- package/rules/no-regex-spaces.cjs +115 -0
- package/rules/no-restricted-exports.cjs +117 -0
- package/rules/no-restricted-globals.cjs +147 -0
- package/rules/no-restricted-imports.cjs +421 -0
- package/rules/no-restricted-modules.cjs +144 -0
- package/rules/no-restricted-properties.cjs +123 -0
- package/rules/no-restricted-syntax.cjs +49 -0
- package/rules/no-return-assign.cjs +45 -0
- package/rules/no-return-await.cjs +88 -0
- package/rules/no-script-url.cjs +49 -0
- package/rules/no-self-assign.cjs +88 -0
- package/rules/no-self-compare.cjs +53 -0
- package/rules/no-sequences.cjs +81 -0
- package/rules/no-setter-return.cjs +110 -0
- package/rules/no-shadow-restricted-names.cjs +60 -0
- package/rules/no-shadow.cjs +302 -0
- package/rules/no-spaced-func.cjs +69 -0
- package/rules/no-sparse-arrays.cjs +40 -0
- package/rules/no-sync.cjs +58 -0
- package/rules/no-tabs.cjs +73 -0
- package/rules/no-template-curly-in-string.cjs +33 -0
- package/rules/no-ternary.cjs +33 -0
- package/rules/no-this-before-super.cjs +177 -0
- package/rules/no-throw-literal.cjs +40 -0
- package/rules/no-trailing-spaces.cjs +123 -0
- package/rules/no-unassigned-vars.cjs +54 -0
- package/rules/no-undef-init.cjs +46 -0
- package/rules/no-undef.cjs +51 -0
- package/rules/no-undefined.cjs +58 -0
- package/rules/no-underscore-dangle.cjs +211 -0
- package/rules/no-unexpected-multiline.cjs +76 -0
- package/rules/no-unmodified-loop-condition.cjs +849 -0
- package/rules/no-unneeded-ternary.cjs +112 -0
- package/rules/no-unreachable-loop.cjs +128 -0
- package/rules/no-unreachable.cjs +195 -0
- package/rules/no-unsafe-finally.cjs +67 -0
- package/rules/no-unsafe-negation.cjs +86 -0
- package/rules/no-unsafe-optional-chaining.cjs +164 -0
- package/rules/no-unused-expressions.cjs +163 -0
- package/rules/no-unused-labels.cjs +97 -0
- package/rules/no-unused-private-class-members.cjs +69 -0
- package/rules/no-unused-vars.cjs +639 -0
- package/rules/no-use-before-define.cjs +245 -0
- package/rules/no-useless-assignment.cjs +250 -0
- package/rules/no-useless-backreference.cjs +137 -0
- package/rules/no-useless-call.cjs +57 -0
- package/rules/no-useless-catch.cjs +38 -0
- package/rules/no-useless-computed-key.cjs +106 -0
- package/rules/no-useless-concat.cjs +78 -0
- package/rules/no-useless-constructor.cjs +152 -0
- package/rules/no-useless-escape.cjs +164 -0
- package/rules/no-useless-rename.cjs +94 -0
- package/rules/no-useless-return.cjs +229 -0
- package/rules/no-var.cjs +235 -0
- package/rules/no-void.cjs +39 -0
- package/rules/no-warning-comments.cjs +112 -0
- package/rules/no-whitespace-before-property.cjs +72 -0
- package/rules/no-with.cjs +32 -0
- package/rules/nonblock-statement-body-position.cjs +107 -0
- package/rules/object-curly-newline.cjs +194 -0
- package/rules/object-curly-spacing.cjs +225 -0
- package/rules/object-property-newline.cjs +81 -0
- package/rules/object-shorthand.cjs +284 -0
- package/rules/one-var-declaration-per-line.cjs +75 -0
- package/rules/one-var.cjs +378 -0
- package/rules/operator-assignment.cjs +146 -0
- package/rules/operator-linebreak.cjs +150 -0
- package/rules/padded-blocks.cjs +192 -0
- package/rules/padding-line-between-statements.cjs +377 -0
- package/rules/prefer-arrow-callback.cjs +185 -0
- package/rules/prefer-const.cjs +240 -0
- package/rules/prefer-destructuring.cjs +188 -0
- package/rules/prefer-exponentiation-operator.cjs +100 -0
- package/rules/prefer-named-capture-group.cjs +111 -0
- package/rules/prefer-numeric-literals.cjs +75 -0
- package/rules/prefer-object-has-own.cjs +54 -0
- package/rules/prefer-object-spread.cjs +170 -0
- package/rules/prefer-promise-reject-errors.cjs +62 -0
- package/rules/prefer-reflect.cjs +100 -0
- package/rules/prefer-regex-literals.cjs +256 -0
- package/rules/prefer-rest-params.cjs +80 -0
- package/rules/prefer-spread.cjs +57 -0
- package/rules/prefer-template.cjs +147 -0
- package/rules/preserve-caught-error.cjs +196 -0
- package/rules/quote-props.cjs +224 -0
- package/rules/quotes.cjs +187 -0
- package/rules/radix.cjs +124 -0
- package/rules/require-atomic-updates.cjs +197 -0
- package/rules/require-await.cjs +90 -0
- package/rules/require-unicode-regexp.cjs +101 -0
- package/rules/require-yield.cjs +56 -0
- package/rules/rest-spread-spacing.cjs +99 -0
- package/rules/semi-spacing.cjs +215 -0
- package/rules/semi-style.cjs +116 -0
- package/rules/semi.cjs +239 -0
- package/rules/sort-imports.cjs +140 -0
- package/rules/sort-keys.cjs +165 -0
- package/rules/sort-vars.cjs +50 -0
- package/rules/space-before-blocks.cjs +132 -0
- package/rules/space-before-function-paren.cjs +126 -0
- package/rules/space-in-parens.cjs +175 -0
- package/rules/space-infix-ops.cjs +133 -0
- package/rules/space-unary-ops.cjs +237 -0
- package/rules/spaced-comment.cjs +233 -0
- package/rules/strict.cjs +206 -0
- package/rules/switch-colon-spacing.cjs +114 -0
- package/rules/symbol-description.cjs +49 -0
- package/rules/template-curly-spacing.cjs +112 -0
- package/rules/template-tag-spacing.cjs +82 -0
- package/rules/unicode-bom.cjs +52 -0
- package/rules/use-isnan.cjs +144 -0
- package/rules/valid-typeof.cjs +104 -0
- package/rules/vars-on-top.cjs +94 -0
- package/rules/wrap-iife.cjs +131 -0
- package/rules/wrap-regex.cjs +57 -0
- package/rules/yield-star-spacing.cjs +115 -0
- package/rules/yoda.cjs +185 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const require_chunk = require("../common/chunk.cjs"), require_ast_utils$1 = require("../common/ast-utils.cjs");
|
|
2
|
+
//#region ../../node_modules/.pnpm/eslint@9.39.3_jiti@2.6.1/node_modules/eslint/lib/rules/no-useless-call.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview A rule to disallow unnecessary `.call()` and `.apply()`.
|
|
5
|
+
* @author Toru Nagashima
|
|
6
|
+
*/
|
|
7
|
+
var require_no_useless_call = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
8
|
+
let astUtils = require_ast_utils$1.t();
|
|
9
|
+
/**
|
|
10
|
+
* Checks whether or not a node is a `.call()`/`.apply()`.
|
|
11
|
+
* @param {ASTNode} node A CallExpression node to check.
|
|
12
|
+
* @returns {boolean} Whether or not the node is a `.call()`/`.apply()`.
|
|
13
|
+
*/
|
|
14
|
+
function isCallOrNonVariadicApply(node) {
|
|
15
|
+
let callee = astUtils.skipChainExpression(node.callee);
|
|
16
|
+
return callee.type === "MemberExpression" && callee.property.type === "Identifier" && callee.computed === !1 && (callee.property.name === "call" && node.arguments.length >= 1 || callee.property.name === "apply" && node.arguments.length === 2 && node.arguments[1].type === "ArrayExpression");
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Checks whether or not `thisArg` is not changed by `.call()`/`.apply()`.
|
|
20
|
+
* @param {ASTNode|null} expectedThis The node that is the owner of the applied function.
|
|
21
|
+
* @param {ASTNode} thisArg The node that is given to the first argument of the `.call()`/`.apply()`.
|
|
22
|
+
* @param {SourceCode} sourceCode The ESLint source code object.
|
|
23
|
+
* @returns {boolean} Whether or not `thisArg` is not changed by `.call()`/`.apply()`.
|
|
24
|
+
*/
|
|
25
|
+
function isValidThisArg(expectedThis, thisArg, sourceCode) {
|
|
26
|
+
return expectedThis ? astUtils.equalTokens(expectedThis, thisArg, sourceCode) : astUtils.isNullOrUndefined(thisArg);
|
|
27
|
+
}
|
|
28
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
29
|
+
module.exports = {
|
|
30
|
+
meta: {
|
|
31
|
+
type: "suggestion",
|
|
32
|
+
docs: {
|
|
33
|
+
description: "Disallow unnecessary calls to `.call()` and `.apply()`",
|
|
34
|
+
recommended: !1,
|
|
35
|
+
url: "https://eslint.org/docs/latest/rules/no-useless-call"
|
|
36
|
+
},
|
|
37
|
+
schema: [],
|
|
38
|
+
messages: { unnecessaryCall: "Unnecessary '.{{name}}()'." }
|
|
39
|
+
},
|
|
40
|
+
create(context) {
|
|
41
|
+
let sourceCode = context.sourceCode;
|
|
42
|
+
return { CallExpression(node) {
|
|
43
|
+
if (!isCallOrNonVariadicApply(node)) return;
|
|
44
|
+
let callee = astUtils.skipChainExpression(node.callee), applied = astUtils.skipChainExpression(callee.object), expectedThis = applied.type === "MemberExpression" ? applied.object : null, thisArg = node.arguments[0];
|
|
45
|
+
isValidThisArg(expectedThis, thisArg, sourceCode) && context.report({
|
|
46
|
+
node,
|
|
47
|
+
messageId: "unnecessaryCall",
|
|
48
|
+
data: { name: callee.property.name }
|
|
49
|
+
});
|
|
50
|
+
} };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}));
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src-js/generated/plugin-eslint/rules/no-useless-call.cjs
|
|
56
|
+
module.exports = require_no_useless_call().create;
|
|
57
|
+
//#endregion
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/eslint@9.39.3_jiti@2.6.1/node_modules/eslint/lib/rules/no-useless-catch.js
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Reports useless `catch` clauses that just rethrow their error.
|
|
4
|
+
* @author Teddy Katz
|
|
5
|
+
*/
|
|
6
|
+
var require_no_useless_catch = /* @__PURE__ */ require("../common/chunk.cjs").t(((exports, module) => {
|
|
7
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
8
|
+
module.exports = {
|
|
9
|
+
meta: {
|
|
10
|
+
type: "suggestion",
|
|
11
|
+
docs: {
|
|
12
|
+
description: "Disallow unnecessary `catch` clauses",
|
|
13
|
+
recommended: !0,
|
|
14
|
+
url: "https://eslint.org/docs/latest/rules/no-useless-catch"
|
|
15
|
+
},
|
|
16
|
+
schema: [],
|
|
17
|
+
messages: {
|
|
18
|
+
unnecessaryCatchClause: "Unnecessary catch clause.",
|
|
19
|
+
unnecessaryCatch: "Unnecessary try/catch wrapper."
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
create(context) {
|
|
23
|
+
return { CatchClause(node) {
|
|
24
|
+
node.param && node.param.type === "Identifier" && node.body.body.length && node.body.body[0].type === "ThrowStatement" && node.body.body[0].argument.type === "Identifier" && node.body.body[0].argument.name === node.param.name && (node.parent.finalizer ? context.report({
|
|
25
|
+
node,
|
|
26
|
+
messageId: "unnecessaryCatchClause"
|
|
27
|
+
}) : context.report({
|
|
28
|
+
node: node.parent,
|
|
29
|
+
messageId: "unnecessaryCatch"
|
|
30
|
+
}));
|
|
31
|
+
} };
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}));
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src-js/generated/plugin-eslint/rules/no-useless-catch.cjs
|
|
37
|
+
module.exports = require_no_useless_catch().create;
|
|
38
|
+
//#endregion
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
const require_chunk = require("../common/chunk.cjs"), require_ast_utils$1 = require("../common/ast-utils.cjs");
|
|
2
|
+
//#region ../../node_modules/.pnpm/eslint@9.39.3_jiti@2.6.1/node_modules/eslint/lib/rules/no-useless-computed-key.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Rule to disallow unnecessary computed property keys in object literals
|
|
5
|
+
* @author Burak Yigit Kaya
|
|
6
|
+
*/
|
|
7
|
+
var require_no_useless_computed_key = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
8
|
+
let astUtils = require_ast_utils$1.t();
|
|
9
|
+
/**
|
|
10
|
+
* Determines whether the computed key syntax is unnecessarily used for the given node.
|
|
11
|
+
* In particular, it determines whether removing the square brackets and using the content between them
|
|
12
|
+
* directly as the key (e.g. ['foo'] -> 'foo') would produce valid syntax and preserve the same behavior.
|
|
13
|
+
* Valid non-computed keys are only: identifiers, number literals and string literals.
|
|
14
|
+
* Only literals can preserve the same behavior, with a few exceptions for specific node types:
|
|
15
|
+
* Property
|
|
16
|
+
* - { ["__proto__"]: foo } defines a property named "__proto__"
|
|
17
|
+
* { "__proto__": foo } defines object's prototype
|
|
18
|
+
* PropertyDefinition
|
|
19
|
+
* - class C { ["constructor"]; } defines an instance field named "constructor"
|
|
20
|
+
* class C { "constructor"; } produces a parsing error
|
|
21
|
+
* - class C { static ["constructor"]; } defines a static field named "constructor"
|
|
22
|
+
* class C { static "constructor"; } produces a parsing error
|
|
23
|
+
* - class C { static ["prototype"]; } produces a runtime error (doesn't break the whole script)
|
|
24
|
+
* class C { static "prototype"; } produces a parsing error (breaks the whole script)
|
|
25
|
+
* MethodDefinition
|
|
26
|
+
* - class C { ["constructor"]() {} } defines a prototype method named "constructor"
|
|
27
|
+
* class C { "constructor"() {} } defines the constructor
|
|
28
|
+
* - class C { static ["prototype"]() {} } produces a runtime error (doesn't break the whole script)
|
|
29
|
+
* class C { static "prototype"() {} } produces a parsing error (breaks the whole script)
|
|
30
|
+
* @param {ASTNode} node The node to check. It can be `Property`, `PropertyDefinition` or `MethodDefinition`.
|
|
31
|
+
* @throws {Error} (Unreachable.)
|
|
32
|
+
* @returns {void} `true` if the node has useless computed key.
|
|
33
|
+
*/
|
|
34
|
+
function hasUselessComputedKey(node) {
|
|
35
|
+
if (!node.computed) return !1;
|
|
36
|
+
let { key } = node;
|
|
37
|
+
if (key.type !== "Literal") return !1;
|
|
38
|
+
let { value } = key;
|
|
39
|
+
if (typeof value != "number" && typeof value != "string") return !1;
|
|
40
|
+
switch (node.type) {
|
|
41
|
+
case "Property": return node.parent.type === "ObjectExpression" ? value !== "__proto__" : !0;
|
|
42
|
+
case "PropertyDefinition": return node.static ? value !== "constructor" && value !== "prototype" : value !== "constructor";
|
|
43
|
+
case "MethodDefinition": return node.static ? value !== "prototype" : value !== "constructor";
|
|
44
|
+
default: throw Error(`Unexpected node type: ${node.type}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
48
|
+
module.exports = {
|
|
49
|
+
meta: {
|
|
50
|
+
type: "suggestion",
|
|
51
|
+
defaultOptions: [{ enforceForClassMembers: !0 }],
|
|
52
|
+
docs: {
|
|
53
|
+
description: "Disallow unnecessary computed property keys in objects and classes",
|
|
54
|
+
recommended: !1,
|
|
55
|
+
frozen: !0,
|
|
56
|
+
url: "https://eslint.org/docs/latest/rules/no-useless-computed-key"
|
|
57
|
+
},
|
|
58
|
+
schema: [{
|
|
59
|
+
type: "object",
|
|
60
|
+
properties: { enforceForClassMembers: { type: "boolean" } },
|
|
61
|
+
additionalProperties: !1
|
|
62
|
+
}],
|
|
63
|
+
fixable: "code",
|
|
64
|
+
messages: { unnecessarilyComputedProperty: "Unnecessarily computed property [{{property}}] found." }
|
|
65
|
+
},
|
|
66
|
+
create(context) {
|
|
67
|
+
let sourceCode = context.sourceCode, [{ enforceForClassMembers }] = context.options;
|
|
68
|
+
/**
|
|
69
|
+
* Reports a given node if it violated this rule.
|
|
70
|
+
* @param {ASTNode} node The node to check.
|
|
71
|
+
* @returns {void}
|
|
72
|
+
*/
|
|
73
|
+
function check(node) {
|
|
74
|
+
if (hasUselessComputedKey(node)) {
|
|
75
|
+
let { key } = node;
|
|
76
|
+
context.report({
|
|
77
|
+
node,
|
|
78
|
+
messageId: "unnecessarilyComputedProperty",
|
|
79
|
+
data: { property: sourceCode.getText(key) },
|
|
80
|
+
fix(fixer) {
|
|
81
|
+
let leftSquareBracket = sourceCode.getTokenBefore(key, astUtils.isOpeningBracketToken), rightSquareBracket = sourceCode.getTokenAfter(key, astUtils.isClosingBracketToken);
|
|
82
|
+
if (sourceCode.commentsExistBetween(leftSquareBracket, rightSquareBracket)) return null;
|
|
83
|
+
let tokenBeforeLeftBracket = sourceCode.getTokenBefore(leftSquareBracket), replacementKey = (tokenBeforeLeftBracket.range[1] === leftSquareBracket.range[0] && !astUtils.canTokensBeAdjacent(tokenBeforeLeftBracket, sourceCode.getFirstToken(key)) ? " " : "") + key.raw;
|
|
84
|
+
return fixer.replaceTextRange([leftSquareBracket.range[0], rightSquareBracket.range[1]], replacementKey);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* A no-op function to act as placeholder for checking a node when the `enforceForClassMembers` option is `false`.
|
|
91
|
+
* @returns {void}
|
|
92
|
+
* @private
|
|
93
|
+
*/
|
|
94
|
+
function noop() {}
|
|
95
|
+
return {
|
|
96
|
+
Property: check,
|
|
97
|
+
MethodDefinition: enforceForClassMembers ? check : noop,
|
|
98
|
+
PropertyDefinition: enforceForClassMembers ? check : noop
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}));
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src-js/generated/plugin-eslint/rules/no-useless-computed-key.cjs
|
|
105
|
+
module.exports = require_no_useless_computed_key().create;
|
|
106
|
+
//#endregion
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
const require_chunk = require("../common/chunk.cjs"), require_ast_utils$1 = require("../common/ast-utils.cjs");
|
|
2
|
+
//#region ../../node_modules/.pnpm/eslint@9.39.3_jiti@2.6.1/node_modules/eslint/lib/rules/no-useless-concat.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview disallow unnecessary concatenation of template strings
|
|
5
|
+
* @author Henry Zhu
|
|
6
|
+
*/
|
|
7
|
+
var require_no_useless_concat = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
8
|
+
let astUtils = require_ast_utils$1.t();
|
|
9
|
+
/**
|
|
10
|
+
* Checks whether or not a given node is a concatenation.
|
|
11
|
+
* @param {ASTNode} node A node to check.
|
|
12
|
+
* @returns {boolean} `true` if the node is a concatenation.
|
|
13
|
+
*/
|
|
14
|
+
function isConcatenation(node) {
|
|
15
|
+
return node.type === "BinaryExpression" && node.operator === "+";
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Checks if the given token is a `+` token or not.
|
|
19
|
+
* @param {Token} token The token to check.
|
|
20
|
+
* @returns {boolean} `true` if the token is a `+` token.
|
|
21
|
+
*/
|
|
22
|
+
function isConcatOperatorToken(token) {
|
|
23
|
+
return token.value === "+" && token.type === "Punctuator";
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get's the right most node on the left side of a BinaryExpression with + operator.
|
|
27
|
+
* @param {ASTNode} node A BinaryExpression node to check.
|
|
28
|
+
* @returns {ASTNode} node
|
|
29
|
+
*/
|
|
30
|
+
function getLeft(node) {
|
|
31
|
+
let left = node.left;
|
|
32
|
+
for (; isConcatenation(left);) left = left.right;
|
|
33
|
+
return left;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Get's the left most node on the right side of a BinaryExpression with + operator.
|
|
37
|
+
* @param {ASTNode} node A BinaryExpression node to check.
|
|
38
|
+
* @returns {ASTNode} node
|
|
39
|
+
*/
|
|
40
|
+
function getRight(node) {
|
|
41
|
+
let right = node.right;
|
|
42
|
+
for (; isConcatenation(right);) right = right.left;
|
|
43
|
+
return right;
|
|
44
|
+
}
|
|
45
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
46
|
+
module.exports = {
|
|
47
|
+
meta: {
|
|
48
|
+
type: "suggestion",
|
|
49
|
+
docs: {
|
|
50
|
+
description: "Disallow unnecessary concatenation of literals or template literals",
|
|
51
|
+
recommended: !1,
|
|
52
|
+
frozen: !0,
|
|
53
|
+
url: "https://eslint.org/docs/latest/rules/no-useless-concat"
|
|
54
|
+
},
|
|
55
|
+
schema: [],
|
|
56
|
+
messages: { unexpectedConcat: "Unexpected string concatenation of literals." }
|
|
57
|
+
},
|
|
58
|
+
create(context) {
|
|
59
|
+
let sourceCode = context.sourceCode;
|
|
60
|
+
return { BinaryExpression(node) {
|
|
61
|
+
if (node.operator !== "+") return;
|
|
62
|
+
let left = getLeft(node), right = getRight(node);
|
|
63
|
+
if (astUtils.isStringLiteral(left) && astUtils.isStringLiteral(right) && astUtils.isTokenOnSameLine(left, right)) {
|
|
64
|
+
let operatorToken = sourceCode.getFirstTokenBetween(left, right, isConcatOperatorToken);
|
|
65
|
+
context.report({
|
|
66
|
+
node,
|
|
67
|
+
loc: operatorToken.loc,
|
|
68
|
+
messageId: "unexpectedConcat"
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
} };
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}));
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src-js/generated/plugin-eslint/rules/no-useless-concat.cjs
|
|
77
|
+
module.exports = require_no_useless_concat().create;
|
|
78
|
+
//#endregion
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
const require_chunk = require("../common/chunk.cjs"), require_ast_utils$1 = require("../common/ast-utils.cjs");
|
|
2
|
+
//#region ../../node_modules/.pnpm/eslint@9.39.3_jiti@2.6.1/node_modules/eslint/lib/rules/no-useless-constructor.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Rule to flag the use of redundant constructors in classes.
|
|
5
|
+
* @author Alberto Rodríguez
|
|
6
|
+
*/
|
|
7
|
+
var require_no_useless_constructor = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
8
|
+
let astUtils = require_ast_utils$1.t();
|
|
9
|
+
/**
|
|
10
|
+
* Checks whether any of a method's parameters have a decorator or are a parameter property.
|
|
11
|
+
* @param {ASTNode} node A method definition node.
|
|
12
|
+
* @returns {boolean} `true` if any parameter had a decorator or is a parameter property.
|
|
13
|
+
*/
|
|
14
|
+
function hasDecoratorsOrParameterProperty(node) {
|
|
15
|
+
return node.value.params.some((param) => param.decorators?.length || param.type === "TSParameterProperty");
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Checks whether a node's accessibility makes it not useless.
|
|
19
|
+
* @param {ASTNode} node A method definition node.
|
|
20
|
+
* @returns {boolean} `true` if the node has a useful accessibility.
|
|
21
|
+
*/
|
|
22
|
+
function hasUsefulAccessibility(node) {
|
|
23
|
+
switch (node.accessibility) {
|
|
24
|
+
case "protected":
|
|
25
|
+
case "private": return !0;
|
|
26
|
+
case "public": return !!node.parent.parent.superClass;
|
|
27
|
+
default: return !1;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Checks whether a given array of statements is a single call of `super`.
|
|
32
|
+
* @param {ASTNode[]} body An array of statements to check.
|
|
33
|
+
* @returns {boolean} `true` if the body is a single call of `super`.
|
|
34
|
+
*/
|
|
35
|
+
function isSingleSuperCall(body) {
|
|
36
|
+
return body.length === 1 && body[0].type === "ExpressionStatement" && body[0].expression.type === "CallExpression" && body[0].expression.callee.type === "Super";
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Checks whether a given node is a pattern which doesn't have any side effects.
|
|
40
|
+
* Default parameters and Destructuring parameters can have side effects.
|
|
41
|
+
* @param {ASTNode} node A pattern node.
|
|
42
|
+
* @returns {boolean} `true` if the node doesn't have any side effects.
|
|
43
|
+
*/
|
|
44
|
+
function isSimple(node) {
|
|
45
|
+
return node.type === "Identifier" || node.type === "RestElement";
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Checks whether a given array of expressions is `...arguments` or not.
|
|
49
|
+
* `super(...arguments)` passes all arguments through.
|
|
50
|
+
* @param {ASTNode[]} superArgs An array of expressions to check.
|
|
51
|
+
* @returns {boolean} `true` if the superArgs is `...arguments`.
|
|
52
|
+
*/
|
|
53
|
+
function isSpreadArguments(superArgs) {
|
|
54
|
+
return superArgs.length === 1 && superArgs[0].type === "SpreadElement" && superArgs[0].argument.type === "Identifier" && superArgs[0].argument.name === "arguments";
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Checks whether given 2 nodes are identifiers which have the same name or not.
|
|
58
|
+
* @param {ASTNode} ctorParam A node to check.
|
|
59
|
+
* @param {ASTNode} superArg A node to check.
|
|
60
|
+
* @returns {boolean} `true` if the nodes are identifiers which have the same
|
|
61
|
+
* name.
|
|
62
|
+
*/
|
|
63
|
+
function isValidIdentifierPair(ctorParam, superArg) {
|
|
64
|
+
return ctorParam.type === "Identifier" && superArg.type === "Identifier" && ctorParam.name === superArg.name;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Checks whether given 2 nodes are a rest/spread pair which has the same values.
|
|
68
|
+
* @param {ASTNode} ctorParam A node to check.
|
|
69
|
+
* @param {ASTNode} superArg A node to check.
|
|
70
|
+
* @returns {boolean} `true` if the nodes are a rest/spread pair which has the
|
|
71
|
+
* same values.
|
|
72
|
+
*/
|
|
73
|
+
function isValidRestSpreadPair(ctorParam, superArg) {
|
|
74
|
+
return ctorParam.type === "RestElement" && superArg.type === "SpreadElement" && isValidIdentifierPair(ctorParam.argument, superArg.argument);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Checks whether given 2 nodes have the same value or not.
|
|
78
|
+
* @param {ASTNode} ctorParam A node to check.
|
|
79
|
+
* @param {ASTNode} superArg A node to check.
|
|
80
|
+
* @returns {boolean} `true` if the nodes have the same value or not.
|
|
81
|
+
*/
|
|
82
|
+
function isValidPair(ctorParam, superArg) {
|
|
83
|
+
return isValidIdentifierPair(ctorParam, superArg) || isValidRestSpreadPair(ctorParam, superArg);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Checks whether the parameters of a constructor and the arguments of `super()`
|
|
87
|
+
* have the same values or not.
|
|
88
|
+
* @param {ASTNode} ctorParams The parameters of a constructor to check.
|
|
89
|
+
* @param {ASTNode} superArgs The arguments of `super()` to check.
|
|
90
|
+
* @returns {boolean} `true` if those have the same values.
|
|
91
|
+
*/
|
|
92
|
+
function isPassingThrough(ctorParams, superArgs) {
|
|
93
|
+
if (ctorParams.length !== superArgs.length) return !1;
|
|
94
|
+
for (let i = 0; i < ctorParams.length; ++i) if (!isValidPair(ctorParams[i], superArgs[i])) return !1;
|
|
95
|
+
return !0;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Checks whether the constructor body is a redundant super call.
|
|
99
|
+
* @param {Array} body constructor body content.
|
|
100
|
+
* @param {Array} ctorParams The params to check against super call.
|
|
101
|
+
* @returns {boolean} true if the constructor body is redundant
|
|
102
|
+
*/
|
|
103
|
+
function isRedundantSuperCall(body, ctorParams) {
|
|
104
|
+
return isSingleSuperCall(body) && ctorParams.every(isSimple) && (isSpreadArguments(body[0].expression.arguments) || isPassingThrough(ctorParams, body[0].expression.arguments));
|
|
105
|
+
}
|
|
106
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
107
|
+
module.exports = {
|
|
108
|
+
meta: {
|
|
109
|
+
dialects: ["javascript", "typescript"],
|
|
110
|
+
language: "javascript",
|
|
111
|
+
type: "suggestion",
|
|
112
|
+
docs: {
|
|
113
|
+
description: "Disallow unnecessary constructors",
|
|
114
|
+
recommended: !1,
|
|
115
|
+
url: "https://eslint.org/docs/latest/rules/no-useless-constructor"
|
|
116
|
+
},
|
|
117
|
+
hasSuggestions: !0,
|
|
118
|
+
schema: [],
|
|
119
|
+
messages: {
|
|
120
|
+
noUselessConstructor: "Useless constructor.",
|
|
121
|
+
removeConstructor: "Remove the constructor."
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
create(context) {
|
|
125
|
+
/**
|
|
126
|
+
* Checks whether a node is a redundant constructor
|
|
127
|
+
* @param {ASTNode} node node to check
|
|
128
|
+
* @returns {void}
|
|
129
|
+
*/
|
|
130
|
+
function checkForConstructor(node) {
|
|
131
|
+
if (node.kind !== "constructor" || node.value.type !== "FunctionExpression" || hasDecoratorsOrParameterProperty(node) || hasUsefulAccessibility(node) || !node.value.body) return;
|
|
132
|
+
let body = node.value.body.body, ctorParams = node.value.params;
|
|
133
|
+
(node.parent.parent.superClass ? isRedundantSuperCall(body, ctorParams) : body.length === 0) && context.report({
|
|
134
|
+
node,
|
|
135
|
+
messageId: "noUselessConstructor",
|
|
136
|
+
suggest: [{
|
|
137
|
+
messageId: "removeConstructor",
|
|
138
|
+
*fix(fixer) {
|
|
139
|
+
let nextToken = context.sourceCode.getTokenAfter(node), addSemiColon = nextToken.type === "Punctuator" && nextToken.value === "[" && astUtils.needsPrecedingSemicolon(context.sourceCode, node);
|
|
140
|
+
yield fixer.replaceText(node, addSemiColon ? ";" : "");
|
|
141
|
+
}
|
|
142
|
+
}]
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
return { MethodDefinition: checkForConstructor };
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
}));
|
|
149
|
+
//#endregion
|
|
150
|
+
//#region src-js/generated/plugin-eslint/rules/no-useless-constructor.cjs
|
|
151
|
+
module.exports = require_no_useless_constructor().create;
|
|
152
|
+
//#endregion
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
const require_chunk = require("../common/chunk.cjs"), require_ast_utils$1 = require("../common/ast-utils.cjs"), require_regexpp$1 = require("../common/regexpp.cjs");
|
|
2
|
+
//#region ../../node_modules/.pnpm/eslint@9.39.3_jiti@2.6.1/node_modules/eslint/lib/rules/no-useless-escape.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Look for useless escapes in strings and regexes
|
|
5
|
+
* @author Onur Temizkan
|
|
6
|
+
*/
|
|
7
|
+
var require_no_useless_escape = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
8
|
+
let astUtils = require_ast_utils$1.t(), { RegExpParser, visitRegExpAST } = require_regexpp$1.t();
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {import('@eslint-community/regexpp').AST.CharacterClass} CharacterClass
|
|
11
|
+
* @typedef {import('@eslint-community/regexpp').AST.ExpressionCharacterClass} ExpressionCharacterClass
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Returns the union of two sets.
|
|
15
|
+
* @param {Set} setA The first set
|
|
16
|
+
* @param {Set} setB The second set
|
|
17
|
+
* @returns {Set} The union of the two sets
|
|
18
|
+
*/
|
|
19
|
+
function union(setA, setB) {
|
|
20
|
+
return new Set((function* () {
|
|
21
|
+
yield* setA, yield* setB;
|
|
22
|
+
})());
|
|
23
|
+
}
|
|
24
|
+
let VALID_STRING_ESCAPES = union(/* @__PURE__ */ new Set("\\nrvtbfux"), astUtils.LINEBREAKS), REGEX_GENERAL_ESCAPES = /* @__PURE__ */ new Set("\\bcdDfnpPrsStvwWxu0123456789]"), REGEX_NON_CHARCLASS_ESCAPES = union(REGEX_GENERAL_ESCAPES, /* @__PURE__ */ new Set("^/.$*+?[{}|()Bk")), REGEX_CLASSSET_CHARACTER_ESCAPES = union(REGEX_GENERAL_ESCAPES, /* @__PURE__ */ new Set("q/[{}|()-")), REGEX_CLASS_SET_RESERVED_DOUBLE_PUNCTUATOR = /* @__PURE__ */ new Set("!#$%&*+,.:;<=>?@^`~");
|
|
25
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
26
|
+
module.exports = {
|
|
27
|
+
meta: {
|
|
28
|
+
type: "suggestion",
|
|
29
|
+
defaultOptions: [{ allowRegexCharacters: [] }],
|
|
30
|
+
docs: {
|
|
31
|
+
description: "Disallow unnecessary escape characters",
|
|
32
|
+
recommended: !0,
|
|
33
|
+
url: "https://eslint.org/docs/latest/rules/no-useless-escape"
|
|
34
|
+
},
|
|
35
|
+
hasSuggestions: !0,
|
|
36
|
+
messages: {
|
|
37
|
+
unnecessaryEscape: "Unnecessary escape character: \\{{character}}.",
|
|
38
|
+
removeEscape: "Remove the `\\`. This maintains the current functionality.",
|
|
39
|
+
removeEscapeDoNotKeepSemantics: "Remove the `\\` if it was inserted by mistake.",
|
|
40
|
+
escapeBackslash: "Replace the `\\` with `\\\\` to include the actual backslash character."
|
|
41
|
+
},
|
|
42
|
+
schema: [{
|
|
43
|
+
type: "object",
|
|
44
|
+
properties: { allowRegexCharacters: {
|
|
45
|
+
type: "array",
|
|
46
|
+
items: { type: "string" },
|
|
47
|
+
uniqueItems: !0
|
|
48
|
+
} },
|
|
49
|
+
additionalProperties: !1
|
|
50
|
+
}]
|
|
51
|
+
},
|
|
52
|
+
create(context) {
|
|
53
|
+
let sourceCode = context.sourceCode, [{ allowRegexCharacters }] = context.options, parser = new RegExpParser();
|
|
54
|
+
/**
|
|
55
|
+
* Reports a node
|
|
56
|
+
* @param {ASTNode} node The node to report
|
|
57
|
+
* @param {number} startOffset The backslash's offset from the start of the node
|
|
58
|
+
* @param {string} character The uselessly escaped character (not including the backslash)
|
|
59
|
+
* @param {boolean} [disableEscapeBackslashSuggest] `true` if escapeBackslash suggestion should be turned off.
|
|
60
|
+
* @returns {void}
|
|
61
|
+
*/
|
|
62
|
+
function report(node, startOffset, character, disableEscapeBackslashSuggest) {
|
|
63
|
+
let rangeStart = node.range[0] + startOffset, range = [rangeStart, rangeStart + 1], start = sourceCode.getLocFromIndex(rangeStart);
|
|
64
|
+
context.report({
|
|
65
|
+
node,
|
|
66
|
+
loc: {
|
|
67
|
+
start,
|
|
68
|
+
end: {
|
|
69
|
+
line: start.line,
|
|
70
|
+
column: start.column + 1
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
messageId: "unnecessaryEscape",
|
|
74
|
+
data: { character },
|
|
75
|
+
suggest: [{
|
|
76
|
+
messageId: astUtils.isDirective(node.parent) ? "removeEscapeDoNotKeepSemantics" : "removeEscape",
|
|
77
|
+
fix(fixer) {
|
|
78
|
+
return fixer.removeRange(range);
|
|
79
|
+
}
|
|
80
|
+
}, ...disableEscapeBackslashSuggest ? [] : [{
|
|
81
|
+
messageId: "escapeBackslash",
|
|
82
|
+
fix(fixer) {
|
|
83
|
+
return fixer.insertTextBeforeRange(range, "\\");
|
|
84
|
+
}
|
|
85
|
+
}]]
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Checks if the escape character in given string slice is unnecessary.
|
|
90
|
+
* @private
|
|
91
|
+
* @param {ASTNode} node node to validate.
|
|
92
|
+
* @param {string} match string slice to validate.
|
|
93
|
+
* @returns {void}
|
|
94
|
+
*/
|
|
95
|
+
function validateString(node, match) {
|
|
96
|
+
let isTemplateElement = node.type === "TemplateElement", escapedChar = match[0][1], isUnnecessaryEscape = !VALID_STRING_ESCAPES.has(escapedChar), isQuoteEscape;
|
|
97
|
+
isTemplateElement ? (isQuoteEscape = escapedChar === "`", escapedChar === "$" ? isUnnecessaryEscape = match.input[match.index + 2] !== "{" : escapedChar === "{" && (isUnnecessaryEscape = match.input[match.index - 1] !== "$")) : isQuoteEscape = escapedChar === node.raw[0], isUnnecessaryEscape && !isQuoteEscape && report(node, match.index, match[0].slice(1));
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Checks if the escape character in given regexp is unnecessary.
|
|
101
|
+
* @private
|
|
102
|
+
* @param {ASTNode} node node to validate.
|
|
103
|
+
* @returns {void}
|
|
104
|
+
*/
|
|
105
|
+
function validateRegExp(node) {
|
|
106
|
+
let { pattern, flags } = node.regex, patternNode, unicode = flags.includes("u"), unicodeSets = flags.includes("v");
|
|
107
|
+
try {
|
|
108
|
+
patternNode = parser.parsePattern(pattern, 0, pattern.length, {
|
|
109
|
+
unicode,
|
|
110
|
+
unicodeSets
|
|
111
|
+
});
|
|
112
|
+
} catch {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
/** @type {(CharacterClass | ExpressionCharacterClass)[]} */
|
|
116
|
+
let characterClassStack = [];
|
|
117
|
+
visitRegExpAST(patternNode, {
|
|
118
|
+
onCharacterClassEnter: (characterClassNode) => characterClassStack.unshift(characterClassNode),
|
|
119
|
+
onCharacterClassLeave: () => characterClassStack.shift(),
|
|
120
|
+
onExpressionCharacterClassEnter: (characterClassNode) => characterClassStack.unshift(characterClassNode),
|
|
121
|
+
onExpressionCharacterClassLeave: () => characterClassStack.shift(),
|
|
122
|
+
onCharacterEnter(characterNode) {
|
|
123
|
+
if (!characterNode.raw.startsWith("\\")) return;
|
|
124
|
+
let escapedChar = characterNode.raw.slice(1);
|
|
125
|
+
if (escapedChar !== String.fromCodePoint(characterNode.value) || allowRegexCharacters.includes(escapedChar)) return;
|
|
126
|
+
let allowedEscapes;
|
|
127
|
+
if (allowedEscapes = characterClassStack.length ? unicodeSets ? REGEX_CLASSSET_CHARACTER_ESCAPES : REGEX_GENERAL_ESCAPES : REGEX_NON_CHARCLASS_ESCAPES, allowedEscapes.has(escapedChar)) return;
|
|
128
|
+
let reportedIndex = characterNode.start + 1, disableEscapeBackslashSuggest = !1;
|
|
129
|
+
if (characterClassStack.length) {
|
|
130
|
+
let characterClassNode = characterClassStack[0];
|
|
131
|
+
if (escapedChar === "^" && characterClassNode.start + 1 === characterNode.start) return;
|
|
132
|
+
if (unicodeSets) {
|
|
133
|
+
if (REGEX_CLASS_SET_RESERVED_DOUBLE_PUNCTUATOR.has(escapedChar) && (pattern[characterNode.end] === escapedChar || pattern[characterNode.start - 1] === escapedChar && (escapedChar !== "^" || !characterClassNode.negate || characterClassNode.start + 1 < characterNode.start - 1))) return;
|
|
134
|
+
(characterNode.parent.type === "ClassIntersection" || characterNode.parent.type === "ClassSubtraction") && (disableEscapeBackslashSuggest = !0);
|
|
135
|
+
} else if (escapedChar === "-" && characterClassNode.start + 1 !== characterNode.start && characterNode.end !== characterClassNode.end - 1) return;
|
|
136
|
+
}
|
|
137
|
+
report(node, reportedIndex, escapedChar, disableEscapeBackslashSuggest);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Checks if a node has an escape.
|
|
143
|
+
* @param {ASTNode} node node to check.
|
|
144
|
+
* @returns {void}
|
|
145
|
+
*/
|
|
146
|
+
function check(node) {
|
|
147
|
+
let isTemplateElement = node.type === "TemplateElement";
|
|
148
|
+
if (!(isTemplateElement && node.parent && node.parent.parent && node.parent.parent.type === "TaggedTemplateExpression" && node.parent === node.parent.parent.quasi)) if (typeof node.value == "string" || isTemplateElement) {
|
|
149
|
+
if (node.parent.type === "JSXAttribute" || node.parent.type === "JSXElement" || node.parent.type === "JSXFragment") return;
|
|
150
|
+
let value = isTemplateElement ? sourceCode.getText(node) : node.raw, pattern = /\\\D/gu, match;
|
|
151
|
+
for (; match = pattern.exec(value);) validateString(node, match);
|
|
152
|
+
} else node.regex && validateRegExp(node);
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
Literal: check,
|
|
156
|
+
TemplateElement: check
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
}));
|
|
161
|
+
//#endregion
|
|
162
|
+
//#region src-js/generated/plugin-eslint/rules/no-useless-escape.cjs
|
|
163
|
+
module.exports = require_no_useless_escape().create;
|
|
164
|
+
//#endregion
|