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,94 @@
|
|
|
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-rename.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Disallow renaming import, export, and destructured assignments to the same name.
|
|
5
|
+
* @author Kai Cataldo
|
|
6
|
+
*/
|
|
7
|
+
var require_no_useless_rename = /* @__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: [{
|
|
14
|
+
ignoreDestructuring: !1,
|
|
15
|
+
ignoreImport: !1,
|
|
16
|
+
ignoreExport: !1
|
|
17
|
+
}],
|
|
18
|
+
docs: {
|
|
19
|
+
description: "Disallow renaming import, export, and destructured assignments to the same name",
|
|
20
|
+
recommended: !1,
|
|
21
|
+
url: "https://eslint.org/docs/latest/rules/no-useless-rename"
|
|
22
|
+
},
|
|
23
|
+
fixable: "code",
|
|
24
|
+
schema: [{
|
|
25
|
+
type: "object",
|
|
26
|
+
properties: {
|
|
27
|
+
ignoreDestructuring: { type: "boolean" },
|
|
28
|
+
ignoreImport: { type: "boolean" },
|
|
29
|
+
ignoreExport: { type: "boolean" }
|
|
30
|
+
},
|
|
31
|
+
additionalProperties: !1
|
|
32
|
+
}],
|
|
33
|
+
messages: { unnecessarilyRenamed: "{{type}} {{name}} unnecessarily renamed." }
|
|
34
|
+
},
|
|
35
|
+
create(context) {
|
|
36
|
+
let sourceCode = context.sourceCode, [{ ignoreDestructuring, ignoreImport, ignoreExport }] = context.options;
|
|
37
|
+
/**
|
|
38
|
+
* Reports error for unnecessarily renamed assignments
|
|
39
|
+
* @param {ASTNode} node node to report
|
|
40
|
+
* @param {ASTNode} initial node with initial name value
|
|
41
|
+
* @param {string} type the type of the offending node
|
|
42
|
+
* @returns {void}
|
|
43
|
+
*/
|
|
44
|
+
function reportError(node, initial, type) {
|
|
45
|
+
let name = initial.type === "Identifier" ? initial.name : initial.value;
|
|
46
|
+
return context.report({
|
|
47
|
+
node,
|
|
48
|
+
messageId: "unnecessarilyRenamed",
|
|
49
|
+
data: {
|
|
50
|
+
name,
|
|
51
|
+
type
|
|
52
|
+
},
|
|
53
|
+
fix(fixer) {
|
|
54
|
+
let replacementNode = node.type === "Property" ? node.value : node.local;
|
|
55
|
+
return sourceCode.getCommentsInside(node).length > sourceCode.getCommentsInside(replacementNode).length || replacementNode.type === "AssignmentPattern" && astUtils.isParenthesised(sourceCode, replacementNode.left) ? null : fixer.replaceText(node, sourceCode.getText(replacementNode));
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Checks whether a destructured assignment is unnecessarily renamed
|
|
61
|
+
* @param {ASTNode} node node to check
|
|
62
|
+
* @returns {void}
|
|
63
|
+
*/
|
|
64
|
+
function checkDestructured(node) {
|
|
65
|
+
if (!ignoreDestructuring) for (let property of node.properties) property.type !== "Property" || property.shorthand || property.computed || (property.key.type === "Identifier" && property.key.name || property.key.type === "Literal" && property.key.value) === (property.value.type === "AssignmentPattern" ? property.value.left.name : property.value.name) && reportError(property, property.key, "Destructuring assignment");
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Checks whether an import is unnecessarily renamed
|
|
69
|
+
* @param {ASTNode} node node to check
|
|
70
|
+
* @returns {void}
|
|
71
|
+
*/
|
|
72
|
+
function checkImport(node) {
|
|
73
|
+
ignoreImport || node.imported.range[0] !== node.local.range[0] && astUtils.getModuleExportName(node.imported) === node.local.name && reportError(node, node.imported, "Import");
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Checks whether an export is unnecessarily renamed
|
|
77
|
+
* @param {ASTNode} node node to check
|
|
78
|
+
* @returns {void}
|
|
79
|
+
*/
|
|
80
|
+
function checkExport(node) {
|
|
81
|
+
ignoreExport || node.local.range[0] !== node.exported.range[0] && astUtils.getModuleExportName(node.local) === astUtils.getModuleExportName(node.exported) && reportError(node, node.local, "Export");
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
ObjectPattern: checkDestructured,
|
|
85
|
+
ImportSpecifier: checkImport,
|
|
86
|
+
ExportSpecifier: checkExport
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}));
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src-js/generated/plugin-eslint/rules/no-useless-rename.cjs
|
|
93
|
+
module.exports = require_no_useless_rename().create;
|
|
94
|
+
//#endregion
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
const require_chunk = require("../common/chunk.cjs"), require_ast_utils$1 = require("../common/ast-utils.cjs"), require_fix_tracker$1 = require("../common/fix-tracker.cjs");
|
|
2
|
+
//#region ../../node_modules/.pnpm/eslint@9.39.3_jiti@2.6.1/node_modules/eslint/lib/rules/no-useless-return.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Disallow redundant return statements
|
|
5
|
+
* @author Teddy Katz
|
|
6
|
+
*/
|
|
7
|
+
var require_no_useless_return = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
8
|
+
let astUtils = require_ast_utils$1.t(), FixTracker = require_fix_tracker$1.t();
|
|
9
|
+
/**
|
|
10
|
+
* Removes the given element from the array.
|
|
11
|
+
* @param {Array} array The source array to remove.
|
|
12
|
+
* @param {any} element The target item to remove.
|
|
13
|
+
* @returns {void}
|
|
14
|
+
*/
|
|
15
|
+
function remove(array, element) {
|
|
16
|
+
let index = array.indexOf(element);
|
|
17
|
+
index !== -1 && array.splice(index, 1);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Checks whether it can remove the given return statement or not.
|
|
21
|
+
* @param {ASTNode} node The return statement node to check.
|
|
22
|
+
* @returns {boolean} `true` if the node is removable.
|
|
23
|
+
*/
|
|
24
|
+
function isRemovable(node) {
|
|
25
|
+
return astUtils.STATEMENT_LIST_PARENTS.has(node.parent.type);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Checks whether the given return statement is in a `finally` block or not.
|
|
29
|
+
* @param {ASTNode} node The return statement node to check.
|
|
30
|
+
* @returns {boolean} `true` if the node is in a `finally` block.
|
|
31
|
+
*/
|
|
32
|
+
function isInFinally(node) {
|
|
33
|
+
for (let currentNode = node; currentNode && currentNode.parent && !astUtils.isFunction(currentNode); currentNode = currentNode.parent) if (currentNode.parent.type === "TryStatement" && currentNode.parent.finalizer === currentNode) return !0;
|
|
34
|
+
return !1;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Checks all segments in a set and returns true if any are reachable.
|
|
38
|
+
* @param {Set<CodePathSegment>} segments The segments to check.
|
|
39
|
+
* @returns {boolean} True if any segment is reachable; false otherwise.
|
|
40
|
+
*/
|
|
41
|
+
function isAnySegmentReachable(segments) {
|
|
42
|
+
for (let segment of segments) if (segment.reachable) return !0;
|
|
43
|
+
return !1;
|
|
44
|
+
}
|
|
45
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
46
|
+
module.exports = {
|
|
47
|
+
meta: {
|
|
48
|
+
type: "suggestion",
|
|
49
|
+
docs: {
|
|
50
|
+
description: "Disallow redundant return statements",
|
|
51
|
+
recommended: !1,
|
|
52
|
+
url: "https://eslint.org/docs/latest/rules/no-useless-return"
|
|
53
|
+
},
|
|
54
|
+
fixable: "code",
|
|
55
|
+
schema: [],
|
|
56
|
+
messages: { unnecessaryReturn: "Unnecessary return statement." }
|
|
57
|
+
},
|
|
58
|
+
create(context) {
|
|
59
|
+
let segmentInfoMap = /* @__PURE__ */ new WeakMap(), sourceCode = context.sourceCode, scopeInfo = null;
|
|
60
|
+
/**
|
|
61
|
+
* Checks whether the given segment is terminated by a return statement or not.
|
|
62
|
+
* @param {CodePathSegment} segment The segment to check.
|
|
63
|
+
* @returns {boolean} `true` if the segment is terminated by a return statement, or if it's still a part of unreachable.
|
|
64
|
+
*/
|
|
65
|
+
function isReturned(segment) {
|
|
66
|
+
let info = segmentInfoMap.get(segment);
|
|
67
|
+
return !info || info.returned;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Collects useless return statements from the given previous segments.
|
|
71
|
+
*
|
|
72
|
+
* A previous segment may be an unreachable segment.
|
|
73
|
+
* In that case, the information object of the unreachable segment is not
|
|
74
|
+
* initialized because `onCodePathSegmentStart` event is not notified for
|
|
75
|
+
* unreachable segments.
|
|
76
|
+
* This goes to the previous segments of the unreachable segment recursively
|
|
77
|
+
* if the unreachable segment was generated by a return statement. Otherwise,
|
|
78
|
+
* this ignores the unreachable segment.
|
|
79
|
+
*
|
|
80
|
+
* This behavior would simulate code paths for the case that the return
|
|
81
|
+
* statement does not exist.
|
|
82
|
+
* @param {ASTNode[]} uselessReturns The collected return statements.
|
|
83
|
+
* @param {CodePathSegment[]} prevSegments The previous segments to traverse.
|
|
84
|
+
* @param {WeakSet<CodePathSegment>} [providedTraversedSegments] A set of segments that have already been traversed in this call
|
|
85
|
+
* @returns {ASTNode[]} `uselessReturns`.
|
|
86
|
+
*/
|
|
87
|
+
function getUselessReturns(uselessReturns, prevSegments, providedTraversedSegments) {
|
|
88
|
+
let traversedSegments = providedTraversedSegments || /* @__PURE__ */ new WeakSet();
|
|
89
|
+
for (let segment of prevSegments) {
|
|
90
|
+
if (!segment.reachable) {
|
|
91
|
+
traversedSegments.has(segment) || (traversedSegments.add(segment), getUselessReturns(uselessReturns, segment.allPrevSegments.filter(isReturned), traversedSegments));
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
segmentInfoMap.has(segment) && uselessReturns.push(...segmentInfoMap.get(segment).uselessReturns);
|
|
95
|
+
}
|
|
96
|
+
return uselessReturns;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Removes the return statements on the given segment from the useless return
|
|
100
|
+
* statement list.
|
|
101
|
+
*
|
|
102
|
+
* This segment may be an unreachable segment.
|
|
103
|
+
* In that case, the information object of the unreachable segment is not
|
|
104
|
+
* initialized because `onCodePathSegmentStart` event is not notified for
|
|
105
|
+
* unreachable segments.
|
|
106
|
+
* This goes to the previous segments of the unreachable segment recursively
|
|
107
|
+
* if the unreachable segment was generated by a return statement. Otherwise,
|
|
108
|
+
* this ignores the unreachable segment.
|
|
109
|
+
*
|
|
110
|
+
* This behavior would simulate code paths for the case that the return
|
|
111
|
+
* statement does not exist.
|
|
112
|
+
* @param {CodePathSegment} segment The segment to get return statements.
|
|
113
|
+
* @param {Set<CodePathSegment>} usedUnreachableSegments A set of segments that have already been traversed in this call.
|
|
114
|
+
* @returns {void}
|
|
115
|
+
*/
|
|
116
|
+
function markReturnStatementsOnSegmentAsUsed(segment, usedUnreachableSegments) {
|
|
117
|
+
if (!segment.reachable) {
|
|
118
|
+
usedUnreachableSegments.add(segment), segment.allPrevSegments.filter(isReturned).filter((prevSegment) => !usedUnreachableSegments.has(prevSegment)).forEach((prevSegment) => markReturnStatementsOnSegmentAsUsed(prevSegment, usedUnreachableSegments));
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
let info = segmentInfoMap.get(segment);
|
|
122
|
+
info && (info.uselessReturns = info.uselessReturns.filter((node) => {
|
|
123
|
+
if (scopeInfo.traversedTryBlockStatements && scopeInfo.traversedTryBlockStatements.length > 0) {
|
|
124
|
+
let returnInitialRange = node.range[0], returnFinalRange = node.range[1];
|
|
125
|
+
if (scopeInfo.traversedTryBlockStatements.some((tryBlockStatement) => {
|
|
126
|
+
let blockInitialRange = tryBlockStatement.range[0], blockFinalRange = tryBlockStatement.range[1];
|
|
127
|
+
return returnInitialRange >= blockInitialRange && returnFinalRange <= blockFinalRange;
|
|
128
|
+
})) return !0;
|
|
129
|
+
}
|
|
130
|
+
return remove(scopeInfo.uselessReturns, node), !1;
|
|
131
|
+
}));
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Removes the return statements on the current segments from the useless
|
|
135
|
+
* return statement list.
|
|
136
|
+
*
|
|
137
|
+
* This function will be called at every statement except FunctionDeclaration,
|
|
138
|
+
* BlockStatement, and BreakStatement.
|
|
139
|
+
*
|
|
140
|
+
* - FunctionDeclarations are always executed whether it's returned or not.
|
|
141
|
+
* - BlockStatements do nothing.
|
|
142
|
+
* - BreakStatements go the next merely.
|
|
143
|
+
* @returns {void}
|
|
144
|
+
*/
|
|
145
|
+
function markReturnStatementsOnCurrentSegmentsAsUsed() {
|
|
146
|
+
scopeInfo.currentSegments.forEach((segment) => markReturnStatementsOnSegmentAsUsed(segment, /* @__PURE__ */ new Set()));
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
onCodePathStart(codePath) {
|
|
150
|
+
scopeInfo = {
|
|
151
|
+
upper: scopeInfo,
|
|
152
|
+
uselessReturns: [],
|
|
153
|
+
traversedTryBlockStatements: [],
|
|
154
|
+
codePath,
|
|
155
|
+
currentSegments: /* @__PURE__ */ new Set()
|
|
156
|
+
};
|
|
157
|
+
},
|
|
158
|
+
onCodePathEnd() {
|
|
159
|
+
for (let node of scopeInfo.uselessReturns) context.report({
|
|
160
|
+
node,
|
|
161
|
+
loc: node.loc,
|
|
162
|
+
messageId: "unnecessaryReturn",
|
|
163
|
+
fix(fixer) {
|
|
164
|
+
return isRemovable(node) && !sourceCode.getCommentsInside(node).length ? new FixTracker(fixer, sourceCode).retainEnclosingFunction(node).remove(node) : null;
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
scopeInfo = scopeInfo.upper;
|
|
168
|
+
},
|
|
169
|
+
onCodePathSegmentStart(segment) {
|
|
170
|
+
scopeInfo.currentSegments.add(segment);
|
|
171
|
+
let info = {
|
|
172
|
+
uselessReturns: getUselessReturns([], segment.allPrevSegments),
|
|
173
|
+
returned: !1
|
|
174
|
+
};
|
|
175
|
+
segmentInfoMap.set(segment, info);
|
|
176
|
+
},
|
|
177
|
+
onUnreachableCodePathSegmentStart(segment) {
|
|
178
|
+
scopeInfo.currentSegments.add(segment);
|
|
179
|
+
},
|
|
180
|
+
onUnreachableCodePathSegmentEnd(segment) {
|
|
181
|
+
scopeInfo.currentSegments.delete(segment);
|
|
182
|
+
},
|
|
183
|
+
onCodePathSegmentEnd(segment) {
|
|
184
|
+
scopeInfo.currentSegments.delete(segment);
|
|
185
|
+
},
|
|
186
|
+
ReturnStatement(node) {
|
|
187
|
+
if (node.argument && markReturnStatementsOnCurrentSegmentsAsUsed(), !(node.argument || astUtils.isInLoop(node) || isInFinally(node) || !isAnySegmentReachable(scopeInfo.currentSegments))) {
|
|
188
|
+
for (let segment of scopeInfo.currentSegments) {
|
|
189
|
+
let info = segmentInfoMap.get(segment);
|
|
190
|
+
info && (info.uselessReturns.push(node), info.returned = !0);
|
|
191
|
+
}
|
|
192
|
+
scopeInfo.uselessReturns.push(node);
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
"TryStatement > BlockStatement.block:exit"(node) {
|
|
196
|
+
scopeInfo.traversedTryBlockStatements.push(node);
|
|
197
|
+
},
|
|
198
|
+
"TryStatement:exit"() {
|
|
199
|
+
scopeInfo.traversedTryBlockStatements.pop();
|
|
200
|
+
},
|
|
201
|
+
ClassDeclaration: markReturnStatementsOnCurrentSegmentsAsUsed,
|
|
202
|
+
ContinueStatement: markReturnStatementsOnCurrentSegmentsAsUsed,
|
|
203
|
+
DebuggerStatement: markReturnStatementsOnCurrentSegmentsAsUsed,
|
|
204
|
+
DoWhileStatement: markReturnStatementsOnCurrentSegmentsAsUsed,
|
|
205
|
+
EmptyStatement: markReturnStatementsOnCurrentSegmentsAsUsed,
|
|
206
|
+
ExpressionStatement: markReturnStatementsOnCurrentSegmentsAsUsed,
|
|
207
|
+
ForInStatement: markReturnStatementsOnCurrentSegmentsAsUsed,
|
|
208
|
+
ForOfStatement: markReturnStatementsOnCurrentSegmentsAsUsed,
|
|
209
|
+
ForStatement: markReturnStatementsOnCurrentSegmentsAsUsed,
|
|
210
|
+
IfStatement: markReturnStatementsOnCurrentSegmentsAsUsed,
|
|
211
|
+
ImportDeclaration: markReturnStatementsOnCurrentSegmentsAsUsed,
|
|
212
|
+
LabeledStatement: markReturnStatementsOnCurrentSegmentsAsUsed,
|
|
213
|
+
SwitchStatement: markReturnStatementsOnCurrentSegmentsAsUsed,
|
|
214
|
+
ThrowStatement: markReturnStatementsOnCurrentSegmentsAsUsed,
|
|
215
|
+
TryStatement: markReturnStatementsOnCurrentSegmentsAsUsed,
|
|
216
|
+
VariableDeclaration: markReturnStatementsOnCurrentSegmentsAsUsed,
|
|
217
|
+
WhileStatement: markReturnStatementsOnCurrentSegmentsAsUsed,
|
|
218
|
+
WithStatement: markReturnStatementsOnCurrentSegmentsAsUsed,
|
|
219
|
+
ExportNamedDeclaration: markReturnStatementsOnCurrentSegmentsAsUsed,
|
|
220
|
+
ExportDefaultDeclaration: markReturnStatementsOnCurrentSegmentsAsUsed,
|
|
221
|
+
ExportAllDeclaration: markReturnStatementsOnCurrentSegmentsAsUsed
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
}));
|
|
226
|
+
//#endregion
|
|
227
|
+
//#region src-js/generated/plugin-eslint/rules/no-useless-return.cjs
|
|
228
|
+
module.exports = require_no_useless_return().create;
|
|
229
|
+
//#endregion
|
package/rules/no-var.cjs
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
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-var.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Rule to check for the usage of var.
|
|
5
|
+
* @author Jamund Ferguson
|
|
6
|
+
*/
|
|
7
|
+
var require_no_var = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
8
|
+
let astUtils = require_ast_utils$1.t();
|
|
9
|
+
/**
|
|
10
|
+
* Check whether a given variable is a global variable or not.
|
|
11
|
+
* @param {eslint-scope.Variable} variable The variable to check.
|
|
12
|
+
* @returns {boolean} `true` if the variable is a global variable.
|
|
13
|
+
*/
|
|
14
|
+
function isGlobal(variable) {
|
|
15
|
+
return !!variable.scope && variable.scope.type === "global";
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Finds the nearest function scope or global scope walking up the scope
|
|
19
|
+
* hierarchy.
|
|
20
|
+
* @param {eslint-scope.Scope} scope The scope to traverse.
|
|
21
|
+
* @returns {eslint-scope.Scope} a function scope or global scope containing the given
|
|
22
|
+
* scope.
|
|
23
|
+
*/
|
|
24
|
+
function getEnclosingFunctionScope(scope) {
|
|
25
|
+
let currentScope = scope;
|
|
26
|
+
for (; currentScope.type !== "function" && currentScope.type !== "global";) currentScope = currentScope.upper;
|
|
27
|
+
return currentScope;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Checks whether the given variable has any references from a more specific
|
|
31
|
+
* function expression (i.e. a closure).
|
|
32
|
+
* @param {eslint-scope.Variable} variable A variable to check.
|
|
33
|
+
* @returns {boolean} `true` if the variable is used from a closure.
|
|
34
|
+
*/
|
|
35
|
+
function isReferencedInClosure(variable) {
|
|
36
|
+
let enclosingFunctionScope = getEnclosingFunctionScope(variable.scope);
|
|
37
|
+
return variable.references.some((reference) => getEnclosingFunctionScope(reference.from) !== enclosingFunctionScope);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Checks whether the given node is the assignee of a loop.
|
|
41
|
+
* @param {ASTNode} node A VariableDeclaration node to check.
|
|
42
|
+
* @returns {boolean} `true` if the declaration is assigned as part of loop
|
|
43
|
+
* iteration.
|
|
44
|
+
*/
|
|
45
|
+
function isLoopAssignee(node) {
|
|
46
|
+
return (node.parent.type === "ForOfStatement" || node.parent.type === "ForInStatement") && node === node.parent.left;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Checks whether the given variable declaration is immediately initialized.
|
|
50
|
+
* @param {ASTNode} node A VariableDeclaration node to check.
|
|
51
|
+
* @returns {boolean} `true` if the declaration has an initializer.
|
|
52
|
+
*/
|
|
53
|
+
function isDeclarationInitialized(node) {
|
|
54
|
+
return node.declarations.every((declarator) => declarator.init !== null);
|
|
55
|
+
}
|
|
56
|
+
let SCOPE_NODE_TYPE = /^(?:Program|BlockStatement|SwitchStatement|ForStatement|ForInStatement|ForOfStatement)$/u;
|
|
57
|
+
/**
|
|
58
|
+
* Gets the scope node which directly contains a given node.
|
|
59
|
+
* @param {ASTNode} node A node to get. This is a `VariableDeclaration` or
|
|
60
|
+
* an `Identifier`.
|
|
61
|
+
* @returns {ASTNode} A scope node. This is one of `Program`, `BlockStatement`,
|
|
62
|
+
* `SwitchStatement`, `ForStatement`, `ForInStatement`, and
|
|
63
|
+
* `ForOfStatement`.
|
|
64
|
+
*/
|
|
65
|
+
function getScopeNode(node) {
|
|
66
|
+
for (let currentNode = node; currentNode; currentNode = currentNode.parent) if (SCOPE_NODE_TYPE.test(currentNode.type)) return currentNode;
|
|
67
|
+
/* c8 ignore next */
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Checks whether a given variable is redeclared or not.
|
|
72
|
+
* @param {eslint-scope.Variable} variable A variable to check.
|
|
73
|
+
* @returns {boolean} `true` if the variable is redeclared.
|
|
74
|
+
*/
|
|
75
|
+
function isRedeclared(variable) {
|
|
76
|
+
return variable.defs.length >= 2;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Checks whether a given variable is used from outside of the specified scope.
|
|
80
|
+
* @param {ASTNode} scopeNode A scope node to check.
|
|
81
|
+
* @returns {Function} The predicate function which checks whether a given
|
|
82
|
+
* variable is used from outside of the specified scope.
|
|
83
|
+
*/
|
|
84
|
+
function isUsedFromOutsideOf(scopeNode) {
|
|
85
|
+
/**
|
|
86
|
+
* Checks whether a given reference is inside of the specified scope or not.
|
|
87
|
+
* @param {eslint-scope.Reference} reference A reference to check.
|
|
88
|
+
* @returns {boolean} `true` if the reference is inside of the specified
|
|
89
|
+
* scope.
|
|
90
|
+
*/
|
|
91
|
+
function isOutsideOfScope(reference) {
|
|
92
|
+
let scope = scopeNode.range, id = reference.identifier.range;
|
|
93
|
+
return id[0] < scope[0] || id[1] > scope[1];
|
|
94
|
+
}
|
|
95
|
+
return function(variable) {
|
|
96
|
+
return variable.references.some(isOutsideOfScope);
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Creates the predicate function which checks whether a variable has their references in TDZ.
|
|
101
|
+
*
|
|
102
|
+
* The predicate function would return `true`:
|
|
103
|
+
*
|
|
104
|
+
* - if a reference is before the declarator. E.g. (var a = b, b = 1;)(var {a = b, b} = {};)
|
|
105
|
+
* - if a reference is in the expression of their default value. E.g. (var {a = a} = {};)
|
|
106
|
+
* - if a reference is in the expression of their initializer. E.g. (var a = a;)
|
|
107
|
+
* @param {ASTNode} node The initializer node of VariableDeclarator.
|
|
108
|
+
* @returns {Function} The predicate function.
|
|
109
|
+
* @private
|
|
110
|
+
*/
|
|
111
|
+
function hasReferenceInTDZ(node) {
|
|
112
|
+
let initStart = node.range[0], initEnd = node.range[1];
|
|
113
|
+
return (variable) => {
|
|
114
|
+
let id = variable.defs[0].name, idStart = id.range[0], defaultValue = id.parent.type === "AssignmentPattern" ? id.parent.right : null, defaultStart = defaultValue && defaultValue.range[0], defaultEnd = defaultValue && defaultValue.range[1];
|
|
115
|
+
return variable.references.some((reference) => {
|
|
116
|
+
let start = reference.identifier.range[0], end = reference.identifier.range[1];
|
|
117
|
+
return !reference.init && (start < idStart || defaultValue !== null && start >= defaultStart && end <= defaultEnd || !astUtils.isFunction(node) && start >= initStart && end <= initEnd);
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Checks whether a given variable has name that is allowed for 'var' declarations,
|
|
123
|
+
* but disallowed for `let` declarations.
|
|
124
|
+
* @param {eslint-scope.Variable} variable The variable to check.
|
|
125
|
+
* @returns {boolean} `true` if the variable has a disallowed name.
|
|
126
|
+
*/
|
|
127
|
+
function hasNameDisallowedForLetDeclarations(variable) {
|
|
128
|
+
return variable.name === "let";
|
|
129
|
+
}
|
|
130
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
131
|
+
module.exports = {
|
|
132
|
+
meta: {
|
|
133
|
+
type: "suggestion",
|
|
134
|
+
dialects: ["typescript", "javascript"],
|
|
135
|
+
language: "javascript",
|
|
136
|
+
docs: {
|
|
137
|
+
description: "Require `let` or `const` instead of `var`",
|
|
138
|
+
recommended: !1,
|
|
139
|
+
url: "https://eslint.org/docs/latest/rules/no-var"
|
|
140
|
+
},
|
|
141
|
+
schema: [],
|
|
142
|
+
fixable: "code",
|
|
143
|
+
messages: { unexpectedVar: "Unexpected var, use let or const instead." }
|
|
144
|
+
},
|
|
145
|
+
create(context) {
|
|
146
|
+
let sourceCode = context.sourceCode;
|
|
147
|
+
/**
|
|
148
|
+
* Checks whether the variables which are defined by the given declarator node have their references in TDZ.
|
|
149
|
+
* @param {ASTNode} declarator The VariableDeclarator node to check.
|
|
150
|
+
* @returns {boolean} `true` if one of the variables which are defined by the given declarator node have their references in TDZ.
|
|
151
|
+
*/
|
|
152
|
+
function hasSelfReferenceInTDZ(declarator) {
|
|
153
|
+
return declarator.init ? sourceCode.getDeclaredVariables(declarator).some(hasReferenceInTDZ(declarator.init)) : !1;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Checks whether it can fix a given variable declaration or not.
|
|
157
|
+
* It cannot fix if the following cases:
|
|
158
|
+
*
|
|
159
|
+
* - A variable is a global variable.
|
|
160
|
+
* - A variable is declared on a SwitchCase node.
|
|
161
|
+
* - A variable is redeclared.
|
|
162
|
+
* - A variable is used from outside the scope.
|
|
163
|
+
* - A variable is used from a closure within a loop.
|
|
164
|
+
* - A variable might be used before it is assigned within a loop.
|
|
165
|
+
* - A variable might be used in TDZ.
|
|
166
|
+
* - A variable is declared in statement position (e.g. a single-line `IfStatement`)
|
|
167
|
+
* - A variable has name that is disallowed for `let` declarations.
|
|
168
|
+
*
|
|
169
|
+
* ## A variable is declared on a SwitchCase node.
|
|
170
|
+
*
|
|
171
|
+
* If this rule modifies 'var' declarations on a SwitchCase node, it
|
|
172
|
+
* would generate the warnings of 'no-case-declarations' rule. And the
|
|
173
|
+
* 'eslint:recommended' preset includes 'no-case-declarations' rule, so
|
|
174
|
+
* this rule doesn't modify those declarations.
|
|
175
|
+
*
|
|
176
|
+
* ## A variable is redeclared.
|
|
177
|
+
*
|
|
178
|
+
* The language spec disallows redeclarations of `let` declarations.
|
|
179
|
+
* Those variables would cause syntax errors.
|
|
180
|
+
*
|
|
181
|
+
* ## A variable is used from outside the scope.
|
|
182
|
+
*
|
|
183
|
+
* The language spec disallows accesses from outside of the scope for
|
|
184
|
+
* `let` declarations. Those variables would cause reference errors.
|
|
185
|
+
*
|
|
186
|
+
* ## A variable is used from a closure within a loop.
|
|
187
|
+
*
|
|
188
|
+
* A `var` declaration within a loop shares the same variable instance
|
|
189
|
+
* across all loop iterations, while a `let` declaration creates a new
|
|
190
|
+
* instance for each iteration. This means if a variable in a loop is
|
|
191
|
+
* referenced by any closure, changing it from `var` to `let` would
|
|
192
|
+
* change the behavior in a way that is generally unsafe.
|
|
193
|
+
*
|
|
194
|
+
* ## A variable might be used before it is assigned within a loop.
|
|
195
|
+
*
|
|
196
|
+
* Within a loop, a `let` declaration without an initializer will be
|
|
197
|
+
* initialized to null, while a `var` declaration will retain its value
|
|
198
|
+
* from the previous iteration, so it is only safe to change `var` to
|
|
199
|
+
* `let` if we can statically determine that the variable is always
|
|
200
|
+
* assigned a value before its first access in the loop body. To keep
|
|
201
|
+
* the implementation simple, we only convert `var` to `let` within
|
|
202
|
+
* loops when the variable is a loop assignee or the declaration has an
|
|
203
|
+
* initializer.
|
|
204
|
+
* @param {ASTNode} node A variable declaration node to check.
|
|
205
|
+
* @returns {boolean} `true` if it can fix the node.
|
|
206
|
+
*/
|
|
207
|
+
function canFix(node) {
|
|
208
|
+
let variables = sourceCode.getDeclaredVariables(node), scopeNode = getScopeNode(node);
|
|
209
|
+
return !(node.parent.type === "SwitchCase" || node.declarations.some(hasSelfReferenceInTDZ) || variables.some(isGlobal) || variables.some(isRedeclared) || variables.some(isUsedFromOutsideOf(scopeNode)) || variables.some(hasNameDisallowedForLetDeclarations) || astUtils.isInLoop(node) && (variables.some(isReferencedInClosure) || !isLoopAssignee(node) && !isDeclarationInitialized(node)) || !isLoopAssignee(node) && !(node.parent.type === "ForStatement" && node.parent.init === node) && !astUtils.STATEMENT_LIST_PARENTS.has(node.parent.type));
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Reports a given variable declaration node.
|
|
213
|
+
* @param {ASTNode} node A variable declaration node to report.
|
|
214
|
+
* @returns {void}
|
|
215
|
+
*/
|
|
216
|
+
function report(node) {
|
|
217
|
+
context.report({
|
|
218
|
+
node,
|
|
219
|
+
messageId: "unexpectedVar",
|
|
220
|
+
fix(fixer) {
|
|
221
|
+
let varToken = sourceCode.getFirstToken(node, { filter: (t) => t.value === "var" });
|
|
222
|
+
return canFix(node) ? fixer.replaceText(varToken, "let") : null;
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
return { "VariableDeclaration:exit"(node) {
|
|
227
|
+
node.kind === "var" && (node.parent.type === "TSModuleBlock" && node.parent.parent.type === "TSModuleDeclaration" && node.parent.parent.global || report(node));
|
|
228
|
+
} };
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
}));
|
|
232
|
+
//#endregion
|
|
233
|
+
//#region src-js/generated/plugin-eslint/rules/no-var.cjs
|
|
234
|
+
module.exports = require_no_var().create;
|
|
235
|
+
//#endregion
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/eslint@9.39.3_jiti@2.6.1/node_modules/eslint/lib/rules/no-void.js
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Rule to disallow use of void operator.
|
|
4
|
+
* @author Mike Sidorov
|
|
5
|
+
*/
|
|
6
|
+
var require_no_void = /* @__PURE__ */ require("../common/chunk.cjs").t(((exports, module) => {
|
|
7
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
8
|
+
module.exports = {
|
|
9
|
+
meta: {
|
|
10
|
+
type: "suggestion",
|
|
11
|
+
defaultOptions: [{ allowAsStatement: !1 }],
|
|
12
|
+
docs: {
|
|
13
|
+
description: "Disallow `void` operators",
|
|
14
|
+
recommended: !1,
|
|
15
|
+
frozen: !0,
|
|
16
|
+
url: "https://eslint.org/docs/latest/rules/no-void"
|
|
17
|
+
},
|
|
18
|
+
messages: { noVoid: "Expected 'undefined' and instead saw 'void'." },
|
|
19
|
+
schema: [{
|
|
20
|
+
type: "object",
|
|
21
|
+
properties: { allowAsStatement: { type: "boolean" } },
|
|
22
|
+
additionalProperties: !1
|
|
23
|
+
}]
|
|
24
|
+
},
|
|
25
|
+
create(context) {
|
|
26
|
+
let [{ allowAsStatement }] = context.options;
|
|
27
|
+
return { "UnaryExpression[operator=\"void\"]"(node) {
|
|
28
|
+
allowAsStatement && node.parent && node.parent.type === "ExpressionStatement" || context.report({
|
|
29
|
+
node,
|
|
30
|
+
messageId: "noVoid"
|
|
31
|
+
});
|
|
32
|
+
} };
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}));
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src-js/generated/plugin-eslint/rules/no-void.cjs
|
|
38
|
+
module.exports = require_no_void().create;
|
|
39
|
+
//#endregion
|