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,500 @@
|
|
|
1
|
+
const require_chunk = require("../common/chunk.cjs"), require_ast_utils$1 = require("../common/ast-utils.cjs"), require_eslint_utils$1 = require("../common/eslint-utils.cjs"), require_regexpp$1 = require("../common/regexpp.cjs"), require_regular_expressions$1 = require("../common/regular-expressions.cjs");
|
|
2
|
+
//#region ../../node_modules/.pnpm/eslint@9.39.3_jiti@2.6.1/node_modules/eslint/lib/rules/utils/unicode/is-combining-character.js
|
|
3
|
+
/**
|
|
4
|
+
* @author Toru Nagashima <https://github.com/mysticatea>
|
|
5
|
+
*/
|
|
6
|
+
var require_is_combining_character = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
7
|
+
/**
|
|
8
|
+
* Check whether a given character is a combining mark or not.
|
|
9
|
+
* @param {number} codePoint The character code to check.
|
|
10
|
+
* @returns {boolean} `true` if the character belongs to the category, any of `Mc`, `Me`, and `Mn`.
|
|
11
|
+
*/
|
|
12
|
+
module.exports = function isCombiningCharacter(codePoint) {
|
|
13
|
+
return /^[\p{Mc}\p{Me}\p{Mn}]$/u.test(String.fromCodePoint(codePoint));
|
|
14
|
+
};
|
|
15
|
+
})), require_is_emoji_modifier = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
16
|
+
/**
|
|
17
|
+
* Check whether a given character is an emoji modifier.
|
|
18
|
+
* @param {number} code The character code to check.
|
|
19
|
+
* @returns {boolean} `true` if the character is an emoji modifier.
|
|
20
|
+
*/
|
|
21
|
+
module.exports = function isEmojiModifier(code) {
|
|
22
|
+
return code >= 127995 && code <= 127999;
|
|
23
|
+
};
|
|
24
|
+
})), require_is_regional_indicator_symbol = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
25
|
+
/**
|
|
26
|
+
* Check whether a given character is a regional indicator symbol.
|
|
27
|
+
* @param {number} code The character code to check.
|
|
28
|
+
* @returns {boolean} `true` if the character is a regional indicator symbol.
|
|
29
|
+
*/
|
|
30
|
+
module.exports = function isRegionalIndicatorSymbol(code) {
|
|
31
|
+
return code >= 127462 && code <= 127487;
|
|
32
|
+
};
|
|
33
|
+
})), require_is_surrogate_pair = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
34
|
+
/**
|
|
35
|
+
* Check whether given two characters are a surrogate pair.
|
|
36
|
+
* @param {number} lead The code of the lead character.
|
|
37
|
+
* @param {number} tail The code of the tail character.
|
|
38
|
+
* @returns {boolean} `true` if the character pair is a surrogate pair.
|
|
39
|
+
*/
|
|
40
|
+
module.exports = function isSurrogatePair(lead, tail) {
|
|
41
|
+
return lead >= 55296 && lead < 56320 && tail >= 56320 && tail < 57344;
|
|
42
|
+
};
|
|
43
|
+
})), require_unicode = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
44
|
+
module.exports = {
|
|
45
|
+
isCombiningCharacter: require_is_combining_character(),
|
|
46
|
+
isEmojiModifier: require_is_emoji_modifier(),
|
|
47
|
+
isRegionalIndicatorSymbol: require_is_regional_indicator_symbol(),
|
|
48
|
+
isSurrogatePair: require_is_surrogate_pair()
|
|
49
|
+
};
|
|
50
|
+
})), require_char_source = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
51
|
+
/**
|
|
52
|
+
* Represents a code unit produced by the evaluation of a JavaScript common token like a string
|
|
53
|
+
* literal or template token.
|
|
54
|
+
*/
|
|
55
|
+
var CodeUnit = class {
|
|
56
|
+
constructor(start, source) {
|
|
57
|
+
this.start = start, this.source = source;
|
|
58
|
+
}
|
|
59
|
+
get end() {
|
|
60
|
+
return this.start + this.length;
|
|
61
|
+
}
|
|
62
|
+
get length() {
|
|
63
|
+
return this.source.length;
|
|
64
|
+
}
|
|
65
|
+
}, TextReader = class {
|
|
66
|
+
constructor(source) {
|
|
67
|
+
this.source = source, this.pos = 0;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Advances the reading position of the specified number of characters.
|
|
71
|
+
* @param {number} length Number of characters to advance.
|
|
72
|
+
* @returns {void}
|
|
73
|
+
*/
|
|
74
|
+
advance(length) {
|
|
75
|
+
this.pos += length;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Reads characters from the source.
|
|
79
|
+
* @param {number} [offset=0] The offset where reading starts, relative to the current position.
|
|
80
|
+
* @param {number} [length=1] Number of characters to read.
|
|
81
|
+
* @returns {string} A substring of source characters.
|
|
82
|
+
*/
|
|
83
|
+
read(offset = 0, length = 1) {
|
|
84
|
+
let start = offset + this.pos;
|
|
85
|
+
return this.source.slice(start, start + length);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
let SIMPLE_ESCAPE_SEQUENCES = {
|
|
89
|
+
__proto__: null,
|
|
90
|
+
b: "\b",
|
|
91
|
+
f: "\f",
|
|
92
|
+
n: "\n",
|
|
93
|
+
r: "\r",
|
|
94
|
+
t: " ",
|
|
95
|
+
v: "\v"
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Reads a hex escape sequence.
|
|
99
|
+
* @param {TextReader} reader The reader should be positioned on the first hexadecimal digit.
|
|
100
|
+
* @param {number} length The number of hexadecimal digits.
|
|
101
|
+
* @returns {string} A code unit.
|
|
102
|
+
*/
|
|
103
|
+
function readHexSequence(reader, length) {
|
|
104
|
+
let str = reader.read(0, length), charCode = parseInt(str, 16);
|
|
105
|
+
return reader.advance(length), String.fromCharCode(charCode);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Reads a Unicode escape sequence.
|
|
109
|
+
* @param {TextReader} reader The reader should be positioned after the "u".
|
|
110
|
+
* @returns {string} A code unit.
|
|
111
|
+
*/
|
|
112
|
+
function readUnicodeSequence(reader) {
|
|
113
|
+
let regExp = /\{(?<hexDigits>[\dA-F]+)\}/iuy;
|
|
114
|
+
regExp.lastIndex = reader.pos;
|
|
115
|
+
let match = regExp.exec(reader.source);
|
|
116
|
+
if (match) {
|
|
117
|
+
let codePoint = parseInt(match.groups.hexDigits, 16);
|
|
118
|
+
return reader.pos = regExp.lastIndex, String.fromCodePoint(codePoint);
|
|
119
|
+
}
|
|
120
|
+
return readHexSequence(reader, 4);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Reads an octal escape sequence.
|
|
124
|
+
* @param {TextReader} reader The reader should be positioned after the first octal digit.
|
|
125
|
+
* @param {number} maxLength The maximum number of octal digits.
|
|
126
|
+
* @returns {string} A code unit.
|
|
127
|
+
*/
|
|
128
|
+
function readOctalSequence(reader, maxLength) {
|
|
129
|
+
let [octalStr] = reader.read(-1, maxLength).match(/^[0-7]+/u);
|
|
130
|
+
reader.advance(octalStr.length - 1);
|
|
131
|
+
let octal = parseInt(octalStr, 8);
|
|
132
|
+
return String.fromCharCode(octal);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Reads an escape sequence or line continuation.
|
|
136
|
+
* @param {TextReader} reader The reader should be positioned on the backslash.
|
|
137
|
+
* @returns {string} A string of zero, one or two code units.
|
|
138
|
+
*/
|
|
139
|
+
function readEscapeSequenceOrLineContinuation(reader) {
|
|
140
|
+
let char = reader.read(1);
|
|
141
|
+
reader.advance(2);
|
|
142
|
+
let unitChar = SIMPLE_ESCAPE_SEQUENCES[char];
|
|
143
|
+
if (unitChar) return unitChar;
|
|
144
|
+
switch (char) {
|
|
145
|
+
case "x": return readHexSequence(reader, 2);
|
|
146
|
+
case "u": return readUnicodeSequence(reader);
|
|
147
|
+
case "\r": reader.read() === "\n" && reader.advance(1);
|
|
148
|
+
case "\n":
|
|
149
|
+
case "\u2028":
|
|
150
|
+
case "\u2029": return "";
|
|
151
|
+
case "0":
|
|
152
|
+
case "1":
|
|
153
|
+
case "2":
|
|
154
|
+
case "3": return readOctalSequence(reader, 3);
|
|
155
|
+
case "4":
|
|
156
|
+
case "5":
|
|
157
|
+
case "6":
|
|
158
|
+
case "7": return readOctalSequence(reader, 2);
|
|
159
|
+
default: return char;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Reads an escape sequence or line continuation and generates the respective `CodeUnit` elements.
|
|
164
|
+
* @param {TextReader} reader The reader should be positioned on the backslash.
|
|
165
|
+
* @returns {Generator<CodeUnit>} Zero, one or two `CodeUnit` elements.
|
|
166
|
+
*/
|
|
167
|
+
function* mapEscapeSequenceOrLineContinuation(reader) {
|
|
168
|
+
let start = reader.pos, str = readEscapeSequenceOrLineContinuation(reader), end = reader.pos, source = reader.source.slice(start, end);
|
|
169
|
+
switch (str.length) {
|
|
170
|
+
case 0: break;
|
|
171
|
+
case 1:
|
|
172
|
+
yield new CodeUnit(start, source);
|
|
173
|
+
break;
|
|
174
|
+
default:
|
|
175
|
+
yield new CodeUnit(start, source), yield new CodeUnit(start, source);
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Parses a string literal.
|
|
181
|
+
* @param {string} source The string literal to parse, including the delimiting quotes.
|
|
182
|
+
* @returns {CodeUnit[]} A list of code units produced by the string literal.
|
|
183
|
+
*/
|
|
184
|
+
function parseStringLiteral(source) {
|
|
185
|
+
let reader = new TextReader(source), quote = reader.read();
|
|
186
|
+
reader.advance(1);
|
|
187
|
+
let codeUnits = [];
|
|
188
|
+
for (;;) {
|
|
189
|
+
let char = reader.read();
|
|
190
|
+
if (char === quote) break;
|
|
191
|
+
char === "\\" ? codeUnits.push(...mapEscapeSequenceOrLineContinuation(reader)) : (codeUnits.push(new CodeUnit(reader.pos, char)), reader.advance(1));
|
|
192
|
+
}
|
|
193
|
+
return codeUnits;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Parses a template token.
|
|
197
|
+
* @param {string} source The template token to parse, including the delimiting sequences `` ` ``, `${` and `}`.
|
|
198
|
+
* @returns {CodeUnit[]} A list of code units produced by the template token.
|
|
199
|
+
*/
|
|
200
|
+
function parseTemplateToken(source) {
|
|
201
|
+
let reader = new TextReader(source);
|
|
202
|
+
reader.advance(1);
|
|
203
|
+
let codeUnits = [];
|
|
204
|
+
for (;;) {
|
|
205
|
+
let char = reader.read();
|
|
206
|
+
if (char === "`" || char === "$" && reader.read(1) === "{") break;
|
|
207
|
+
if (char === "\\") codeUnits.push(...mapEscapeSequenceOrLineContinuation(reader));
|
|
208
|
+
else {
|
|
209
|
+
let unitSource;
|
|
210
|
+
unitSource = char === "\r" && reader.read(1) === "\n" ? "\r\n" : char, codeUnits.push(new CodeUnit(reader.pos, unitSource)), reader.advance(unitSource.length);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return codeUnits;
|
|
214
|
+
}
|
|
215
|
+
module.exports = {
|
|
216
|
+
parseStringLiteral,
|
|
217
|
+
parseTemplateToken
|
|
218
|
+
};
|
|
219
|
+
})), require_no_misleading_character_class = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
220
|
+
let { CALL, CONSTRUCT, ReferenceTracker, getStaticValue, getStringIfConstant } = require_eslint_utils$1.t(), { RegExpParser, visitRegExpAST } = require_regexpp$1.t(), { isCombiningCharacter, isEmojiModifier, isRegionalIndicatorSymbol, isSurrogatePair } = require_unicode(), astUtils = require_ast_utils$1.t(), { isValidWithUnicodeFlag } = require_regular_expressions$1.t(), { parseStringLiteral, parseTemplateToken } = require_char_source();
|
|
221
|
+
/**
|
|
222
|
+
* @typedef {import('@eslint-community/regexpp').AST.Character} Character
|
|
223
|
+
* @typedef {import('@eslint-community/regexpp').AST.CharacterClassElement} CharacterClassElement
|
|
224
|
+
*/
|
|
225
|
+
/**
|
|
226
|
+
* Iterate character sequences of a given nodes.
|
|
227
|
+
*
|
|
228
|
+
* CharacterClassRange syntax can steal a part of character sequence,
|
|
229
|
+
* so this function reverts CharacterClassRange syntax and restore the sequence.
|
|
230
|
+
* @param {CharacterClassElement[]} nodes The node list to iterate character sequences.
|
|
231
|
+
* @returns {IterableIterator<Character[]>} The list of character sequences.
|
|
232
|
+
*/
|
|
233
|
+
function* iterateCharacterSequence(nodes) {
|
|
234
|
+
/** @type {Character[]} */
|
|
235
|
+
let seq = [];
|
|
236
|
+
for (let node of nodes) switch (node.type) {
|
|
237
|
+
case "Character":
|
|
238
|
+
seq.push(node);
|
|
239
|
+
break;
|
|
240
|
+
case "CharacterClassRange":
|
|
241
|
+
seq.push(node.min), yield seq, seq = [node.max];
|
|
242
|
+
break;
|
|
243
|
+
case "CharacterSet":
|
|
244
|
+
case "CharacterClass":
|
|
245
|
+
case "ClassStringDisjunction":
|
|
246
|
+
case "ExpressionCharacterClass":
|
|
247
|
+
seq.length > 0 && (yield seq, seq = []);
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
seq.length > 0 && (yield seq);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Checks whether the given character node is a Unicode code point escape or not.
|
|
254
|
+
* @param {Character} char the character node to check.
|
|
255
|
+
* @returns {boolean} `true` if the character node is a Unicode code point escape.
|
|
256
|
+
*/
|
|
257
|
+
function isUnicodeCodePointEscape(char) {
|
|
258
|
+
return /^\\u\{[\da-f]+\}$/iu.test(char.raw);
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Each function returns matched characters if it detects that kind of problem.
|
|
262
|
+
* @type {Record<string, (chars: Character[]) => IterableIterator<Character[]>>}
|
|
263
|
+
*/
|
|
264
|
+
let findCharacterSequences = {
|
|
265
|
+
*surrogatePairWithoutUFlag(chars) {
|
|
266
|
+
for (let [index, char] of chars.entries()) {
|
|
267
|
+
let previous = chars[index - 1];
|
|
268
|
+
previous && char && isSurrogatePair(previous.value, char.value) && !isUnicodeCodePointEscape(previous) && !isUnicodeCodePointEscape(char) && (yield [previous, char]);
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
*surrogatePair(chars) {
|
|
272
|
+
for (let [index, char] of chars.entries()) {
|
|
273
|
+
let previous = chars[index - 1];
|
|
274
|
+
previous && char && isSurrogatePair(previous.value, char.value) && (isUnicodeCodePointEscape(previous) || isUnicodeCodePointEscape(char)) && (yield [previous, char]);
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
*combiningClass(chars, unfilteredChars) {
|
|
278
|
+
for (let [index, char] of chars.entries()) {
|
|
279
|
+
let previous = unfilteredChars[index - 1];
|
|
280
|
+
previous && char && isCombiningCharacter(char.value) && !isCombiningCharacter(previous.value) && (yield [previous, char]);
|
|
281
|
+
}
|
|
282
|
+
},
|
|
283
|
+
*emojiModifier(chars) {
|
|
284
|
+
for (let [index, char] of chars.entries()) {
|
|
285
|
+
let previous = chars[index - 1];
|
|
286
|
+
previous && char && isEmojiModifier(char.value) && !isEmojiModifier(previous.value) && (yield [previous, char]);
|
|
287
|
+
}
|
|
288
|
+
},
|
|
289
|
+
*regionalIndicatorSymbol(chars) {
|
|
290
|
+
for (let [index, char] of chars.entries()) {
|
|
291
|
+
let previous = chars[index - 1];
|
|
292
|
+
previous && char && isRegionalIndicatorSymbol(char.value) && isRegionalIndicatorSymbol(previous.value) && (yield [previous, char]);
|
|
293
|
+
}
|
|
294
|
+
},
|
|
295
|
+
*zwj(chars) {
|
|
296
|
+
let sequence = null;
|
|
297
|
+
for (let [index, char] of chars.entries()) {
|
|
298
|
+
let previous = chars[index - 1], next = chars[index + 1];
|
|
299
|
+
previous && char && next && char.value === 8205 && previous.value !== 8205 && next.value !== 8205 && (sequence ? sequence.at(-1) === previous ? sequence.push(char, next) : (yield sequence, sequence = chars.slice(index - 1, index + 2)) : sequence = chars.slice(index - 1, index + 2));
|
|
300
|
+
}
|
|
301
|
+
sequence && (yield sequence);
|
|
302
|
+
}
|
|
303
|
+
}, kinds = Object.keys(findCharacterSequences);
|
|
304
|
+
/**
|
|
305
|
+
* Gets the value of the given node if it's a static value other than a regular expression object,
|
|
306
|
+
* or the node's `regex` property.
|
|
307
|
+
* The purpose of this method is to provide a replacement for `getStaticValue` in environments where certain regular expressions cannot be evaluated.
|
|
308
|
+
* A known example is Node.js 18 which does not support the `v` flag.
|
|
309
|
+
* Calling `getStaticValue` on a regular expression node with the `v` flag on Node.js 18 always returns `null`.
|
|
310
|
+
* A limitation of this method is that it can only detect a regular expression if the specified node is itself a regular expression literal node.
|
|
311
|
+
* @param {ASTNode | undefined} node The node to be inspected.
|
|
312
|
+
* @param {Scope} initialScope Scope to start finding variables. This function tries to resolve identifier references which are in the given scope.
|
|
313
|
+
* @returns {{ value: any } | { regex: { pattern: string, flags: string } } | null} The static value of the node, or `null`.
|
|
314
|
+
*/
|
|
315
|
+
function getStaticValueOrRegex(node, initialScope) {
|
|
316
|
+
if (!node) return null;
|
|
317
|
+
if (node.type === "Literal" && node.regex) return { regex: node.regex };
|
|
318
|
+
let staticValue = getStaticValue(node, initialScope);
|
|
319
|
+
return staticValue?.value instanceof RegExp ? null : staticValue;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Checks whether a specified regexpp character is represented as an acceptable escape sequence.
|
|
323
|
+
* This function requires the source text of the character to be known.
|
|
324
|
+
* @param {Character} char Character to check.
|
|
325
|
+
* @param {string} charSource Source text of the character to check.
|
|
326
|
+
* @returns {boolean} Whether the specified regexpp character is represented as an acceptable escape sequence.
|
|
327
|
+
*/
|
|
328
|
+
function checkForAcceptableEscape(char, charSource) {
|
|
329
|
+
return charSource.startsWith("\\") ? /(?<=^\\+).$/su.exec(charSource)?.[0] !== String.fromCodePoint(char.value) : !1;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Checks whether a specified regexpp character is represented as an acceptable escape sequence.
|
|
333
|
+
* This function works with characters that are produced by a string or template literal.
|
|
334
|
+
* It requires the source text and the CodeUnit list of the literal to be known.
|
|
335
|
+
* @param {Character} char Character to check.
|
|
336
|
+
* @param {string} nodeSource Source text of the string or template literal that produces the character.
|
|
337
|
+
* @param {CodeUnit[]} codeUnits List of CodeUnit objects of the literal that produces the character.
|
|
338
|
+
* @returns {boolean} Whether the specified regexpp character is represented as an acceptable escape sequence.
|
|
339
|
+
*/
|
|
340
|
+
function checkForAcceptableEscapeInString(char, nodeSource, codeUnits) {
|
|
341
|
+
let firstIndex = char.start, lastIndex = char.end - 1, start = codeUnits[firstIndex].start, end = codeUnits[lastIndex].end;
|
|
342
|
+
return checkForAcceptableEscape(char, nodeSource.slice(start, end));
|
|
343
|
+
}
|
|
344
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
345
|
+
module.exports = {
|
|
346
|
+
meta: {
|
|
347
|
+
type: "problem",
|
|
348
|
+
defaultOptions: [{ allowEscape: !1 }],
|
|
349
|
+
docs: {
|
|
350
|
+
description: "Disallow characters which are made with multiple code points in character class syntax",
|
|
351
|
+
recommended: !0,
|
|
352
|
+
url: "https://eslint.org/docs/latest/rules/no-misleading-character-class"
|
|
353
|
+
},
|
|
354
|
+
hasSuggestions: !0,
|
|
355
|
+
schema: [{
|
|
356
|
+
type: "object",
|
|
357
|
+
properties: { allowEscape: { type: "boolean" } },
|
|
358
|
+
additionalProperties: !1
|
|
359
|
+
}],
|
|
360
|
+
messages: {
|
|
361
|
+
surrogatePairWithoutUFlag: "Unexpected surrogate pair in character class. Use 'u' flag.",
|
|
362
|
+
surrogatePair: "Unexpected surrogate pair in character class.",
|
|
363
|
+
combiningClass: "Unexpected combined character in character class.",
|
|
364
|
+
emojiModifier: "Unexpected modified Emoji in character class.",
|
|
365
|
+
regionalIndicatorSymbol: "Unexpected national flag in character class.",
|
|
366
|
+
zwj: "Unexpected joined character sequence in character class.",
|
|
367
|
+
suggestUnicodeFlag: "Add unicode 'u' flag to regex."
|
|
368
|
+
}
|
|
369
|
+
},
|
|
370
|
+
create(context) {
|
|
371
|
+
let [{ allowEscape }] = context.options, sourceCode = context.sourceCode, parser = new RegExpParser(), checkedPatternNodes = /* @__PURE__ */ new Set();
|
|
372
|
+
/**
|
|
373
|
+
* Verify a given regular expression.
|
|
374
|
+
* @param {Node} node The node to report.
|
|
375
|
+
* @param {string} pattern The regular expression pattern to verify.
|
|
376
|
+
* @param {string} flags The flags of the regular expression.
|
|
377
|
+
* @param {Function} unicodeFixer Fixer for missing "u" flag.
|
|
378
|
+
* @returns {void}
|
|
379
|
+
*/
|
|
380
|
+
function verify(node, pattern, flags, unicodeFixer) {
|
|
381
|
+
let patternNode;
|
|
382
|
+
try {
|
|
383
|
+
patternNode = parser.parsePattern(pattern, 0, pattern.length, {
|
|
384
|
+
unicode: flags.includes("u"),
|
|
385
|
+
unicodeSets: flags.includes("v")
|
|
386
|
+
});
|
|
387
|
+
} catch {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
let codeUnits = null;
|
|
391
|
+
/**
|
|
392
|
+
* Checks whether a specified regexpp character is represented as an acceptable escape sequence.
|
|
393
|
+
* For the purposes of this rule, an escape sequence is considered acceptable if it consists of one or more backslashes followed by the character being escaped.
|
|
394
|
+
* @param {Character} char Character to check.
|
|
395
|
+
* @returns {boolean} Whether the specified regexpp character is represented as an acceptable escape sequence.
|
|
396
|
+
*/
|
|
397
|
+
function isAcceptableEscapeSequence(char) {
|
|
398
|
+
if (node.type === "Literal" && node.regex) return checkForAcceptableEscape(char, char.raw);
|
|
399
|
+
if (node.type === "Literal" && typeof node.value == "string") {
|
|
400
|
+
let nodeSource = node.raw;
|
|
401
|
+
return codeUnits ??= parseStringLiteral(nodeSource), checkForAcceptableEscapeInString(char, nodeSource, codeUnits);
|
|
402
|
+
}
|
|
403
|
+
if (astUtils.isStaticTemplateLiteral(node)) {
|
|
404
|
+
let nodeSource = sourceCode.getText(node);
|
|
405
|
+
return codeUnits ??= parseTemplateToken(nodeSource), checkForAcceptableEscapeInString(char, nodeSource, codeUnits);
|
|
406
|
+
}
|
|
407
|
+
return !1;
|
|
408
|
+
}
|
|
409
|
+
let foundKindMatches = /* @__PURE__ */ new Map();
|
|
410
|
+
visitRegExpAST(patternNode, { onCharacterClassEnter(ccNode) {
|
|
411
|
+
for (let unfilteredChars of iterateCharacterSequence(ccNode.elements)) {
|
|
412
|
+
let chars;
|
|
413
|
+
chars = allowEscape ? unfilteredChars.map((char) => isAcceptableEscapeSequence(char) ? null : char) : unfilteredChars;
|
|
414
|
+
for (let kind of kinds) {
|
|
415
|
+
let matches = findCharacterSequences[kind](chars, unfilteredChars);
|
|
416
|
+
foundKindMatches.has(kind) ? foundKindMatches.get(kind).push(...matches) : foundKindMatches.set(kind, [...matches]);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
} });
|
|
420
|
+
/**
|
|
421
|
+
* Finds the report loc(s) for a range of matches.
|
|
422
|
+
* Only literals and expression-less templates generate granular errors.
|
|
423
|
+
* @param {Character[][]} matches Lists of individual characters being reported on.
|
|
424
|
+
* @returns {Location[]} locs for context.report.
|
|
425
|
+
* @see https://github.com/eslint/eslint/pull/17515
|
|
426
|
+
*/
|
|
427
|
+
function getNodeReportLocations(matches) {
|
|
428
|
+
return !astUtils.isStaticTemplateLiteral(node) && node.type !== "Literal" ? matches.length ? [node.loc] : [] : matches.map((chars) => {
|
|
429
|
+
let firstIndex = chars[0].start, lastIndex = chars.at(-1).end - 1, start, end;
|
|
430
|
+
if (node.type === "TemplateLiteral") {
|
|
431
|
+
let source = sourceCode.getText(node), offset = node.range[0];
|
|
432
|
+
codeUnits ??= parseTemplateToken(source), start = offset + codeUnits[firstIndex].start, end = offset + codeUnits[lastIndex].end;
|
|
433
|
+
} else if (typeof node.value == "string") {
|
|
434
|
+
let source = node.raw, offset = node.range[0];
|
|
435
|
+
codeUnits ??= parseStringLiteral(source), start = offset + codeUnits[firstIndex].start, end = offset + codeUnits[lastIndex].end;
|
|
436
|
+
} else {
|
|
437
|
+
let offset = node.range[0] + 1;
|
|
438
|
+
start = offset + firstIndex, end = offset + lastIndex + 1;
|
|
439
|
+
}
|
|
440
|
+
return {
|
|
441
|
+
start: sourceCode.getLocFromIndex(start),
|
|
442
|
+
end: sourceCode.getLocFromIndex(end)
|
|
443
|
+
};
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
for (let [kind, matches] of foundKindMatches) {
|
|
447
|
+
let suggest;
|
|
448
|
+
kind === "surrogatePairWithoutUFlag" && (suggest = [{
|
|
449
|
+
messageId: "suggestUnicodeFlag",
|
|
450
|
+
fix: unicodeFixer
|
|
451
|
+
}]);
|
|
452
|
+
let locs = getNodeReportLocations(matches);
|
|
453
|
+
for (let loc of locs) context.report({
|
|
454
|
+
node,
|
|
455
|
+
loc,
|
|
456
|
+
messageId: kind,
|
|
457
|
+
suggest
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
return {
|
|
462
|
+
"Literal[regex]"(node) {
|
|
463
|
+
checkedPatternNodes.has(node) || verify(node, node.regex.pattern, node.regex.flags, (fixer) => isValidWithUnicodeFlag(context.languageOptions.ecmaVersion, node.regex.pattern) ? fixer.insertTextAfter(node, "u") : null);
|
|
464
|
+
},
|
|
465
|
+
Program(node) {
|
|
466
|
+
let scope = sourceCode.getScope(node), tracker = new ReferenceTracker(scope);
|
|
467
|
+
for (let { node: refNode } of tracker.iterateGlobalReferences({ RegExp: {
|
|
468
|
+
[CALL]: !0,
|
|
469
|
+
[CONSTRUCT]: !0
|
|
470
|
+
} })) {
|
|
471
|
+
let pattern, flags, [patternNode, flagsNode] = refNode.arguments, evaluatedPattern = getStaticValueOrRegex(patternNode, scope);
|
|
472
|
+
if (evaluatedPattern) {
|
|
473
|
+
if (flagsNode) evaluatedPattern.regex ? (pattern = evaluatedPattern.regex.pattern, checkedPatternNodes.add(patternNode)) : pattern = String(evaluatedPattern.value), flags = getStringIfConstant(flagsNode, scope);
|
|
474
|
+
else {
|
|
475
|
+
if (evaluatedPattern.regex) continue;
|
|
476
|
+
pattern = String(evaluatedPattern.value), flags = "";
|
|
477
|
+
}
|
|
478
|
+
typeof flags == "string" && verify(patternNode, pattern, flags, (fixer) => {
|
|
479
|
+
if (!isValidWithUnicodeFlag(context.languageOptions.ecmaVersion, pattern)) return null;
|
|
480
|
+
if (refNode.arguments.length === 1) {
|
|
481
|
+
let penultimateToken = sourceCode.getLastToken(refNode, { skip: 1 });
|
|
482
|
+
return fixer.insertTextAfter(penultimateToken, astUtils.isCommaToken(penultimateToken) ? " \"u\"," : ", \"u\"");
|
|
483
|
+
}
|
|
484
|
+
if (flagsNode.type === "Literal" && typeof flagsNode.value == "string" || flagsNode.type === "TemplateLiteral") {
|
|
485
|
+
let range = [flagsNode.range[0], flagsNode.range[1] - 1];
|
|
486
|
+
return fixer.insertTextAfterRange(range, "u");
|
|
487
|
+
}
|
|
488
|
+
return null;
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
}));
|
|
497
|
+
//#endregion
|
|
498
|
+
//#region src-js/generated/plugin-eslint/rules/no-misleading-character-class.cjs
|
|
499
|
+
module.exports = require_no_misleading_character_class().create;
|
|
500
|
+
//#endregion
|
|
@@ -0,0 +1,197 @@
|
|
|
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-mixed-operators.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Rule to disallow mixed binary operators.
|
|
5
|
+
* @author Toru Nagashima
|
|
6
|
+
* @deprecated in ESLint v8.53.0
|
|
7
|
+
*/
|
|
8
|
+
var require_no_mixed_operators = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
9
|
+
let astUtils = require_ast_utils$1.t(), ARITHMETIC_OPERATORS = [
|
|
10
|
+
"+",
|
|
11
|
+
"-",
|
|
12
|
+
"*",
|
|
13
|
+
"/",
|
|
14
|
+
"%",
|
|
15
|
+
"**"
|
|
16
|
+
], BITWISE_OPERATORS = [
|
|
17
|
+
"&",
|
|
18
|
+
"|",
|
|
19
|
+
"^",
|
|
20
|
+
"~",
|
|
21
|
+
"<<",
|
|
22
|
+
">>",
|
|
23
|
+
">>>"
|
|
24
|
+
], COMPARISON_OPERATORS = [
|
|
25
|
+
"==",
|
|
26
|
+
"!=",
|
|
27
|
+
"===",
|
|
28
|
+
"!==",
|
|
29
|
+
">",
|
|
30
|
+
">=",
|
|
31
|
+
"<",
|
|
32
|
+
"<="
|
|
33
|
+
], LOGICAL_OPERATORS = ["&&", "||"], RELATIONAL_OPERATORS = ["in", "instanceof"], ALL_OPERATORS = [].concat(ARITHMETIC_OPERATORS, BITWISE_OPERATORS, COMPARISON_OPERATORS, LOGICAL_OPERATORS, RELATIONAL_OPERATORS, ["?:"], ["??"]), DEFAULT_GROUPS = [
|
|
34
|
+
ARITHMETIC_OPERATORS,
|
|
35
|
+
BITWISE_OPERATORS,
|
|
36
|
+
COMPARISON_OPERATORS,
|
|
37
|
+
LOGICAL_OPERATORS,
|
|
38
|
+
RELATIONAL_OPERATORS
|
|
39
|
+
], TARGET_NODE_TYPE = /^(?:Binary|Logical|Conditional)Expression$/u;
|
|
40
|
+
/**
|
|
41
|
+
* Normalizes options.
|
|
42
|
+
* @param {Object|undefined} options A options object to normalize.
|
|
43
|
+
* @returns {Object} Normalized option object.
|
|
44
|
+
*/
|
|
45
|
+
function normalizeOptions(options = {}) {
|
|
46
|
+
return {
|
|
47
|
+
groups: options.groups && options.groups.length > 0 ? options.groups : DEFAULT_GROUPS,
|
|
48
|
+
allowSamePrecedence: options.allowSamePrecedence !== !1
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Checks whether any group which includes both given operator exists or not.
|
|
53
|
+
* @param {Array<string[]>} groups A list of groups to check.
|
|
54
|
+
* @param {string} left An operator.
|
|
55
|
+
* @param {string} right Another operator.
|
|
56
|
+
* @returns {boolean} `true` if such group existed.
|
|
57
|
+
*/
|
|
58
|
+
function includesBothInAGroup(groups, left, right) {
|
|
59
|
+
return groups.some((group) => group.includes(left) && group.includes(right));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Checks whether the given node is a conditional expression and returns the test node else the left node.
|
|
63
|
+
* @param {ASTNode} node A node which can be a BinaryExpression or a LogicalExpression node.
|
|
64
|
+
* This parent node can be BinaryExpression, LogicalExpression
|
|
65
|
+
* , or a ConditionalExpression node
|
|
66
|
+
* @returns {ASTNode} node the appropriate node(left or test).
|
|
67
|
+
*/
|
|
68
|
+
function getChildNode(node) {
|
|
69
|
+
return node.type === "ConditionalExpression" ? node.test : node.left;
|
|
70
|
+
}
|
|
71
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
72
|
+
module.exports = {
|
|
73
|
+
meta: {
|
|
74
|
+
deprecated: {
|
|
75
|
+
message: "Formatting rules are being moved out of ESLint core.",
|
|
76
|
+
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
|
|
77
|
+
deprecatedSince: "8.53.0",
|
|
78
|
+
availableUntil: "11.0.0",
|
|
79
|
+
replacedBy: [{
|
|
80
|
+
message: "ESLint Stylistic now maintains deprecated stylistic core rules.",
|
|
81
|
+
url: "https://eslint.style/guide/migration",
|
|
82
|
+
plugin: {
|
|
83
|
+
name: "@stylistic/eslint-plugin",
|
|
84
|
+
url: "https://eslint.style"
|
|
85
|
+
},
|
|
86
|
+
rule: {
|
|
87
|
+
name: "no-mixed-operators",
|
|
88
|
+
url: "https://eslint.style/rules/no-mixed-operators"
|
|
89
|
+
}
|
|
90
|
+
}]
|
|
91
|
+
},
|
|
92
|
+
type: "suggestion",
|
|
93
|
+
docs: {
|
|
94
|
+
description: "Disallow mixed binary operators",
|
|
95
|
+
recommended: !1,
|
|
96
|
+
url: "https://eslint.org/docs/latest/rules/no-mixed-operators"
|
|
97
|
+
},
|
|
98
|
+
schema: [{
|
|
99
|
+
type: "object",
|
|
100
|
+
properties: {
|
|
101
|
+
groups: {
|
|
102
|
+
type: "array",
|
|
103
|
+
items: {
|
|
104
|
+
type: "array",
|
|
105
|
+
items: { enum: ALL_OPERATORS },
|
|
106
|
+
minItems: 2,
|
|
107
|
+
uniqueItems: !0
|
|
108
|
+
},
|
|
109
|
+
uniqueItems: !0
|
|
110
|
+
},
|
|
111
|
+
allowSamePrecedence: {
|
|
112
|
+
type: "boolean",
|
|
113
|
+
default: !0
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
additionalProperties: !1
|
|
117
|
+
}],
|
|
118
|
+
messages: { unexpectedMixedOperator: "Unexpected mix of '{{leftOperator}}' and '{{rightOperator}}'. Use parentheses to clarify the intended order of operations." }
|
|
119
|
+
},
|
|
120
|
+
create(context) {
|
|
121
|
+
let sourceCode = context.sourceCode, options = normalizeOptions(context.options[0]);
|
|
122
|
+
/**
|
|
123
|
+
* Checks whether a given node should be ignored by options or not.
|
|
124
|
+
* @param {ASTNode} node A node to check. This is a BinaryExpression
|
|
125
|
+
* node or a LogicalExpression node. This parent node is one of
|
|
126
|
+
* them, too.
|
|
127
|
+
* @returns {boolean} `true` if the node should be ignored.
|
|
128
|
+
*/
|
|
129
|
+
function shouldIgnore(node) {
|
|
130
|
+
let a = node, b = node.parent;
|
|
131
|
+
return !includesBothInAGroup(options.groups, a.operator, b.type === "ConditionalExpression" ? "?:" : b.operator) || options.allowSamePrecedence && astUtils.getPrecedence(a) === astUtils.getPrecedence(b);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Checks whether the operator of a given node is mixed with parent
|
|
135
|
+
* node's operator or not.
|
|
136
|
+
* @param {ASTNode} node A node to check. This is a BinaryExpression
|
|
137
|
+
* node or a LogicalExpression node. This parent node is one of
|
|
138
|
+
* them, too.
|
|
139
|
+
* @returns {boolean} `true` if the node was mixed.
|
|
140
|
+
*/
|
|
141
|
+
function isMixedWithParent(node) {
|
|
142
|
+
return node.operator !== node.parent.operator && !astUtils.isParenthesised(sourceCode, node);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Gets the operator token of a given node.
|
|
146
|
+
* @param {ASTNode} node A node to check. This is a BinaryExpression
|
|
147
|
+
* node or a LogicalExpression node.
|
|
148
|
+
* @returns {Token} The operator token of the node.
|
|
149
|
+
*/
|
|
150
|
+
function getOperatorToken(node) {
|
|
151
|
+
return sourceCode.getTokenAfter(getChildNode(node), astUtils.isNotClosingParenToken);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Reports both the operator of a given node and the operator of the
|
|
155
|
+
* parent node.
|
|
156
|
+
* @param {ASTNode} node A node to check. This is a BinaryExpression
|
|
157
|
+
* node or a LogicalExpression node. This parent node is one of
|
|
158
|
+
* them, too.
|
|
159
|
+
* @returns {void}
|
|
160
|
+
*/
|
|
161
|
+
function reportBothOperators(node) {
|
|
162
|
+
let parent = node.parent, left = getChildNode(parent) === node ? node : parent, right = getChildNode(parent) === node ? parent : node, data = {
|
|
163
|
+
leftOperator: left.operator || "?:",
|
|
164
|
+
rightOperator: right.operator || "?:"
|
|
165
|
+
};
|
|
166
|
+
context.report({
|
|
167
|
+
node: left,
|
|
168
|
+
loc: getOperatorToken(left).loc,
|
|
169
|
+
messageId: "unexpectedMixedOperator",
|
|
170
|
+
data
|
|
171
|
+
}), context.report({
|
|
172
|
+
node: right,
|
|
173
|
+
loc: getOperatorToken(right).loc,
|
|
174
|
+
messageId: "unexpectedMixedOperator",
|
|
175
|
+
data
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Checks between the operator of this node and the operator of the
|
|
180
|
+
* parent node.
|
|
181
|
+
* @param {ASTNode} node A node to check.
|
|
182
|
+
* @returns {void}
|
|
183
|
+
*/
|
|
184
|
+
function check(node) {
|
|
185
|
+
TARGET_NODE_TYPE.test(node.parent.type) && isMixedWithParent(node) && !shouldIgnore(node) && reportBothOperators(node);
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
BinaryExpression: check,
|
|
189
|
+
LogicalExpression: check
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
}));
|
|
194
|
+
//#endregion
|
|
195
|
+
//#region src-js/generated/plugin-eslint/rules/no-mixed-operators.cjs
|
|
196
|
+
module.exports = require_no_mixed_operators().create;
|
|
197
|
+
//#endregion
|