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,520 @@
|
|
|
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/indent-legacy.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview This option sets a specific tab width for your code
|
|
5
|
+
*
|
|
6
|
+
* This rule has been ported and modified from nodeca.
|
|
7
|
+
* @author Vitaly Puzrin
|
|
8
|
+
* @author Gyandeep Singh
|
|
9
|
+
* @deprecated in ESLint v4.0.0
|
|
10
|
+
*/
|
|
11
|
+
var require_indent_legacy = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
12
|
+
let astUtils = require_ast_utils$1.t();
|
|
13
|
+
/* c8 ignore next */
|
|
14
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
15
|
+
module.exports = {
|
|
16
|
+
meta: {
|
|
17
|
+
type: "layout",
|
|
18
|
+
docs: {
|
|
19
|
+
description: "Enforce consistent indentation",
|
|
20
|
+
recommended: !1,
|
|
21
|
+
url: "https://eslint.org/docs/latest/rules/indent-legacy"
|
|
22
|
+
},
|
|
23
|
+
deprecated: {
|
|
24
|
+
message: "Formatting rules are being moved out of ESLint core.",
|
|
25
|
+
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
|
|
26
|
+
deprecatedSince: "4.0.0",
|
|
27
|
+
availableUntil: "11.0.0",
|
|
28
|
+
replacedBy: [{
|
|
29
|
+
message: "ESLint Stylistic now maintains deprecated stylistic core rules.",
|
|
30
|
+
url: "https://eslint.style/guide/migration",
|
|
31
|
+
plugin: {
|
|
32
|
+
name: "@stylistic/eslint-plugin",
|
|
33
|
+
url: "https://eslint.style"
|
|
34
|
+
},
|
|
35
|
+
rule: {
|
|
36
|
+
name: "indent",
|
|
37
|
+
url: "https://eslint.style/rules/indent"
|
|
38
|
+
}
|
|
39
|
+
}]
|
|
40
|
+
},
|
|
41
|
+
fixable: "whitespace",
|
|
42
|
+
schema: [{ oneOf: [{ enum: ["tab"] }, {
|
|
43
|
+
type: "integer",
|
|
44
|
+
minimum: 0
|
|
45
|
+
}] }, {
|
|
46
|
+
type: "object",
|
|
47
|
+
properties: {
|
|
48
|
+
SwitchCase: {
|
|
49
|
+
type: "integer",
|
|
50
|
+
minimum: 0
|
|
51
|
+
},
|
|
52
|
+
VariableDeclarator: { oneOf: [{
|
|
53
|
+
type: "integer",
|
|
54
|
+
minimum: 0
|
|
55
|
+
}, {
|
|
56
|
+
type: "object",
|
|
57
|
+
properties: {
|
|
58
|
+
var: {
|
|
59
|
+
type: "integer",
|
|
60
|
+
minimum: 0
|
|
61
|
+
},
|
|
62
|
+
let: {
|
|
63
|
+
type: "integer",
|
|
64
|
+
minimum: 0
|
|
65
|
+
},
|
|
66
|
+
const: {
|
|
67
|
+
type: "integer",
|
|
68
|
+
minimum: 0
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}] },
|
|
72
|
+
outerIIFEBody: {
|
|
73
|
+
type: "integer",
|
|
74
|
+
minimum: 0
|
|
75
|
+
},
|
|
76
|
+
MemberExpression: {
|
|
77
|
+
type: "integer",
|
|
78
|
+
minimum: 0
|
|
79
|
+
},
|
|
80
|
+
FunctionDeclaration: {
|
|
81
|
+
type: "object",
|
|
82
|
+
properties: {
|
|
83
|
+
parameters: { oneOf: [{
|
|
84
|
+
type: "integer",
|
|
85
|
+
minimum: 0
|
|
86
|
+
}, { enum: ["first"] }] },
|
|
87
|
+
body: {
|
|
88
|
+
type: "integer",
|
|
89
|
+
minimum: 0
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
FunctionExpression: {
|
|
94
|
+
type: "object",
|
|
95
|
+
properties: {
|
|
96
|
+
parameters: { oneOf: [{
|
|
97
|
+
type: "integer",
|
|
98
|
+
minimum: 0
|
|
99
|
+
}, { enum: ["first"] }] },
|
|
100
|
+
body: {
|
|
101
|
+
type: "integer",
|
|
102
|
+
minimum: 0
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
CallExpression: {
|
|
107
|
+
type: "object",
|
|
108
|
+
properties: { parameters: { oneOf: [{
|
|
109
|
+
type: "integer",
|
|
110
|
+
minimum: 0
|
|
111
|
+
}, { enum: ["first"] }] } }
|
|
112
|
+
},
|
|
113
|
+
ArrayExpression: { oneOf: [{
|
|
114
|
+
type: "integer",
|
|
115
|
+
minimum: 0
|
|
116
|
+
}, { enum: ["first"] }] },
|
|
117
|
+
ObjectExpression: { oneOf: [{
|
|
118
|
+
type: "integer",
|
|
119
|
+
minimum: 0
|
|
120
|
+
}, { enum: ["first"] }] }
|
|
121
|
+
},
|
|
122
|
+
additionalProperties: !1
|
|
123
|
+
}],
|
|
124
|
+
messages: { expected: "Expected indentation of {{expected}} but found {{actual}}." }
|
|
125
|
+
},
|
|
126
|
+
create(context) {
|
|
127
|
+
let indentType = "space", indentSize = 4, options = {
|
|
128
|
+
SwitchCase: 0,
|
|
129
|
+
VariableDeclarator: {
|
|
130
|
+
var: 1,
|
|
131
|
+
let: 1,
|
|
132
|
+
const: 1
|
|
133
|
+
},
|
|
134
|
+
outerIIFEBody: null,
|
|
135
|
+
FunctionDeclaration: {
|
|
136
|
+
parameters: null,
|
|
137
|
+
body: 1
|
|
138
|
+
},
|
|
139
|
+
FunctionExpression: {
|
|
140
|
+
parameters: null,
|
|
141
|
+
body: 1
|
|
142
|
+
},
|
|
143
|
+
CallExpression: { arguments: null },
|
|
144
|
+
ArrayExpression: 1,
|
|
145
|
+
ObjectExpression: 1
|
|
146
|
+
}, sourceCode = context.sourceCode;
|
|
147
|
+
if (context.options.length && (context.options[0] === "tab" ? (indentSize = 1, indentType = "tab") : typeof context.options[0] == "number" && (indentSize = context.options[0], indentType = "space"), context.options[1])) {
|
|
148
|
+
let opts = context.options[1];
|
|
149
|
+
options.SwitchCase = opts.SwitchCase || 0;
|
|
150
|
+
let variableDeclaratorRules = opts.VariableDeclarator;
|
|
151
|
+
typeof variableDeclaratorRules == "number" ? options.VariableDeclarator = {
|
|
152
|
+
var: variableDeclaratorRules,
|
|
153
|
+
let: variableDeclaratorRules,
|
|
154
|
+
const: variableDeclaratorRules
|
|
155
|
+
} : typeof variableDeclaratorRules == "object" && Object.assign(options.VariableDeclarator, variableDeclaratorRules), typeof opts.outerIIFEBody == "number" && (options.outerIIFEBody = opts.outerIIFEBody), typeof opts.MemberExpression == "number" && (options.MemberExpression = opts.MemberExpression), typeof opts.FunctionDeclaration == "object" && Object.assign(options.FunctionDeclaration, opts.FunctionDeclaration), typeof opts.FunctionExpression == "object" && Object.assign(options.FunctionExpression, opts.FunctionExpression), typeof opts.CallExpression == "object" && Object.assign(options.CallExpression, opts.CallExpression), (typeof opts.ArrayExpression == "number" || typeof opts.ArrayExpression == "string") && (options.ArrayExpression = opts.ArrayExpression), (typeof opts.ObjectExpression == "number" || typeof opts.ObjectExpression == "string") && (options.ObjectExpression = opts.ObjectExpression);
|
|
156
|
+
}
|
|
157
|
+
let caseIndentStore = {};
|
|
158
|
+
/**
|
|
159
|
+
* Creates an error message for a line, given the expected/actual indentation.
|
|
160
|
+
* @param {number} expectedAmount The expected amount of indentation characters for this line
|
|
161
|
+
* @param {number} actualSpaces The actual number of indentation spaces that were found on this line
|
|
162
|
+
* @param {number} actualTabs The actual number of indentation tabs that were found on this line
|
|
163
|
+
* @returns {string} An error message for this line
|
|
164
|
+
*/
|
|
165
|
+
function createErrorMessageData(expectedAmount, actualSpaces, actualTabs) {
|
|
166
|
+
let expectedStatement = `${expectedAmount} ${indentType}${expectedAmount === 1 ? "" : "s"}`, foundSpacesWord = `space${actualSpaces === 1 ? "" : "s"}`, foundTabsWord = `tab${actualTabs === 1 ? "" : "s"}`, foundStatement;
|
|
167
|
+
return foundStatement = actualSpaces > 0 && actualTabs > 0 ? `${actualSpaces} ${foundSpacesWord} and ${actualTabs} ${foundTabsWord}` : actualSpaces > 0 ? indentType === "space" ? actualSpaces : `${actualSpaces} ${foundSpacesWord}` : actualTabs > 0 ? indentType === "tab" ? actualTabs : `${actualTabs} ${foundTabsWord}` : "0", {
|
|
168
|
+
expected: expectedStatement,
|
|
169
|
+
actual: foundStatement
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Reports a given indent violation
|
|
174
|
+
* @param {ASTNode} node Node violating the indent rule
|
|
175
|
+
* @param {number} needed Expected indentation character count
|
|
176
|
+
* @param {number} gottenSpaces Indentation space count in the actual node/code
|
|
177
|
+
* @param {number} gottenTabs Indentation tab count in the actual node/code
|
|
178
|
+
* @param {Object} [loc] Error line and column location
|
|
179
|
+
* @param {boolean} isLastNodeCheck Is the error for last node check
|
|
180
|
+
* @returns {void}
|
|
181
|
+
*/
|
|
182
|
+
function report(node, needed, gottenSpaces, gottenTabs, loc, isLastNodeCheck) {
|
|
183
|
+
if (gottenSpaces && gottenTabs) return;
|
|
184
|
+
let desiredIndent = (indentType === "space" ? " " : " ").repeat(needed), textRange = isLastNodeCheck ? [node.range[1] - node.loc.end.column, node.range[1] - node.loc.end.column + gottenSpaces + gottenTabs] : [node.range[0] - node.loc.start.column, node.range[0] - node.loc.start.column + gottenSpaces + gottenTabs];
|
|
185
|
+
context.report({
|
|
186
|
+
node,
|
|
187
|
+
loc,
|
|
188
|
+
messageId: "expected",
|
|
189
|
+
data: createErrorMessageData(needed, gottenSpaces, gottenTabs),
|
|
190
|
+
fix: (fixer) => fixer.replaceTextRange(textRange, desiredIndent)
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Get the actual indent of node
|
|
195
|
+
* @param {ASTNode|Token} node Node to examine
|
|
196
|
+
* @param {boolean} [byLastLine=false] get indent of node's last line
|
|
197
|
+
* @returns {Object} The node's indent. Contains keys `space` and `tab`, representing the indent of each character. Also
|
|
198
|
+
* contains keys `goodChar` and `badChar`, where `goodChar` is the amount of the user's desired indentation character, and
|
|
199
|
+
* `badChar` is the amount of the other indentation character.
|
|
200
|
+
*/
|
|
201
|
+
function getNodeIndent(node, byLastLine) {
|
|
202
|
+
let token = byLastLine ? sourceCode.getLastToken(node) : sourceCode.getFirstToken(node), srcCharsBeforeNode = sourceCode.getText(token, token.loc.start.column).split(""), indentChars = srcCharsBeforeNode.slice(0, srcCharsBeforeNode.findIndex((char) => char !== " " && char !== " ")), spaces = indentChars.filter((char) => char === " ").length, tabs = indentChars.filter((char) => char === " ").length;
|
|
203
|
+
return {
|
|
204
|
+
space: spaces,
|
|
205
|
+
tab: tabs,
|
|
206
|
+
goodChar: indentType === "space" ? spaces : tabs,
|
|
207
|
+
badChar: indentType === "space" ? tabs : spaces
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Checks node is the first in its own start line. By default it looks by start line.
|
|
212
|
+
* @param {ASTNode} node The node to check
|
|
213
|
+
* @param {boolean} [byEndLocation=false] Lookup based on start position or end
|
|
214
|
+
* @returns {boolean} true if its the first in the its start line
|
|
215
|
+
*/
|
|
216
|
+
function isNodeFirstInLine(node, byEndLocation) {
|
|
217
|
+
let firstToken = byEndLocation === !0 ? sourceCode.getLastToken(node, 1) : sourceCode.getTokenBefore(node);
|
|
218
|
+
return (byEndLocation === !0 ? node.loc.end.line : node.loc.start.line) !== (firstToken ? firstToken.loc.end.line : -1);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Check indent for node
|
|
222
|
+
* @param {ASTNode} node Node to check
|
|
223
|
+
* @param {number} neededIndent needed indent
|
|
224
|
+
* @returns {void}
|
|
225
|
+
*/
|
|
226
|
+
function checkNodeIndent(node, neededIndent) {
|
|
227
|
+
let actualIndent = getNodeIndent(node, !1);
|
|
228
|
+
node.type !== "ArrayExpression" && node.type !== "ObjectExpression" && (actualIndent.goodChar !== neededIndent || actualIndent.badChar !== 0) && isNodeFirstInLine(node) && report(node, neededIndent, actualIndent.space, actualIndent.tab), node.type === "IfStatement" && node.alternate && (checkNodeIndent(sourceCode.getTokenBefore(node.alternate), neededIndent), isNodeFirstInLine(node.alternate) || checkNodeIndent(node.alternate, neededIndent)), node.type === "TryStatement" && node.handler && checkNodeIndent(sourceCode.getFirstToken(node.handler), neededIndent), node.type === "TryStatement" && node.finalizer && checkNodeIndent(sourceCode.getTokenBefore(node.finalizer), neededIndent), node.type === "DoWhileStatement" && checkNodeIndent(sourceCode.getTokenAfter(node.body), neededIndent);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Check indent for nodes list
|
|
232
|
+
* @param {ASTNode[]} nodes list of node objects
|
|
233
|
+
* @param {number} indent needed indent
|
|
234
|
+
* @returns {void}
|
|
235
|
+
*/
|
|
236
|
+
function checkNodesIndent(nodes, indent) {
|
|
237
|
+
nodes.forEach((node) => checkNodeIndent(node, indent));
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Check last node line indent this detects, that block closed correctly
|
|
241
|
+
* @param {ASTNode} node Node to examine
|
|
242
|
+
* @param {number} lastLineIndent needed indent
|
|
243
|
+
* @returns {void}
|
|
244
|
+
*/
|
|
245
|
+
function checkLastNodeLineIndent(node, lastLineIndent) {
|
|
246
|
+
let lastToken = sourceCode.getLastToken(node), endIndent = getNodeIndent(lastToken, !0);
|
|
247
|
+
(endIndent.goodChar !== lastLineIndent || endIndent.badChar !== 0) && isNodeFirstInLine(node, !0) && report(node, lastLineIndent, endIndent.space, endIndent.tab, {
|
|
248
|
+
line: lastToken.loc.start.line,
|
|
249
|
+
column: lastToken.loc.start.column
|
|
250
|
+
}, !0);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Check last node line indent this detects, that block closed correctly
|
|
254
|
+
* This function for more complicated return statement case, where closing parenthesis may be followed by ';'
|
|
255
|
+
* @param {ASTNode} node Node to examine
|
|
256
|
+
* @param {number} firstLineIndent first line needed indent
|
|
257
|
+
* @returns {void}
|
|
258
|
+
*/
|
|
259
|
+
function checkLastReturnStatementLineIndent(node, firstLineIndent) {
|
|
260
|
+
let lastToken = sourceCode.getLastToken(node, astUtils.isClosingParenToken);
|
|
261
|
+
if (sourceCode.getText(lastToken, lastToken.loc.start.column).slice(0, -1).trim()) return;
|
|
262
|
+
let endIndent = getNodeIndent(lastToken, !0);
|
|
263
|
+
endIndent.goodChar !== firstLineIndent && report(node, firstLineIndent, endIndent.space, endIndent.tab, {
|
|
264
|
+
line: lastToken.loc.start.line,
|
|
265
|
+
column: lastToken.loc.start.column
|
|
266
|
+
}, !0);
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Check first node line indent is correct
|
|
270
|
+
* @param {ASTNode} node Node to examine
|
|
271
|
+
* @param {number} firstLineIndent needed indent
|
|
272
|
+
* @returns {void}
|
|
273
|
+
*/
|
|
274
|
+
function checkFirstNodeLineIndent(node, firstLineIndent) {
|
|
275
|
+
let startIndent = getNodeIndent(node, !1);
|
|
276
|
+
(startIndent.goodChar !== firstLineIndent || startIndent.badChar !== 0) && isNodeFirstInLine(node) && report(node, firstLineIndent, startIndent.space, startIndent.tab, {
|
|
277
|
+
line: node.loc.start.line,
|
|
278
|
+
column: node.loc.start.column
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Returns a parent node of given node based on a specified type
|
|
283
|
+
* if not present then return null
|
|
284
|
+
* @param {ASTNode} node node to examine
|
|
285
|
+
* @param {string} type type that is being looked for
|
|
286
|
+
* @param {string} stopAtList end points for the evaluating code
|
|
287
|
+
* @returns {ASTNode|void} if found then node otherwise null
|
|
288
|
+
*/
|
|
289
|
+
function getParentNodeByType(node, type, stopAtList) {
|
|
290
|
+
let parent = node.parent, stopAtSet = new Set(stopAtList || ["Program"]);
|
|
291
|
+
for (; parent.type !== type && !stopAtSet.has(parent.type) && parent.type !== "Program";) parent = parent.parent;
|
|
292
|
+
return parent.type === type ? parent : null;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Returns the VariableDeclarator based on the current node
|
|
296
|
+
* if not present then return null
|
|
297
|
+
* @param {ASTNode} node node to examine
|
|
298
|
+
* @returns {ASTNode|void} if found then node otherwise null
|
|
299
|
+
*/
|
|
300
|
+
function getVariableDeclaratorNode(node) {
|
|
301
|
+
return getParentNodeByType(node, "VariableDeclarator");
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Check to see if the node is part of the multi-line variable declaration.
|
|
305
|
+
* Also if its on the same line as the varNode
|
|
306
|
+
* @param {ASTNode} node node to check
|
|
307
|
+
* @param {ASTNode} varNode variable declaration node to check against
|
|
308
|
+
* @returns {boolean} True if all the above condition satisfy
|
|
309
|
+
*/
|
|
310
|
+
function isNodeInVarOnTop(node, varNode) {
|
|
311
|
+
return varNode && varNode.parent.loc.start.line === node.loc.start.line && varNode.parent.declarations.length > 1;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Check to see if the argument before the callee node is multi-line and
|
|
315
|
+
* there should only be 1 argument before the callee node
|
|
316
|
+
* @param {ASTNode} node node to check
|
|
317
|
+
* @returns {boolean} True if arguments are multi-line
|
|
318
|
+
*/
|
|
319
|
+
function isArgBeforeCalleeNodeMultiline(node) {
|
|
320
|
+
let parent = node.parent;
|
|
321
|
+
return parent.arguments.length >= 2 && parent.arguments[1] === node ? parent.arguments[0].loc.end.line > parent.arguments[0].loc.start.line : !1;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Check to see if the node is a file level IIFE
|
|
325
|
+
* @param {ASTNode} node The function node to check.
|
|
326
|
+
* @returns {boolean} True if the node is the outer IIFE
|
|
327
|
+
*/
|
|
328
|
+
function isOuterIIFE(node) {
|
|
329
|
+
let parent = node.parent, stmt = parent.parent;
|
|
330
|
+
if (parent.type !== "CallExpression" || parent.callee !== node) return !1;
|
|
331
|
+
for (; stmt.type === "UnaryExpression" && (stmt.operator === "!" || stmt.operator === "~" || stmt.operator === "+" || stmt.operator === "-") || stmt.type === "AssignmentExpression" || stmt.type === "LogicalExpression" || stmt.type === "SequenceExpression" || stmt.type === "VariableDeclarator";) stmt = stmt.parent;
|
|
332
|
+
return (stmt.type === "ExpressionStatement" || stmt.type === "VariableDeclaration") && stmt.parent && stmt.parent.type === "Program";
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Check indent for function block content
|
|
336
|
+
* @param {ASTNode} node A BlockStatement node that is inside of a function.
|
|
337
|
+
* @returns {void}
|
|
338
|
+
*/
|
|
339
|
+
function checkIndentInFunctionBlock(node) {
|
|
340
|
+
let calleeNode = node.parent, indent;
|
|
341
|
+
if (indent = calleeNode.parent && (calleeNode.parent.type === "Property" || calleeNode.parent.type === "ArrayExpression") ? getNodeIndent(calleeNode, !1).goodChar : getNodeIndent(calleeNode).goodChar, calleeNode.parent.type === "CallExpression") {
|
|
342
|
+
let calleeParent = calleeNode.parent;
|
|
343
|
+
calleeNode.type !== "FunctionExpression" && calleeNode.type !== "ArrowFunctionExpression" ? calleeParent && calleeParent.loc.start.line < node.loc.start.line && (indent = getNodeIndent(calleeParent).goodChar) : isArgBeforeCalleeNodeMultiline(calleeNode) && calleeParent.callee.loc.start.line === calleeParent.callee.loc.end.line && !isNodeFirstInLine(calleeNode) && (indent = getNodeIndent(calleeParent).goodChar);
|
|
344
|
+
}
|
|
345
|
+
let functionOffset = indentSize;
|
|
346
|
+
options.outerIIFEBody !== null && isOuterIIFE(calleeNode) ? functionOffset = options.outerIIFEBody * indentSize : calleeNode.type === "FunctionExpression" ? functionOffset = options.FunctionExpression.body * indentSize : calleeNode.type === "FunctionDeclaration" && (functionOffset = options.FunctionDeclaration.body * indentSize), indent += functionOffset;
|
|
347
|
+
let parentVarNode = getVariableDeclaratorNode(node);
|
|
348
|
+
parentVarNode && isNodeInVarOnTop(node, parentVarNode) && (indent += indentSize * options.VariableDeclarator[parentVarNode.parent.kind]), node.body.length > 0 && checkNodesIndent(node.body, indent), checkLastNodeLineIndent(node, indent - functionOffset);
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Checks if the given node starts and ends on the same line
|
|
352
|
+
* @param {ASTNode} node The node to check
|
|
353
|
+
* @returns {boolean} Whether or not the block starts and ends on the same line.
|
|
354
|
+
*/
|
|
355
|
+
function isSingleLineNode(node) {
|
|
356
|
+
let lastToken = sourceCode.getLastToken(node);
|
|
357
|
+
return node.loc.start.line === lastToken.loc.end.line;
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Check indent for array block content or object block content
|
|
361
|
+
* @param {ASTNode} node node to examine
|
|
362
|
+
* @returns {void}
|
|
363
|
+
*/
|
|
364
|
+
function checkIndentInArrayOrObjectBlock(node) {
|
|
365
|
+
if (isSingleLineNode(node)) return;
|
|
366
|
+
let elements = node.type === "ArrayExpression" ? node.elements : node.properties;
|
|
367
|
+
elements = elements.filter((elem) => elem !== null);
|
|
368
|
+
let nodeIndent, elementsIndent, parentVarNode = getVariableDeclaratorNode(node);
|
|
369
|
+
if (isNodeFirstInLine(node)) {
|
|
370
|
+
let parent = node.parent;
|
|
371
|
+
if (nodeIndent = getNodeIndent(parent).goodChar, (!parentVarNode || parentVarNode.loc.start.line !== node.loc.start.line) && (parent.type !== "VariableDeclarator" || parentVarNode === parentVarNode.parent.declarations[0])) if (parent.type === "VariableDeclarator" && parentVarNode.loc.start.line === parent.loc.start.line) nodeIndent += indentSize * options.VariableDeclarator[parentVarNode.parent.kind];
|
|
372
|
+
else if (parent.type === "ObjectExpression" || parent.type === "ArrayExpression") {
|
|
373
|
+
let parentElements = node.parent.type === "ObjectExpression" ? node.parent.properties : node.parent.elements;
|
|
374
|
+
parentElements[0] && parentElements[0].loc.start.line === parent.loc.start.line && parentElements[0].loc.end.line !== parent.loc.start.line || (typeof options[parent.type] == "number" ? nodeIndent += options[parent.type] * indentSize : nodeIndent = parentElements[0].loc.start.column);
|
|
375
|
+
} else parent.type === "CallExpression" || parent.type === "NewExpression" ? typeof options.CallExpression.arguments == "number" ? nodeIndent += options.CallExpression.arguments * indentSize : options.CallExpression.arguments === "first" ? parent.arguments.includes(node) && (nodeIndent = parent.arguments[0].loc.start.column) : nodeIndent += indentSize : (parent.type === "LogicalExpression" || parent.type === "ArrowFunctionExpression") && (nodeIndent += indentSize);
|
|
376
|
+
checkFirstNodeLineIndent(node, nodeIndent);
|
|
377
|
+
} else nodeIndent = getNodeIndent(node).goodChar;
|
|
378
|
+
elementsIndent = options[node.type] === "first" ? elements.length ? elements[0].loc.start.column : 0 : nodeIndent + indentSize * options[node.type], isNodeInVarOnTop(node, parentVarNode) && (elementsIndent += indentSize * options.VariableDeclarator[parentVarNode.parent.kind]), checkNodesIndent(elements, elementsIndent), !(elements.length > 0 && elements.at(-1).loc.end.line === node.loc.end.line) && checkLastNodeLineIndent(node, nodeIndent + (isNodeInVarOnTop(node, parentVarNode) ? options.VariableDeclarator[parentVarNode.parent.kind] * indentSize : 0));
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Check if the node or node body is a BlockStatement or not
|
|
382
|
+
* @param {ASTNode} node node to test
|
|
383
|
+
* @returns {boolean} True if it or its body is a block statement
|
|
384
|
+
*/
|
|
385
|
+
function isNodeBodyBlock(node) {
|
|
386
|
+
return node.type === "BlockStatement" || node.type === "ClassBody" || node.body && node.body.type === "BlockStatement" || node.consequent && node.consequent.type === "BlockStatement";
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Check indentation for blocks
|
|
390
|
+
* @param {ASTNode} node node to check
|
|
391
|
+
* @returns {void}
|
|
392
|
+
*/
|
|
393
|
+
function blockIndentationCheck(node) {
|
|
394
|
+
if (isSingleLineNode(node)) return;
|
|
395
|
+
if (node.parent && (node.parent.type === "FunctionExpression" || node.parent.type === "FunctionDeclaration" || node.parent.type === "ArrowFunctionExpression")) {
|
|
396
|
+
checkIndentInFunctionBlock(node);
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
let indent, nodesToCheck;
|
|
400
|
+
indent = node.parent && [
|
|
401
|
+
"IfStatement",
|
|
402
|
+
"WhileStatement",
|
|
403
|
+
"ForStatement",
|
|
404
|
+
"ForInStatement",
|
|
405
|
+
"ForOfStatement",
|
|
406
|
+
"DoWhileStatement",
|
|
407
|
+
"ClassDeclaration",
|
|
408
|
+
"TryStatement"
|
|
409
|
+
].includes(node.parent.type) && isNodeBodyBlock(node) ? getNodeIndent(node.parent).goodChar : node.parent && node.parent.type === "CatchClause" ? getNodeIndent(node.parent.parent).goodChar : getNodeIndent(node).goodChar, nodesToCheck = node.type === "IfStatement" && node.consequent.type !== "BlockStatement" ? [node.consequent] : Array.isArray(node.body) ? node.body : [node.body], nodesToCheck.length > 0 && checkNodesIndent(nodesToCheck, indent + indentSize), node.type === "BlockStatement" && checkLastNodeLineIndent(node, indent);
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Filter out the elements which are on the same line of each other or the node.
|
|
413
|
+
* basically have only 1 elements from each line except the variable declaration line.
|
|
414
|
+
* @param {ASTNode} node Variable declaration node
|
|
415
|
+
* @returns {ASTNode[]} Filtered elements
|
|
416
|
+
*/
|
|
417
|
+
function filterOutSameLineVars(node) {
|
|
418
|
+
return node.declarations.reduce((finalCollection, elem) => {
|
|
419
|
+
let lastElem = finalCollection.at(-1);
|
|
420
|
+
return (elem.loc.start.line !== node.loc.start.line && !lastElem || lastElem && lastElem.loc.start.line !== elem.loc.start.line) && finalCollection.push(elem), finalCollection;
|
|
421
|
+
}, []);
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Check indentation for variable declarations
|
|
425
|
+
* @param {ASTNode} node node to examine
|
|
426
|
+
* @returns {void}
|
|
427
|
+
*/
|
|
428
|
+
function checkIndentInVariableDeclarations(node) {
|
|
429
|
+
let elements = filterOutSameLineVars(node), nodeIndent = getNodeIndent(node).goodChar, lastElement = elements.at(-1), elementsIndent = nodeIndent + indentSize * options.VariableDeclarator[node.kind];
|
|
430
|
+
if (checkNodesIndent(elements, elementsIndent), sourceCode.getLastToken(node).loc.end.line <= lastElement.loc.end.line) return;
|
|
431
|
+
let tokenBeforeLastElement = sourceCode.getTokenBefore(lastElement);
|
|
432
|
+
tokenBeforeLastElement.value === "," ? checkLastNodeLineIndent(node, getNodeIndent(tokenBeforeLastElement).goodChar) : checkLastNodeLineIndent(node, elementsIndent - indentSize);
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Check and decide whether to check for indentation for blockless nodes
|
|
436
|
+
* Scenarios are for or while statements without braces around them
|
|
437
|
+
* @param {ASTNode} node node to examine
|
|
438
|
+
* @returns {void}
|
|
439
|
+
*/
|
|
440
|
+
function blockLessNodes(node) {
|
|
441
|
+
node.body.type !== "BlockStatement" && blockIndentationCheck(node);
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Returns the expected indentation for the case statement
|
|
445
|
+
* @param {ASTNode} node node to examine
|
|
446
|
+
* @param {number} [providedSwitchIndent] indent for switch statement
|
|
447
|
+
* @returns {number} indent size
|
|
448
|
+
*/
|
|
449
|
+
function expectedCaseIndent(node, providedSwitchIndent) {
|
|
450
|
+
let switchNode = node.type === "SwitchStatement" ? node : node.parent, switchIndent = providedSwitchIndent === void 0 ? getNodeIndent(switchNode).goodChar : providedSwitchIndent, caseIndent;
|
|
451
|
+
return caseIndentStore[switchNode.loc.start.line] ? caseIndentStore[switchNode.loc.start.line] : (caseIndent = switchNode.cases.length > 0 && options.SwitchCase === 0 ? switchIndent : switchIndent + indentSize * options.SwitchCase, caseIndentStore[switchNode.loc.start.line] = caseIndent, caseIndent);
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Checks whether a return statement is wrapped in ()
|
|
455
|
+
* @param {ASTNode} node node to examine
|
|
456
|
+
* @returns {boolean} the result
|
|
457
|
+
*/
|
|
458
|
+
function isWrappedInParenthesis(node) {
|
|
459
|
+
let regex = /^return\s*\(\s*\)/u, statementWithoutArgument = sourceCode.getText(node).replace(sourceCode.getText(node.argument), "");
|
|
460
|
+
return regex.test(statementWithoutArgument);
|
|
461
|
+
}
|
|
462
|
+
return {
|
|
463
|
+
Program(node) {
|
|
464
|
+
node.body.length > 0 && checkNodesIndent(node.body, getNodeIndent(node).goodChar);
|
|
465
|
+
},
|
|
466
|
+
ClassBody: blockIndentationCheck,
|
|
467
|
+
BlockStatement: blockIndentationCheck,
|
|
468
|
+
WhileStatement: blockLessNodes,
|
|
469
|
+
ForStatement: blockLessNodes,
|
|
470
|
+
ForInStatement: blockLessNodes,
|
|
471
|
+
ForOfStatement: blockLessNodes,
|
|
472
|
+
DoWhileStatement: blockLessNodes,
|
|
473
|
+
IfStatement(node) {
|
|
474
|
+
node.consequent.type !== "BlockStatement" && node.consequent.loc.start.line > node.loc.start.line && blockIndentationCheck(node);
|
|
475
|
+
},
|
|
476
|
+
VariableDeclaration(node) {
|
|
477
|
+
node.declarations.at(-1).loc.start.line > node.declarations[0].loc.start.line && checkIndentInVariableDeclarations(node);
|
|
478
|
+
},
|
|
479
|
+
ObjectExpression(node) {
|
|
480
|
+
checkIndentInArrayOrObjectBlock(node);
|
|
481
|
+
},
|
|
482
|
+
ArrayExpression(node) {
|
|
483
|
+
checkIndentInArrayOrObjectBlock(node);
|
|
484
|
+
},
|
|
485
|
+
MemberExpression(node) {
|
|
486
|
+
if (options.MemberExpression === void 0 || isSingleLineNode(node) || getParentNodeByType(node, "VariableDeclarator", ["FunctionExpression", "ArrowFunctionExpression"]) || getParentNodeByType(node, "AssignmentExpression", ["FunctionExpression"])) return;
|
|
487
|
+
let propertyIndent = getNodeIndent(node).goodChar + indentSize * options.MemberExpression, checkNodes = [node.property], dot = sourceCode.getTokenBefore(node.property);
|
|
488
|
+
dot.type === "Punctuator" && dot.value === "." && checkNodes.push(dot), checkNodesIndent(checkNodes, propertyIndent);
|
|
489
|
+
},
|
|
490
|
+
SwitchStatement(node) {
|
|
491
|
+
let switchIndent = getNodeIndent(node).goodChar, caseIndent = expectedCaseIndent(node, switchIndent);
|
|
492
|
+
checkNodesIndent(node.cases, caseIndent), checkLastNodeLineIndent(node, switchIndent);
|
|
493
|
+
},
|
|
494
|
+
SwitchCase(node) {
|
|
495
|
+
if (isSingleLineNode(node)) return;
|
|
496
|
+
let caseIndent = expectedCaseIndent(node);
|
|
497
|
+
checkNodesIndent(node.consequent, caseIndent + indentSize);
|
|
498
|
+
},
|
|
499
|
+
FunctionDeclaration(node) {
|
|
500
|
+
isSingleLineNode(node) || (options.FunctionDeclaration.parameters === "first" && node.params.length ? checkNodesIndent(node.params.slice(1), node.params[0].loc.start.column) : options.FunctionDeclaration.parameters !== null && checkNodesIndent(node.params, getNodeIndent(node).goodChar + indentSize * options.FunctionDeclaration.parameters));
|
|
501
|
+
},
|
|
502
|
+
FunctionExpression(node) {
|
|
503
|
+
isSingleLineNode(node) || (options.FunctionExpression.parameters === "first" && node.params.length ? checkNodesIndent(node.params.slice(1), node.params[0].loc.start.column) : options.FunctionExpression.parameters !== null && checkNodesIndent(node.params, getNodeIndent(node).goodChar + indentSize * options.FunctionExpression.parameters));
|
|
504
|
+
},
|
|
505
|
+
ReturnStatement(node) {
|
|
506
|
+
if (isSingleLineNode(node)) return;
|
|
507
|
+
let firstLineIndent = getNodeIndent(node).goodChar;
|
|
508
|
+
isWrappedInParenthesis(node) ? checkLastReturnStatementLineIndent(node, firstLineIndent) : checkNodeIndent(node, firstLineIndent);
|
|
509
|
+
},
|
|
510
|
+
CallExpression(node) {
|
|
511
|
+
isSingleLineNode(node) || (options.CallExpression.arguments === "first" && node.arguments.length ? checkNodesIndent(node.arguments.slice(1), node.arguments[0].loc.start.column) : options.CallExpression.arguments !== null && checkNodesIndent(node.arguments, getNodeIndent(node).goodChar + indentSize * options.CallExpression.arguments));
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
}));
|
|
517
|
+
//#endregion
|
|
518
|
+
//#region src-js/generated/plugin-eslint/rules/indent-legacy.cjs
|
|
519
|
+
module.exports = require_indent_legacy().create;
|
|
520
|
+
//#endregion
|