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,256 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/eslint@9.39.3_jiti@2.6.1/node_modules/eslint/lib/rules/max-len.js
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Rule to check for max length on a line.
|
|
4
|
+
* @author Matt DuVall <http://www.mattduvall.com>
|
|
5
|
+
* @deprecated in ESLint v8.53.0
|
|
6
|
+
*/
|
|
7
|
+
var require_max_len = /* @__PURE__ */ require("../common/chunk.cjs").t(((exports, module) => {
|
|
8
|
+
let OPTIONS_SCHEMA = {
|
|
9
|
+
type: "object",
|
|
10
|
+
properties: {
|
|
11
|
+
code: {
|
|
12
|
+
type: "integer",
|
|
13
|
+
minimum: 0
|
|
14
|
+
},
|
|
15
|
+
comments: {
|
|
16
|
+
type: "integer",
|
|
17
|
+
minimum: 0
|
|
18
|
+
},
|
|
19
|
+
tabWidth: {
|
|
20
|
+
type: "integer",
|
|
21
|
+
minimum: 0
|
|
22
|
+
},
|
|
23
|
+
ignorePattern: { type: "string" },
|
|
24
|
+
ignoreComments: { type: "boolean" },
|
|
25
|
+
ignoreStrings: { type: "boolean" },
|
|
26
|
+
ignoreUrls: { type: "boolean" },
|
|
27
|
+
ignoreTemplateLiterals: { type: "boolean" },
|
|
28
|
+
ignoreRegExpLiterals: { type: "boolean" },
|
|
29
|
+
ignoreTrailingComments: { type: "boolean" }
|
|
30
|
+
},
|
|
31
|
+
additionalProperties: !1
|
|
32
|
+
}, OPTIONS_OR_INTEGER_SCHEMA = { anyOf: [OPTIONS_SCHEMA, {
|
|
33
|
+
type: "integer",
|
|
34
|
+
minimum: 0
|
|
35
|
+
}] };
|
|
36
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
37
|
+
module.exports = {
|
|
38
|
+
meta: {
|
|
39
|
+
deprecated: {
|
|
40
|
+
message: "Formatting rules are being moved out of ESLint core.",
|
|
41
|
+
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
|
|
42
|
+
deprecatedSince: "8.53.0",
|
|
43
|
+
availableUntil: "11.0.0",
|
|
44
|
+
replacedBy: [{
|
|
45
|
+
message: "ESLint Stylistic now maintains deprecated stylistic core rules.",
|
|
46
|
+
url: "https://eslint.style/guide/migration",
|
|
47
|
+
plugin: {
|
|
48
|
+
name: "@stylistic/eslint-plugin",
|
|
49
|
+
url: "https://eslint.style"
|
|
50
|
+
},
|
|
51
|
+
rule: {
|
|
52
|
+
name: "max-len",
|
|
53
|
+
url: "https://eslint.style/rules/max-len"
|
|
54
|
+
}
|
|
55
|
+
}]
|
|
56
|
+
},
|
|
57
|
+
type: "layout",
|
|
58
|
+
docs: {
|
|
59
|
+
description: "Enforce a maximum line length",
|
|
60
|
+
recommended: !1,
|
|
61
|
+
url: "https://eslint.org/docs/latest/rules/max-len"
|
|
62
|
+
},
|
|
63
|
+
schema: [
|
|
64
|
+
OPTIONS_OR_INTEGER_SCHEMA,
|
|
65
|
+
OPTIONS_OR_INTEGER_SCHEMA,
|
|
66
|
+
OPTIONS_SCHEMA
|
|
67
|
+
],
|
|
68
|
+
messages: {
|
|
69
|
+
max: "This line has a length of {{lineLength}}. Maximum allowed is {{maxLength}}.",
|
|
70
|
+
maxComment: "This line has a comment length of {{lineLength}}. Maximum allowed is {{maxCommentLength}}."
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
create(context) {
|
|
74
|
+
let URL_REGEXP = /[^:/?#]:\/\/[^?#]/u, sourceCode = context.sourceCode;
|
|
75
|
+
/**
|
|
76
|
+
* Computes the length of a line that may contain tabs. The width of each
|
|
77
|
+
* tab will be the number of spaces to the next tab stop.
|
|
78
|
+
* @param {string} line The line.
|
|
79
|
+
* @param {number} tabWidth The width of each tab stop in spaces.
|
|
80
|
+
* @returns {number} The computed line length.
|
|
81
|
+
* @private
|
|
82
|
+
*/
|
|
83
|
+
function computeLineLength(line, tabWidth) {
|
|
84
|
+
let extraCharacterCount = 0;
|
|
85
|
+
return line.replace(/\t/gu, (match, offset) => {
|
|
86
|
+
let totalOffset = offset + extraCharacterCount, spaceCount = tabWidth - (tabWidth ? totalOffset % tabWidth : 0);
|
|
87
|
+
extraCharacterCount += spaceCount - 1;
|
|
88
|
+
}), Array.from(line).length + extraCharacterCount;
|
|
89
|
+
}
|
|
90
|
+
let options = Object.assign({}, context.options.at(-1));
|
|
91
|
+
typeof context.options[0] == "number" && (options.code = context.options[0]), typeof context.options[1] == "number" && (options.tabWidth = context.options[1]);
|
|
92
|
+
let maxLength = typeof options.code == "number" ? options.code : 80, tabWidth = typeof options.tabWidth == "number" ? options.tabWidth : 4, ignoreComments = !!options.ignoreComments, ignoreStrings = !!options.ignoreStrings, ignoreTemplateLiterals = !!options.ignoreTemplateLiterals, ignoreRegExpLiterals = !!options.ignoreRegExpLiterals, ignoreTrailingComments = !!options.ignoreTrailingComments || !!options.ignoreComments, ignoreUrls = !!options.ignoreUrls, maxCommentLength = options.comments, ignorePattern = options.ignorePattern || null;
|
|
93
|
+
ignorePattern &&= new RegExp(ignorePattern, "u");
|
|
94
|
+
/**
|
|
95
|
+
* Tells if a given comment is trailing: it starts on the current line and
|
|
96
|
+
* extends to or past the end of the current line.
|
|
97
|
+
* @param {string} line The source line we want to check for a trailing comment on
|
|
98
|
+
* @param {number} lineNumber The one-indexed line number for line
|
|
99
|
+
* @param {ASTNode} comment The comment to inspect
|
|
100
|
+
* @returns {boolean} If the comment is trailing on the given line
|
|
101
|
+
*/
|
|
102
|
+
function isTrailingComment(line, lineNumber, comment) {
|
|
103
|
+
return comment && comment.loc.start.line === lineNumber && lineNumber <= comment.loc.end.line && (comment.loc.end.line > lineNumber || comment.loc.end.column === line.length);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Tells if a comment encompasses the entire line.
|
|
107
|
+
* @param {string} line The source line with a trailing comment
|
|
108
|
+
* @param {number} lineNumber The one-indexed line number this is on
|
|
109
|
+
* @param {ASTNode} comment The comment to remove
|
|
110
|
+
* @returns {boolean} If the comment covers the entire line
|
|
111
|
+
*/
|
|
112
|
+
function isFullLineComment(line, lineNumber, comment) {
|
|
113
|
+
let start = comment.loc.start, end = comment.loc.end, isFirstTokenOnLine = !line.slice(0, comment.loc.start.column).trim();
|
|
114
|
+
return comment && (start.line < lineNumber || start.line === lineNumber && isFirstTokenOnLine) && (end.line > lineNumber || end.line === lineNumber && end.column === line.length);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Check if a node is a JSXEmptyExpression contained in a single line JSXExpressionContainer.
|
|
118
|
+
* @param {ASTNode} node A node to check.
|
|
119
|
+
* @returns {boolean} True if the node is a JSXEmptyExpression contained in a single line JSXExpressionContainer.
|
|
120
|
+
*/
|
|
121
|
+
function isJSXEmptyExpressionInSingleLineContainer(node) {
|
|
122
|
+
if (!node || !node.parent || node.type !== "JSXEmptyExpression" || node.parent.type !== "JSXExpressionContainer") return !1;
|
|
123
|
+
let parent = node.parent;
|
|
124
|
+
return parent.loc.start.line === parent.loc.end.line;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Gets the line after the comment and any remaining trailing whitespace is
|
|
128
|
+
* stripped.
|
|
129
|
+
* @param {string} line The source line with a trailing comment
|
|
130
|
+
* @param {ASTNode} comment The comment to remove
|
|
131
|
+
* @returns {string} Line without comment and trailing whitespace
|
|
132
|
+
*/
|
|
133
|
+
function stripTrailingComment(line, comment) {
|
|
134
|
+
return line.slice(0, comment.loc.start.column).replace(/\s+$/u, "");
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Ensure that an array exists at [key] on `object`, and add `value` to it.
|
|
138
|
+
* @param {Object} object the object to mutate
|
|
139
|
+
* @param {string} key the object's key
|
|
140
|
+
* @param {any} value the value to add
|
|
141
|
+
* @returns {void}
|
|
142
|
+
* @private
|
|
143
|
+
*/
|
|
144
|
+
function ensureArrayAndPush(object, key, value) {
|
|
145
|
+
Array.isArray(object[key]) || (object[key] = []), object[key].push(value);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Retrieves an array containing all strings (" or ') in the source code.
|
|
149
|
+
* @returns {ASTNode[]} An array of string nodes.
|
|
150
|
+
*/
|
|
151
|
+
function getAllStrings() {
|
|
152
|
+
return sourceCode.ast.tokens.filter((token) => token.type === "String" || token.type === "JSXText" && sourceCode.getNodeByRangeIndex(token.range[0] - 1).type === "JSXAttribute");
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Retrieves an array containing all template literals in the source code.
|
|
156
|
+
* @returns {ASTNode[]} An array of template literal nodes.
|
|
157
|
+
*/
|
|
158
|
+
function getAllTemplateLiterals() {
|
|
159
|
+
return sourceCode.ast.tokens.filter((token) => token.type === "Template");
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Retrieves an array containing all RegExp literals in the source code.
|
|
163
|
+
* @returns {ASTNode[]} An array of RegExp literal nodes.
|
|
164
|
+
*/
|
|
165
|
+
function getAllRegExpLiterals() {
|
|
166
|
+
return sourceCode.ast.tokens.filter((token) => token.type === "RegularExpression");
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
*
|
|
170
|
+
* reduce an array of AST nodes by line number, both start and end.
|
|
171
|
+
* @param {ASTNode[]} arr array of AST nodes
|
|
172
|
+
* @returns {Object} accululated AST nodes
|
|
173
|
+
*/
|
|
174
|
+
function groupArrayByLineNumber(arr) {
|
|
175
|
+
let obj = {};
|
|
176
|
+
for (let i = 0; i < arr.length; i++) {
|
|
177
|
+
let node = arr[i];
|
|
178
|
+
for (let j = node.loc.start.line; j <= node.loc.end.line; ++j) ensureArrayAndPush(obj, j, node);
|
|
179
|
+
}
|
|
180
|
+
return obj;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Returns an array of all comments in the source code.
|
|
184
|
+
* If the element in the array is a JSXEmptyExpression contained with a single line JSXExpressionContainer,
|
|
185
|
+
* the element is changed with JSXExpressionContainer node.
|
|
186
|
+
* @returns {ASTNode[]} An array of comment nodes
|
|
187
|
+
*/
|
|
188
|
+
function getAllComments() {
|
|
189
|
+
let comments = [];
|
|
190
|
+
return sourceCode.getAllComments().forEach((commentNode) => {
|
|
191
|
+
let containingNode = sourceCode.getNodeByRangeIndex(commentNode.range[0]);
|
|
192
|
+
isJSXEmptyExpressionInSingleLineContainer(containingNode) ? comments.at(-1) !== containingNode.parent && comments.push(containingNode.parent) : comments.push(commentNode);
|
|
193
|
+
}), comments;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Check the program for max length
|
|
197
|
+
* @param {ASTNode} node Node to examine
|
|
198
|
+
* @returns {void}
|
|
199
|
+
* @private
|
|
200
|
+
*/
|
|
201
|
+
function checkProgramForMaxLength(node) {
|
|
202
|
+
let lines = sourceCode.lines, comments = ignoreComments || maxCommentLength || ignoreTrailingComments ? getAllComments() : [], commentsIndex = 0, stringsByLine = groupArrayByLineNumber(getAllStrings()), templateLiteralsByLine = groupArrayByLineNumber(getAllTemplateLiterals()), regExpLiteralsByLine = groupArrayByLineNumber(getAllRegExpLiterals());
|
|
203
|
+
lines.forEach((line, i) => {
|
|
204
|
+
let lineNumber = i + 1, lineIsComment = !1, textToMeasure;
|
|
205
|
+
if (commentsIndex < comments.length) {
|
|
206
|
+
let comment;
|
|
207
|
+
do
|
|
208
|
+
comment = comments[++commentsIndex];
|
|
209
|
+
while (comment && comment.loc.start.line <= lineNumber);
|
|
210
|
+
if (comment = comments[--commentsIndex], isFullLineComment(line, lineNumber, comment)) lineIsComment = !0, textToMeasure = line;
|
|
211
|
+
else if (ignoreTrailingComments && isTrailingComment(line, lineNumber, comment)) {
|
|
212
|
+
textToMeasure = stripTrailingComment(line, comment);
|
|
213
|
+
let lastIndex = commentsIndex;
|
|
214
|
+
for (; isTrailingComment(textToMeasure, lineNumber, comments[--lastIndex]);) textToMeasure = stripTrailingComment(textToMeasure, comments[lastIndex]);
|
|
215
|
+
} else textToMeasure = line;
|
|
216
|
+
} else textToMeasure = line;
|
|
217
|
+
if (ignorePattern && ignorePattern.test(textToMeasure) || ignoreUrls && URL_REGEXP.test(textToMeasure) || ignoreStrings && stringsByLine[lineNumber] || ignoreTemplateLiterals && templateLiteralsByLine[lineNumber] || ignoreRegExpLiterals && regExpLiteralsByLine[lineNumber]) return;
|
|
218
|
+
let lineLength = computeLineLength(textToMeasure, tabWidth), commentLengthApplies = lineIsComment && maxCommentLength;
|
|
219
|
+
if (lineIsComment && ignoreComments) return;
|
|
220
|
+
let loc = {
|
|
221
|
+
start: {
|
|
222
|
+
line: lineNumber,
|
|
223
|
+
column: 0
|
|
224
|
+
},
|
|
225
|
+
end: {
|
|
226
|
+
line: lineNumber,
|
|
227
|
+
column: textToMeasure.length
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
commentLengthApplies ? lineLength > maxCommentLength && context.report({
|
|
231
|
+
node,
|
|
232
|
+
loc,
|
|
233
|
+
messageId: "maxComment",
|
|
234
|
+
data: {
|
|
235
|
+
lineLength,
|
|
236
|
+
maxCommentLength
|
|
237
|
+
}
|
|
238
|
+
}) : lineLength > maxLength && context.report({
|
|
239
|
+
node,
|
|
240
|
+
loc,
|
|
241
|
+
messageId: "max",
|
|
242
|
+
data: {
|
|
243
|
+
lineLength,
|
|
244
|
+
maxLength
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
return { Program: checkProgramForMaxLength };
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
}));
|
|
253
|
+
//#endregion
|
|
254
|
+
//#region src-js/generated/plugin-eslint/rules/max-len.cjs
|
|
255
|
+
module.exports = require_max_len().create;
|
|
256
|
+
//#endregion
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
const require_chunk = require("../common/chunk.cjs"), require_ast_utils$1 = require("../common/ast-utils.cjs"), require_string_utils$1 = require("../common/string-utils.cjs");
|
|
2
|
+
//#region ../../node_modules/.pnpm/eslint@9.39.3_jiti@2.6.1/node_modules/eslint/lib/rules/max-lines-per-function.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview A rule to set the maximum number of line of code in a function.
|
|
5
|
+
* @author Pete Ward <peteward44@gmail.com>
|
|
6
|
+
*/
|
|
7
|
+
var require_max_lines_per_function = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
8
|
+
let astUtils = require_ast_utils$1.t(), { upperCaseFirst } = require_string_utils$1.t(), OPTIONS_OR_INTEGER_SCHEMA = { oneOf: [{
|
|
9
|
+
type: "object",
|
|
10
|
+
properties: {
|
|
11
|
+
max: {
|
|
12
|
+
type: "integer",
|
|
13
|
+
minimum: 0
|
|
14
|
+
},
|
|
15
|
+
skipComments: { type: "boolean" },
|
|
16
|
+
skipBlankLines: { type: "boolean" },
|
|
17
|
+
IIFEs: { type: "boolean" }
|
|
18
|
+
},
|
|
19
|
+
additionalProperties: !1
|
|
20
|
+
}, {
|
|
21
|
+
type: "integer",
|
|
22
|
+
minimum: 1
|
|
23
|
+
}] };
|
|
24
|
+
/**
|
|
25
|
+
* Given a list of comment nodes, return a map with numeric keys (source code line numbers) and comment token values.
|
|
26
|
+
* @param {Array} comments An array of comment nodes.
|
|
27
|
+
* @returns {Map<string, Node>} A map with numeric keys (source code line numbers) and comment token values.
|
|
28
|
+
*/
|
|
29
|
+
function getCommentLineNumbers(comments) {
|
|
30
|
+
let map = /* @__PURE__ */ new Map();
|
|
31
|
+
return comments.forEach((comment) => {
|
|
32
|
+
for (let i = comment.loc.start.line; i <= comment.loc.end.line; i++) map.set(i, comment);
|
|
33
|
+
}), map;
|
|
34
|
+
}
|
|
35
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
36
|
+
module.exports = {
|
|
37
|
+
meta: {
|
|
38
|
+
type: "suggestion",
|
|
39
|
+
docs: {
|
|
40
|
+
description: "Enforce a maximum number of lines of code in a function",
|
|
41
|
+
recommended: !1,
|
|
42
|
+
url: "https://eslint.org/docs/latest/rules/max-lines-per-function"
|
|
43
|
+
},
|
|
44
|
+
schema: [OPTIONS_OR_INTEGER_SCHEMA],
|
|
45
|
+
messages: { exceed: "{{name}} has too many lines ({{lineCount}}). Maximum allowed is {{maxLines}}." }
|
|
46
|
+
},
|
|
47
|
+
create(context) {
|
|
48
|
+
let sourceCode = context.sourceCode, lines = sourceCode.lines, option = context.options[0], maxLines = 50, skipComments = !1, skipBlankLines = !1, IIFEs = !1;
|
|
49
|
+
typeof option == "object" ? (maxLines = typeof option.max == "number" ? option.max : 50, skipComments = !!option.skipComments, skipBlankLines = !!option.skipBlankLines, IIFEs = !!option.IIFEs) : typeof option == "number" && (maxLines = option);
|
|
50
|
+
let commentLineNumbers = getCommentLineNumbers(sourceCode.getAllComments());
|
|
51
|
+
/**
|
|
52
|
+
* Tells if a comment encompasses the entire line.
|
|
53
|
+
* @param {string} line The source line with a trailing comment
|
|
54
|
+
* @param {number} lineNumber The one-indexed line number this is on
|
|
55
|
+
* @param {ASTNode} comment The comment to remove
|
|
56
|
+
* @returns {boolean} If the comment covers the entire line
|
|
57
|
+
*/
|
|
58
|
+
function isFullLineComment(line, lineNumber, comment) {
|
|
59
|
+
let start = comment.loc.start, end = comment.loc.end, isFirstTokenOnLine = start.line === lineNumber && !line.slice(0, start.column).trim(), isLastTokenOnLine = end.line === lineNumber && !line.slice(end.column).trim();
|
|
60
|
+
return comment && (start.line < lineNumber || isFirstTokenOnLine) && (end.line > lineNumber || isLastTokenOnLine);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Identifies is a node is a FunctionExpression which is part of an IIFE
|
|
64
|
+
* @param {ASTNode} node Node to test
|
|
65
|
+
* @returns {boolean} True if it's an IIFE
|
|
66
|
+
*/
|
|
67
|
+
function isIIFE(node) {
|
|
68
|
+
return (node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression") && node.parent && node.parent.type === "CallExpression" && node.parent.callee === node;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Identifies is a node is a FunctionExpression which is embedded within a MethodDefinition or Property
|
|
72
|
+
* @param {ASTNode} node Node to test
|
|
73
|
+
* @returns {boolean} True if it's a FunctionExpression embedded within a MethodDefinition or Property
|
|
74
|
+
*/
|
|
75
|
+
function isEmbedded(node) {
|
|
76
|
+
return !node.parent || node !== node.parent.value ? !1 : node.parent.type === "MethodDefinition" ? !0 : node.parent.type === "Property" ? node.parent.method === !0 || node.parent.kind === "get" || node.parent.kind === "set" : !1;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Count the lines in the function
|
|
80
|
+
* @param {ASTNode} funcNode Function AST node
|
|
81
|
+
* @returns {void}
|
|
82
|
+
* @private
|
|
83
|
+
*/
|
|
84
|
+
function processFunction(funcNode) {
|
|
85
|
+
let node = isEmbedded(funcNode) ? funcNode.parent : funcNode;
|
|
86
|
+
if (!IIFEs && isIIFE(node)) return;
|
|
87
|
+
let lineCount = 0;
|
|
88
|
+
for (let i = node.loc.start.line - 1; i < node.loc.end.line; ++i) {
|
|
89
|
+
let line = lines[i];
|
|
90
|
+
skipComments && commentLineNumbers.has(i + 1) && isFullLineComment(line, i + 1, commentLineNumbers.get(i + 1)) || skipBlankLines && line.match(/^\s*$/u) || lineCount++;
|
|
91
|
+
}
|
|
92
|
+
if (lineCount > maxLines) {
|
|
93
|
+
let name = upperCaseFirst(astUtils.getFunctionNameWithKind(funcNode));
|
|
94
|
+
context.report({
|
|
95
|
+
node,
|
|
96
|
+
messageId: "exceed",
|
|
97
|
+
data: {
|
|
98
|
+
name,
|
|
99
|
+
lineCount,
|
|
100
|
+
maxLines
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
FunctionDeclaration: processFunction,
|
|
107
|
+
FunctionExpression: processFunction,
|
|
108
|
+
ArrowFunctionExpression: processFunction
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}));
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src-js/generated/plugin-eslint/rules/max-lines-per-function.cjs
|
|
115
|
+
module.exports = require_max_lines_per_function().create;
|
|
116
|
+
//#endregion
|
|
@@ -0,0 +1,109 @@
|
|
|
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/max-lines.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview enforce a maximum file length
|
|
5
|
+
* @author Alberto Rodríguez
|
|
6
|
+
*/
|
|
7
|
+
var require_max_lines = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
8
|
+
let astUtils = require_ast_utils$1.t();
|
|
9
|
+
/**
|
|
10
|
+
* Creates an array of numbers from `start` up to, but not including, `end`
|
|
11
|
+
* @param {number} start The start of the range
|
|
12
|
+
* @param {number} end The end of the range
|
|
13
|
+
* @returns {number[]} The range of numbers
|
|
14
|
+
*/
|
|
15
|
+
function range(start, end) {
|
|
16
|
+
return [...Array(end - start).keys()].map((x) => x + start);
|
|
17
|
+
}
|
|
18
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
19
|
+
module.exports = {
|
|
20
|
+
meta: {
|
|
21
|
+
type: "suggestion",
|
|
22
|
+
docs: {
|
|
23
|
+
description: "Enforce a maximum number of lines per file",
|
|
24
|
+
recommended: !1,
|
|
25
|
+
url: "https://eslint.org/docs/latest/rules/max-lines"
|
|
26
|
+
},
|
|
27
|
+
schema: [{ oneOf: [{
|
|
28
|
+
type: "integer",
|
|
29
|
+
minimum: 0
|
|
30
|
+
}, {
|
|
31
|
+
type: "object",
|
|
32
|
+
properties: {
|
|
33
|
+
max: {
|
|
34
|
+
type: "integer",
|
|
35
|
+
minimum: 0
|
|
36
|
+
},
|
|
37
|
+
skipComments: { type: "boolean" },
|
|
38
|
+
skipBlankLines: { type: "boolean" }
|
|
39
|
+
},
|
|
40
|
+
additionalProperties: !1
|
|
41
|
+
}] }],
|
|
42
|
+
messages: { exceed: "File has too many lines ({{actual}}). Maximum allowed is {{max}}." }
|
|
43
|
+
},
|
|
44
|
+
create(context) {
|
|
45
|
+
let option = context.options[0], max = 300;
|
|
46
|
+
typeof option == "object" && Object.hasOwn(option, "max") ? max = option.max : typeof option == "number" && (max = option);
|
|
47
|
+
let skipComments = option && option.skipComments, skipBlankLines = option && option.skipBlankLines, sourceCode = context.sourceCode;
|
|
48
|
+
/**
|
|
49
|
+
* Returns whether or not a token is a comment node type
|
|
50
|
+
* @param {Token} token The token to check
|
|
51
|
+
* @returns {boolean} True if the token is a comment node
|
|
52
|
+
*/
|
|
53
|
+
function isCommentNodeType(token) {
|
|
54
|
+
return token && (token.type === "Block" || token.type === "Line");
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Returns the line numbers of a comment that don't have any code on the same line
|
|
58
|
+
* @param {Node} comment The comment node to check
|
|
59
|
+
* @returns {number[]} The line numbers
|
|
60
|
+
*/
|
|
61
|
+
function getLinesWithoutCode(comment) {
|
|
62
|
+
let start = comment.loc.start.line, end = comment.loc.end.line, token;
|
|
63
|
+
token = comment;
|
|
64
|
+
do
|
|
65
|
+
token = sourceCode.getTokenBefore(token, { includeComments: !0 });
|
|
66
|
+
while (isCommentNodeType(token));
|
|
67
|
+
token && astUtils.isTokenOnSameLine(token, comment) && (start += 1), token = comment;
|
|
68
|
+
do
|
|
69
|
+
token = sourceCode.getTokenAfter(token, { includeComments: !0 });
|
|
70
|
+
while (isCommentNodeType(token));
|
|
71
|
+
return token && astUtils.isTokenOnSameLine(comment, token) && --end, start <= end ? range(start, end + 1) : [];
|
|
72
|
+
}
|
|
73
|
+
return { "Program:exit"() {
|
|
74
|
+
let lines = sourceCode.lines.map((text, i) => ({
|
|
75
|
+
lineNumber: i + 1,
|
|
76
|
+
text
|
|
77
|
+
}));
|
|
78
|
+
if (lines.length > 1 && lines.at(-1).text === "" && lines.pop(), skipBlankLines && (lines = lines.filter((l) => l.text.trim() !== "")), skipComments) {
|
|
79
|
+
let comments = sourceCode.getAllComments(), commentLines = new Set(comments.flatMap(getLinesWithoutCode));
|
|
80
|
+
lines = lines.filter((l) => !commentLines.has(l.lineNumber));
|
|
81
|
+
}
|
|
82
|
+
if (lines.length > max) {
|
|
83
|
+
let loc = {
|
|
84
|
+
start: {
|
|
85
|
+
line: lines[max].lineNumber,
|
|
86
|
+
column: 0
|
|
87
|
+
},
|
|
88
|
+
end: {
|
|
89
|
+
line: sourceCode.lines.length,
|
|
90
|
+
column: sourceCode.lines.at(-1).length
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
context.report({
|
|
94
|
+
loc,
|
|
95
|
+
messageId: "exceed",
|
|
96
|
+
data: {
|
|
97
|
+
max,
|
|
98
|
+
actual: lines.length
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
} };
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}));
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region src-js/generated/plugin-eslint/rules/max-lines.cjs
|
|
108
|
+
module.exports = require_max_lines().create;
|
|
109
|
+
//#endregion
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/eslint@9.39.3_jiti@2.6.1/node_modules/eslint/lib/rules/max-nested-callbacks.js
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Rule to enforce a maximum number of nested callbacks.
|
|
4
|
+
* @author Ian Christian Myers
|
|
5
|
+
*/
|
|
6
|
+
var require_max_nested_callbacks = /* @__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: "Enforce a maximum depth that callbacks can be nested",
|
|
13
|
+
recommended: !1,
|
|
14
|
+
url: "https://eslint.org/docs/latest/rules/max-nested-callbacks"
|
|
15
|
+
},
|
|
16
|
+
schema: [{ oneOf: [{
|
|
17
|
+
type: "integer",
|
|
18
|
+
minimum: 0
|
|
19
|
+
}, {
|
|
20
|
+
type: "object",
|
|
21
|
+
properties: {
|
|
22
|
+
maximum: {
|
|
23
|
+
type: "integer",
|
|
24
|
+
minimum: 0
|
|
25
|
+
},
|
|
26
|
+
max: {
|
|
27
|
+
type: "integer",
|
|
28
|
+
minimum: 0
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
additionalProperties: !1
|
|
32
|
+
}] }],
|
|
33
|
+
messages: { exceed: "Too many nested callbacks ({{num}}). Maximum allowed is {{max}}." }
|
|
34
|
+
},
|
|
35
|
+
create(context) {
|
|
36
|
+
let option = context.options[0], THRESHOLD = 10;
|
|
37
|
+
typeof option == "object" && (Object.hasOwn(option, "maximum") || Object.hasOwn(option, "max")) ? THRESHOLD = option.maximum || option.max : typeof option == "number" && (THRESHOLD = option);
|
|
38
|
+
let callbackStack = [];
|
|
39
|
+
/**
|
|
40
|
+
* Checks a given function node for too many callbacks.
|
|
41
|
+
* @param {ASTNode} node The node to check.
|
|
42
|
+
* @returns {void}
|
|
43
|
+
* @private
|
|
44
|
+
*/
|
|
45
|
+
function checkFunction(node) {
|
|
46
|
+
if (node.parent.type === "CallExpression" && callbackStack.push(node), callbackStack.length > THRESHOLD) {
|
|
47
|
+
let opts = {
|
|
48
|
+
num: callbackStack.length,
|
|
49
|
+
max: THRESHOLD
|
|
50
|
+
};
|
|
51
|
+
context.report({
|
|
52
|
+
node,
|
|
53
|
+
messageId: "exceed",
|
|
54
|
+
data: opts
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Pops the call stack.
|
|
60
|
+
* @returns {void}
|
|
61
|
+
* @private
|
|
62
|
+
*/
|
|
63
|
+
function popStack() {
|
|
64
|
+
callbackStack.pop();
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
ArrowFunctionExpression: checkFunction,
|
|
68
|
+
"ArrowFunctionExpression:exit": popStack,
|
|
69
|
+
FunctionExpression: checkFunction,
|
|
70
|
+
"FunctionExpression:exit": popStack
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}));
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src-js/generated/plugin-eslint/rules/max-nested-callbacks.cjs
|
|
77
|
+
module.exports = require_max_nested_callbacks().create;
|
|
78
|
+
//#endregion
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
const require_chunk = require("../common/chunk.cjs"), require_ast_utils$1 = require("../common/ast-utils.cjs"), require_string_utils$1 = require("../common/string-utils.cjs");
|
|
2
|
+
//#region ../../node_modules/.pnpm/eslint@9.39.3_jiti@2.6.1/node_modules/eslint/lib/rules/max-params.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Rule to flag when a function has too many parameters
|
|
5
|
+
* @author Ilya Volodin
|
|
6
|
+
*/
|
|
7
|
+
var require_max_params = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
8
|
+
let astUtils = require_ast_utils$1.t(), { upperCaseFirst } = require_string_utils$1.t();
|
|
9
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
10
|
+
module.exports = {
|
|
11
|
+
meta: {
|
|
12
|
+
type: "suggestion",
|
|
13
|
+
dialects: ["typescript", "javascript"],
|
|
14
|
+
language: "javascript",
|
|
15
|
+
docs: {
|
|
16
|
+
description: "Enforce a maximum number of parameters in function definitions",
|
|
17
|
+
recommended: !1,
|
|
18
|
+
url: "https://eslint.org/docs/latest/rules/max-params"
|
|
19
|
+
},
|
|
20
|
+
schema: [{ oneOf: [{
|
|
21
|
+
type: "integer",
|
|
22
|
+
minimum: 0
|
|
23
|
+
}, {
|
|
24
|
+
type: "object",
|
|
25
|
+
properties: {
|
|
26
|
+
maximum: {
|
|
27
|
+
type: "integer",
|
|
28
|
+
minimum: 0
|
|
29
|
+
},
|
|
30
|
+
max: {
|
|
31
|
+
type: "integer",
|
|
32
|
+
minimum: 0
|
|
33
|
+
},
|
|
34
|
+
countVoidThis: {
|
|
35
|
+
type: "boolean",
|
|
36
|
+
description: "Whether to count a `this` declaration when the type is `void`."
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
additionalProperties: !1
|
|
40
|
+
}] }],
|
|
41
|
+
messages: { exceed: "{{name}} has too many parameters ({{count}}). Maximum allowed is {{max}}." }
|
|
42
|
+
},
|
|
43
|
+
create(context) {
|
|
44
|
+
let sourceCode = context.sourceCode, option = context.options[0], numParams = 3, countVoidThis = !1;
|
|
45
|
+
typeof option == "object" && ((Object.hasOwn(option, "maximum") || Object.hasOwn(option, "max")) && (numParams = option.maximum || option.max), countVoidThis = option.countVoidThis), typeof option == "number" && (numParams = option);
|
|
46
|
+
/**
|
|
47
|
+
* Checks a function to see if it has too many parameters.
|
|
48
|
+
* @param {ASTNode} node The node to check.
|
|
49
|
+
* @returns {void}
|
|
50
|
+
* @private
|
|
51
|
+
*/
|
|
52
|
+
function checkFunction(node) {
|
|
53
|
+
let effectiveParamCount = node.params.length > 0 && node.params[0].type === "Identifier" && node.params[0].name === "this" && node.params[0].typeAnnotation?.typeAnnotation.type === "TSVoidKeyword" && !countVoidThis ? node.params.length - 1 : node.params.length;
|
|
54
|
+
effectiveParamCount > numParams && context.report({
|
|
55
|
+
loc: astUtils.getFunctionHeadLoc(node, sourceCode),
|
|
56
|
+
node,
|
|
57
|
+
messageId: "exceed",
|
|
58
|
+
data: {
|
|
59
|
+
name: upperCaseFirst(astUtils.getFunctionNameWithKind(node)),
|
|
60
|
+
count: effectiveParamCount,
|
|
61
|
+
max: numParams
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
FunctionDeclaration: checkFunction,
|
|
67
|
+
ArrowFunctionExpression: checkFunction,
|
|
68
|
+
FunctionExpression: checkFunction,
|
|
69
|
+
TSDeclareFunction: checkFunction,
|
|
70
|
+
TSFunctionType: checkFunction
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}));
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src-js/generated/plugin-eslint/rules/max-params.cjs
|
|
77
|
+
module.exports = require_max_params().create;
|
|
78
|
+
//#endregion
|