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
package/rules/eqeqeq.cjs
ADDED
|
@@ -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/eqeqeq.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Rule to flag statements that use != and == instead of !== and ===
|
|
5
|
+
* @author Nicholas C. Zakas
|
|
6
|
+
*/
|
|
7
|
+
var require_eqeqeq = /* @__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
|
+
hasSuggestions: !0,
|
|
14
|
+
docs: {
|
|
15
|
+
description: "Require the use of `===` and `!==`",
|
|
16
|
+
recommended: !1,
|
|
17
|
+
url: "https://eslint.org/docs/latest/rules/eqeqeq"
|
|
18
|
+
},
|
|
19
|
+
schema: { anyOf: [{
|
|
20
|
+
type: "array",
|
|
21
|
+
items: [{ enum: ["always"] }, {
|
|
22
|
+
type: "object",
|
|
23
|
+
properties: { null: { enum: [
|
|
24
|
+
"always",
|
|
25
|
+
"never",
|
|
26
|
+
"ignore"
|
|
27
|
+
] } },
|
|
28
|
+
additionalProperties: !1
|
|
29
|
+
}],
|
|
30
|
+
additionalItems: !1
|
|
31
|
+
}, {
|
|
32
|
+
type: "array",
|
|
33
|
+
items: [{ enum: ["smart", "allow-null"] }],
|
|
34
|
+
additionalItems: !1
|
|
35
|
+
}] },
|
|
36
|
+
fixable: "code",
|
|
37
|
+
messages: {
|
|
38
|
+
unexpected: "Expected '{{expectedOperator}}' and instead saw '{{actualOperator}}'.",
|
|
39
|
+
replaceOperator: "Use '{{expectedOperator}}' instead of '{{actualOperator}}'."
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
create(context) {
|
|
43
|
+
let config = context.options[0] || "always", options = context.options[1] || {}, sourceCode = context.sourceCode, nullOption = config === "always" ? options.null || "always" : "ignore", enforceRuleForNull = nullOption === "always", enforceInverseRuleForNull = nullOption === "never";
|
|
44
|
+
/**
|
|
45
|
+
* Checks if an expression is a typeof expression
|
|
46
|
+
* @param {ASTNode} node The node to check
|
|
47
|
+
* @returns {boolean} if the node is a typeof expression
|
|
48
|
+
*/
|
|
49
|
+
function isTypeOf(node) {
|
|
50
|
+
return node.type === "UnaryExpression" && node.operator === "typeof";
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Checks if either operand of a binary expression is a typeof operation
|
|
54
|
+
* @param {ASTNode} node The node to check
|
|
55
|
+
* @returns {boolean} if one of the operands is typeof
|
|
56
|
+
* @private
|
|
57
|
+
*/
|
|
58
|
+
function isTypeOfBinary(node) {
|
|
59
|
+
return isTypeOf(node.left) || isTypeOf(node.right);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Checks if operands are literals of the same type (via typeof)
|
|
63
|
+
* @param {ASTNode} node The node to check
|
|
64
|
+
* @returns {boolean} if operands are of same type
|
|
65
|
+
* @private
|
|
66
|
+
*/
|
|
67
|
+
function areLiteralsAndSameType(node) {
|
|
68
|
+
return node.left.type === "Literal" && node.right.type === "Literal" && typeof node.left.value == typeof node.right.value;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Checks if one of the operands is a literal null
|
|
72
|
+
* @param {ASTNode} node The node to check
|
|
73
|
+
* @returns {boolean} if operands are null
|
|
74
|
+
* @private
|
|
75
|
+
*/
|
|
76
|
+
function isNullCheck(node) {
|
|
77
|
+
return astUtils.isNullLiteral(node.right) || astUtils.isNullLiteral(node.left);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Reports a message for this rule.
|
|
81
|
+
* @param {ASTNode} node The binary expression node that was checked
|
|
82
|
+
* @param {string} expectedOperator The operator that was expected (either '==', '!=', '===', or '!==')
|
|
83
|
+
* @returns {void}
|
|
84
|
+
* @private
|
|
85
|
+
*/
|
|
86
|
+
function report(node, expectedOperator) {
|
|
87
|
+
let operatorToken = sourceCode.getFirstTokenBetween(node.left, node.right, (token) => token.value === node.operator), commonReportParams = {
|
|
88
|
+
node,
|
|
89
|
+
loc: operatorToken.loc,
|
|
90
|
+
messageId: "unexpected",
|
|
91
|
+
data: {
|
|
92
|
+
expectedOperator,
|
|
93
|
+
actualOperator: node.operator
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
isTypeOfBinary(node) || areLiteralsAndSameType(node) ? context.report({
|
|
97
|
+
...commonReportParams,
|
|
98
|
+
fix(fixer) {
|
|
99
|
+
return fixer.replaceText(operatorToken, expectedOperator);
|
|
100
|
+
}
|
|
101
|
+
}) : context.report({
|
|
102
|
+
...commonReportParams,
|
|
103
|
+
suggest: [{
|
|
104
|
+
messageId: "replaceOperator",
|
|
105
|
+
data: {
|
|
106
|
+
expectedOperator,
|
|
107
|
+
actualOperator: node.operator
|
|
108
|
+
},
|
|
109
|
+
fix: (fixer) => fixer.replaceText(operatorToken, expectedOperator)
|
|
110
|
+
}]
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return { BinaryExpression(node) {
|
|
114
|
+
let isNull = isNullCheck(node);
|
|
115
|
+
if (node.operator !== "==" && node.operator !== "!=") {
|
|
116
|
+
enforceInverseRuleForNull && isNull && report(node, node.operator.slice(0, -1));
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
config === "smart" && (isTypeOfBinary(node) || areLiteralsAndSameType(node) || isNull) || !enforceRuleForNull && isNull || report(node, `${node.operator}=`);
|
|
120
|
+
} };
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}));
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region src-js/generated/plugin-eslint/rules/eqeqeq.cjs
|
|
126
|
+
module.exports = require_eqeqeq().create;
|
|
127
|
+
//#endregion
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
const require_chunk = require("../common/chunk.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/for-direction.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview enforce `for` loop update clause moving the counter in the right direction.(for-direction)
|
|
5
|
+
* @author Aladdin-ADD<hh_2013@foxmail.com>
|
|
6
|
+
*/
|
|
7
|
+
var require_for_direction = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
8
|
+
let { getStaticValue } = require_eslint_utils$1.t();
|
|
9
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
10
|
+
module.exports = {
|
|
11
|
+
meta: {
|
|
12
|
+
type: "problem",
|
|
13
|
+
docs: {
|
|
14
|
+
description: "Enforce `for` loop update clause moving the counter in the right direction",
|
|
15
|
+
recommended: !0,
|
|
16
|
+
url: "https://eslint.org/docs/latest/rules/for-direction"
|
|
17
|
+
},
|
|
18
|
+
fixable: null,
|
|
19
|
+
schema: [],
|
|
20
|
+
messages: { incorrectDirection: "The update clause in this loop moves the variable in the wrong direction." }
|
|
21
|
+
},
|
|
22
|
+
create(context) {
|
|
23
|
+
let { sourceCode } = context;
|
|
24
|
+
/**
|
|
25
|
+
* report an error.
|
|
26
|
+
* @param {ASTNode} node the node to report.
|
|
27
|
+
* @returns {void}
|
|
28
|
+
*/
|
|
29
|
+
function report(node) {
|
|
30
|
+
context.report({
|
|
31
|
+
loc: {
|
|
32
|
+
start: node.loc.start,
|
|
33
|
+
end: sourceCode.getTokenBefore(node.body).loc.end
|
|
34
|
+
},
|
|
35
|
+
messageId: "incorrectDirection"
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* check the right side of the assignment
|
|
40
|
+
* @param {ASTNode} update UpdateExpression to check
|
|
41
|
+
* @param {number} dir expected direction that could either be turned around or invalidated
|
|
42
|
+
* @returns {number} return dir, the negated dir, or zero if the counter does not change or the direction is not clear
|
|
43
|
+
*/
|
|
44
|
+
function getRightDirection(update, dir) {
|
|
45
|
+
let staticValue = getStaticValue(update.right, sourceCode.getScope(update));
|
|
46
|
+
return staticValue && [
|
|
47
|
+
"bigint",
|
|
48
|
+
"boolean",
|
|
49
|
+
"number"
|
|
50
|
+
].includes(typeof staticValue.value) ? dir * (Math.sign(Number(staticValue.value)) || 0) : 0;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* check UpdateExpression add/sub the counter
|
|
54
|
+
* @param {ASTNode} update UpdateExpression to check
|
|
55
|
+
* @param {string} counter variable name to check
|
|
56
|
+
* @returns {number} if add return 1, if sub return -1, if nochange, return 0
|
|
57
|
+
*/
|
|
58
|
+
function getUpdateDirection(update, counter) {
|
|
59
|
+
if (update.argument.type === "Identifier" && update.argument.name === counter) {
|
|
60
|
+
if (update.operator === "++") return 1;
|
|
61
|
+
if (update.operator === "--") return -1;
|
|
62
|
+
}
|
|
63
|
+
return 0;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* check AssignmentExpression add/sub the counter
|
|
67
|
+
* @param {ASTNode} update AssignmentExpression to check
|
|
68
|
+
* @param {string} counter variable name to check
|
|
69
|
+
* @returns {number} if add return 1, if sub return -1, if nochange, return 0
|
|
70
|
+
*/
|
|
71
|
+
function getAssignmentDirection(update, counter) {
|
|
72
|
+
if (update.left.name === counter) {
|
|
73
|
+
if (update.operator === "+=") return getRightDirection(update, 1);
|
|
74
|
+
if (update.operator === "-=") return getRightDirection(update, -1);
|
|
75
|
+
}
|
|
76
|
+
return 0;
|
|
77
|
+
}
|
|
78
|
+
return { ForStatement(node) {
|
|
79
|
+
if (node.test && node.test.type === "BinaryExpression" && node.update) for (let counterPosition of ["left", "right"]) {
|
|
80
|
+
if (node.test[counterPosition].type !== "Identifier") continue;
|
|
81
|
+
let counter = node.test[counterPosition].name, operator = node.test.operator, update = node.update, wrongDirection;
|
|
82
|
+
if (operator === "<" || operator === "<=") wrongDirection = counterPosition === "left" ? -1 : 1;
|
|
83
|
+
else if (operator === ">" || operator === ">=") wrongDirection = counterPosition === "left" ? 1 : -1;
|
|
84
|
+
else return;
|
|
85
|
+
update.type === "UpdateExpression" ? getUpdateDirection(update, counter) === wrongDirection && report(node) : update.type === "AssignmentExpression" && getAssignmentDirection(update, counter) === wrongDirection && report(node);
|
|
86
|
+
}
|
|
87
|
+
} };
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}));
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src-js/generated/plugin-eslint/rules/for-direction.cjs
|
|
93
|
+
module.exports = require_for_direction().create;
|
|
94
|
+
//#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/func-call-spacing.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Rule to control spacing within function calls
|
|
5
|
+
* @author Matt DuVall <http://www.mattduvall.com>
|
|
6
|
+
* @deprecated in ESLint v8.53.0
|
|
7
|
+
*/
|
|
8
|
+
var require_func_call_spacing = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
9
|
+
let astUtils = require_ast_utils$1.t();
|
|
10
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
11
|
+
module.exports = {
|
|
12
|
+
meta: {
|
|
13
|
+
deprecated: {
|
|
14
|
+
message: "Formatting rules are being moved out of ESLint core.",
|
|
15
|
+
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
|
|
16
|
+
deprecatedSince: "8.53.0",
|
|
17
|
+
availableUntil: "11.0.0",
|
|
18
|
+
replacedBy: [{
|
|
19
|
+
message: "ESLint Stylistic now maintains deprecated stylistic core rules.",
|
|
20
|
+
url: "https://eslint.style/guide/migration",
|
|
21
|
+
plugin: {
|
|
22
|
+
name: "@stylistic/eslint-plugin",
|
|
23
|
+
url: "https://eslint.style"
|
|
24
|
+
},
|
|
25
|
+
rule: {
|
|
26
|
+
name: "function-call-spacing",
|
|
27
|
+
url: "https://eslint.style/rules/function-call-spacing"
|
|
28
|
+
}
|
|
29
|
+
}]
|
|
30
|
+
},
|
|
31
|
+
type: "layout",
|
|
32
|
+
docs: {
|
|
33
|
+
description: "Require or disallow spacing between function identifiers and their invocations",
|
|
34
|
+
recommended: !1,
|
|
35
|
+
url: "https://eslint.org/docs/latest/rules/func-call-spacing"
|
|
36
|
+
},
|
|
37
|
+
fixable: "whitespace",
|
|
38
|
+
schema: { anyOf: [{
|
|
39
|
+
type: "array",
|
|
40
|
+
items: [{ enum: ["never"] }],
|
|
41
|
+
minItems: 0,
|
|
42
|
+
maxItems: 1
|
|
43
|
+
}, {
|
|
44
|
+
type: "array",
|
|
45
|
+
items: [{ enum: ["always"] }, {
|
|
46
|
+
type: "object",
|
|
47
|
+
properties: { allowNewlines: { type: "boolean" } },
|
|
48
|
+
additionalProperties: !1
|
|
49
|
+
}],
|
|
50
|
+
minItems: 0,
|
|
51
|
+
maxItems: 2
|
|
52
|
+
}] },
|
|
53
|
+
messages: {
|
|
54
|
+
unexpectedWhitespace: "Unexpected whitespace between function name and paren.",
|
|
55
|
+
unexpectedNewline: "Unexpected newline between function name and paren.",
|
|
56
|
+
missing: "Missing space between function name and paren."
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
create(context) {
|
|
60
|
+
let never = context.options[0] !== "always", allowNewlines = !never && context.options[1] && context.options[1].allowNewlines, sourceCode = context.sourceCode, text = sourceCode.getText();
|
|
61
|
+
/**
|
|
62
|
+
* Check if open space is present in a function name
|
|
63
|
+
* @param {ASTNode} node node to evaluate
|
|
64
|
+
* @param {Token} leftToken The last token of the callee. This may be the closing parenthesis that encloses the callee.
|
|
65
|
+
* @param {Token} rightToken The first token of the arguments. this is the opening parenthesis that encloses the arguments.
|
|
66
|
+
* @returns {void}
|
|
67
|
+
* @private
|
|
68
|
+
*/
|
|
69
|
+
function checkSpacing(node, leftToken, rightToken) {
|
|
70
|
+
let textBetweenTokens = text.slice(leftToken.range[1], rightToken.range[0]).replace(/\/\*.*?\*\//gu, ""), hasWhitespace = /\s/u.test(textBetweenTokens), hasNewline = hasWhitespace && astUtils.LINEBREAK_MATCHER.test(textBetweenTokens);
|
|
71
|
+
never && hasWhitespace ? context.report({
|
|
72
|
+
node,
|
|
73
|
+
loc: {
|
|
74
|
+
start: leftToken.loc.end,
|
|
75
|
+
end: {
|
|
76
|
+
line: rightToken.loc.start.line,
|
|
77
|
+
column: rightToken.loc.start.column - 1
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
messageId: "unexpectedWhitespace",
|
|
81
|
+
fix(fixer) {
|
|
82
|
+
return sourceCode.commentsExistBetween(leftToken, rightToken) ? null : node.optional ? fixer.replaceTextRange([leftToken.range[1], rightToken.range[0]], "?.") : hasNewline ? null : fixer.removeRange([leftToken.range[1], rightToken.range[0]]);
|
|
83
|
+
}
|
|
84
|
+
}) : !never && !hasWhitespace ? context.report({
|
|
85
|
+
node,
|
|
86
|
+
loc: {
|
|
87
|
+
start: {
|
|
88
|
+
line: leftToken.loc.end.line,
|
|
89
|
+
column: leftToken.loc.end.column - 1
|
|
90
|
+
},
|
|
91
|
+
end: rightToken.loc.start
|
|
92
|
+
},
|
|
93
|
+
messageId: "missing",
|
|
94
|
+
fix(fixer) {
|
|
95
|
+
return node.optional ? null : fixer.insertTextBefore(rightToken, " ");
|
|
96
|
+
}
|
|
97
|
+
}) : !never && !allowNewlines && hasNewline && context.report({
|
|
98
|
+
node,
|
|
99
|
+
loc: {
|
|
100
|
+
start: leftToken.loc.end,
|
|
101
|
+
end: rightToken.loc.start
|
|
102
|
+
},
|
|
103
|
+
messageId: "unexpectedNewline",
|
|
104
|
+
fix(fixer) {
|
|
105
|
+
if (!node.optional || sourceCode.commentsExistBetween(leftToken, rightToken)) return null;
|
|
106
|
+
let range = [leftToken.range[1], rightToken.range[0]], qdToken = sourceCode.getTokenAfter(leftToken);
|
|
107
|
+
return qdToken.range[0] === leftToken.range[1] ? fixer.replaceTextRange(range, "?. ") : qdToken.range[1] === rightToken.range[0] ? fixer.replaceTextRange(range, " ?.") : fixer.replaceTextRange(range, " ?. ");
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
"CallExpression, NewExpression"(node) {
|
|
113
|
+
let lastToken = sourceCode.getLastToken(node), lastCalleeToken = sourceCode.getLastToken(node.callee), parenToken = sourceCode.getFirstTokenBetween(lastCalleeToken, lastToken, astUtils.isOpeningParenToken), prevToken = parenToken && sourceCode.getTokenBefore(parenToken, astUtils.isNotQuestionDotToken);
|
|
114
|
+
parenToken && parenToken.range[1] < node.range[1] && checkSpacing(node, prevToken, parenToken);
|
|
115
|
+
},
|
|
116
|
+
ImportExpression(node) {
|
|
117
|
+
let leftToken = sourceCode.getFirstToken(node);
|
|
118
|
+
checkSpacing(node, leftToken, sourceCode.getTokenAfter(leftToken));
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}));
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region src-js/generated/plugin-eslint/rules/func-call-spacing.cjs
|
|
126
|
+
module.exports = require_func_call_spacing().create;
|
|
127
|
+
//#endregion
|
|
@@ -0,0 +1,138 @@
|
|
|
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/func-name-matching.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Rule to require function names to match the name of the variable or property to which they are assigned.
|
|
5
|
+
* @author Annie Zhang, Pavel Strashkin
|
|
6
|
+
*/
|
|
7
|
+
var require_func_name_matching = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
8
|
+
let astUtils = require_ast_utils$1.t(), esutils = require_ast_utils$1.i();
|
|
9
|
+
/**
|
|
10
|
+
* Determines if a pattern is `module.exports` or `module["exports"]`
|
|
11
|
+
* @param {ASTNode} pattern The left side of the AssignmentExpression
|
|
12
|
+
* @returns {boolean} True if the pattern is `module.exports` or `module["exports"]`
|
|
13
|
+
*/
|
|
14
|
+
function isModuleExports(pattern) {
|
|
15
|
+
return pattern.type === "MemberExpression" && pattern.object.type === "Identifier" && pattern.object.name === "module" && (pattern.property.type === "Identifier" && pattern.property.name === "exports" || pattern.property.type === "Literal" && pattern.property.value === "exports");
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Determines if a string name is a valid identifier
|
|
19
|
+
* @param {string} name The string to be checked
|
|
20
|
+
* @param {number} ecmaVersion The ECMAScript version if specified in the parserOptions config
|
|
21
|
+
* @returns {boolean} True if the string is a valid identifier
|
|
22
|
+
*/
|
|
23
|
+
function isIdentifier(name, ecmaVersion) {
|
|
24
|
+
return ecmaVersion >= 2015 ? esutils.keyword.isIdentifierES6(name) : esutils.keyword.isIdentifierES5(name);
|
|
25
|
+
}
|
|
26
|
+
let alwaysOrNever = { enum: ["always", "never"] }, optionsObject = {
|
|
27
|
+
type: "object",
|
|
28
|
+
properties: {
|
|
29
|
+
considerPropertyDescriptor: { type: "boolean" },
|
|
30
|
+
includeCommonJSModuleExports: { type: "boolean" }
|
|
31
|
+
},
|
|
32
|
+
additionalProperties: !1
|
|
33
|
+
};
|
|
34
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
35
|
+
module.exports = {
|
|
36
|
+
meta: {
|
|
37
|
+
type: "suggestion",
|
|
38
|
+
docs: {
|
|
39
|
+
description: "Require function names to match the name of the variable or property to which they are assigned",
|
|
40
|
+
recommended: !1,
|
|
41
|
+
frozen: !0,
|
|
42
|
+
url: "https://eslint.org/docs/latest/rules/func-name-matching"
|
|
43
|
+
},
|
|
44
|
+
schema: { anyOf: [{
|
|
45
|
+
type: "array",
|
|
46
|
+
additionalItems: !1,
|
|
47
|
+
items: [alwaysOrNever, optionsObject]
|
|
48
|
+
}, {
|
|
49
|
+
type: "array",
|
|
50
|
+
additionalItems: !1,
|
|
51
|
+
items: [optionsObject]
|
|
52
|
+
}] },
|
|
53
|
+
messages: {
|
|
54
|
+
matchProperty: "Function name `{{funcName}}` should match property name `{{name}}`.",
|
|
55
|
+
matchVariable: "Function name `{{funcName}}` should match variable name `{{name}}`.",
|
|
56
|
+
notMatchProperty: "Function name `{{funcName}}` should not match property name `{{name}}`.",
|
|
57
|
+
notMatchVariable: "Function name `{{funcName}}` should not match variable name `{{name}}`."
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
create(context) {
|
|
61
|
+
let options = (typeof context.options[0] == "object" ? context.options[0] : context.options[1]) || {}, nameMatches = typeof context.options[0] == "string" ? context.options[0] : "always", considerPropertyDescriptor = options.considerPropertyDescriptor, includeModuleExports = options.includeCommonJSModuleExports, ecmaVersion = context.languageOptions.ecmaVersion;
|
|
62
|
+
/**
|
|
63
|
+
* Check whether node is a certain CallExpression.
|
|
64
|
+
* @param {string} objName object name
|
|
65
|
+
* @param {string} funcName function name
|
|
66
|
+
* @param {ASTNode} node The node to check
|
|
67
|
+
* @returns {boolean} `true` if node matches CallExpression
|
|
68
|
+
*/
|
|
69
|
+
function isPropertyCall(objName, funcName, node) {
|
|
70
|
+
return node ? node.type === "CallExpression" && astUtils.isSpecificMemberAccess(node.callee, objName, funcName) : !1;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Compares identifiers based on the nameMatches option
|
|
74
|
+
* @param {string} x the first identifier
|
|
75
|
+
* @param {string} y the second identifier
|
|
76
|
+
* @returns {boolean} whether the two identifiers should warn.
|
|
77
|
+
*/
|
|
78
|
+
function shouldWarn(x, y) {
|
|
79
|
+
return nameMatches === "always" && x !== y || nameMatches === "never" && x === y;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Reports
|
|
83
|
+
* @param {ASTNode} node The node to report
|
|
84
|
+
* @param {string} name The variable or property name
|
|
85
|
+
* @param {string} funcName The function name
|
|
86
|
+
* @param {boolean} isProp True if the reported node is a property assignment
|
|
87
|
+
* @returns {void}
|
|
88
|
+
*/
|
|
89
|
+
function report(node, name, funcName, isProp) {
|
|
90
|
+
let messageId;
|
|
91
|
+
messageId = nameMatches === "always" && isProp ? "matchProperty" : nameMatches === "always" ? "matchVariable" : isProp ? "notMatchProperty" : "notMatchVariable", context.report({
|
|
92
|
+
node,
|
|
93
|
+
messageId,
|
|
94
|
+
data: {
|
|
95
|
+
name,
|
|
96
|
+
funcName
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Determines whether a given node is a string literal
|
|
102
|
+
* @param {ASTNode} node The node to check
|
|
103
|
+
* @returns {boolean} `true` if the node is a string literal
|
|
104
|
+
*/
|
|
105
|
+
function isStringLiteral(node) {
|
|
106
|
+
return node.type === "Literal" && typeof node.value == "string";
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
VariableDeclarator(node) {
|
|
110
|
+
!node.init || node.init.type !== "FunctionExpression" || node.id.type !== "Identifier" || node.init.id && shouldWarn(node.id.name, node.init.id.name) && report(node, node.id.name, node.init.id.name, !1);
|
|
111
|
+
},
|
|
112
|
+
AssignmentExpression(node) {
|
|
113
|
+
if (node.right.type !== "FunctionExpression" || node.left.computed && node.left.property.type !== "Literal" || !includeModuleExports && isModuleExports(node.left) || node.left.type !== "Identifier" && node.left.type !== "MemberExpression") return;
|
|
114
|
+
let isProp = node.left.type === "MemberExpression", name = isProp ? astUtils.getStaticPropertyName(node.left) : node.left.name;
|
|
115
|
+
node.right.id && name && isIdentifier(name) && shouldWarn(name, node.right.id.name) && report(node, name, node.right.id.name, isProp);
|
|
116
|
+
},
|
|
117
|
+
"Property, PropertyDefinition[value]"(node) {
|
|
118
|
+
if (node.value.type === "FunctionExpression" && node.value.id) {
|
|
119
|
+
if (node.key.type === "Identifier" && !node.computed) {
|
|
120
|
+
let functionName = node.value.id.name, propertyName = node.key.name;
|
|
121
|
+
if (considerPropertyDescriptor && propertyName === "value" && node.parent.type === "ObjectExpression") if (isPropertyCall("Object", "defineProperty", node.parent.parent) || isPropertyCall("Reflect", "defineProperty", node.parent.parent)) {
|
|
122
|
+
let property = node.parent.parent.arguments[1];
|
|
123
|
+
isStringLiteral(property) && shouldWarn(property.value, functionName) && report(node, property.value, functionName, !0);
|
|
124
|
+
} else isPropertyCall("Object", "defineProperties", node.parent.parent.parent.parent) || isPropertyCall("Object", "create", node.parent.parent.parent.parent) ? (propertyName = node.parent.parent.key.name, !node.parent.parent.computed && shouldWarn(propertyName, functionName) && report(node, propertyName, functionName, !0)) : shouldWarn(propertyName, functionName) && report(node, propertyName, functionName, !0);
|
|
125
|
+
else shouldWarn(propertyName, functionName) && report(node, propertyName, functionName, !0);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
isStringLiteral(node.key) && isIdentifier(node.key.value, ecmaVersion) && shouldWarn(node.key.value, node.value.id.name) && report(node, node.key.value, node.value.id.name, !0);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}));
|
|
135
|
+
//#endregion
|
|
136
|
+
//#region src-js/generated/plugin-eslint/rules/func-name-matching.cjs
|
|
137
|
+
module.exports = require_func_name_matching().create;
|
|
138
|
+
//#endregion
|
|
@@ -0,0 +1,121 @@
|
|
|
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/func-names.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Rule to warn when a function expression does not have a name.
|
|
5
|
+
* @author Kyle T. Nunery
|
|
6
|
+
*/
|
|
7
|
+
var require_func_names = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
8
|
+
let astUtils = require_ast_utils$1.t();
|
|
9
|
+
/**
|
|
10
|
+
* Checks whether or not a given variable is a function name.
|
|
11
|
+
* @param {eslint-scope.Variable} variable A variable to check.
|
|
12
|
+
* @returns {boolean} `true` if the variable is a function name.
|
|
13
|
+
*/
|
|
14
|
+
function isFunctionName(variable) {
|
|
15
|
+
return variable && variable.defs[0].type === "FunctionName";
|
|
16
|
+
}
|
|
17
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
18
|
+
module.exports = {
|
|
19
|
+
meta: {
|
|
20
|
+
type: "suggestion",
|
|
21
|
+
defaultOptions: ["always", {}],
|
|
22
|
+
docs: {
|
|
23
|
+
description: "Require or disallow named `function` expressions",
|
|
24
|
+
recommended: !1,
|
|
25
|
+
url: "https://eslint.org/docs/latest/rules/func-names"
|
|
26
|
+
},
|
|
27
|
+
schema: {
|
|
28
|
+
definitions: { value: { enum: [
|
|
29
|
+
"always",
|
|
30
|
+
"as-needed",
|
|
31
|
+
"never"
|
|
32
|
+
] } },
|
|
33
|
+
items: [{ $ref: "#/definitions/value" }, {
|
|
34
|
+
type: "object",
|
|
35
|
+
properties: { generators: { $ref: "#/definitions/value" } },
|
|
36
|
+
additionalProperties: !1
|
|
37
|
+
}]
|
|
38
|
+
},
|
|
39
|
+
messages: {
|
|
40
|
+
unnamed: "Unexpected unnamed {{name}}.",
|
|
41
|
+
named: "Unexpected named {{name}}."
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
create(context) {
|
|
45
|
+
let sourceCode = context.sourceCode;
|
|
46
|
+
/**
|
|
47
|
+
* Returns the config option for the given node.
|
|
48
|
+
* @param {ASTNode} node A node to get the config for.
|
|
49
|
+
* @returns {string} The config option.
|
|
50
|
+
*/
|
|
51
|
+
function getConfigForNode(node) {
|
|
52
|
+
return node.generator && context.options[1].generators ? context.options[1].generators : context.options[0];
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Determines whether the current FunctionExpression node is a get, set, or
|
|
56
|
+
* shorthand method in an object literal or a class.
|
|
57
|
+
* @param {ASTNode} node A node to check.
|
|
58
|
+
* @returns {boolean} True if the node is a get, set, or shorthand method.
|
|
59
|
+
*/
|
|
60
|
+
function isObjectOrClassMethod(node) {
|
|
61
|
+
let parent = node.parent;
|
|
62
|
+
return parent.type === "MethodDefinition" || parent.type === "Property" && (parent.method || parent.kind === "get" || parent.kind === "set");
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Determines whether the current FunctionExpression node has a name that would be
|
|
66
|
+
* inferred from context in a conforming ES6 environment.
|
|
67
|
+
* @param {ASTNode} node A node to check.
|
|
68
|
+
* @returns {boolean} True if the node would have a name assigned automatically.
|
|
69
|
+
*/
|
|
70
|
+
function hasInferredName(node) {
|
|
71
|
+
let parent = node.parent;
|
|
72
|
+
return isObjectOrClassMethod(node) || parent.type === "VariableDeclarator" && parent.id.type === "Identifier" && parent.init === node || parent.type === "Property" && parent.value === node || parent.type === "PropertyDefinition" && parent.value === node || parent.type === "AssignmentExpression" && parent.left.type === "Identifier" && parent.right === node || parent.type === "AssignmentPattern" && parent.left.type === "Identifier" && parent.right === node;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Reports that an unnamed function should be named
|
|
76
|
+
* @param {ASTNode} node The node to report in the event of an error.
|
|
77
|
+
* @returns {void}
|
|
78
|
+
*/
|
|
79
|
+
function reportUnexpectedUnnamedFunction(node) {
|
|
80
|
+
context.report({
|
|
81
|
+
node,
|
|
82
|
+
messageId: "unnamed",
|
|
83
|
+
loc: astUtils.getFunctionHeadLoc(node, sourceCode),
|
|
84
|
+
data: { name: astUtils.getFunctionNameWithKind(node) }
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Reports that a named function should be unnamed
|
|
89
|
+
* @param {ASTNode} node The node to report in the event of an error.
|
|
90
|
+
* @returns {void}
|
|
91
|
+
*/
|
|
92
|
+
function reportUnexpectedNamedFunction(node) {
|
|
93
|
+
context.report({
|
|
94
|
+
node,
|
|
95
|
+
messageId: "named",
|
|
96
|
+
loc: astUtils.getFunctionHeadLoc(node, sourceCode),
|
|
97
|
+
data: { name: astUtils.getFunctionNameWithKind(node) }
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The listener for function nodes.
|
|
102
|
+
* @param {ASTNode} node function node
|
|
103
|
+
* @returns {void}
|
|
104
|
+
*/
|
|
105
|
+
function handleFunction(node) {
|
|
106
|
+
let nameVar = sourceCode.getDeclaredVariables(node)[0];
|
|
107
|
+
if (isFunctionName(nameVar) && nameVar.references.length > 0) return;
|
|
108
|
+
let hasName = !!(node.id && node.id.name), config = getConfigForNode(node);
|
|
109
|
+
config === "never" ? hasName && node.type !== "FunctionDeclaration" && reportUnexpectedNamedFunction(node) : config === "as-needed" ? !hasName && !hasInferredName(node) && reportUnexpectedUnnamedFunction(node) : !hasName && !isObjectOrClassMethod(node) && reportUnexpectedUnnamedFunction(node);
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
"FunctionExpression:exit": handleFunction,
|
|
113
|
+
"ExportDefaultDeclaration > FunctionDeclaration": handleFunction
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}));
|
|
118
|
+
//#endregion
|
|
119
|
+
//#region src-js/generated/plugin-eslint/rules/func-names.cjs
|
|
120
|
+
module.exports = require_func_names().create;
|
|
121
|
+
//#endregion
|