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,165 @@
|
|
|
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-eval.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Rule to flag use of eval() statement
|
|
5
|
+
* @author Nicholas C. Zakas
|
|
6
|
+
*/
|
|
7
|
+
var require_no_eval = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
8
|
+
let astUtils = require_ast_utils$1.t(), candidatesOfGlobalObject = Object.freeze([
|
|
9
|
+
"global",
|
|
10
|
+
"window",
|
|
11
|
+
"globalThis"
|
|
12
|
+
]);
|
|
13
|
+
/**
|
|
14
|
+
* Checks a given node is a MemberExpression node which has the specified name's
|
|
15
|
+
* property.
|
|
16
|
+
* @param {ASTNode} node A node to check.
|
|
17
|
+
* @param {string} name A name to check.
|
|
18
|
+
* @returns {boolean} `true` if the node is a MemberExpression node which has
|
|
19
|
+
* the specified name's property
|
|
20
|
+
*/
|
|
21
|
+
function isMember(node, name) {
|
|
22
|
+
return astUtils.isSpecificMemberAccess(node, null, name);
|
|
23
|
+
}
|
|
24
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
25
|
+
module.exports = {
|
|
26
|
+
meta: {
|
|
27
|
+
type: "suggestion",
|
|
28
|
+
defaultOptions: [{ allowIndirect: !1 }],
|
|
29
|
+
docs: {
|
|
30
|
+
description: "Disallow the use of `eval()`",
|
|
31
|
+
recommended: !1,
|
|
32
|
+
url: "https://eslint.org/docs/latest/rules/no-eval"
|
|
33
|
+
},
|
|
34
|
+
schema: [{
|
|
35
|
+
type: "object",
|
|
36
|
+
properties: { allowIndirect: { type: "boolean" } },
|
|
37
|
+
additionalProperties: !1
|
|
38
|
+
}],
|
|
39
|
+
messages: { unexpected: "eval can be harmful." }
|
|
40
|
+
},
|
|
41
|
+
create(context) {
|
|
42
|
+
let [{ allowIndirect }] = context.options, sourceCode = context.sourceCode, funcInfo = null;
|
|
43
|
+
/**
|
|
44
|
+
* Pushes a `this` scope (non-arrow function, class static block, or class field initializer) information to the stack.
|
|
45
|
+
* Top-level scopes are handled separately.
|
|
46
|
+
*
|
|
47
|
+
* This is used in order to check whether or not `this` binding is a
|
|
48
|
+
* reference to the global object.
|
|
49
|
+
* @param {ASTNode} node A node of the scope.
|
|
50
|
+
* For functions, this is one of FunctionDeclaration, FunctionExpression.
|
|
51
|
+
* For class static blocks, this is StaticBlock.
|
|
52
|
+
* For class field initializers, this can be any node that is PropertyDefinition#value.
|
|
53
|
+
* @returns {void}
|
|
54
|
+
*/
|
|
55
|
+
function enterThisScope(node) {
|
|
56
|
+
let strict = sourceCode.getScope(node).isStrict;
|
|
57
|
+
funcInfo = {
|
|
58
|
+
upper: funcInfo,
|
|
59
|
+
node,
|
|
60
|
+
strict,
|
|
61
|
+
isTopLevelOfScript: !1,
|
|
62
|
+
defaultThis: !1,
|
|
63
|
+
initialized: strict
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Pops a variable scope from the stack.
|
|
68
|
+
* @returns {void}
|
|
69
|
+
*/
|
|
70
|
+
function exitThisScope() {
|
|
71
|
+
funcInfo = funcInfo.upper;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Reports a given node.
|
|
75
|
+
*
|
|
76
|
+
* `node` is `Identifier` or `MemberExpression`.
|
|
77
|
+
* The parent of `node` might be `CallExpression`.
|
|
78
|
+
*
|
|
79
|
+
* The location of the report is always `eval` `Identifier` (or possibly
|
|
80
|
+
* `Literal`). The type of the report is `CallExpression` if the parent is
|
|
81
|
+
* `CallExpression`. Otherwise, it's the given node type.
|
|
82
|
+
* @param {ASTNode} node A node to report.
|
|
83
|
+
* @returns {void}
|
|
84
|
+
*/
|
|
85
|
+
function report(node) {
|
|
86
|
+
let parent = node.parent, locationNode = node.type === "MemberExpression" ? node.property : node, reportNode = parent.type === "CallExpression" && parent.callee === node ? parent : node;
|
|
87
|
+
context.report({
|
|
88
|
+
node: reportNode,
|
|
89
|
+
loc: locationNode.loc,
|
|
90
|
+
messageId: "unexpected"
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Reports accesses of `eval` via the global object.
|
|
95
|
+
* @param {eslint-scope.Scope} globalScope The global scope.
|
|
96
|
+
* @returns {void}
|
|
97
|
+
*/
|
|
98
|
+
function reportAccessingEvalViaGlobalObject(globalScope) {
|
|
99
|
+
for (let i = 0; i < candidatesOfGlobalObject.length; ++i) {
|
|
100
|
+
let name = candidatesOfGlobalObject[i], variable = astUtils.getVariableByName(globalScope, name);
|
|
101
|
+
if (!variable) continue;
|
|
102
|
+
let references = variable.references;
|
|
103
|
+
for (let j = 0; j < references.length; ++j) {
|
|
104
|
+
let node = references[j].identifier.parent;
|
|
105
|
+
for (; isMember(node, name);) node = node.parent;
|
|
106
|
+
isMember(node, "eval") && report(node);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Reports all accesses of `eval` (excludes direct calls to eval).
|
|
112
|
+
* @param {eslint-scope.Scope} globalScope The global scope.
|
|
113
|
+
* @returns {void}
|
|
114
|
+
*/
|
|
115
|
+
function reportAccessingEval(globalScope) {
|
|
116
|
+
let variable = astUtils.getVariableByName(globalScope, "eval");
|
|
117
|
+
if (!variable) return;
|
|
118
|
+
let references = variable.references;
|
|
119
|
+
for (let i = 0; i < references.length; ++i) {
|
|
120
|
+
let id = references[i].identifier;
|
|
121
|
+
id.name === "eval" && !astUtils.isCallee(id) && report(id);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return allowIndirect ? { "CallExpression:exit"(node) {
|
|
125
|
+
let callee = node.callee;
|
|
126
|
+
!node.optional && astUtils.isSpecificId(callee, "eval") && report(callee);
|
|
127
|
+
} } : {
|
|
128
|
+
"CallExpression:exit"(node) {
|
|
129
|
+
let callee = node.callee;
|
|
130
|
+
astUtils.isSpecificId(callee, "eval") && report(callee);
|
|
131
|
+
},
|
|
132
|
+
Program(node) {
|
|
133
|
+
let scope = sourceCode.getScope(node), features = context.languageOptions.parserOptions.ecmaFeatures || {};
|
|
134
|
+
funcInfo = {
|
|
135
|
+
upper: null,
|
|
136
|
+
node,
|
|
137
|
+
strict: scope.isStrict || node.sourceType === "module" || features.globalReturn && scope.childScopes[0].isStrict,
|
|
138
|
+
isTopLevelOfScript: node.sourceType !== "module" && !features.globalReturn,
|
|
139
|
+
defaultThis: !0,
|
|
140
|
+
initialized: !0
|
|
141
|
+
};
|
|
142
|
+
},
|
|
143
|
+
"Program:exit"(node) {
|
|
144
|
+
let globalScope = sourceCode.getScope(node);
|
|
145
|
+
exitThisScope(), reportAccessingEval(globalScope), reportAccessingEvalViaGlobalObject(globalScope);
|
|
146
|
+
},
|
|
147
|
+
FunctionDeclaration: enterThisScope,
|
|
148
|
+
"FunctionDeclaration:exit": exitThisScope,
|
|
149
|
+
FunctionExpression: enterThisScope,
|
|
150
|
+
"FunctionExpression:exit": exitThisScope,
|
|
151
|
+
"PropertyDefinition > *.value": enterThisScope,
|
|
152
|
+
"PropertyDefinition > *.value:exit": exitThisScope,
|
|
153
|
+
StaticBlock: enterThisScope,
|
|
154
|
+
"StaticBlock:exit": exitThisScope,
|
|
155
|
+
ThisExpression(node) {
|
|
156
|
+
isMember(node.parent, "eval") && (funcInfo.initialized || (funcInfo.initialized = !0, funcInfo.defaultThis = astUtils.isDefaultThisBinding(funcInfo.node, sourceCode)), (funcInfo.isTopLevelOfScript || !funcInfo.strict && funcInfo.defaultThis) && report(node.parent));
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
}));
|
|
162
|
+
//#endregion
|
|
163
|
+
//#region src-js/generated/plugin-eslint/rules/no-eval.cjs
|
|
164
|
+
module.exports = require_no_eval().create;
|
|
165
|
+
//#endregion
|
|
@@ -0,0 +1,45 @@
|
|
|
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-ex-assign.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Rule to flag assignment of the exception parameter
|
|
5
|
+
* @author Stephen Murray <spmurrayzzz>
|
|
6
|
+
*/
|
|
7
|
+
var require_no_ex_assign = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
8
|
+
let astUtils = require_ast_utils$1.t();
|
|
9
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
10
|
+
module.exports = {
|
|
11
|
+
meta: {
|
|
12
|
+
type: "problem",
|
|
13
|
+
docs: {
|
|
14
|
+
description: "Disallow reassigning exceptions in `catch` clauses",
|
|
15
|
+
recommended: !0,
|
|
16
|
+
url: "https://eslint.org/docs/latest/rules/no-ex-assign"
|
|
17
|
+
},
|
|
18
|
+
schema: [],
|
|
19
|
+
messages: { unexpected: "Do not assign to the exception parameter." }
|
|
20
|
+
},
|
|
21
|
+
create(context) {
|
|
22
|
+
let sourceCode = context.sourceCode;
|
|
23
|
+
/**
|
|
24
|
+
* Finds and reports references that are non initializer and writable.
|
|
25
|
+
* @param {Variable} variable A variable to check.
|
|
26
|
+
* @returns {void}
|
|
27
|
+
*/
|
|
28
|
+
function checkVariable(variable) {
|
|
29
|
+
astUtils.getModifyingReferences(variable.references).forEach((reference) => {
|
|
30
|
+
context.report({
|
|
31
|
+
node: reference.identifier,
|
|
32
|
+
messageId: "unexpected"
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return { CatchClause(node) {
|
|
37
|
+
sourceCode.getDeclaredVariables(node).forEach(checkVariable);
|
|
38
|
+
} };
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}));
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src-js/generated/plugin-eslint/rules/no-ex-assign.cjs
|
|
44
|
+
module.exports = require_no_ex_assign().create;
|
|
45
|
+
//#endregion
|
|
@@ -0,0 +1,103 @@
|
|
|
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-extend-native.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Rule to flag adding properties to native object's prototypes.
|
|
5
|
+
* @author David Nelson
|
|
6
|
+
*/
|
|
7
|
+
var require_no_extend_native = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
8
|
+
let astUtils = require_ast_utils$1.t();
|
|
9
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
10
|
+
module.exports = {
|
|
11
|
+
meta: {
|
|
12
|
+
type: "suggestion",
|
|
13
|
+
defaultOptions: [{ exceptions: [] }],
|
|
14
|
+
docs: {
|
|
15
|
+
description: "Disallow extending native types",
|
|
16
|
+
recommended: !1,
|
|
17
|
+
url: "https://eslint.org/docs/latest/rules/no-extend-native"
|
|
18
|
+
},
|
|
19
|
+
schema: [{
|
|
20
|
+
type: "object",
|
|
21
|
+
properties: { exceptions: {
|
|
22
|
+
type: "array",
|
|
23
|
+
items: { type: "string" },
|
|
24
|
+
uniqueItems: !0
|
|
25
|
+
} },
|
|
26
|
+
additionalProperties: !1
|
|
27
|
+
}],
|
|
28
|
+
messages: { unexpected: "{{builtin}} prototype is read only, properties should not be added." }
|
|
29
|
+
},
|
|
30
|
+
create(context) {
|
|
31
|
+
let sourceCode = context.sourceCode, exceptions = new Set(context.options[0].exceptions), modifiedBuiltins = new Set(Object.keys(astUtils.ECMASCRIPT_GLOBALS).filter((builtin) => builtin[0].toUpperCase() === builtin[0]).filter((builtin) => !exceptions.has(builtin)));
|
|
32
|
+
/**
|
|
33
|
+
* Reports a lint error for the given node.
|
|
34
|
+
* @param {ASTNode} node The node to report.
|
|
35
|
+
* @param {string} builtin The name of the native builtin being extended.
|
|
36
|
+
* @returns {void}
|
|
37
|
+
*/
|
|
38
|
+
function reportNode(node, builtin) {
|
|
39
|
+
context.report({
|
|
40
|
+
node,
|
|
41
|
+
messageId: "unexpected",
|
|
42
|
+
data: { builtin }
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Check to see if the `prototype` property of the given object
|
|
47
|
+
* identifier node is being accessed.
|
|
48
|
+
* @param {ASTNode} identifierNode The Identifier representing the object
|
|
49
|
+
* to check.
|
|
50
|
+
* @returns {boolean} True if the identifier is the object of a
|
|
51
|
+
* MemberExpression and its `prototype` property is being accessed,
|
|
52
|
+
* false otherwise.
|
|
53
|
+
*/
|
|
54
|
+
function isPrototypePropertyAccessed(identifierNode) {
|
|
55
|
+
return !!(identifierNode && identifierNode.parent && identifierNode.parent.type === "MemberExpression" && identifierNode.parent.object === identifierNode && astUtils.getStaticPropertyName(identifierNode.parent) === "prototype");
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Check if it's an assignment to the property of the given node.
|
|
59
|
+
* Example: `*.prop = 0` // the `*` is the given node.
|
|
60
|
+
* @param {ASTNode} node The node to check.
|
|
61
|
+
* @returns {boolean} True if an assignment to the property of the node.
|
|
62
|
+
*/
|
|
63
|
+
function isAssigningToPropertyOf(node) {
|
|
64
|
+
return node.parent.type === "MemberExpression" && node.parent.object === node && node.parent.parent.type === "AssignmentExpression" && node.parent.parent.left === node.parent;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Checks if the given node is at the first argument of the method call of `Object.defineProperty()` or `Object.defineProperties()`.
|
|
68
|
+
* @param {ASTNode} node The node to check.
|
|
69
|
+
* @returns {boolean} True if the node is at the first argument of the method call of `Object.defineProperty()` or `Object.defineProperties()`.
|
|
70
|
+
*/
|
|
71
|
+
function isInDefinePropertyCall(node) {
|
|
72
|
+
return node.parent.type === "CallExpression" && node.parent.arguments[0] === node && astUtils.isSpecificMemberAccess(node.parent.callee, "Object", /^definePropert(?:y|ies)$/u);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Check to see if object prototype access is part of a prototype
|
|
76
|
+
* extension. There are three ways a prototype can be extended:
|
|
77
|
+
* 1. Assignment to prototype property (Object.prototype.foo = 1)
|
|
78
|
+
* 2. Object.defineProperty()/Object.defineProperties() on a prototype
|
|
79
|
+
* If prototype extension is detected, report the AssignmentExpression
|
|
80
|
+
* or CallExpression node.
|
|
81
|
+
* @param {ASTNode} identifierNode The Identifier representing the object
|
|
82
|
+
* which prototype is being accessed and possibly extended.
|
|
83
|
+
* @returns {void}
|
|
84
|
+
*/
|
|
85
|
+
function checkAndReportPrototypeExtension(identifierNode) {
|
|
86
|
+
if (!isPrototypePropertyAccessed(identifierNode)) return;
|
|
87
|
+
let prototypeNode = identifierNode.parent.parent.type === "ChainExpression" ? identifierNode.parent.parent : identifierNode.parent;
|
|
88
|
+
isAssigningToPropertyOf(prototypeNode) ? reportNode(prototypeNode.parent.parent, identifierNode.name) : isInDefinePropertyCall(prototypeNode) && reportNode(prototypeNode.parent, identifierNode.name);
|
|
89
|
+
}
|
|
90
|
+
return { "Program:exit"(node) {
|
|
91
|
+
let globalScope = sourceCode.getScope(node);
|
|
92
|
+
modifiedBuiltins.forEach((builtin) => {
|
|
93
|
+
let builtinVar = globalScope.set.get(builtin);
|
|
94
|
+
builtinVar && builtinVar.references && builtinVar.references.map((ref) => ref.identifier).forEach(checkAndReportPrototypeExtension);
|
|
95
|
+
});
|
|
96
|
+
} };
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}));
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region src-js/generated/plugin-eslint/rules/no-extend-native.cjs
|
|
102
|
+
module.exports = require_no_extend_native().create;
|
|
103
|
+
//#endregion
|
|
@@ -0,0 +1,127 @@
|
|
|
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-extra-bind.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Rule to flag unnecessary bind calls
|
|
5
|
+
* @author Bence Dányi <bence@danyi.me>
|
|
6
|
+
*/
|
|
7
|
+
var require_no_extra_bind = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
8
|
+
let astUtils = require_ast_utils$1.t(), SIDE_EFFECT_FREE_NODE_TYPES = new Set([
|
|
9
|
+
"Literal",
|
|
10
|
+
"Identifier",
|
|
11
|
+
"ThisExpression",
|
|
12
|
+
"FunctionExpression"
|
|
13
|
+
]);
|
|
14
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
15
|
+
module.exports = {
|
|
16
|
+
meta: {
|
|
17
|
+
type: "suggestion",
|
|
18
|
+
docs: {
|
|
19
|
+
description: "Disallow unnecessary calls to `.bind()`",
|
|
20
|
+
recommended: !1,
|
|
21
|
+
url: "https://eslint.org/docs/latest/rules/no-extra-bind"
|
|
22
|
+
},
|
|
23
|
+
schema: [],
|
|
24
|
+
fixable: "code",
|
|
25
|
+
messages: { unexpected: "The function binding is unnecessary." }
|
|
26
|
+
},
|
|
27
|
+
create(context) {
|
|
28
|
+
let sourceCode = context.sourceCode, scopeInfo = null;
|
|
29
|
+
/**
|
|
30
|
+
* Checks if a node is free of side effects.
|
|
31
|
+
*
|
|
32
|
+
* This check is stricter than it needs to be, in order to keep the implementation simple.
|
|
33
|
+
* @param {ASTNode} node A node to check.
|
|
34
|
+
* @returns {boolean} True if the node is known to be side-effect free, false otherwise.
|
|
35
|
+
*/
|
|
36
|
+
function isSideEffectFree(node) {
|
|
37
|
+
return SIDE_EFFECT_FREE_NODE_TYPES.has(node.type);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Reports a given function node.
|
|
41
|
+
* @param {ASTNode} node A node to report. This is a FunctionExpression or
|
|
42
|
+
* an ArrowFunctionExpression.
|
|
43
|
+
* @returns {void}
|
|
44
|
+
*/
|
|
45
|
+
function report(node) {
|
|
46
|
+
let memberNode = node.parent, callNode = memberNode.parent.type === "ChainExpression" ? memberNode.parent.parent : memberNode.parent;
|
|
47
|
+
context.report({
|
|
48
|
+
node: callNode,
|
|
49
|
+
messageId: "unexpected",
|
|
50
|
+
loc: memberNode.property.loc,
|
|
51
|
+
fix(fixer) {
|
|
52
|
+
if (!isSideEffectFree(callNode.arguments[0])) return null;
|
|
53
|
+
let tokenPairs = [[sourceCode.getTokenAfter(memberNode.object, astUtils.isNotClosingParenToken), sourceCode.getLastToken(memberNode)], [sourceCode.getTokenAfter(memberNode, astUtils.isNotClosingParenToken), sourceCode.getLastToken(callNode)]], firstTokenToRemove = tokenPairs[0][0], lastTokenToRemove = tokenPairs[1][1];
|
|
54
|
+
return sourceCode.commentsExistBetween(firstTokenToRemove, lastTokenToRemove) ? null : tokenPairs.map(([start, end]) => fixer.removeRange([start.range[0], end.range[1]]));
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Checks whether or not a given function node is the callee of `.bind()`
|
|
60
|
+
* method.
|
|
61
|
+
*
|
|
62
|
+
* e.g. `(function() {}.bind(foo))`
|
|
63
|
+
* @param {ASTNode} node A node to report. This is a FunctionExpression or
|
|
64
|
+
* an ArrowFunctionExpression.
|
|
65
|
+
* @returns {boolean} `true` if the node is the callee of `.bind()` method.
|
|
66
|
+
*/
|
|
67
|
+
function isCalleeOfBindMethod(node) {
|
|
68
|
+
if (!astUtils.isSpecificMemberAccess(node.parent, null, "bind")) return !1;
|
|
69
|
+
let bindNode = node.parent.parent.type === "ChainExpression" ? node.parent.parent : node.parent;
|
|
70
|
+
return bindNode.parent.type === "CallExpression" && bindNode.parent.callee === bindNode && bindNode.parent.arguments.length === 1 && bindNode.parent.arguments[0].type !== "SpreadElement";
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Adds a scope information object to the stack.
|
|
74
|
+
* @param {ASTNode} node A node to add. This node is a FunctionExpression
|
|
75
|
+
* or a FunctionDeclaration node.
|
|
76
|
+
* @returns {void}
|
|
77
|
+
*/
|
|
78
|
+
function enterFunction(node) {
|
|
79
|
+
scopeInfo = {
|
|
80
|
+
isBound: isCalleeOfBindMethod(node),
|
|
81
|
+
thisFound: !1,
|
|
82
|
+
upper: scopeInfo
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Removes the scope information object from the top of the stack.
|
|
87
|
+
* At the same time, this reports the function node if the function has
|
|
88
|
+
* `.bind()` and the `this` keywords found.
|
|
89
|
+
* @param {ASTNode} node A node to remove. This node is a
|
|
90
|
+
* FunctionExpression or a FunctionDeclaration node.
|
|
91
|
+
* @returns {void}
|
|
92
|
+
*/
|
|
93
|
+
function exitFunction(node) {
|
|
94
|
+
scopeInfo.isBound && !scopeInfo.thisFound && report(node), scopeInfo = scopeInfo.upper;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Reports a given arrow function if the function is callee of `.bind()`
|
|
98
|
+
* method.
|
|
99
|
+
* @param {ASTNode} node A node to report. This node is an
|
|
100
|
+
* ArrowFunctionExpression.
|
|
101
|
+
* @returns {void}
|
|
102
|
+
*/
|
|
103
|
+
function exitArrowFunction(node) {
|
|
104
|
+
isCalleeOfBindMethod(node) && report(node);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Set the mark as the `this` keyword was found in this scope.
|
|
108
|
+
* @returns {void}
|
|
109
|
+
*/
|
|
110
|
+
function markAsThisFound() {
|
|
111
|
+
scopeInfo && (scopeInfo.thisFound = !0);
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
"ArrowFunctionExpression:exit": exitArrowFunction,
|
|
115
|
+
FunctionDeclaration: enterFunction,
|
|
116
|
+
"FunctionDeclaration:exit": exitFunction,
|
|
117
|
+
FunctionExpression: enterFunction,
|
|
118
|
+
"FunctionExpression:exit": exitFunction,
|
|
119
|
+
ThisExpression: markAsThisFound
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}));
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region src-js/generated/plugin-eslint/rules/no-extra-bind.cjs
|
|
126
|
+
module.exports = require_no_extra_bind().create;
|
|
127
|
+
//#endregion
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
const require_chunk = require("../common/chunk.cjs"), require_ast_utils$1 = require("../common/ast-utils.cjs"), require_eslint_utils$1 = require("../common/eslint-utils.cjs");
|
|
2
|
+
//#region ../../node_modules/.pnpm/eslint@9.39.3_jiti@2.6.1/node_modules/eslint/lib/rules/no-extra-boolean-cast.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Rule to flag unnecessary double negation in Boolean contexts
|
|
5
|
+
* @author Brandon Mills
|
|
6
|
+
*/
|
|
7
|
+
var require_no_extra_boolean_cast = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
8
|
+
let astUtils = require_ast_utils$1.t(), eslintUtils = require_eslint_utils$1.t(), precedence = astUtils.getPrecedence;
|
|
9
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
10
|
+
module.exports = {
|
|
11
|
+
meta: {
|
|
12
|
+
type: "suggestion",
|
|
13
|
+
defaultOptions: [{}],
|
|
14
|
+
docs: {
|
|
15
|
+
description: "Disallow unnecessary boolean casts",
|
|
16
|
+
recommended: !0,
|
|
17
|
+
frozen: !0,
|
|
18
|
+
url: "https://eslint.org/docs/latest/rules/no-extra-boolean-cast"
|
|
19
|
+
},
|
|
20
|
+
schema: [{ anyOf: [{
|
|
21
|
+
type: "object",
|
|
22
|
+
properties: { enforceForInnerExpressions: { type: "boolean" } },
|
|
23
|
+
additionalProperties: !1
|
|
24
|
+
}, {
|
|
25
|
+
type: "object",
|
|
26
|
+
properties: { enforceForLogicalOperands: { type: "boolean" } },
|
|
27
|
+
additionalProperties: !1
|
|
28
|
+
}] }],
|
|
29
|
+
fixable: "code",
|
|
30
|
+
messages: {
|
|
31
|
+
unexpectedCall: "Redundant Boolean call.",
|
|
32
|
+
unexpectedNegation: "Redundant double negation."
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
create(context) {
|
|
36
|
+
let sourceCode = context.sourceCode, [{ enforceForLogicalOperands, enforceForInnerExpressions }] = context.options, BOOLEAN_NODE_TYPES = new Set([
|
|
37
|
+
"IfStatement",
|
|
38
|
+
"DoWhileStatement",
|
|
39
|
+
"WhileStatement",
|
|
40
|
+
"ConditionalExpression",
|
|
41
|
+
"ForStatement"
|
|
42
|
+
]);
|
|
43
|
+
/**
|
|
44
|
+
* Check if a node is a Boolean function or constructor.
|
|
45
|
+
* @param {ASTNode} node the node
|
|
46
|
+
* @returns {boolean} If the node is Boolean function or constructor
|
|
47
|
+
*/
|
|
48
|
+
function isBooleanFunctionOrConstructorCall(node) {
|
|
49
|
+
return (node.type === "CallExpression" || node.type === "NewExpression") && node.callee.type === "Identifier" && node.callee.name === "Boolean";
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Check if a node is in a context where its value would be coerced to a boolean at runtime.
|
|
53
|
+
* @param {ASTNode} node The node
|
|
54
|
+
* @returns {boolean} If it is in a boolean context
|
|
55
|
+
*/
|
|
56
|
+
function isInBooleanContext(node) {
|
|
57
|
+
return isBooleanFunctionOrConstructorCall(node.parent) && node === node.parent.arguments[0] || BOOLEAN_NODE_TYPES.has(node.parent.type) && node === node.parent.test || node.parent.type === "UnaryExpression" && node.parent.operator === "!";
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Checks whether the node is a context that should report an error
|
|
61
|
+
* Acts recursively if it is in a logical context
|
|
62
|
+
* @param {ASTNode} node the node
|
|
63
|
+
* @returns {boolean} If the node is in one of the flagged contexts
|
|
64
|
+
*/
|
|
65
|
+
function isInFlaggedContext(node) {
|
|
66
|
+
return node.parent.type === "ChainExpression" || (enforceForLogicalOperands || enforceForInnerExpressions) && node.parent.type === "LogicalExpression" && (node.parent.operator === "||" || node.parent.operator === "&&" || enforceForInnerExpressions && node.parent.operator === "??" && node.parent.right === node) || enforceForInnerExpressions && (node.parent.type === "ConditionalExpression" && (node.parent.consequent === node || node.parent.alternate === node) || node.parent.type === "SequenceExpression" && node.parent.expressions.at(-1) === node) ? isInFlaggedContext(node.parent) : isInBooleanContext(node);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Check if a node has comments inside.
|
|
70
|
+
* @param {ASTNode} node The node to check.
|
|
71
|
+
* @returns {boolean} `true` if it has comments inside.
|
|
72
|
+
*/
|
|
73
|
+
function hasCommentsInside(node) {
|
|
74
|
+
return !!sourceCode.getCommentsInside(node).length;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Checks if the given node is wrapped in grouping parentheses. Parentheses for constructs such as if() don't count.
|
|
78
|
+
* @param {ASTNode} node The node to check.
|
|
79
|
+
* @returns {boolean} `true` if the node is parenthesized.
|
|
80
|
+
* @private
|
|
81
|
+
*/
|
|
82
|
+
function isParenthesized(node) {
|
|
83
|
+
return eslintUtils.isParenthesized(1, node, sourceCode);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Determines whether the given node needs to be parenthesized when replacing the previous node.
|
|
87
|
+
* It assumes that `previousNode` is the node to be reported by this rule, so it has a limited list
|
|
88
|
+
* of possible parent node types. By the same assumption, the node's role in a particular parent is already known.
|
|
89
|
+
* @param {ASTNode} previousNode Previous node.
|
|
90
|
+
* @param {ASTNode} node The node to check.
|
|
91
|
+
* @throws {Error} (Unreachable.)
|
|
92
|
+
* @returns {boolean} `true` if the node needs to be parenthesized.
|
|
93
|
+
*/
|
|
94
|
+
function needsParens(previousNode, node) {
|
|
95
|
+
if (previousNode.parent.type === "ChainExpression") return needsParens(previousNode.parent, node);
|
|
96
|
+
if (isParenthesized(previousNode)) return !1;
|
|
97
|
+
let parent = previousNode.parent;
|
|
98
|
+
switch (parent.type) {
|
|
99
|
+
case "CallExpression":
|
|
100
|
+
case "NewExpression": return node.type === "SequenceExpression";
|
|
101
|
+
case "IfStatement":
|
|
102
|
+
case "DoWhileStatement":
|
|
103
|
+
case "WhileStatement":
|
|
104
|
+
case "ForStatement":
|
|
105
|
+
case "SequenceExpression": return !1;
|
|
106
|
+
case "ConditionalExpression":
|
|
107
|
+
if (previousNode === parent.test) return precedence(node) <= precedence(parent);
|
|
108
|
+
if (previousNode === parent.consequent || previousNode === parent.alternate) return precedence(node) < precedence({ type: "AssignmentExpression" });
|
|
109
|
+
/* c8 ignore next */
|
|
110
|
+
throw Error("Ternary child must be test, consequent, or alternate.");
|
|
111
|
+
case "UnaryExpression": return precedence(node) < precedence(parent);
|
|
112
|
+
case "LogicalExpression": return astUtils.isMixedLogicalAndCoalesceExpressions(node, parent) ? !0 : previousNode === parent.left ? precedence(node) < precedence(parent) : precedence(node) <= precedence(parent);
|
|
113
|
+
default: throw Error(`Unexpected parent type: ${parent.type}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
UnaryExpression(node) {
|
|
118
|
+
let parent = node.parent;
|
|
119
|
+
node.operator !== "!" || parent.type !== "UnaryExpression" || parent.operator !== "!" || isInFlaggedContext(parent) && context.report({
|
|
120
|
+
node: parent,
|
|
121
|
+
messageId: "unexpectedNegation",
|
|
122
|
+
fix(fixer) {
|
|
123
|
+
if (hasCommentsInside(parent)) return null;
|
|
124
|
+
if (needsParens(parent, node.argument)) return fixer.replaceText(parent, `(${sourceCode.getText(node.argument)})`);
|
|
125
|
+
let prefix = "", tokenBefore = sourceCode.getTokenBefore(parent), firstReplacementToken = sourceCode.getFirstToken(node.argument);
|
|
126
|
+
return tokenBefore && tokenBefore.range[1] === parent.range[0] && !astUtils.canTokensBeAdjacent(tokenBefore, firstReplacementToken) && (prefix = " "), fixer.replaceText(parent, prefix + sourceCode.getText(node.argument));
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
},
|
|
130
|
+
CallExpression(node) {
|
|
131
|
+
node.callee.type !== "Identifier" || node.callee.name !== "Boolean" || isInFlaggedContext(node) && context.report({
|
|
132
|
+
node,
|
|
133
|
+
messageId: "unexpectedCall",
|
|
134
|
+
fix(fixer) {
|
|
135
|
+
let parent = node.parent;
|
|
136
|
+
if (node.arguments.length === 0) {
|
|
137
|
+
if (parent.type === "UnaryExpression" && parent.operator === "!") {
|
|
138
|
+
if (hasCommentsInside(parent)) return null;
|
|
139
|
+
let replacement = "true", prefix = "", tokenBefore = sourceCode.getTokenBefore(parent);
|
|
140
|
+
return tokenBefore && tokenBefore.range[1] === parent.range[0] && !astUtils.canTokensBeAdjacent(tokenBefore, replacement) && (prefix = " "), fixer.replaceText(parent, prefix + replacement);
|
|
141
|
+
}
|
|
142
|
+
return hasCommentsInside(node) ? null : fixer.replaceText(node, "false");
|
|
143
|
+
}
|
|
144
|
+
if (node.arguments.length === 1) {
|
|
145
|
+
let argument = node.arguments[0];
|
|
146
|
+
return argument.type === "SpreadElement" || hasCommentsInside(node) ? null : needsParens(node, argument) ? fixer.replaceText(node, `(${sourceCode.getText(argument)})`) : fixer.replaceText(node, sourceCode.getText(argument));
|
|
147
|
+
}
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
}));
|
|
156
|
+
//#endregion
|
|
157
|
+
//#region src-js/generated/plugin-eslint/rules/no-extra-boolean-cast.cjs
|
|
158
|
+
module.exports = require_no_extra_boolean_cast().create;
|
|
159
|
+
//#endregion
|