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,290 @@
|
|
|
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/lines-around-comment.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Enforces empty lines around comments.
|
|
5
|
+
* @author Jamund Ferguson
|
|
6
|
+
* @deprecated in ESLint v8.53.0
|
|
7
|
+
*/
|
|
8
|
+
var require_lines_around_comment = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
9
|
+
let astUtils = require_ast_utils$1.t();
|
|
10
|
+
/**
|
|
11
|
+
* Return an array with any line numbers that are empty.
|
|
12
|
+
* @param {Array} lines An array of each line of the file.
|
|
13
|
+
* @returns {Array} An array of line numbers.
|
|
14
|
+
*/
|
|
15
|
+
function getEmptyLineNums(lines) {
|
|
16
|
+
return lines.map((line, i) => ({
|
|
17
|
+
code: line.trim(),
|
|
18
|
+
num: i + 1
|
|
19
|
+
})).filter((line) => !line.code).map((line) => line.num);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Return an array with any line numbers that contain comments.
|
|
23
|
+
* @param {Array} comments An array of comment tokens.
|
|
24
|
+
* @returns {Array} An array of line numbers.
|
|
25
|
+
*/
|
|
26
|
+
function getCommentLineNums(comments) {
|
|
27
|
+
let lines = [];
|
|
28
|
+
return comments.forEach((token) => {
|
|
29
|
+
let start = token.loc.start.line, end = token.loc.end.line;
|
|
30
|
+
lines.push(start, end);
|
|
31
|
+
}), lines;
|
|
32
|
+
}
|
|
33
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
34
|
+
module.exports = {
|
|
35
|
+
meta: {
|
|
36
|
+
deprecated: {
|
|
37
|
+
message: "Formatting rules are being moved out of ESLint core.",
|
|
38
|
+
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
|
|
39
|
+
deprecatedSince: "8.53.0",
|
|
40
|
+
availableUntil: "11.0.0",
|
|
41
|
+
replacedBy: [{
|
|
42
|
+
message: "ESLint Stylistic now maintains deprecated stylistic core rules.",
|
|
43
|
+
url: "https://eslint.style/guide/migration",
|
|
44
|
+
plugin: {
|
|
45
|
+
name: "@stylistic/eslint-plugin",
|
|
46
|
+
url: "https://eslint.style"
|
|
47
|
+
},
|
|
48
|
+
rule: {
|
|
49
|
+
name: "lines-around-comment",
|
|
50
|
+
url: "https://eslint.style/rules/lines-around-comment"
|
|
51
|
+
}
|
|
52
|
+
}]
|
|
53
|
+
},
|
|
54
|
+
type: "layout",
|
|
55
|
+
docs: {
|
|
56
|
+
description: "Require empty lines around comments",
|
|
57
|
+
recommended: !1,
|
|
58
|
+
url: "https://eslint.org/docs/latest/rules/lines-around-comment"
|
|
59
|
+
},
|
|
60
|
+
fixable: "whitespace",
|
|
61
|
+
schema: [{
|
|
62
|
+
type: "object",
|
|
63
|
+
properties: {
|
|
64
|
+
beforeBlockComment: {
|
|
65
|
+
type: "boolean",
|
|
66
|
+
default: !0
|
|
67
|
+
},
|
|
68
|
+
afterBlockComment: {
|
|
69
|
+
type: "boolean",
|
|
70
|
+
default: !1
|
|
71
|
+
},
|
|
72
|
+
beforeLineComment: {
|
|
73
|
+
type: "boolean",
|
|
74
|
+
default: !1
|
|
75
|
+
},
|
|
76
|
+
afterLineComment: {
|
|
77
|
+
type: "boolean",
|
|
78
|
+
default: !1
|
|
79
|
+
},
|
|
80
|
+
allowBlockStart: {
|
|
81
|
+
type: "boolean",
|
|
82
|
+
default: !1
|
|
83
|
+
},
|
|
84
|
+
allowBlockEnd: {
|
|
85
|
+
type: "boolean",
|
|
86
|
+
default: !1
|
|
87
|
+
},
|
|
88
|
+
allowClassStart: { type: "boolean" },
|
|
89
|
+
allowClassEnd: { type: "boolean" },
|
|
90
|
+
allowObjectStart: { type: "boolean" },
|
|
91
|
+
allowObjectEnd: { type: "boolean" },
|
|
92
|
+
allowArrayStart: { type: "boolean" },
|
|
93
|
+
allowArrayEnd: { type: "boolean" },
|
|
94
|
+
ignorePattern: { type: "string" },
|
|
95
|
+
applyDefaultIgnorePatterns: { type: "boolean" },
|
|
96
|
+
afterHashbangComment: {
|
|
97
|
+
type: "boolean",
|
|
98
|
+
default: !1
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
additionalProperties: !1
|
|
102
|
+
}],
|
|
103
|
+
messages: {
|
|
104
|
+
after: "Expected line after comment.",
|
|
105
|
+
before: "Expected line before comment."
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
create(context) {
|
|
109
|
+
let options = Object.assign({}, context.options[0]), ignorePattern = options.ignorePattern, defaultIgnoreRegExp = astUtils.COMMENTS_IGNORE_PATTERN, customIgnoreRegExp = new RegExp(ignorePattern, "u"), applyDefaultIgnorePatterns = options.applyDefaultIgnorePatterns !== !1;
|
|
110
|
+
options.beforeBlockComment = options.beforeBlockComment === void 0 ? !0 : options.beforeBlockComment;
|
|
111
|
+
let sourceCode = context.sourceCode, lines = sourceCode.lines, numLines = lines.length + 1, comments = sourceCode.getAllComments(), commentLines = getCommentLineNums(comments), emptyLines = getEmptyLineNums(lines), commentAndEmptyLines = new Set(commentLines.concat(emptyLines));
|
|
112
|
+
/**
|
|
113
|
+
* Returns whether or not comments are on lines starting with or ending with code
|
|
114
|
+
* @param {token} token The comment token to check.
|
|
115
|
+
* @returns {boolean} True if the comment is not alone.
|
|
116
|
+
*/
|
|
117
|
+
function codeAroundComment(token) {
|
|
118
|
+
let currentToken = token;
|
|
119
|
+
do
|
|
120
|
+
currentToken = sourceCode.getTokenBefore(currentToken, { includeComments: !0 });
|
|
121
|
+
while (currentToken && astUtils.isCommentToken(currentToken));
|
|
122
|
+
if (currentToken && astUtils.isTokenOnSameLine(currentToken, token)) return !0;
|
|
123
|
+
currentToken = token;
|
|
124
|
+
do
|
|
125
|
+
currentToken = sourceCode.getTokenAfter(currentToken, { includeComments: !0 });
|
|
126
|
+
while (currentToken && astUtils.isCommentToken(currentToken));
|
|
127
|
+
return !!(currentToken && astUtils.isTokenOnSameLine(token, currentToken));
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Returns whether or not comments are inside a node type or not.
|
|
131
|
+
* @param {ASTNode} parent The Comment parent node.
|
|
132
|
+
* @param {string} nodeType The parent type to check against.
|
|
133
|
+
* @returns {boolean} True if the comment is inside nodeType.
|
|
134
|
+
*/
|
|
135
|
+
function isParentNodeType(parent, nodeType) {
|
|
136
|
+
return parent.type === nodeType || parent.body && parent.body.type === nodeType || parent.consequent && parent.consequent.type === nodeType;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Returns the parent node that contains the given token.
|
|
140
|
+
* @param {token} token The token to check.
|
|
141
|
+
* @returns {ASTNode|null} The parent node that contains the given token.
|
|
142
|
+
*/
|
|
143
|
+
function getParentNodeOfToken(token) {
|
|
144
|
+
let node = sourceCode.getNodeByRangeIndex(token.range[0]);
|
|
145
|
+
if (node && node.type === "StaticBlock") {
|
|
146
|
+
let openingBrace = sourceCode.getFirstToken(node, { skip: 1 });
|
|
147
|
+
return token.range[0] >= openingBrace.range[0] ? node : null;
|
|
148
|
+
}
|
|
149
|
+
return node;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Returns whether or not comments are at the parent start or not.
|
|
153
|
+
* @param {token} token The Comment token.
|
|
154
|
+
* @param {string} nodeType The parent type to check against.
|
|
155
|
+
* @returns {boolean} True if the comment is at parent start.
|
|
156
|
+
*/
|
|
157
|
+
function isCommentAtParentStart(token, nodeType) {
|
|
158
|
+
let parent = getParentNodeOfToken(token);
|
|
159
|
+
if (parent && isParentNodeType(parent, nodeType)) {
|
|
160
|
+
let parentStartNodeOrToken = parent;
|
|
161
|
+
return parent.type === "StaticBlock" ? parentStartNodeOrToken = sourceCode.getFirstToken(parent, { skip: 1 }) : parent.type === "SwitchStatement" && (parentStartNodeOrToken = sourceCode.getTokenAfter(parent.discriminant, { filter: astUtils.isOpeningBraceToken })), token.loc.start.line - parentStartNodeOrToken.loc.start.line === 1;
|
|
162
|
+
}
|
|
163
|
+
return !1;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Returns whether or not comments are at the parent end or not.
|
|
167
|
+
* @param {token} token The Comment token.
|
|
168
|
+
* @param {string} nodeType The parent type to check against.
|
|
169
|
+
* @returns {boolean} True if the comment is at parent end.
|
|
170
|
+
*/
|
|
171
|
+
function isCommentAtParentEnd(token, nodeType) {
|
|
172
|
+
let parent = getParentNodeOfToken(token);
|
|
173
|
+
return !!parent && isParentNodeType(parent, nodeType) && parent.loc.end.line - token.loc.end.line === 1;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Returns whether or not comments are at the block start or not.
|
|
177
|
+
* @param {token} token The Comment token.
|
|
178
|
+
* @returns {boolean} True if the comment is at block start.
|
|
179
|
+
*/
|
|
180
|
+
function isCommentAtBlockStart(token) {
|
|
181
|
+
return isCommentAtParentStart(token, "ClassBody") || isCommentAtParentStart(token, "BlockStatement") || isCommentAtParentStart(token, "StaticBlock") || isCommentAtParentStart(token, "SwitchCase") || isCommentAtParentStart(token, "SwitchStatement");
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Returns whether or not comments are at the block end or not.
|
|
185
|
+
* @param {token} token The Comment token.
|
|
186
|
+
* @returns {boolean} True if the comment is at block end.
|
|
187
|
+
*/
|
|
188
|
+
function isCommentAtBlockEnd(token) {
|
|
189
|
+
return isCommentAtParentEnd(token, "ClassBody") || isCommentAtParentEnd(token, "BlockStatement") || isCommentAtParentEnd(token, "StaticBlock") || isCommentAtParentEnd(token, "SwitchCase") || isCommentAtParentEnd(token, "SwitchStatement");
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Returns whether or not comments are at the class start or not.
|
|
193
|
+
* @param {token} token The Comment token.
|
|
194
|
+
* @returns {boolean} True if the comment is at class start.
|
|
195
|
+
*/
|
|
196
|
+
function isCommentAtClassStart(token) {
|
|
197
|
+
return isCommentAtParentStart(token, "ClassBody");
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Returns whether or not comments are at the class end or not.
|
|
201
|
+
* @param {token} token The Comment token.
|
|
202
|
+
* @returns {boolean} True if the comment is at class end.
|
|
203
|
+
*/
|
|
204
|
+
function isCommentAtClassEnd(token) {
|
|
205
|
+
return isCommentAtParentEnd(token, "ClassBody");
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Returns whether or not comments are at the object start or not.
|
|
209
|
+
* @param {token} token The Comment token.
|
|
210
|
+
* @returns {boolean} True if the comment is at object start.
|
|
211
|
+
*/
|
|
212
|
+
function isCommentAtObjectStart(token) {
|
|
213
|
+
return isCommentAtParentStart(token, "ObjectExpression") || isCommentAtParentStart(token, "ObjectPattern");
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Returns whether or not comments are at the object end or not.
|
|
217
|
+
* @param {token} token The Comment token.
|
|
218
|
+
* @returns {boolean} True if the comment is at object end.
|
|
219
|
+
*/
|
|
220
|
+
function isCommentAtObjectEnd(token) {
|
|
221
|
+
return isCommentAtParentEnd(token, "ObjectExpression") || isCommentAtParentEnd(token, "ObjectPattern");
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Returns whether or not comments are at the array start or not.
|
|
225
|
+
* @param {token} token The Comment token.
|
|
226
|
+
* @returns {boolean} True if the comment is at array start.
|
|
227
|
+
*/
|
|
228
|
+
function isCommentAtArrayStart(token) {
|
|
229
|
+
return isCommentAtParentStart(token, "ArrayExpression") || isCommentAtParentStart(token, "ArrayPattern");
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Returns whether or not comments are at the array end or not.
|
|
233
|
+
* @param {token} token The Comment token.
|
|
234
|
+
* @returns {boolean} True if the comment is at array end.
|
|
235
|
+
*/
|
|
236
|
+
function isCommentAtArrayEnd(token) {
|
|
237
|
+
return isCommentAtParentEnd(token, "ArrayExpression") || isCommentAtParentEnd(token, "ArrayPattern");
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Checks if a comment token has lines around it (ignores inline comments)
|
|
241
|
+
* @param {token} token The Comment token.
|
|
242
|
+
* @param {Object} opts Options to determine the newline.
|
|
243
|
+
* @param {boolean} opts.after Should have a newline after this line.
|
|
244
|
+
* @param {boolean} opts.before Should have a newline before this line.
|
|
245
|
+
* @returns {void}
|
|
246
|
+
*/
|
|
247
|
+
function checkForEmptyLine(token, opts) {
|
|
248
|
+
if (applyDefaultIgnorePatterns && defaultIgnoreRegExp.test(token.value) || ignorePattern && customIgnoreRegExp.test(token.value)) return;
|
|
249
|
+
let after = opts.after, before = opts.before, prevLineNum = token.loc.start.line - 1, nextLineNum = token.loc.end.line + 1, commentIsNotAlone = codeAroundComment(token), blockStartAllowed = options.allowBlockStart && isCommentAtBlockStart(token) && !(options.allowClassStart === !1 && isCommentAtClassStart(token)), blockEndAllowed = options.allowBlockEnd && isCommentAtBlockEnd(token) && !(options.allowClassEnd === !1 && isCommentAtClassEnd(token)), classStartAllowed = options.allowClassStart && isCommentAtClassStart(token), classEndAllowed = options.allowClassEnd && isCommentAtClassEnd(token), objectStartAllowed = options.allowObjectStart && isCommentAtObjectStart(token), objectEndAllowed = options.allowObjectEnd && isCommentAtObjectEnd(token), arrayStartAllowed = options.allowArrayStart && isCommentAtArrayStart(token), arrayEndAllowed = options.allowArrayEnd && isCommentAtArrayEnd(token), exceptionStartAllowed = blockStartAllowed || classStartAllowed || objectStartAllowed || arrayStartAllowed, exceptionEndAllowed = blockEndAllowed || classEndAllowed || objectEndAllowed || arrayEndAllowed;
|
|
250
|
+
if (prevLineNum < 1 && (before = !1), nextLineNum >= numLines && (after = !1), commentIsNotAlone) return;
|
|
251
|
+
let previousTokenOrComment = sourceCode.getTokenBefore(token, { includeComments: !0 }), nextTokenOrComment = sourceCode.getTokenAfter(token, { includeComments: !0 });
|
|
252
|
+
if (!exceptionStartAllowed && before && !commentAndEmptyLines.has(prevLineNum) && !(astUtils.isCommentToken(previousTokenOrComment) && astUtils.isTokenOnSameLine(previousTokenOrComment, token))) {
|
|
253
|
+
let lineStart = token.range[0] - token.loc.start.column, range = [lineStart, lineStart];
|
|
254
|
+
context.report({
|
|
255
|
+
node: token,
|
|
256
|
+
messageId: "before",
|
|
257
|
+
fix(fixer) {
|
|
258
|
+
return fixer.insertTextBeforeRange(range, "\n");
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
!exceptionEndAllowed && after && !commentAndEmptyLines.has(nextLineNum) && !(astUtils.isCommentToken(nextTokenOrComment) && astUtils.isTokenOnSameLine(token, nextTokenOrComment)) && context.report({
|
|
263
|
+
node: token,
|
|
264
|
+
messageId: "after",
|
|
265
|
+
fix(fixer) {
|
|
266
|
+
return fixer.insertTextAfter(token, "\n");
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
return { Program() {
|
|
271
|
+
comments.forEach((token) => {
|
|
272
|
+
token.type === "Line" ? (options.beforeLineComment || options.afterLineComment) && checkForEmptyLine(token, {
|
|
273
|
+
after: options.afterLineComment,
|
|
274
|
+
before: options.beforeLineComment
|
|
275
|
+
}) : token.type === "Block" ? (options.beforeBlockComment || options.afterBlockComment) && checkForEmptyLine(token, {
|
|
276
|
+
after: options.afterBlockComment,
|
|
277
|
+
before: options.beforeBlockComment
|
|
278
|
+
}) : token.type === "Shebang" && options.afterHashbangComment && checkForEmptyLine(token, {
|
|
279
|
+
after: options.afterHashbangComment,
|
|
280
|
+
before: !1
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
} };
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
}));
|
|
287
|
+
//#endregion
|
|
288
|
+
//#region src-js/generated/plugin-eslint/rules/lines-around-comment.cjs
|
|
289
|
+
module.exports = require_lines_around_comment().create;
|
|
290
|
+
//#endregion
|
|
@@ -0,0 +1,129 @@
|
|
|
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/lines-around-directive.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Require or disallow newlines around directives.
|
|
5
|
+
* @author Kai Cataldo
|
|
6
|
+
* @deprecated in ESLint v4.0.0
|
|
7
|
+
*/
|
|
8
|
+
var require_lines_around_directive = /* @__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 newlines around directives",
|
|
16
|
+
recommended: !1,
|
|
17
|
+
url: "https://eslint.org/docs/latest/rules/lines-around-directive"
|
|
18
|
+
},
|
|
19
|
+
schema: [{ oneOf: [{ enum: ["always", "never"] }, {
|
|
20
|
+
type: "object",
|
|
21
|
+
properties: {
|
|
22
|
+
before: { enum: ["always", "never"] },
|
|
23
|
+
after: { enum: ["always", "never"] }
|
|
24
|
+
},
|
|
25
|
+
additionalProperties: !1,
|
|
26
|
+
minProperties: 2
|
|
27
|
+
}] }],
|
|
28
|
+
fixable: "whitespace",
|
|
29
|
+
messages: {
|
|
30
|
+
expected: "Expected newline {{location}} \"{{value}}\" directive.",
|
|
31
|
+
unexpected: "Unexpected newline {{location}} \"{{value}}\" directive."
|
|
32
|
+
},
|
|
33
|
+
deprecated: {
|
|
34
|
+
message: "The rule was replaced with a more general rule.",
|
|
35
|
+
url: "https://eslint.org/blog/2017/06/eslint-v4.0.0-released/",
|
|
36
|
+
deprecatedSince: "4.0.0",
|
|
37
|
+
availableUntil: "11.0.0",
|
|
38
|
+
replacedBy: [{
|
|
39
|
+
message: "The new rule moved to a plugin.",
|
|
40
|
+
url: "https://eslint.org/docs/latest/rules/padding-line-between-statements#examples",
|
|
41
|
+
plugin: {
|
|
42
|
+
name: "@stylistic/eslint-plugin",
|
|
43
|
+
url: "https://eslint.style"
|
|
44
|
+
},
|
|
45
|
+
rule: {
|
|
46
|
+
name: "padding-line-between-statements",
|
|
47
|
+
url: "https://eslint.style/rules/padding-line-between-statements"
|
|
48
|
+
}
|
|
49
|
+
}]
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
create(context) {
|
|
53
|
+
let sourceCode = context.sourceCode, config = context.options[0] || "always", expectLineBefore = typeof config == "string" ? config : config.before, expectLineAfter = typeof config == "string" ? config : config.after;
|
|
54
|
+
/**
|
|
55
|
+
* Check if node is preceded by a blank newline.
|
|
56
|
+
* @param {ASTNode} node Node to check.
|
|
57
|
+
* @returns {boolean} Whether or not the passed in node is preceded by a blank newline.
|
|
58
|
+
*/
|
|
59
|
+
function hasNewlineBefore(node) {
|
|
60
|
+
let tokenBefore = sourceCode.getTokenBefore(node, { includeComments: !0 }), tokenLineBefore = tokenBefore ? tokenBefore.loc.end.line : 0;
|
|
61
|
+
return node.loc.start.line - tokenLineBefore >= 2;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Gets the last token of a node that is on the same line as the rest of the node.
|
|
65
|
+
* This will usually be the last token of the node, but it will be the second-to-last token if the node has a trailing
|
|
66
|
+
* semicolon on a different line.
|
|
67
|
+
* @param {ASTNode} node A directive node
|
|
68
|
+
* @returns {Token} The last token of the node on the line
|
|
69
|
+
*/
|
|
70
|
+
function getLastTokenOnLine(node) {
|
|
71
|
+
let lastToken = sourceCode.getLastToken(node), secondToLastToken = sourceCode.getTokenBefore(lastToken);
|
|
72
|
+
return astUtils.isSemicolonToken(lastToken) && lastToken.loc.start.line > secondToLastToken.loc.end.line ? secondToLastToken : lastToken;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Check if node is followed by a blank newline.
|
|
76
|
+
* @param {ASTNode} node Node to check.
|
|
77
|
+
* @returns {boolean} Whether or not the passed in node is followed by a blank newline.
|
|
78
|
+
*/
|
|
79
|
+
function hasNewlineAfter(node) {
|
|
80
|
+
let lastToken = getLastTokenOnLine(node);
|
|
81
|
+
return sourceCode.getTokenAfter(lastToken, { includeComments: !0 }).loc.start.line - lastToken.loc.end.line >= 2;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Report errors for newlines around directives.
|
|
85
|
+
* @param {ASTNode} node Node to check.
|
|
86
|
+
* @param {string} location Whether the error was found before or after the directive.
|
|
87
|
+
* @param {boolean} expected Whether or not a newline was expected or unexpected.
|
|
88
|
+
* @returns {void}
|
|
89
|
+
*/
|
|
90
|
+
function reportError(node, location, expected) {
|
|
91
|
+
context.report({
|
|
92
|
+
node,
|
|
93
|
+
messageId: expected ? "expected" : "unexpected",
|
|
94
|
+
data: {
|
|
95
|
+
value: node.expression.value,
|
|
96
|
+
location
|
|
97
|
+
},
|
|
98
|
+
fix(fixer) {
|
|
99
|
+
let lastToken = getLastTokenOnLine(node);
|
|
100
|
+
return expected ? location === "before" ? fixer.insertTextBefore(node, "\n") : fixer.insertTextAfter(lastToken, "\n") : fixer.removeRange(location === "before" ? [node.range[0] - 1, node.range[0]] : [lastToken.range[1], lastToken.range[1] + 1]);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Check lines around directives in node
|
|
106
|
+
* @param {ASTNode} node node to check
|
|
107
|
+
* @returns {void}
|
|
108
|
+
*/
|
|
109
|
+
function checkDirectives(node) {
|
|
110
|
+
let directives = astUtils.getDirectivePrologue(node);
|
|
111
|
+
if (!directives.length) return;
|
|
112
|
+
let firstDirective = directives[0], leadingComments = sourceCode.getCommentsBefore(firstDirective);
|
|
113
|
+
leadingComments.length ? (expectLineBefore === "always" && !hasNewlineBefore(firstDirective) && reportError(firstDirective, "before", !0), expectLineBefore === "never" && hasNewlineBefore(firstDirective) && reportError(firstDirective, "before", !1)) : node.type === "Program" && expectLineBefore === "never" && !leadingComments.length && hasNewlineBefore(firstDirective) && reportError(firstDirective, "before", !1);
|
|
114
|
+
let lastDirective = directives.at(-1);
|
|
115
|
+
lastDirective === (node.type === "Program" ? node.body : node.body.body).at(-1) && !lastDirective.trailingComments || (expectLineAfter === "always" && !hasNewlineAfter(lastDirective) && reportError(lastDirective, "after", !0), expectLineAfter === "never" && hasNewlineAfter(lastDirective) && reportError(lastDirective, "after", !1));
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
Program: checkDirectives,
|
|
119
|
+
FunctionDeclaration: checkDirectives,
|
|
120
|
+
FunctionExpression: checkDirectives,
|
|
121
|
+
ArrowFunctionExpression: checkDirectives
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}));
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region src-js/generated/plugin-eslint/rules/lines-around-directive.cjs
|
|
128
|
+
module.exports = require_lines_around_directive().create;
|
|
129
|
+
//#endregion
|
|
@@ -0,0 +1,212 @@
|
|
|
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/lines-between-class-members.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Rule to check empty newline between class members
|
|
5
|
+
* @author 薛定谔的猫<hh_2013@foxmail.com>
|
|
6
|
+
* @deprecated in ESLint v8.53.0
|
|
7
|
+
*/
|
|
8
|
+
var require_lines_between_class_members = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
9
|
+
let astUtils = require_ast_utils$1.t(), ClassMemberTypes = {
|
|
10
|
+
"*": { test: () => !0 },
|
|
11
|
+
field: { test: (node) => node.type === "PropertyDefinition" },
|
|
12
|
+
method: { test: (node) => node.type === "MethodDefinition" }
|
|
13
|
+
};
|
|
14
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
15
|
+
module.exports = {
|
|
16
|
+
meta: {
|
|
17
|
+
deprecated: {
|
|
18
|
+
message: "Formatting rules are being moved out of ESLint core.",
|
|
19
|
+
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
|
|
20
|
+
deprecatedSince: "8.53.0",
|
|
21
|
+
availableUntil: "11.0.0",
|
|
22
|
+
replacedBy: [{
|
|
23
|
+
message: "ESLint Stylistic now maintains deprecated stylistic core rules.",
|
|
24
|
+
url: "https://eslint.style/guide/migration",
|
|
25
|
+
plugin: {
|
|
26
|
+
name: "@stylistic/eslint-plugin",
|
|
27
|
+
url: "https://eslint.style"
|
|
28
|
+
},
|
|
29
|
+
rule: {
|
|
30
|
+
name: "lines-between-class-members",
|
|
31
|
+
url: "https://eslint.style/rules/lines-between-class-members"
|
|
32
|
+
}
|
|
33
|
+
}]
|
|
34
|
+
},
|
|
35
|
+
type: "layout",
|
|
36
|
+
docs: {
|
|
37
|
+
description: "Require or disallow an empty line between class members",
|
|
38
|
+
recommended: !1,
|
|
39
|
+
url: "https://eslint.org/docs/latest/rules/lines-between-class-members"
|
|
40
|
+
},
|
|
41
|
+
fixable: "whitespace",
|
|
42
|
+
schema: [{ anyOf: [{
|
|
43
|
+
type: "object",
|
|
44
|
+
properties: { enforce: {
|
|
45
|
+
type: "array",
|
|
46
|
+
items: {
|
|
47
|
+
type: "object",
|
|
48
|
+
properties: {
|
|
49
|
+
blankLine: { enum: ["always", "never"] },
|
|
50
|
+
prev: { enum: [
|
|
51
|
+
"method",
|
|
52
|
+
"field",
|
|
53
|
+
"*"
|
|
54
|
+
] },
|
|
55
|
+
next: { enum: [
|
|
56
|
+
"method",
|
|
57
|
+
"field",
|
|
58
|
+
"*"
|
|
59
|
+
] }
|
|
60
|
+
},
|
|
61
|
+
additionalProperties: !1,
|
|
62
|
+
required: [
|
|
63
|
+
"blankLine",
|
|
64
|
+
"prev",
|
|
65
|
+
"next"
|
|
66
|
+
]
|
|
67
|
+
},
|
|
68
|
+
minItems: 1
|
|
69
|
+
} },
|
|
70
|
+
additionalProperties: !1,
|
|
71
|
+
required: ["enforce"]
|
|
72
|
+
}, { enum: ["always", "never"] }] }, {
|
|
73
|
+
type: "object",
|
|
74
|
+
properties: { exceptAfterSingleLine: {
|
|
75
|
+
type: "boolean",
|
|
76
|
+
default: !1
|
|
77
|
+
} },
|
|
78
|
+
additionalProperties: !1
|
|
79
|
+
}],
|
|
80
|
+
messages: {
|
|
81
|
+
never: "Unexpected blank line between class members.",
|
|
82
|
+
always: "Expected blank line between class members."
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
create(context) {
|
|
86
|
+
let options = [];
|
|
87
|
+
options[0] = context.options[0] || "always", options[1] = context.options[1] || { exceptAfterSingleLine: !1 };
|
|
88
|
+
let configureList = typeof options[0] == "object" ? options[0].enforce : [{
|
|
89
|
+
blankLine: options[0],
|
|
90
|
+
prev: "*",
|
|
91
|
+
next: "*"
|
|
92
|
+
}], sourceCode = context.sourceCode;
|
|
93
|
+
/**
|
|
94
|
+
* Gets a pair of tokens that should be used to check lines between two class member nodes.
|
|
95
|
+
*
|
|
96
|
+
* In most cases, this returns the very last token of the current node and
|
|
97
|
+
* the very first token of the next node.
|
|
98
|
+
* For example:
|
|
99
|
+
*
|
|
100
|
+
* class C {
|
|
101
|
+
* x = 1; // curLast: `;` nextFirst: `in`
|
|
102
|
+
* in = 2
|
|
103
|
+
* }
|
|
104
|
+
*
|
|
105
|
+
* There is only one exception. If the given node ends with a semicolon, and it looks like
|
|
106
|
+
* a semicolon-less style's semicolon - one that is not on the same line as the preceding
|
|
107
|
+
* token, but is on the line where the next class member starts - this returns the preceding
|
|
108
|
+
* token and the semicolon as boundary tokens.
|
|
109
|
+
* For example:
|
|
110
|
+
*
|
|
111
|
+
* class C {
|
|
112
|
+
* x = 1 // curLast: `1` nextFirst: `;`
|
|
113
|
+
* ;in = 2
|
|
114
|
+
* }
|
|
115
|
+
* When determining the desired layout of the code, we should treat this semicolon as
|
|
116
|
+
* a part of the next class member node instead of the one it technically belongs to.
|
|
117
|
+
* @param {ASTNode} curNode Current class member node.
|
|
118
|
+
* @param {ASTNode} nextNode Next class member node.
|
|
119
|
+
* @returns {Token} The actual last token of `node`.
|
|
120
|
+
* @private
|
|
121
|
+
*/
|
|
122
|
+
function getBoundaryTokens(curNode, nextNode) {
|
|
123
|
+
let lastToken = sourceCode.getLastToken(curNode), prevToken = sourceCode.getTokenBefore(lastToken), nextToken = sourceCode.getFirstToken(nextNode);
|
|
124
|
+
return astUtils.isSemicolonToken(lastToken) && !astUtils.isTokenOnSameLine(prevToken, lastToken) && astUtils.isTokenOnSameLine(lastToken, nextToken) ? {
|
|
125
|
+
curLast: prevToken,
|
|
126
|
+
nextFirst: lastToken
|
|
127
|
+
} : {
|
|
128
|
+
curLast: lastToken,
|
|
129
|
+
nextFirst: nextToken
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Return the last token among the consecutive tokens that have no exceed max line difference in between, before the first token in the next member.
|
|
134
|
+
* @param {Token} prevLastToken The last token in the previous member node.
|
|
135
|
+
* @param {Token} nextFirstToken The first token in the next member node.
|
|
136
|
+
* @param {number} maxLine The maximum number of allowed line difference between consecutive tokens.
|
|
137
|
+
* @returns {Token} The last token among the consecutive tokens.
|
|
138
|
+
*/
|
|
139
|
+
function findLastConsecutiveTokenAfter(prevLastToken, nextFirstToken, maxLine) {
|
|
140
|
+
let after = sourceCode.getTokenAfter(prevLastToken, { includeComments: !0 });
|
|
141
|
+
return after !== nextFirstToken && after.loc.start.line - prevLastToken.loc.end.line <= maxLine ? findLastConsecutiveTokenAfter(after, nextFirstToken, maxLine) : prevLastToken;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Return the first token among the consecutive tokens that have no exceed max line difference in between, after the last token in the previous member.
|
|
145
|
+
* @param {Token} nextFirstToken The first token in the next member node.
|
|
146
|
+
* @param {Token} prevLastToken The last token in the previous member node.
|
|
147
|
+
* @param {number} maxLine The maximum number of allowed line difference between consecutive tokens.
|
|
148
|
+
* @returns {Token} The first token among the consecutive tokens.
|
|
149
|
+
*/
|
|
150
|
+
function findFirstConsecutiveTokenBefore(nextFirstToken, prevLastToken, maxLine) {
|
|
151
|
+
let before = sourceCode.getTokenBefore(nextFirstToken, { includeComments: !0 });
|
|
152
|
+
return before !== prevLastToken && nextFirstToken.loc.start.line - before.loc.end.line <= maxLine ? findFirstConsecutiveTokenBefore(before, prevLastToken, maxLine) : nextFirstToken;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Checks if there is a token or comment between two tokens.
|
|
156
|
+
* @param {Token} before The token before.
|
|
157
|
+
* @param {Token} after The token after.
|
|
158
|
+
* @returns {boolean} True if there is a token or comment between two tokens.
|
|
159
|
+
*/
|
|
160
|
+
function hasTokenOrCommentBetween(before, after) {
|
|
161
|
+
return sourceCode.getTokensBetween(before, after, { includeComments: !0 }).length !== 0;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Checks whether the given node matches the given type.
|
|
165
|
+
* @param {ASTNode} node The class member node to check.
|
|
166
|
+
* @param {string} type The class member type to check.
|
|
167
|
+
* @returns {boolean} `true` if the class member node matched the type.
|
|
168
|
+
* @private
|
|
169
|
+
*/
|
|
170
|
+
function match(node, type) {
|
|
171
|
+
return ClassMemberTypes[type].test(node);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Finds the last matched configuration from the configureList.
|
|
175
|
+
* @param {ASTNode} prevNode The previous node to match.
|
|
176
|
+
* @param {ASTNode} nextNode The current node to match.
|
|
177
|
+
* @returns {string|null} Padding type or `null` if no matches were found.
|
|
178
|
+
* @private
|
|
179
|
+
*/
|
|
180
|
+
function getPaddingType(prevNode, nextNode) {
|
|
181
|
+
for (let i = configureList.length - 1; i >= 0; --i) {
|
|
182
|
+
let configure = configureList[i];
|
|
183
|
+
if (match(prevNode, configure.prev) && match(nextNode, configure.next)) return configure.blankLine;
|
|
184
|
+
}
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
return { ClassBody(node) {
|
|
188
|
+
let body = node.body;
|
|
189
|
+
for (let i = 0; i < body.length - 1; i++) {
|
|
190
|
+
let curFirst = sourceCode.getFirstToken(body[i]), { curLast, nextFirst } = getBoundaryTokens(body[i], body[i + 1]), skip = !!astUtils.isTokenOnSameLine(curFirst, curLast) && options[1].exceptAfterSingleLine, beforePadding = findLastConsecutiveTokenAfter(curLast, nextFirst, 1), afterPadding = findFirstConsecutiveTokenBefore(nextFirst, curLast, 1), isPadded = afterPadding.loc.start.line - beforePadding.loc.end.line > 1, hasTokenInPadding = hasTokenOrCommentBetween(beforePadding, afterPadding), curLineLastToken = findLastConsecutiveTokenAfter(curLast, nextFirst, 0), paddingType = getPaddingType(body[i], body[i + 1]);
|
|
191
|
+
paddingType === "never" && isPadded ? context.report({
|
|
192
|
+
node: body[i + 1],
|
|
193
|
+
messageId: "never",
|
|
194
|
+
fix(fixer) {
|
|
195
|
+
return hasTokenInPadding ? null : fixer.replaceTextRange([beforePadding.range[1], afterPadding.range[0]], "\n");
|
|
196
|
+
}
|
|
197
|
+
}) : paddingType === "always" && !skip && !isPadded && context.report({
|
|
198
|
+
node: body[i + 1],
|
|
199
|
+
messageId: "always",
|
|
200
|
+
fix(fixer) {
|
|
201
|
+
return hasTokenInPadding ? null : fixer.insertTextAfter(curLineLastToken, "\n");
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
} };
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
}));
|
|
209
|
+
//#endregion
|
|
210
|
+
//#region src-js/generated/plugin-eslint/rules/lines-between-class-members.cjs
|
|
211
|
+
module.exports = require_lines_between_class_members().create;
|
|
212
|
+
//#endregion
|