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,106 @@
|
|
|
1
|
+
const require_chunk = require("../common/chunk.cjs"), require_ast_utils$1 = require("../common/ast-utils.cjs");
|
|
2
|
+
//#region ../../node_modules/.pnpm/eslint@9.39.3_jiti@2.6.1/node_modules/eslint/lib/rules/multiline-ternary.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Enforce newlines between operands of ternary expressions
|
|
5
|
+
* @author Kai Cataldo
|
|
6
|
+
* @deprecated in ESLint v8.53.0
|
|
7
|
+
*/
|
|
8
|
+
var require_multiline_ternary = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
9
|
+
let astUtils = require_ast_utils$1.t();
|
|
10
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
11
|
+
module.exports = {
|
|
12
|
+
meta: {
|
|
13
|
+
deprecated: {
|
|
14
|
+
message: "Formatting rules are being moved out of ESLint core.",
|
|
15
|
+
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
|
|
16
|
+
deprecatedSince: "8.53.0",
|
|
17
|
+
availableUntil: "11.0.0",
|
|
18
|
+
replacedBy: [{
|
|
19
|
+
message: "ESLint Stylistic now maintains deprecated stylistic core rules.",
|
|
20
|
+
url: "https://eslint.style/guide/migration",
|
|
21
|
+
plugin: {
|
|
22
|
+
name: "@stylistic/eslint-plugin",
|
|
23
|
+
url: "https://eslint.style"
|
|
24
|
+
},
|
|
25
|
+
rule: {
|
|
26
|
+
name: "multiline-ternary",
|
|
27
|
+
url: "https://eslint.style/rules/multiline-ternary"
|
|
28
|
+
}
|
|
29
|
+
}]
|
|
30
|
+
},
|
|
31
|
+
type: "layout",
|
|
32
|
+
docs: {
|
|
33
|
+
description: "Enforce newlines between operands of ternary expressions",
|
|
34
|
+
recommended: !1,
|
|
35
|
+
url: "https://eslint.org/docs/latest/rules/multiline-ternary"
|
|
36
|
+
},
|
|
37
|
+
schema: [{ enum: [
|
|
38
|
+
"always",
|
|
39
|
+
"always-multiline",
|
|
40
|
+
"never"
|
|
41
|
+
] }],
|
|
42
|
+
messages: {
|
|
43
|
+
expectedTestCons: "Expected newline between test and consequent of ternary expression.",
|
|
44
|
+
expectedConsAlt: "Expected newline between consequent and alternate of ternary expression.",
|
|
45
|
+
unexpectedTestCons: "Unexpected newline between test and consequent of ternary expression.",
|
|
46
|
+
unexpectedConsAlt: "Unexpected newline between consequent and alternate of ternary expression."
|
|
47
|
+
},
|
|
48
|
+
fixable: "whitespace"
|
|
49
|
+
},
|
|
50
|
+
create(context) {
|
|
51
|
+
let sourceCode = context.sourceCode, option = context.options[0], multiline = option !== "never", allowSingleLine = option === "always-multiline";
|
|
52
|
+
return { ConditionalExpression(node) {
|
|
53
|
+
let questionToken = sourceCode.getTokenAfter(node.test, astUtils.isNotClosingParenToken), colonToken = sourceCode.getTokenAfter(node.consequent, astUtils.isNotClosingParenToken), firstTokenOfTest = sourceCode.getFirstToken(node), lastTokenOfTest = sourceCode.getTokenBefore(questionToken), firstTokenOfConsequent = sourceCode.getTokenAfter(questionToken), lastTokenOfConsequent = sourceCode.getTokenBefore(colonToken), firstTokenOfAlternate = sourceCode.getTokenAfter(colonToken), areTestAndConsequentOnSameLine = astUtils.isTokenOnSameLine(lastTokenOfTest, firstTokenOfConsequent), areConsequentAndAlternateOnSameLine = astUtils.isTokenOnSameLine(lastTokenOfConsequent, firstTokenOfAlternate), hasComments = !!sourceCode.getCommentsInside(node).length;
|
|
54
|
+
if (!multiline) areTestAndConsequentOnSameLine || context.report({
|
|
55
|
+
node: node.test,
|
|
56
|
+
loc: {
|
|
57
|
+
start: firstTokenOfTest.loc.start,
|
|
58
|
+
end: lastTokenOfTest.loc.end
|
|
59
|
+
},
|
|
60
|
+
messageId: "unexpectedTestCons",
|
|
61
|
+
fix(fixer) {
|
|
62
|
+
if (hasComments) return null;
|
|
63
|
+
let fixers = [], areTestAndQuestionOnSameLine = astUtils.isTokenOnSameLine(lastTokenOfTest, questionToken), areQuestionAndConsOnSameLine = astUtils.isTokenOnSameLine(questionToken, firstTokenOfConsequent);
|
|
64
|
+
return areTestAndQuestionOnSameLine || fixers.push(fixer.removeRange([lastTokenOfTest.range[1], questionToken.range[0]])), areQuestionAndConsOnSameLine || fixers.push(fixer.removeRange([questionToken.range[1], firstTokenOfConsequent.range[0]])), fixers;
|
|
65
|
+
}
|
|
66
|
+
}), areConsequentAndAlternateOnSameLine || context.report({
|
|
67
|
+
node: node.consequent,
|
|
68
|
+
loc: {
|
|
69
|
+
start: firstTokenOfConsequent.loc.start,
|
|
70
|
+
end: lastTokenOfConsequent.loc.end
|
|
71
|
+
},
|
|
72
|
+
messageId: "unexpectedConsAlt",
|
|
73
|
+
fix(fixer) {
|
|
74
|
+
if (hasComments) return null;
|
|
75
|
+
let fixers = [], areConsAndColonOnSameLine = astUtils.isTokenOnSameLine(lastTokenOfConsequent, colonToken), areColonAndAltOnSameLine = astUtils.isTokenOnSameLine(colonToken, firstTokenOfAlternate);
|
|
76
|
+
return areConsAndColonOnSameLine || fixers.push(fixer.removeRange([lastTokenOfConsequent.range[1], colonToken.range[0]])), areColonAndAltOnSameLine || fixers.push(fixer.removeRange([colonToken.range[1], firstTokenOfAlternate.range[0]])), fixers;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
else {
|
|
80
|
+
if (allowSingleLine && node.loc.start.line === node.loc.end.line) return;
|
|
81
|
+
areTestAndConsequentOnSameLine && context.report({
|
|
82
|
+
node: node.test,
|
|
83
|
+
loc: {
|
|
84
|
+
start: firstTokenOfTest.loc.start,
|
|
85
|
+
end: lastTokenOfTest.loc.end
|
|
86
|
+
},
|
|
87
|
+
messageId: "expectedTestCons",
|
|
88
|
+
fix: (fixer) => hasComments ? null : fixer.replaceTextRange([lastTokenOfTest.range[1], questionToken.range[0]], "\n")
|
|
89
|
+
}), areConsequentAndAlternateOnSameLine && context.report({
|
|
90
|
+
node: node.consequent,
|
|
91
|
+
loc: {
|
|
92
|
+
start: firstTokenOfConsequent.loc.start,
|
|
93
|
+
end: lastTokenOfConsequent.loc.end
|
|
94
|
+
},
|
|
95
|
+
messageId: "expectedConsAlt",
|
|
96
|
+
fix: (fixer) => hasComments ? null : fixer.replaceTextRange([lastTokenOfConsequent.range[1], colonToken.range[0]], "\n")
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
} };
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}));
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src-js/generated/plugin-eslint/rules/multiline-ternary.cjs
|
|
105
|
+
module.exports = require_multiline_ternary().create;
|
|
106
|
+
//#endregion
|
|
@@ -0,0 +1,139 @@
|
|
|
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/new-cap.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Rule to flag use of constructors without capital letters
|
|
5
|
+
* @author Nicholas C. Zakas
|
|
6
|
+
*/
|
|
7
|
+
var require_new_cap = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
8
|
+
let astUtils = require_ast_utils$1.t(), CAPS_ALLOWED = [
|
|
9
|
+
"Array",
|
|
10
|
+
"Boolean",
|
|
11
|
+
"Date",
|
|
12
|
+
"Error",
|
|
13
|
+
"Function",
|
|
14
|
+
"Number",
|
|
15
|
+
"Object",
|
|
16
|
+
"RegExp",
|
|
17
|
+
"String",
|
|
18
|
+
"Symbol",
|
|
19
|
+
"BigInt"
|
|
20
|
+
];
|
|
21
|
+
/**
|
|
22
|
+
* A reducer function to invert an array to an Object mapping the string form of the key, to `true`.
|
|
23
|
+
* @param {Object} map Accumulator object for the reduce.
|
|
24
|
+
* @param {string} key Object key to set to `true`.
|
|
25
|
+
* @returns {Object} Returns the updated Object for further reduction.
|
|
26
|
+
*/
|
|
27
|
+
function invert(map, key) {
|
|
28
|
+
return map[key] = !0, map;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Creates an object with the cap is new exceptions as its keys and true as their values.
|
|
32
|
+
* @param {Object} config Rule configuration
|
|
33
|
+
* @returns {Object} Object with cap is new exceptions.
|
|
34
|
+
*/
|
|
35
|
+
function calculateCapIsNewExceptions(config) {
|
|
36
|
+
return Array.from(new Set([...config.capIsNewExceptions, ...CAPS_ALLOWED])).reduce(invert, {});
|
|
37
|
+
}
|
|
38
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
39
|
+
module.exports = {
|
|
40
|
+
meta: {
|
|
41
|
+
type: "suggestion",
|
|
42
|
+
docs: {
|
|
43
|
+
description: "Require constructor names to begin with a capital letter",
|
|
44
|
+
recommended: !1,
|
|
45
|
+
url: "https://eslint.org/docs/latest/rules/new-cap"
|
|
46
|
+
},
|
|
47
|
+
schema: [{
|
|
48
|
+
type: "object",
|
|
49
|
+
properties: {
|
|
50
|
+
newIsCap: { type: "boolean" },
|
|
51
|
+
capIsNew: { type: "boolean" },
|
|
52
|
+
newIsCapExceptions: {
|
|
53
|
+
type: "array",
|
|
54
|
+
items: { type: "string" }
|
|
55
|
+
},
|
|
56
|
+
newIsCapExceptionPattern: { type: "string" },
|
|
57
|
+
capIsNewExceptions: {
|
|
58
|
+
type: "array",
|
|
59
|
+
items: { type: "string" }
|
|
60
|
+
},
|
|
61
|
+
capIsNewExceptionPattern: { type: "string" },
|
|
62
|
+
properties: { type: "boolean" }
|
|
63
|
+
},
|
|
64
|
+
additionalProperties: !1
|
|
65
|
+
}],
|
|
66
|
+
defaultOptions: [{
|
|
67
|
+
capIsNew: !0,
|
|
68
|
+
capIsNewExceptions: CAPS_ALLOWED,
|
|
69
|
+
newIsCap: !0,
|
|
70
|
+
newIsCapExceptions: [],
|
|
71
|
+
properties: !0
|
|
72
|
+
}],
|
|
73
|
+
messages: {
|
|
74
|
+
upper: "A function with a name starting with an uppercase letter should only be used as a constructor.",
|
|
75
|
+
lower: "A constructor name should not start with a lowercase letter."
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
create(context) {
|
|
79
|
+
let [config] = context.options, skipProperties = !config.properties, newIsCapExceptions = config.newIsCapExceptions.reduce(invert, {}), newIsCapExceptionPattern = config.newIsCapExceptionPattern ? new RegExp(config.newIsCapExceptionPattern, "u") : null, capIsNewExceptions = calculateCapIsNewExceptions(config), capIsNewExceptionPattern = config.capIsNewExceptionPattern ? new RegExp(config.capIsNewExceptionPattern, "u") : null, listeners = {}, sourceCode = context.sourceCode;
|
|
80
|
+
/**
|
|
81
|
+
* Get exact callee name from expression
|
|
82
|
+
* @param {ASTNode} node CallExpression or NewExpression node
|
|
83
|
+
* @returns {string} name
|
|
84
|
+
*/
|
|
85
|
+
function extractNameFromExpression(node) {
|
|
86
|
+
return node.callee.type === "Identifier" ? node.callee.name : astUtils.getStaticPropertyName(node.callee) || "";
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Returns the capitalization state of the string -
|
|
90
|
+
* Whether the first character is uppercase, lowercase, or non-alphabetic
|
|
91
|
+
* @param {string} str String
|
|
92
|
+
* @returns {string} capitalization state: "non-alpha", "lower", or "upper"
|
|
93
|
+
*/
|
|
94
|
+
function getCap(str) {
|
|
95
|
+
let firstChar = str.charAt(0), firstCharLower = firstChar.toLowerCase();
|
|
96
|
+
return firstCharLower === firstChar.toUpperCase() ? "non-alpha" : firstChar === firstCharLower ? "lower" : "upper";
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Check if capitalization is allowed for a CallExpression
|
|
100
|
+
* @param {Object} allowedMap Object mapping calleeName to a Boolean
|
|
101
|
+
* @param {ASTNode} node CallExpression node
|
|
102
|
+
* @param {string} calleeName Capitalized callee name from a CallExpression
|
|
103
|
+
* @param {Object} pattern RegExp object from options pattern
|
|
104
|
+
* @returns {boolean} Returns true if the callee may be capitalized
|
|
105
|
+
*/
|
|
106
|
+
function isCapAllowed(allowedMap, node, calleeName, pattern) {
|
|
107
|
+
let sourceText = sourceCode.getText(node.callee);
|
|
108
|
+
if (allowedMap[calleeName] || allowedMap[sourceText] || pattern && pattern.test(sourceText)) return !0;
|
|
109
|
+
let callee = astUtils.skipChainExpression(node.callee);
|
|
110
|
+
return calleeName === "UTC" && callee.type === "MemberExpression" ? callee.object.type === "Identifier" && callee.object.name === "Date" : skipProperties && callee.type === "MemberExpression";
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Reports the given messageId for the given node. The location will be the start of the property or the callee.
|
|
114
|
+
* @param {ASTNode} node CallExpression or NewExpression node.
|
|
115
|
+
* @param {string} messageId The messageId to report.
|
|
116
|
+
* @returns {void}
|
|
117
|
+
*/
|
|
118
|
+
function report(node, messageId) {
|
|
119
|
+
let callee = astUtils.skipChainExpression(node.callee);
|
|
120
|
+
callee.type === "MemberExpression" && (callee = callee.property), context.report({
|
|
121
|
+
node,
|
|
122
|
+
loc: callee.loc,
|
|
123
|
+
messageId
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
return config.newIsCap && (listeners.NewExpression = function(node) {
|
|
127
|
+
let constructorName = extractNameFromExpression(node);
|
|
128
|
+
constructorName && (getCap(constructorName) !== "lower" || isCapAllowed(newIsCapExceptions, node, constructorName, newIsCapExceptionPattern) || report(node, "lower"));
|
|
129
|
+
}), config.capIsNew && (listeners.CallExpression = function(node) {
|
|
130
|
+
let calleeName = extractNameFromExpression(node);
|
|
131
|
+
calleeName && (getCap(calleeName) !== "upper" || isCapAllowed(capIsNewExceptions, node, calleeName, capIsNewExceptionPattern) || report(node, "upper"));
|
|
132
|
+
}), listeners;
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
}));
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src-js/generated/plugin-eslint/rules/new-cap.cjs
|
|
138
|
+
module.exports = require_new_cap().create;
|
|
139
|
+
//#endregion
|
|
@@ -0,0 +1,70 @@
|
|
|
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/new-parens.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Rule to flag when using constructor without parentheses
|
|
5
|
+
* @author Ilya Volodin
|
|
6
|
+
* @deprecated in ESLint v8.53.0
|
|
7
|
+
*/
|
|
8
|
+
var require_new_parens = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
9
|
+
let astUtils = require_ast_utils$1.t();
|
|
10
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
11
|
+
module.exports = {
|
|
12
|
+
meta: {
|
|
13
|
+
deprecated: {
|
|
14
|
+
message: "Formatting rules are being moved out of ESLint core.",
|
|
15
|
+
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
|
|
16
|
+
deprecatedSince: "8.53.0",
|
|
17
|
+
availableUntil: "11.0.0",
|
|
18
|
+
replacedBy: [{
|
|
19
|
+
message: "ESLint Stylistic now maintains deprecated stylistic core rules.",
|
|
20
|
+
url: "https://eslint.style/guide/migration",
|
|
21
|
+
plugin: {
|
|
22
|
+
name: "@stylistic/eslint-plugin",
|
|
23
|
+
url: "https://eslint.style"
|
|
24
|
+
},
|
|
25
|
+
rule: {
|
|
26
|
+
name: "new-parens",
|
|
27
|
+
url: "https://eslint.style/rules/new-parens"
|
|
28
|
+
}
|
|
29
|
+
}]
|
|
30
|
+
},
|
|
31
|
+
type: "layout",
|
|
32
|
+
docs: {
|
|
33
|
+
description: "Enforce or disallow parentheses when invoking a constructor with no arguments",
|
|
34
|
+
recommended: !1,
|
|
35
|
+
url: "https://eslint.org/docs/latest/rules/new-parens"
|
|
36
|
+
},
|
|
37
|
+
fixable: "code",
|
|
38
|
+
schema: [{ enum: ["always", "never"] }],
|
|
39
|
+
messages: {
|
|
40
|
+
missing: "Missing '()' invoking a constructor.",
|
|
41
|
+
unnecessary: "Unnecessary '()' invoking a constructor with no arguments."
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
create(context) {
|
|
45
|
+
let always = context.options[0] !== "never", sourceCode = context.sourceCode;
|
|
46
|
+
return { NewExpression(node) {
|
|
47
|
+
if (node.arguments.length !== 0) return;
|
|
48
|
+
let lastToken = sourceCode.getLastToken(node), hasParens = lastToken && astUtils.isClosingParenToken(lastToken) && astUtils.isOpeningParenToken(sourceCode.getTokenBefore(lastToken)) && node.callee.range[1] < node.range[1];
|
|
49
|
+
always ? hasParens || context.report({
|
|
50
|
+
node,
|
|
51
|
+
messageId: "missing",
|
|
52
|
+
fix: (fixer) => fixer.insertTextAfter(node, "()")
|
|
53
|
+
}) : hasParens && context.report({
|
|
54
|
+
node,
|
|
55
|
+
messageId: "unnecessary",
|
|
56
|
+
fix: (fixer) => [
|
|
57
|
+
fixer.remove(sourceCode.getTokenBefore(lastToken)),
|
|
58
|
+
fixer.remove(lastToken),
|
|
59
|
+
fixer.insertTextBefore(node, "("),
|
|
60
|
+
fixer.insertTextAfter(node, ")")
|
|
61
|
+
]
|
|
62
|
+
});
|
|
63
|
+
} };
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}));
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src-js/generated/plugin-eslint/rules/new-parens.cjs
|
|
69
|
+
module.exports = require_new_parens().create;
|
|
70
|
+
//#endregion
|
|
@@ -0,0 +1,159 @@
|
|
|
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/newline-after-var.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Rule to check empty newline after "var" statement
|
|
5
|
+
* @author Gopal Venkatesan
|
|
6
|
+
* @deprecated in ESLint v4.0.0
|
|
7
|
+
*/
|
|
8
|
+
var require_newline_after_var = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
9
|
+
let astUtils = require_ast_utils$1.t();
|
|
10
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
11
|
+
module.exports = {
|
|
12
|
+
meta: {
|
|
13
|
+
type: "layout",
|
|
14
|
+
docs: {
|
|
15
|
+
description: "Require or disallow an empty line after variable declarations",
|
|
16
|
+
recommended: !1,
|
|
17
|
+
url: "https://eslint.org/docs/latest/rules/newline-after-var"
|
|
18
|
+
},
|
|
19
|
+
schema: [{ enum: ["never", "always"] }],
|
|
20
|
+
fixable: "whitespace",
|
|
21
|
+
messages: {
|
|
22
|
+
expected: "Expected blank line after variable declarations.",
|
|
23
|
+
unexpected: "Unexpected blank line after variable declarations."
|
|
24
|
+
},
|
|
25
|
+
deprecated: {
|
|
26
|
+
message: "The rule was replaced with a more general rule.",
|
|
27
|
+
url: "https://eslint.org/blog/2017/06/eslint-v4.0.0-released/",
|
|
28
|
+
deprecatedSince: "4.0.0",
|
|
29
|
+
availableUntil: "11.0.0",
|
|
30
|
+
replacedBy: [{
|
|
31
|
+
message: "The new rule moved to a plugin.",
|
|
32
|
+
url: "https://eslint.org/docs/latest/rules/padding-line-between-statements#examples",
|
|
33
|
+
plugin: {
|
|
34
|
+
name: "@stylistic/eslint-plugin",
|
|
35
|
+
url: "https://eslint.style"
|
|
36
|
+
},
|
|
37
|
+
rule: {
|
|
38
|
+
name: "padding-line-between-statements",
|
|
39
|
+
url: "https://eslint.style/rules/padding-line-between-statements"
|
|
40
|
+
}
|
|
41
|
+
}]
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
create(context) {
|
|
45
|
+
let sourceCode = context.sourceCode, mode = context.options[0] === "never" ? "never" : "always", commentEndLine = sourceCode.getAllComments().reduce((result, token) => (result[token.loc.start.line] = token.loc.end.line, result), {});
|
|
46
|
+
/**
|
|
47
|
+
* Gets a token from the given node to compare line to the next statement.
|
|
48
|
+
*
|
|
49
|
+
* In general, the token is the last token of the node. However, the token is the second last token if the following conditions satisfy.
|
|
50
|
+
*
|
|
51
|
+
* - The last token is semicolon.
|
|
52
|
+
* - The semicolon is on a different line from the previous token of the semicolon.
|
|
53
|
+
*
|
|
54
|
+
* This behavior would address semicolon-less style code. e.g.:
|
|
55
|
+
*
|
|
56
|
+
* var foo = 1
|
|
57
|
+
*
|
|
58
|
+
* ;(a || b).doSomething()
|
|
59
|
+
* @param {ASTNode} node The node to get.
|
|
60
|
+
* @returns {Token} The token to compare line to the next statement.
|
|
61
|
+
*/
|
|
62
|
+
function getLastToken(node) {
|
|
63
|
+
let lastToken = sourceCode.getLastToken(node);
|
|
64
|
+
if (lastToken.type === "Punctuator" && lastToken.value === ";") {
|
|
65
|
+
let prevToken = sourceCode.getTokenBefore(lastToken);
|
|
66
|
+
if (prevToken.loc.end.line !== lastToken.loc.start.line) return prevToken;
|
|
67
|
+
}
|
|
68
|
+
return lastToken;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Determine if provided keyword is a variable declaration
|
|
72
|
+
* @private
|
|
73
|
+
* @param {string} keyword keyword to test
|
|
74
|
+
* @returns {boolean} True if `keyword` is a type of var
|
|
75
|
+
*/
|
|
76
|
+
function isVar(keyword) {
|
|
77
|
+
return keyword === "var" || keyword === "let" || keyword === "const";
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Determine if provided keyword is a variant of for specifiers
|
|
81
|
+
* @private
|
|
82
|
+
* @param {string} keyword keyword to test
|
|
83
|
+
* @returns {boolean} True if `keyword` is a variant of for specifier
|
|
84
|
+
*/
|
|
85
|
+
function isForTypeSpecifier(keyword) {
|
|
86
|
+
return keyword === "ForStatement" || keyword === "ForInStatement" || keyword === "ForOfStatement";
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Determine if provided keyword is an export specifiers
|
|
90
|
+
* @private
|
|
91
|
+
* @param {string} nodeType nodeType to test
|
|
92
|
+
* @returns {boolean} True if `nodeType` is an export specifier
|
|
93
|
+
*/
|
|
94
|
+
function isExportSpecifier(nodeType) {
|
|
95
|
+
return nodeType === "ExportNamedDeclaration" || nodeType === "ExportSpecifier" || nodeType === "ExportDefaultDeclaration" || nodeType === "ExportAllDeclaration";
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Determine if provided node is the last of their parent block.
|
|
99
|
+
* @private
|
|
100
|
+
* @param {ASTNode} node node to test
|
|
101
|
+
* @returns {boolean} True if `node` is last of their parent block.
|
|
102
|
+
*/
|
|
103
|
+
function isLastNode(node) {
|
|
104
|
+
let token = sourceCode.getTokenAfter(node);
|
|
105
|
+
return !token || token.type === "Punctuator" && token.value === "}";
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Gets the last line of a group of consecutive comments
|
|
109
|
+
* @param {number} commentStartLine The starting line of the group
|
|
110
|
+
* @returns {number} The number of the last comment line of the group
|
|
111
|
+
*/
|
|
112
|
+
function getLastCommentLineOfBlock(commentStartLine) {
|
|
113
|
+
let currentCommentEnd = commentEndLine[commentStartLine];
|
|
114
|
+
return commentEndLine[currentCommentEnd + 1] ? getLastCommentLineOfBlock(currentCommentEnd + 1) : currentCommentEnd;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Determine if a token starts more than one line after a comment ends
|
|
118
|
+
* @param {token} token The token being checked
|
|
119
|
+
* @param {integer} commentStartLine The line number on which the comment starts
|
|
120
|
+
* @returns {boolean} True if `token` does not start immediately after a comment
|
|
121
|
+
*/
|
|
122
|
+
function hasBlankLineAfterComment(token, commentStartLine) {
|
|
123
|
+
return token.loc.start.line > getLastCommentLineOfBlock(commentStartLine) + 1;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Checks that a blank line exists after a variable declaration when mode is
|
|
127
|
+
* set to "always", or checks that there is no blank line when mode is set
|
|
128
|
+
* to "never"
|
|
129
|
+
* @private
|
|
130
|
+
* @param {ASTNode} node `VariableDeclaration` node to test
|
|
131
|
+
* @returns {void}
|
|
132
|
+
*/
|
|
133
|
+
function checkForBlankLine(node) {
|
|
134
|
+
let lastToken = getLastToken(node), nextToken = lastToken === sourceCode.getLastToken(node) ? sourceCode.getTokenAfter(node) : sourceCode.getLastToken(node), nextLineNum = lastToken.loc.end.line + 1;
|
|
135
|
+
if (!nextToken || isForTypeSpecifier(node.parent.type) || isExportSpecifier(node.parent.type) || nextToken.type === "Keyword" && isVar(nextToken.value) || isLastNode(node)) return;
|
|
136
|
+
let noNextLineToken = nextToken.loc.start.line > nextLineNum, hasNextLineComment = commentEndLine[nextLineNum] !== void 0;
|
|
137
|
+
mode === "never" && noNextLineToken && !hasNextLineComment && context.report({
|
|
138
|
+
node,
|
|
139
|
+
messageId: "unexpected",
|
|
140
|
+
fix(fixer) {
|
|
141
|
+
let linesBetween = sourceCode.getText().slice(lastToken.range[1], nextToken.range[0]).split(astUtils.LINEBREAK_MATCHER);
|
|
142
|
+
return fixer.replaceTextRange([lastToken.range[1], nextToken.range[0]], `${linesBetween.slice(0, -1).join("")}\n${linesBetween.at(-1)}`);
|
|
143
|
+
}
|
|
144
|
+
}), mode === "always" && (!noNextLineToken || hasNextLineComment && !hasBlankLineAfterComment(nextToken, nextLineNum)) && context.report({
|
|
145
|
+
node,
|
|
146
|
+
messageId: "expected",
|
|
147
|
+
fix(fixer) {
|
|
148
|
+
return (noNextLineToken ? getLastCommentLineOfBlock(nextLineNum) : lastToken.loc.end.line) === nextToken.loc.start.line ? fixer.insertTextBefore(nextToken, "\n\n") : fixer.insertTextBeforeRange([nextToken.range[0] - nextToken.loc.start.column, nextToken.range[1]], "\n");
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
return { VariableDeclaration: checkForBlankLine };
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
}));
|
|
156
|
+
//#endregion
|
|
157
|
+
//#region src-js/generated/plugin-eslint/rules/newline-after-var.cjs
|
|
158
|
+
module.exports = require_newline_after_var().create;
|
|
159
|
+
//#endregion
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/eslint@9.39.3_jiti@2.6.1/node_modules/eslint/lib/rules/newline-before-return.js
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Rule to require newlines before `return` statement
|
|
4
|
+
* @author Kai Cataldo
|
|
5
|
+
* @deprecated in ESLint v4.0.0
|
|
6
|
+
*/
|
|
7
|
+
var require_newline_before_return = /* @__PURE__ */ require("../common/chunk.cjs").t(((exports, module) => {
|
|
8
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
9
|
+
module.exports = {
|
|
10
|
+
meta: {
|
|
11
|
+
type: "layout",
|
|
12
|
+
docs: {
|
|
13
|
+
description: "Require an empty line before `return` statements",
|
|
14
|
+
recommended: !1,
|
|
15
|
+
url: "https://eslint.org/docs/latest/rules/newline-before-return"
|
|
16
|
+
},
|
|
17
|
+
fixable: "whitespace",
|
|
18
|
+
schema: [],
|
|
19
|
+
messages: { expected: "Expected newline before return statement." },
|
|
20
|
+
deprecated: {
|
|
21
|
+
message: "The rule was replaced with a more general rule.",
|
|
22
|
+
url: "https://eslint.org/blog/2017/06/eslint-v4.0.0-released/",
|
|
23
|
+
deprecatedSince: "4.0.0",
|
|
24
|
+
availableUntil: "11.0.0",
|
|
25
|
+
replacedBy: [{
|
|
26
|
+
message: "The new rule moved to a plugin.",
|
|
27
|
+
url: "https://eslint.org/docs/latest/rules/padding-line-between-statements#examples",
|
|
28
|
+
plugin: {
|
|
29
|
+
name: "@stylistic/eslint-plugin",
|
|
30
|
+
url: "https://eslint.style"
|
|
31
|
+
},
|
|
32
|
+
rule: {
|
|
33
|
+
name: "padding-line-between-statements",
|
|
34
|
+
url: "https://eslint.style/rules/padding-line-between-statements"
|
|
35
|
+
}
|
|
36
|
+
}]
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
create(context) {
|
|
40
|
+
let sourceCode = context.sourceCode;
|
|
41
|
+
/**
|
|
42
|
+
* Tests whether node is preceded by supplied tokens
|
|
43
|
+
* @param {ASTNode} node node to check
|
|
44
|
+
* @param {Array} testTokens array of tokens to test against
|
|
45
|
+
* @returns {boolean} Whether or not the node is preceded by one of the supplied tokens
|
|
46
|
+
* @private
|
|
47
|
+
*/
|
|
48
|
+
function isPrecededByTokens(node, testTokens) {
|
|
49
|
+
let tokenBefore = sourceCode.getTokenBefore(node);
|
|
50
|
+
return testTokens.includes(tokenBefore.value);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Checks whether node is the first node after statement or in block
|
|
54
|
+
* @param {ASTNode} node node to check
|
|
55
|
+
* @returns {boolean} Whether or not the node is the first node after statement or in block
|
|
56
|
+
* @private
|
|
57
|
+
*/
|
|
58
|
+
function isFirstNode(node) {
|
|
59
|
+
let parentType = node.parent.type;
|
|
60
|
+
return node.parent.body ? Array.isArray(node.parent.body) ? node.parent.body[0] === node : node.parent.body === node : parentType === "IfStatement" ? isPrecededByTokens(node, ["else", ")"]) : parentType === "DoWhileStatement" ? isPrecededByTokens(node, ["do"]) : parentType === "SwitchCase" ? isPrecededByTokens(node, [":"]) : isPrecededByTokens(node, [")"]);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Returns the number of lines of comments that precede the node
|
|
64
|
+
* @param {ASTNode} node node to check for overlapping comments
|
|
65
|
+
* @param {number} lineNumTokenBefore line number of previous token, to check for overlapping comments
|
|
66
|
+
* @returns {number} Number of lines of comments that precede the node
|
|
67
|
+
* @private
|
|
68
|
+
*/
|
|
69
|
+
function calcCommentLines(node, lineNumTokenBefore) {
|
|
70
|
+
let comments = sourceCode.getCommentsBefore(node), numLinesComments = 0;
|
|
71
|
+
return comments.length && comments.forEach((comment) => {
|
|
72
|
+
numLinesComments++, comment.type === "Block" && (numLinesComments += comment.loc.end.line - comment.loc.start.line), comment.loc.start.line === lineNumTokenBefore && numLinesComments--, comment.loc.end.line === node.loc.start.line && numLinesComments--;
|
|
73
|
+
}), numLinesComments;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Returns the line number of the token before the node that is passed in as an argument
|
|
77
|
+
* @param {ASTNode} node The node to use as the start of the calculation
|
|
78
|
+
* @returns {number} Line number of the token before `node`
|
|
79
|
+
* @private
|
|
80
|
+
*/
|
|
81
|
+
function getLineNumberOfTokenBefore(node) {
|
|
82
|
+
let tokenBefore = sourceCode.getTokenBefore(node), lineNumTokenBefore;
|
|
83
|
+
return lineNumTokenBefore = tokenBefore ? tokenBefore.loc.end.line : 0, lineNumTokenBefore;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Checks whether node is preceded by a newline
|
|
87
|
+
* @param {ASTNode} node node to check
|
|
88
|
+
* @returns {boolean} Whether or not the node is preceded by a newline
|
|
89
|
+
* @private
|
|
90
|
+
*/
|
|
91
|
+
function hasNewlineBefore(node) {
|
|
92
|
+
let lineNumNode = node.loc.start.line, lineNumTokenBefore = getLineNumberOfTokenBefore(node), commentLines = calcCommentLines(node, lineNumTokenBefore);
|
|
93
|
+
return lineNumNode - lineNumTokenBefore - commentLines > 1;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Checks whether it is safe to apply a fix to a given return statement.
|
|
97
|
+
*
|
|
98
|
+
* The fix is not considered safe if the given return statement has leading comments,
|
|
99
|
+
* as we cannot safely determine if the newline should be added before or after the comments.
|
|
100
|
+
* For more information, see: https://github.com/eslint/eslint/issues/5958#issuecomment-222767211
|
|
101
|
+
* @param {ASTNode} node The return statement node to check.
|
|
102
|
+
* @returns {boolean} `true` if it can fix the node.
|
|
103
|
+
* @private
|
|
104
|
+
*/
|
|
105
|
+
function canFix(node) {
|
|
106
|
+
let leadingComments = sourceCode.getCommentsBefore(node), lastLeadingComment = leadingComments.at(-1), tokenBefore = sourceCode.getTokenBefore(node);
|
|
107
|
+
return leadingComments.length === 0 || lastLeadingComment.loc.end.line === tokenBefore.loc.end.line && lastLeadingComment.loc.end.line !== node.loc.start.line;
|
|
108
|
+
}
|
|
109
|
+
return { ReturnStatement(node) {
|
|
110
|
+
!isFirstNode(node) && !hasNewlineBefore(node) && context.report({
|
|
111
|
+
node,
|
|
112
|
+
messageId: "expected",
|
|
113
|
+
fix(fixer) {
|
|
114
|
+
if (canFix(node)) {
|
|
115
|
+
let tokenBefore = sourceCode.getTokenBefore(node), newlines = node.loc.start.line === tokenBefore.loc.end.line ? "\n\n" : "\n";
|
|
116
|
+
return fixer.insertTextBefore(node, newlines);
|
|
117
|
+
}
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
} };
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}));
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region src-js/generated/plugin-eslint/rules/newline-before-return.cjs
|
|
127
|
+
module.exports = require_newline_before_return().create;
|
|
128
|
+
//#endregion
|