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,157 @@
|
|
|
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-irregular-whitespace.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Rule to disallow whitespace that is not a tab or space, whitespace inside strings and comments are allowed
|
|
5
|
+
* @author Jonathan Kingston
|
|
6
|
+
* @author Christophe Porteneuve
|
|
7
|
+
*/
|
|
8
|
+
var require_no_irregular_whitespace = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
9
|
+
let astUtils = require_ast_utils$1.t(), ALL_IRREGULARS = /[\f\v\u0085\ufeff\u00a0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u202f\u205f\u3000\u2028\u2029]/u, IRREGULAR_WHITESPACE = /[\f\v\u0085\ufeff\u00a0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u202f\u205f\u3000]+/gu, IRREGULAR_LINE_TERMINATORS = /[\u2028\u2029]/gu, LINE_BREAK = astUtils.createGlobalLinebreakMatcher();
|
|
10
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
11
|
+
module.exports = {
|
|
12
|
+
meta: {
|
|
13
|
+
type: "problem",
|
|
14
|
+
defaultOptions: [{
|
|
15
|
+
skipComments: !1,
|
|
16
|
+
skipJSXText: !1,
|
|
17
|
+
skipRegExps: !1,
|
|
18
|
+
skipStrings: !0,
|
|
19
|
+
skipTemplates: !1
|
|
20
|
+
}],
|
|
21
|
+
docs: {
|
|
22
|
+
description: "Disallow irregular whitespace",
|
|
23
|
+
recommended: !0,
|
|
24
|
+
url: "https://eslint.org/docs/latest/rules/no-irregular-whitespace"
|
|
25
|
+
},
|
|
26
|
+
schema: [{
|
|
27
|
+
type: "object",
|
|
28
|
+
properties: {
|
|
29
|
+
skipComments: { type: "boolean" },
|
|
30
|
+
skipStrings: { type: "boolean" },
|
|
31
|
+
skipTemplates: { type: "boolean" },
|
|
32
|
+
skipRegExps: { type: "boolean" },
|
|
33
|
+
skipJSXText: { type: "boolean" }
|
|
34
|
+
},
|
|
35
|
+
additionalProperties: !1
|
|
36
|
+
}],
|
|
37
|
+
messages: { noIrregularWhitespace: "Irregular whitespace not allowed." }
|
|
38
|
+
},
|
|
39
|
+
create(context) {
|
|
40
|
+
let [{ skipComments, skipStrings, skipRegExps, skipTemplates, skipJSXText }] = context.options, sourceCode = context.sourceCode, commentNodes = sourceCode.getAllComments(), errors = [];
|
|
41
|
+
/**
|
|
42
|
+
* Removes errors that occur inside the given node
|
|
43
|
+
* @param {ASTNode} node to check for matching errors.
|
|
44
|
+
* @returns {void}
|
|
45
|
+
* @private
|
|
46
|
+
*/
|
|
47
|
+
function removeWhitespaceError(node) {
|
|
48
|
+
let locStart = node.loc.start, locEnd = node.loc.end;
|
|
49
|
+
errors = errors.filter(({ loc: { start: errorLocStart } }) => errorLocStart.line < locStart.line || errorLocStart.line === locStart.line && errorLocStart.column < locStart.column || errorLocStart.line === locEnd.line && errorLocStart.column >= locEnd.column || errorLocStart.line > locEnd.line);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Checks literal nodes for errors that we are choosing to ignore and calls the relevant methods to remove the errors
|
|
53
|
+
* @param {ASTNode} node to check for matching errors.
|
|
54
|
+
* @returns {void}
|
|
55
|
+
* @private
|
|
56
|
+
*/
|
|
57
|
+
function removeInvalidNodeErrorsInLiteral(node) {
|
|
58
|
+
let shouldCheckStrings = skipStrings && typeof node.value == "string", shouldCheckRegExps = skipRegExps && !!node.regex;
|
|
59
|
+
(shouldCheckStrings || shouldCheckRegExps) && ALL_IRREGULARS.test(node.raw) && removeWhitespaceError(node);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Checks template string literal nodes for errors that we are choosing to ignore and calls the relevant methods to remove the errors
|
|
63
|
+
* @param {ASTNode} node to check for matching errors.
|
|
64
|
+
* @returns {void}
|
|
65
|
+
* @private
|
|
66
|
+
*/
|
|
67
|
+
function removeInvalidNodeErrorsInTemplateLiteral(node) {
|
|
68
|
+
typeof node.value.raw == "string" && ALL_IRREGULARS.test(node.value.raw) && removeWhitespaceError(node);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Checks comment nodes for errors that we are choosing to ignore and calls the relevant methods to remove the errors
|
|
72
|
+
* @param {ASTNode} node to check for matching errors.
|
|
73
|
+
* @returns {void}
|
|
74
|
+
* @private
|
|
75
|
+
*/
|
|
76
|
+
function removeInvalidNodeErrorsInComment(node) {
|
|
77
|
+
ALL_IRREGULARS.test(node.value) && removeWhitespaceError(node);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Checks JSX nodes for errors that we are choosing to ignore and calls the relevant methods to remove the errors
|
|
81
|
+
* @param {ASTNode} node to check for matching errors.
|
|
82
|
+
* @returns {void}
|
|
83
|
+
* @private
|
|
84
|
+
*/
|
|
85
|
+
function removeInvalidNodeErrorsInJSXText(node) {
|
|
86
|
+
ALL_IRREGULARS.test(node.raw) && removeWhitespaceError(node);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Checks the program source for irregular whitespace
|
|
90
|
+
* @param {ASTNode} node The program node
|
|
91
|
+
* @returns {void}
|
|
92
|
+
* @private
|
|
93
|
+
*/
|
|
94
|
+
function checkForIrregularWhitespace(node) {
|
|
95
|
+
sourceCode.lines.forEach((sourceLine, lineIndex) => {
|
|
96
|
+
let lineNumber = lineIndex + 1, match;
|
|
97
|
+
for (; (match = IRREGULAR_WHITESPACE.exec(sourceLine)) !== null;) errors.push({
|
|
98
|
+
node,
|
|
99
|
+
messageId: "noIrregularWhitespace",
|
|
100
|
+
loc: {
|
|
101
|
+
start: {
|
|
102
|
+
line: lineNumber,
|
|
103
|
+
column: match.index
|
|
104
|
+
},
|
|
105
|
+
end: {
|
|
106
|
+
line: lineNumber,
|
|
107
|
+
column: match.index + match[0].length
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Checks the program source for irregular line terminators
|
|
115
|
+
* @param {ASTNode} node The program node
|
|
116
|
+
* @returns {void}
|
|
117
|
+
* @private
|
|
118
|
+
*/
|
|
119
|
+
function checkForIrregularLineTerminators(node) {
|
|
120
|
+
let source = sourceCode.getText(), sourceLines = sourceCode.lines, linebreaks = source.match(LINE_BREAK), lastLineIndex = -1, match;
|
|
121
|
+
for (; (match = IRREGULAR_LINE_TERMINATORS.exec(source)) !== null;) {
|
|
122
|
+
let lineIndex = linebreaks.indexOf(match[0], lastLineIndex + 1) || 0;
|
|
123
|
+
errors.push({
|
|
124
|
+
node,
|
|
125
|
+
messageId: "noIrregularWhitespace",
|
|
126
|
+
loc: {
|
|
127
|
+
start: {
|
|
128
|
+
line: lineIndex + 1,
|
|
129
|
+
column: sourceLines[lineIndex].length
|
|
130
|
+
},
|
|
131
|
+
end: {
|
|
132
|
+
line: lineIndex + 2,
|
|
133
|
+
column: 0
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}), lastLineIndex = lineIndex;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* A no-op function to act as placeholder for comment accumulation when the `skipComments` option is `false`.
|
|
141
|
+
* @returns {void}
|
|
142
|
+
* @private
|
|
143
|
+
*/
|
|
144
|
+
function noop() {}
|
|
145
|
+
let nodes = {};
|
|
146
|
+
return ALL_IRREGULARS.test(sourceCode.getText()) ? (nodes.Program = function(node) {
|
|
147
|
+
checkForIrregularWhitespace(node), checkForIrregularLineTerminators(node);
|
|
148
|
+
}, nodes.Literal = removeInvalidNodeErrorsInLiteral, nodes.TemplateElement = skipTemplates ? removeInvalidNodeErrorsInTemplateLiteral : noop, nodes.JSXText = skipJSXText ? removeInvalidNodeErrorsInJSXText : noop, nodes["Program:exit"] = function() {
|
|
149
|
+
skipComments && commentNodes.forEach(removeInvalidNodeErrorsInComment), errors.forEach((error) => context.report(error));
|
|
150
|
+
}) : nodes.Program = noop, nodes;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
}));
|
|
154
|
+
//#endregion
|
|
155
|
+
//#region src-js/generated/plugin-eslint/rules/no-irregular-whitespace.cjs
|
|
156
|
+
module.exports = require_no_irregular_whitespace().create;
|
|
157
|
+
//#endregion
|
|
@@ -0,0 +1,34 @@
|
|
|
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-iterator.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Rule to flag usage of __iterator__ property
|
|
5
|
+
* @author Ian Christian Myers
|
|
6
|
+
*/
|
|
7
|
+
var require_no_iterator = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
8
|
+
let { getStaticPropertyName } = require_ast_utils$1.t();
|
|
9
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
10
|
+
module.exports = {
|
|
11
|
+
meta: {
|
|
12
|
+
type: "suggestion",
|
|
13
|
+
docs: {
|
|
14
|
+
description: "Disallow the use of the `__iterator__` property",
|
|
15
|
+
recommended: !1,
|
|
16
|
+
url: "https://eslint.org/docs/latest/rules/no-iterator"
|
|
17
|
+
},
|
|
18
|
+
schema: [],
|
|
19
|
+
messages: { noIterator: "Reserved name '__iterator__'." }
|
|
20
|
+
},
|
|
21
|
+
create(context) {
|
|
22
|
+
return { MemberExpression(node) {
|
|
23
|
+
getStaticPropertyName(node) === "__iterator__" && context.report({
|
|
24
|
+
node,
|
|
25
|
+
messageId: "noIterator"
|
|
26
|
+
});
|
|
27
|
+
} };
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}));
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src-js/generated/plugin-eslint/rules/no-iterator.cjs
|
|
33
|
+
module.exports = require_no_iterator().create;
|
|
34
|
+
//#endregion
|
|
@@ -0,0 +1,46 @@
|
|
|
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-label-var.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Rule to flag labels that are the same as an identifier
|
|
5
|
+
* @author Ian Christian Myers
|
|
6
|
+
*/
|
|
7
|
+
var require_no_label_var = /* @__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
|
+
docs: {
|
|
14
|
+
description: "Disallow labels that share a name with a variable",
|
|
15
|
+
recommended: !1,
|
|
16
|
+
frozen: !0,
|
|
17
|
+
url: "https://eslint.org/docs/latest/rules/no-label-var"
|
|
18
|
+
},
|
|
19
|
+
schema: [],
|
|
20
|
+
messages: { identifierClashWithLabel: "Found identifier with same name as label." }
|
|
21
|
+
},
|
|
22
|
+
create(context) {
|
|
23
|
+
let sourceCode = context.sourceCode;
|
|
24
|
+
/**
|
|
25
|
+
* Check if the identifier is present inside current scope
|
|
26
|
+
* @param {Object} scope current scope
|
|
27
|
+
* @param {string} name To evaluate
|
|
28
|
+
* @returns {boolean} True if its present
|
|
29
|
+
* @private
|
|
30
|
+
*/
|
|
31
|
+
function findIdentifier(scope, name) {
|
|
32
|
+
return astUtils.getVariableByName(scope, name) !== null;
|
|
33
|
+
}
|
|
34
|
+
return { LabeledStatement(node) {
|
|
35
|
+
findIdentifier(sourceCode.getScope(node), node.label.name) && context.report({
|
|
36
|
+
node,
|
|
37
|
+
messageId: "identifierClashWithLabel"
|
|
38
|
+
});
|
|
39
|
+
} };
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}));
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src-js/generated/plugin-eslint/rules/no-label-var.cjs
|
|
45
|
+
module.exports = require_no_label_var().create;
|
|
46
|
+
//#endregion
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
const require_chunk = require("../common/chunk.cjs"), require_ast_utils$1 = require("../common/ast-utils.cjs");
|
|
2
|
+
//#region ../../node_modules/.pnpm/eslint@9.39.3_jiti@2.6.1/node_modules/eslint/lib/rules/no-labels.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Disallow Labeled Statements
|
|
5
|
+
* @author Nicholas C. Zakas
|
|
6
|
+
*/
|
|
7
|
+
var require_no_labels = /* @__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
|
+
allowLoop: !1,
|
|
15
|
+
allowSwitch: !1
|
|
16
|
+
}],
|
|
17
|
+
docs: {
|
|
18
|
+
description: "Disallow labeled statements",
|
|
19
|
+
recommended: !1,
|
|
20
|
+
frozen: !0,
|
|
21
|
+
url: "https://eslint.org/docs/latest/rules/no-labels"
|
|
22
|
+
},
|
|
23
|
+
schema: [{
|
|
24
|
+
type: "object",
|
|
25
|
+
properties: {
|
|
26
|
+
allowLoop: { type: "boolean" },
|
|
27
|
+
allowSwitch: { type: "boolean" }
|
|
28
|
+
},
|
|
29
|
+
additionalProperties: !1
|
|
30
|
+
}],
|
|
31
|
+
messages: {
|
|
32
|
+
unexpectedLabel: "Unexpected labeled statement.",
|
|
33
|
+
unexpectedLabelInBreak: "Unexpected label in break statement.",
|
|
34
|
+
unexpectedLabelInContinue: "Unexpected label in continue statement."
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
create(context) {
|
|
38
|
+
let [{ allowLoop, allowSwitch }] = context.options, scopeInfo = null;
|
|
39
|
+
/**
|
|
40
|
+
* Gets the kind of a given node.
|
|
41
|
+
* @param {ASTNode} node A node to get.
|
|
42
|
+
* @returns {string} The kind of the node.
|
|
43
|
+
*/
|
|
44
|
+
function getBodyKind(node) {
|
|
45
|
+
return astUtils.isLoop(node) ? "loop" : node.type === "SwitchStatement" ? "switch" : "other";
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Checks whether the label of a given kind is allowed or not.
|
|
49
|
+
* @param {string} kind A kind to check.
|
|
50
|
+
* @returns {boolean} `true` if the kind is allowed.
|
|
51
|
+
*/
|
|
52
|
+
function isAllowed(kind) {
|
|
53
|
+
switch (kind) {
|
|
54
|
+
case "loop": return allowLoop;
|
|
55
|
+
case "switch": return allowSwitch;
|
|
56
|
+
default: return !1;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Checks whether a given name is a label of a loop or not.
|
|
61
|
+
* @param {string} label A name of a label to check.
|
|
62
|
+
* @returns {boolean} `true` if the name is a label of a loop.
|
|
63
|
+
*/
|
|
64
|
+
function getKind(label) {
|
|
65
|
+
let info = scopeInfo;
|
|
66
|
+
for (; info;) {
|
|
67
|
+
if (info.label === label) return info.kind;
|
|
68
|
+
info = info.upper;
|
|
69
|
+
}
|
|
70
|
+
/* c8 ignore next */
|
|
71
|
+
return "other";
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
LabeledStatement(node) {
|
|
75
|
+
scopeInfo = {
|
|
76
|
+
label: node.label.name,
|
|
77
|
+
kind: getBodyKind(node.body),
|
|
78
|
+
upper: scopeInfo
|
|
79
|
+
};
|
|
80
|
+
},
|
|
81
|
+
"LabeledStatement:exit"(node) {
|
|
82
|
+
isAllowed(scopeInfo.kind) || context.report({
|
|
83
|
+
node,
|
|
84
|
+
messageId: "unexpectedLabel"
|
|
85
|
+
}), scopeInfo = scopeInfo.upper;
|
|
86
|
+
},
|
|
87
|
+
BreakStatement(node) {
|
|
88
|
+
node.label && !isAllowed(getKind(node.label.name)) && context.report({
|
|
89
|
+
node,
|
|
90
|
+
messageId: "unexpectedLabelInBreak"
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
ContinueStatement(node) {
|
|
94
|
+
node.label && !isAllowed(getKind(node.label.name)) && context.report({
|
|
95
|
+
node,
|
|
96
|
+
messageId: "unexpectedLabelInContinue"
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}));
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src-js/generated/plugin-eslint/rules/no-labels.cjs
|
|
105
|
+
module.exports = require_no_labels().create;
|
|
106
|
+
//#endregion
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/eslint@9.39.3_jiti@2.6.1/node_modules/eslint/lib/rules/no-lone-blocks.js
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Rule to flag blocks with no reason to exist
|
|
4
|
+
* @author Brandon Mills
|
|
5
|
+
*/
|
|
6
|
+
var require_no_lone_blocks = /* @__PURE__ */ require("../common/chunk.cjs").t(((exports, module) => {
|
|
7
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
8
|
+
module.exports = {
|
|
9
|
+
meta: {
|
|
10
|
+
type: "suggestion",
|
|
11
|
+
docs: {
|
|
12
|
+
description: "Disallow unnecessary nested blocks",
|
|
13
|
+
recommended: !1,
|
|
14
|
+
url: "https://eslint.org/docs/latest/rules/no-lone-blocks"
|
|
15
|
+
},
|
|
16
|
+
schema: [],
|
|
17
|
+
messages: {
|
|
18
|
+
redundantBlock: "Block is redundant.",
|
|
19
|
+
redundantNestedBlock: "Nested block is redundant."
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
create(context) {
|
|
23
|
+
let loneBlocks = [], ruleDef, sourceCode = context.sourceCode;
|
|
24
|
+
/**
|
|
25
|
+
* Reports a node as invalid.
|
|
26
|
+
* @param {ASTNode} node The node to be reported.
|
|
27
|
+
* @returns {void}
|
|
28
|
+
*/
|
|
29
|
+
function report(node) {
|
|
30
|
+
let messageId = node.parent.type === "BlockStatement" || node.parent.type === "StaticBlock" ? "redundantNestedBlock" : "redundantBlock";
|
|
31
|
+
context.report({
|
|
32
|
+
node,
|
|
33
|
+
messageId
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Checks for any occurrence of a BlockStatement in a place where lists of statements can appear
|
|
38
|
+
* @param {ASTNode} node The node to check
|
|
39
|
+
* @returns {boolean} True if the node is a lone block.
|
|
40
|
+
*/
|
|
41
|
+
function isLoneBlock(node) {
|
|
42
|
+
return node.parent.type === "BlockStatement" || node.parent.type === "StaticBlock" || node.parent.type === "Program" || node.parent.type === "SwitchCase" && !(node.parent.consequent[0] === node && node.parent.consequent.length === 1);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Checks the enclosing block of the current node for block-level bindings,
|
|
46
|
+
* and "marks it" as valid if any.
|
|
47
|
+
* @param {ASTNode} node The current node to check.
|
|
48
|
+
* @returns {void}
|
|
49
|
+
*/
|
|
50
|
+
function markLoneBlock(node) {
|
|
51
|
+
if (loneBlocks.length === 0) return;
|
|
52
|
+
let block = node.parent;
|
|
53
|
+
loneBlocks.at(-1) === block && loneBlocks.pop();
|
|
54
|
+
}
|
|
55
|
+
return ruleDef = { BlockStatement(node) {
|
|
56
|
+
isLoneBlock(node) && report(node);
|
|
57
|
+
} }, context.languageOptions.ecmaVersion >= 2015 && (ruleDef = {
|
|
58
|
+
BlockStatement(node) {
|
|
59
|
+
isLoneBlock(node) && loneBlocks.push(node);
|
|
60
|
+
},
|
|
61
|
+
"BlockStatement:exit"(node) {
|
|
62
|
+
loneBlocks.length > 0 && loneBlocks.at(-1) === node ? (loneBlocks.pop(), report(node)) : (node.parent.type === "BlockStatement" || node.parent.type === "StaticBlock") && node.parent.body.length === 1 && report(node);
|
|
63
|
+
}
|
|
64
|
+
}, ruleDef.VariableDeclaration = function(node) {
|
|
65
|
+
node.kind !== "var" && markLoneBlock(node);
|
|
66
|
+
}, ruleDef.FunctionDeclaration = function(node) {
|
|
67
|
+
sourceCode.getScope(node).isStrict && markLoneBlock(node);
|
|
68
|
+
}, ruleDef.ClassDeclaration = markLoneBlock), ruleDef;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}));
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src-js/generated/plugin-eslint/rules/no-lone-blocks.cjs
|
|
74
|
+
module.exports = require_no_lone_blocks().create;
|
|
75
|
+
//#endregion
|
|
@@ -0,0 +1,42 @@
|
|
|
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-lonely-if.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Rule to disallow if as the only statement in an else block
|
|
5
|
+
* @author Brandon Mills
|
|
6
|
+
*/
|
|
7
|
+
var require_no_lonely_if = /* @__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
|
+
docs: {
|
|
14
|
+
description: "Disallow `if` statements as the only statement in `else` blocks",
|
|
15
|
+
recommended: !1,
|
|
16
|
+
frozen: !0,
|
|
17
|
+
url: "https://eslint.org/docs/latest/rules/no-lonely-if"
|
|
18
|
+
},
|
|
19
|
+
schema: [],
|
|
20
|
+
fixable: "code",
|
|
21
|
+
messages: { unexpectedLonelyIf: "Unexpected if as the only statement in an else block." }
|
|
22
|
+
},
|
|
23
|
+
create(context) {
|
|
24
|
+
let sourceCode = context.sourceCode;
|
|
25
|
+
return { IfStatement(node) {
|
|
26
|
+
let parent = node.parent, grandparent = parent.parent;
|
|
27
|
+
parent && parent.type === "BlockStatement" && parent.body.length === 1 && !astUtils.areBracesNecessary(parent, sourceCode) && grandparent && grandparent.type === "IfStatement" && parent === grandparent.alternate && context.report({
|
|
28
|
+
node,
|
|
29
|
+
messageId: "unexpectedLonelyIf",
|
|
30
|
+
fix(fixer) {
|
|
31
|
+
let openingElseCurly = sourceCode.getFirstToken(parent), closingElseCurly = sourceCode.getLastToken(parent), elseKeyword = sourceCode.getTokenBefore(openingElseCurly), tokenAfterElseBlock = sourceCode.getTokenAfter(closingElseCurly), lastIfToken = sourceCode.getLastToken(node.consequent), sourceText = sourceCode.getText();
|
|
32
|
+
return sourceText.slice(openingElseCurly.range[1], node.range[0]).trim() || sourceText.slice(node.range[1], closingElseCurly.range[0]).trim() || node.consequent.type !== "BlockStatement" && lastIfToken.value !== ";" && tokenAfterElseBlock && (node.consequent.loc.end.line === tokenAfterElseBlock.loc.start.line || /^[([/+`-]/u.test(tokenAfterElseBlock.value) || lastIfToken.value === "++" || lastIfToken.value === "--") ? null : fixer.replaceTextRange([openingElseCurly.range[0], closingElseCurly.range[1]], (elseKeyword.range[1] === openingElseCurly.range[0] ? " " : "") + sourceCode.getText(node));
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
} };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}));
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src-js/generated/plugin-eslint/rules/no-lonely-if.cjs
|
|
41
|
+
module.exports = require_no_lonely_if().create;
|
|
42
|
+
//#endregion
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/eslint@9.39.3_jiti@2.6.1/node_modules/eslint/lib/rules/no-loop-func.js
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Rule to flag creation of function inside a loop
|
|
4
|
+
* @author Ilya Volodin
|
|
5
|
+
*/
|
|
6
|
+
var require_no_loop_func = /* @__PURE__ */ require("../common/chunk.cjs").t(((exports, module) => {
|
|
7
|
+
let CONSTANT_BINDINGS = new Set([
|
|
8
|
+
"const",
|
|
9
|
+
"using",
|
|
10
|
+
"await using"
|
|
11
|
+
]);
|
|
12
|
+
/**
|
|
13
|
+
* Identifies is a node is a FunctionExpression which is part of an IIFE
|
|
14
|
+
* @param {ASTNode} node Node to test
|
|
15
|
+
* @returns {boolean} True if it's an IIFE
|
|
16
|
+
*/
|
|
17
|
+
function isIIFE(node) {
|
|
18
|
+
return (node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression") && node.parent && node.parent.type === "CallExpression" && node.parent.callee === node;
|
|
19
|
+
}
|
|
20
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
21
|
+
module.exports = {
|
|
22
|
+
meta: {
|
|
23
|
+
type: "suggestion",
|
|
24
|
+
dialects: ["typescript", "javascript"],
|
|
25
|
+
language: "javascript",
|
|
26
|
+
docs: {
|
|
27
|
+
description: "Disallow function declarations that contain unsafe references inside loop statements",
|
|
28
|
+
recommended: !1,
|
|
29
|
+
url: "https://eslint.org/docs/latest/rules/no-loop-func"
|
|
30
|
+
},
|
|
31
|
+
schema: [],
|
|
32
|
+
messages: { unsafeRefs: "Function declared in a loop contains unsafe references to variable(s) {{ varNames }}." }
|
|
33
|
+
},
|
|
34
|
+
create(context) {
|
|
35
|
+
let SKIPPED_IIFE_NODES = /* @__PURE__ */ new Set(), sourceCode = context.sourceCode;
|
|
36
|
+
/**
|
|
37
|
+
* Gets the containing loop node of a specified node.
|
|
38
|
+
*
|
|
39
|
+
* We don't need to check nested functions, so this ignores those, with the exception of IIFE.
|
|
40
|
+
* `Scope.through` contains references of nested functions.
|
|
41
|
+
* @param {ASTNode} node An AST node to get.
|
|
42
|
+
* @returns {ASTNode|null} The containing loop node of the specified node, or
|
|
43
|
+
* `null`.
|
|
44
|
+
*/
|
|
45
|
+
function getContainingLoopNode(node) {
|
|
46
|
+
for (let currentNode = node; currentNode.parent; currentNode = currentNode.parent) {
|
|
47
|
+
let parent = currentNode.parent;
|
|
48
|
+
switch (parent.type) {
|
|
49
|
+
case "WhileStatement":
|
|
50
|
+
case "DoWhileStatement": return parent;
|
|
51
|
+
case "ForStatement":
|
|
52
|
+
if (parent.init !== currentNode) return parent;
|
|
53
|
+
break;
|
|
54
|
+
case "ForInStatement":
|
|
55
|
+
case "ForOfStatement":
|
|
56
|
+
if (parent.right !== currentNode) return parent;
|
|
57
|
+
break;
|
|
58
|
+
case "ArrowFunctionExpression":
|
|
59
|
+
case "FunctionExpression":
|
|
60
|
+
case "FunctionDeclaration":
|
|
61
|
+
if (SKIPPED_IIFE_NODES.has(parent)) break;
|
|
62
|
+
return null;
|
|
63
|
+
default: break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Gets the containing loop node of a given node.
|
|
70
|
+
* If the loop was nested, this returns the most outer loop.
|
|
71
|
+
* @param {ASTNode} node A node to get. This is a loop node.
|
|
72
|
+
* @param {ASTNode|null} excludedNode A node that the result node should not
|
|
73
|
+
* include.
|
|
74
|
+
* @returns {ASTNode} The most outer loop node.
|
|
75
|
+
*/
|
|
76
|
+
function getTopLoopNode(node, excludedNode) {
|
|
77
|
+
let border = excludedNode ? excludedNode.range[1] : 0, retv = node, containingLoopNode = node;
|
|
78
|
+
for (; containingLoopNode && containingLoopNode.range[0] >= border;) retv = containingLoopNode, containingLoopNode = getContainingLoopNode(containingLoopNode);
|
|
79
|
+
return retv;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Checks whether a given reference which refers to an upper scope's variable is
|
|
83
|
+
* safe or not.
|
|
84
|
+
* @param {ASTNode} loopNode A containing loop node.
|
|
85
|
+
* @param {eslint-scope.Reference} reference A reference to check.
|
|
86
|
+
* @returns {boolean} `true` if the reference is safe or not.
|
|
87
|
+
*/
|
|
88
|
+
function isSafe(loopNode, reference) {
|
|
89
|
+
let variable = reference.resolved, definition = variable && variable.defs[0], declaration = definition && definition.parent, kind = declaration && declaration.type === "VariableDeclaration" ? declaration.kind : "";
|
|
90
|
+
if (CONSTANT_BINDINGS.has(kind) || kind === "let" && declaration.range[0] > loopNode.range[0] && declaration.range[1] < loopNode.range[1]) return !0;
|
|
91
|
+
let border = getTopLoopNode(loopNode, kind === "let" ? declaration : null).range[0];
|
|
92
|
+
/**
|
|
93
|
+
* Checks whether a given reference is safe or not.
|
|
94
|
+
* The reference is every reference of the upper scope's variable we are
|
|
95
|
+
* looking now.
|
|
96
|
+
*
|
|
97
|
+
* It's safe if the reference matches one of the following condition.
|
|
98
|
+
* - is readonly.
|
|
99
|
+
* - doesn't exist inside a local function and after the border.
|
|
100
|
+
* @param {eslint-scope.Reference} upperRef A reference to check.
|
|
101
|
+
* @returns {boolean} `true` if the reference is safe.
|
|
102
|
+
*/
|
|
103
|
+
function isSafeReference(upperRef) {
|
|
104
|
+
let id = upperRef.identifier;
|
|
105
|
+
return !upperRef.isWrite() || variable.scope.variableScope === upperRef.from.variableScope && id.range[0] < border;
|
|
106
|
+
}
|
|
107
|
+
return !!variable && variable.references.every(isSafeReference);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Reports functions which match the following condition:
|
|
111
|
+
*
|
|
112
|
+
* - has a loop node in ancestors.
|
|
113
|
+
* - has any references which refers to an unsafe variable.
|
|
114
|
+
* @param {ASTNode} node The AST node to check.
|
|
115
|
+
* @returns {void}
|
|
116
|
+
*/
|
|
117
|
+
function checkForLoops(node) {
|
|
118
|
+
let loopNode = getContainingLoopNode(node);
|
|
119
|
+
if (!loopNode) return;
|
|
120
|
+
let references = sourceCode.getScope(node).through;
|
|
121
|
+
if (!(node.async || node.generator) && isIIFE(node) && !(node.type === "FunctionExpression" && node.id && references.some((r) => r.identifier.name === node.id.name))) {
|
|
122
|
+
SKIPPED_IIFE_NODES.add(node);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
let unsafeRefs = [...new Set(references.filter((r) => r.resolved && !isSafe(loopNode, r)).map((r) => r.identifier.name))];
|
|
126
|
+
unsafeRefs.length > 0 && context.report({
|
|
127
|
+
node,
|
|
128
|
+
messageId: "unsafeRefs",
|
|
129
|
+
data: { varNames: `'${unsafeRefs.join("', '")}'` }
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
ArrowFunctionExpression: checkForLoops,
|
|
134
|
+
FunctionExpression: checkForLoops,
|
|
135
|
+
FunctionDeclaration: checkForLoops
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
}));
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region src-js/generated/plugin-eslint/rules/no-loop-func.cjs
|
|
142
|
+
module.exports = require_no_loop_func().create;
|
|
143
|
+
//#endregion
|