@kikiutils/eslint-config 9.2.0 → 9.3.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/dist/base.d.ts +2 -4
- package/dist/base.d.ts.map +1 -1
- package/dist/base.js +14 -2
- package/dist/base.js.map +1 -1
- package/dist/internals/plugins.d.ts +11 -0
- package/dist/internals/plugins.d.ts.map +1 -0
- package/dist/internals/plugins.js +15 -0
- package/dist/internals/plugins.js.map +1 -0
- package/dist/internals/rules/compact-iteration-layout.d.ts +5 -0
- package/dist/internals/rules/compact-iteration-layout.d.ts.map +1 -0
- package/dist/internals/rules/compact-iteration-layout.js +35 -0
- package/dist/internals/rules/compact-iteration-layout.js.map +1 -0
- package/dist/internals/rules/consistent-condition-layout.d.ts +5 -0
- package/dist/internals/rules/consistent-condition-layout.d.ts.map +1 -0
- package/dist/internals/rules/consistent-condition-layout.js +86 -0
- package/dist/internals/rules/consistent-condition-layout.js.map +1 -0
- package/dist/internals/rules/consistent-parameter-layout.d.ts +5 -0
- package/dist/internals/rules/consistent-parameter-layout.d.ts.map +1 -0
- package/dist/internals/rules/consistent-parameter-layout.js +91 -0
- package/dist/internals/rules/consistent-parameter-layout.js.map +1 -0
- package/dist/internals/rules/statement-padding.d.ts +5 -0
- package/dist/internals/rules/statement-padding.d.ts.map +1 -0
- package/dist/internals/rules/statement-padding.js +60 -0
- package/dist/internals/rules/statement-padding.js.map +1 -0
- package/dist/internals/utils.d.ts +6 -0
- package/dist/internals/utils.d.ts.map +1 -0
- package/dist/internals/utils.js +11 -0
- package/dist/internals/utils.js.map +1 -0
- package/dist/style.d.ts +1 -3
- package/dist/style.d.ts.map +1 -1
- package/dist/vue.d.ts +1 -3
- package/dist/vue.d.ts.map +1 -1
- package/dist/vue.js +2 -0
- package/dist/vue.js.map +1 -1
- package/package.json +51 -21
- package/src/base.ts +20 -2
- package/src/internals/plugins.ts +13 -0
- package/src/internals/rules/compact-iteration-layout.ts +57 -0
- package/src/internals/rules/consistent-condition-layout.ts +130 -0
- package/src/internals/rules/consistent-parameter-layout.ts +163 -0
- package/src/internals/rules/statement-padding.ts +86 -0
- package/src/internals/utils.ts +32 -0
- package/src/vue.ts +2 -0
package/dist/base.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { Rules, TypedFlatConfigItem } from "@antfu/eslint-config";
|
|
2
|
-
|
|
3
2
|
//#region src/base.d.ts
|
|
4
|
-
declare function createBaseConfigs(environment?: 'bun' | 'node'): TypedFlatConfigItem[];
|
|
5
|
-
declare function createBaseRules(environment?: 'bun' | 'node'): Rules;
|
|
3
|
+
export declare function createBaseConfigs(environment?: 'bun' | 'node'): TypedFlatConfigItem[];
|
|
4
|
+
export declare function createBaseRules(environment?: 'bun' | 'node'): Rules;
|
|
6
5
|
//#endregion
|
|
7
|
-
export { createBaseConfigs, createBaseRules };
|
|
8
6
|
//# sourceMappingURL=base.d.ts.map
|
package/dist/base.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","names":[],"sources":["../src/base.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"base.d.ts","names":[],"sources":["../src/base.ts"],"mappings":";;wBAgBgB,kBAAkB,+BAAuC;wBA+EzD,gBAAgB,+BAAuC"}
|
package/dist/base.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { customPlugins } from "./internals/plugins.js";
|
|
1
2
|
import promise from "eslint-plugin-promise";
|
|
2
3
|
//#region src/base.ts
|
|
3
4
|
const basePerfectionistSortOptions = {
|
|
@@ -12,7 +13,10 @@ function createBaseConfigs(environment = "node") {
|
|
|
12
13
|
} },
|
|
13
14
|
{
|
|
14
15
|
files: ["**/*.{cjs,js,mjs}"],
|
|
15
|
-
plugins: {
|
|
16
|
+
plugins: {
|
|
17
|
+
kikiutils: customPlugins,
|
|
18
|
+
promise
|
|
19
|
+
},
|
|
16
20
|
rules: {
|
|
17
21
|
...createBaseRules(environment),
|
|
18
22
|
"node/prefer-global/process": ["error", "always"]
|
|
@@ -20,7 +24,10 @@ function createBaseConfigs(environment = "node") {
|
|
|
20
24
|
},
|
|
21
25
|
{
|
|
22
26
|
files: ["**/*.{ts,tsx}"],
|
|
23
|
-
plugins: {
|
|
27
|
+
plugins: {
|
|
28
|
+
kikiutils: customPlugins,
|
|
29
|
+
promise
|
|
30
|
+
},
|
|
24
31
|
rules: {
|
|
25
32
|
...createBaseRules(environment),
|
|
26
33
|
"node/prefer-global/process": ["error", "always"],
|
|
@@ -59,7 +66,12 @@ function createBaseRules(environment = "node") {
|
|
|
59
66
|
"antfu/curly": "off",
|
|
60
67
|
"antfu/if-newline": "off",
|
|
61
68
|
"antfu/no-top-level-await": "off",
|
|
69
|
+
"arrow-body-style": ["error", "as-needed"],
|
|
62
70
|
"curly": ["error", "multi-line"],
|
|
71
|
+
"kikiutils/compact-iteration-layout": "error",
|
|
72
|
+
"kikiutils/consistent-condition-layout": "error",
|
|
73
|
+
"kikiutils/consistent-parameter-layout": "error",
|
|
74
|
+
"kikiutils/statement-padding": "error",
|
|
63
75
|
"max-classes-per-file": ["error", 1],
|
|
64
76
|
"no-promise-executor-return": ["error", { allowVoid: true }],
|
|
65
77
|
"perfectionist/sort-array-includes": ["error", basePerfectionistSortOptions],
|
package/dist/base.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","names":[],"sources":["../src/base.ts"],"sourcesContent":["import type {\n Rules,\n TypedFlatConfigItem,\n} from '@antfu/eslint-config';\n// @ts-expect-error No declare file.\nimport promise from 'eslint-plugin-promise';\n\nconst basePerfectionistSortOptions = {\n ignoreCase: false,\n type: 'natural',\n} as const;\n\nexport function createBaseConfigs(environment: 'bun' | 'node' = 'node'): TypedFlatConfigItem[] {\n return [\n // All files\n {\n rules: {\n 'e18e/ban-dependencies': [\n 'error',\n {\n allowed: [\n 'axios',\n 'rimraf',\n ],\n },\n ],\n 'e18e/prefer-static-regex': ['off'],\n },\n },\n // JavaScript\n {\n files: ['**/*.{cjs,js,mjs}'],\n plugins: { promise },\n rules: {\n ...createBaseRules(environment),\n 'node/prefer-global/process': [\n 'error',\n 'always',\n ],\n },\n },\n // TypeScript\n {\n files: ['**/*.{ts,tsx}'],\n plugins: { promise },\n rules: {\n ...createBaseRules(environment),\n 'node/prefer-global/process': [\n 'error',\n 'always',\n ],\n 'ts/consistent-generic-constructors': [\n 'error',\n 'constructor',\n ],\n 'ts/no-redeclare': 'off',\n },\n },\n // VsCode jsonc\n {\n files: ['**/.vscode/*.json'],\n rules: {\n 'jsonc/sort-array-values': [\n 'error',\n {\n order: {\n natural: true,\n type: 'asc',\n },\n pathPattern: '^.*$',\n },\n ],\n 'jsonc/sort-keys': [\n 'error',\n 'asc',\n {\n caseSensitive: true,\n natural: true,\n },\n ],\n },\n },\n ];\n}\n\nexport function createBaseRules(environment: 'bun' | 'node' = 'node'): Rules {\n return {\n 'antfu/consistent-list-newline': [\n 'error',\n {\n ArrayExpression: false,\n ArrayPattern: false,\n },\n ],\n 'antfu/curly': 'off',\n 'antfu/if-newline': 'off',\n 'antfu/no-top-level-await': 'off',\n 'curly': [\n 'error',\n 'multi-line',\n ],\n 'max-classes-per-file': [\n 'error',\n 1,\n ],\n 'no-promise-executor-return': [\n 'error',\n { allowVoid: true },\n ],\n 'perfectionist/sort-array-includes': [\n 'error',\n basePerfectionistSortOptions,\n ],\n 'perfectionist/sort-enums': [\n 'error',\n {\n ...basePerfectionistSortOptions,\n sortByValue: 'never',\n },\n ],\n 'perfectionist/sort-heritage-clauses': [\n 'error',\n {\n ignoreCase: false,\n type: 'natural',\n },\n ],\n 'perfectionist/sort-imports': [\n 'error',\n {\n environment,\n groups: [\n 'side-effect',\n 'side-effect-style',\n 'style',\n [\n 'value-builtin',\n 'type-builtin',\n ],\n [\n 'value-external',\n 'type-external',\n ],\n [\n 'value-internal',\n 'type-internal',\n ],\n [\n 'value-parent',\n 'type-parent',\n ],\n [\n 'value-sibling',\n 'type-sibling',\n ],\n [\n 'value-index',\n 'type-index',\n ],\n 'unknown',\n ],\n ignoreCase: false,\n internalPattern: [\n '^#.*',\n '^@/.*',\n '^~/.*',\n ],\n type: 'natural',\n },\n ],\n 'perfectionist/sort-interfaces': [\n 'error',\n basePerfectionistSortOptions,\n ],\n 'perfectionist/sort-intersection-types': [\n 'error',\n basePerfectionistSortOptions,\n ],\n 'perfectionist/sort-maps': [\n 'error',\n basePerfectionistSortOptions,\n ],\n 'perfectionist/sort-modules': [\n 'error',\n {\n ...basePerfectionistSortOptions,\n groups: [\n 'declare-type',\n [\n 'export-type',\n 'type',\n ],\n 'declare-interface',\n [\n 'export-interface',\n 'interface',\n ],\n 'declare-enum',\n [\n 'enum',\n 'export-enum',\n ],\n 'declare-class',\n [\n 'class',\n 'export-class',\n ],\n 'declare-function',\n [\n 'export-function',\n 'function',\n ],\n ],\n },\n ],\n 'perfectionist/sort-object-types': [\n 'error',\n basePerfectionistSortOptions,\n ],\n 'perfectionist/sort-objects': [\n 'error',\n basePerfectionistSortOptions,\n ],\n 'perfectionist/sort-sets': [\n 'error',\n basePerfectionistSortOptions,\n ],\n 'perfectionist/sort-switch-case': [\n 'error',\n {\n ignoreCase: false,\n type: 'natural',\n },\n ],\n 'perfectionist/sort-union-types': [\n 'error',\n basePerfectionistSortOptions,\n ],\n 'perfectionist/sort-variable-declarations': [\n 'error',\n basePerfectionistSortOptions,\n ],\n 'promise/no-multiple-resolved': 'error',\n 'promise/no-return-in-finally': 'error',\n 'promise/no-return-wrap': 'error',\n 'require-await': 'error',\n 'style/array-bracket-newline': [\n 'error',\n { multiline: true },\n ],\n 'style/array-element-newline': [\n 'error',\n {\n ArrayExpression: {\n consistent: true,\n minItems: 2,\n },\n ArrayPattern: { minItems: 3 },\n },\n ],\n 'style/arrow-parens': [\n 'error',\n 'always',\n ],\n 'style/brace-style': [\n 'error',\n '1tbs',\n { allowSingleLine: false },\n ],\n 'style/function-call-spacing': [\n 'error',\n 'never',\n ],\n 'style/indent': [\n 'error',\n 4,\n ],\n 'style/max-len': [\n 'warn',\n {\n code: 120,\n comments: 120,\n },\n ],\n 'style/member-delimiter-style': [\n 'error',\n {\n multiline: {\n delimiter: 'semi',\n requireLast: true,\n },\n },\n ],\n 'style/no-extra-parens': [\n 'error',\n 'all',\n { nestedBinaryExpressions: false },\n ],\n 'style/no-extra-semi': 'error',\n 'style/object-curly-newline': [\n 'error',\n {\n ExportDeclaration: {\n minProperties: 2,\n multiline: true,\n },\n ImportDeclaration: {\n minProperties: 2,\n multiline: true,\n },\n ObjectExpression: {\n minProperties: 2,\n multiline: true,\n },\n ObjectPattern: {\n minProperties: 3,\n multiline: true,\n },\n },\n ],\n 'style/operator-linebreak': [\n 'error',\n 'before',\n { overrides: { '=': 'after' } },\n ],\n 'style/padding-line-between-statements': [\n 'error',\n {\n blankLine: 'always',\n next: [\n 'class',\n 'enum',\n 'function',\n ],\n prev: '*',\n },\n {\n blankLine: 'always',\n next: '*',\n prev: [\n 'class',\n 'function',\n ],\n },\n ],\n 'style/semi': [\n 'error',\n 'always',\n ],\n };\n}\n"],"mappings":";;AAOA,MAAM,+BAA+B;CACjC,YAAY;CACZ,MAAM;AACV;AAEA,SAAgB,kBAAkB,cAA8B,QAA+B;CAC3F,OAAO;EAEH,EACI,OAAO;GACH,yBAAyB,CACrB,SACA,EACI,SAAS,CACL,SACA,QACJ,EACJ,CACJ;GACA,4BAA4B,CAAC,KAAK;EACtC,EACJ;EAEA;GACI,OAAO,CAAC,mBAAmB;GAC3B,SAAS,EAAE,QAAQ;GACnB,OAAO;IACH,GAAG,gBAAgB,WAAW;IAC9B,8BAA8B,CAC1B,SACA,QACJ;GACJ;EACJ;EAEA;GACI,OAAO,CAAC,eAAe;GACvB,SAAS,EAAE,QAAQ;GACnB,OAAO;IACH,GAAG,gBAAgB,WAAW;IAC9B,8BAA8B,CAC1B,SACA,QACJ;IACA,sCAAsC,CAClC,SACA,aACJ;IACA,mBAAmB;GACvB;EACJ;EAEA;GACI,OAAO,CAAC,mBAAmB;GAC3B,OAAO;IACH,2BAA2B,CACvB,SACA;KACI,OAAO;MACH,SAAS;MACT,MAAM;KACV;KACA,aAAa;IACjB,CACJ;IACA,mBAAmB;KACf;KACA;KACA;MACI,eAAe;MACf,SAAS;KACb;IACJ;GACJ;EACJ;CACJ;AACJ;AAEA,SAAgB,gBAAgB,cAA8B,QAAe;CACzE,OAAO;EACH,iCAAiC,CAC7B,SACA;GACI,iBAAiB;GACjB,cAAc;EAClB,CACJ;EACA,eAAe;EACf,oBAAoB;EACpB,4BAA4B;EAC5B,SAAS,CACL,SACA,YACJ;EACA,wBAAwB,CACpB,SACA,CACJ;EACA,8BAA8B,CAC1B,SACA,EAAE,WAAW,KAAK,CACtB;EACA,qCAAqC,CACjC,SACA,4BACJ;EACA,4BAA4B,CACxB,SACA;GACI,GAAG;GACH,aAAa;EACjB,CACJ;EACA,uCAAuC,CACnC,SACA;GACI,YAAY;GACZ,MAAM;EACV,CACJ;EACA,8BAA8B,CAC1B,SACA;GACI;GACA,QAAQ;IACJ;IACA;IACA;IACA,CACI,iBACA,cACJ;IACA,CACI,kBACA,eACJ;IACA,CACI,kBACA,eACJ;IACA,CACI,gBACA,aACJ;IACA,CACI,iBACA,cACJ;IACA,CACI,eACA,YACJ;IACA;GACJ;GACA,YAAY;GACZ,iBAAiB;IACb;IACA;IACA;GACJ;GACA,MAAM;EACV,CACJ;EACA,iCAAiC,CAC7B,SACA,4BACJ;EACA,yCAAyC,CACrC,SACA,4BACJ;EACA,2BAA2B,CACvB,SACA,4BACJ;EACA,8BAA8B,CAC1B,SACA;GACI,GAAG;GACH,QAAQ;IACJ;IACA,CACI,eACA,MACJ;IACA;IACA,CACI,oBACA,WACJ;IACA;IACA,CACI,QACA,aACJ;IACA;IACA,CACI,SACA,cACJ;IACA;IACA,CACI,mBACA,UACJ;GACJ;EACJ,CACJ;EACA,mCAAmC,CAC/B,SACA,4BACJ;EACA,8BAA8B,CAC1B,SACA,4BACJ;EACA,2BAA2B,CACvB,SACA,4BACJ;EACA,kCAAkC,CAC9B,SACA;GACI,YAAY;GACZ,MAAM;EACV,CACJ;EACA,kCAAkC,CAC9B,SACA,4BACJ;EACA,4CAA4C,CACxC,SACA,4BACJ;EACA,gCAAgC;EAChC,gCAAgC;EAChC,0BAA0B;EAC1B,iBAAiB;EACjB,+BAA+B,CAC3B,SACA,EAAE,WAAW,KAAK,CACtB;EACA,+BAA+B,CAC3B,SACA;GACI,iBAAiB;IACb,YAAY;IACZ,UAAU;GACd;GACA,cAAc,EAAE,UAAU,EAAE;EAChC,CACJ;EACA,sBAAsB,CAClB,SACA,QACJ;EACA,qBAAqB;GACjB;GACA;GACA,EAAE,iBAAiB,MAAM;EAC7B;EACA,+BAA+B,CAC3B,SACA,OACJ;EACA,gBAAgB,CACZ,SACA,CACJ;EACA,iBAAiB,CACb,QACA;GACI,MAAM;GACN,UAAU;EACd,CACJ;EACA,gCAAgC,CAC5B,SACA,EACI,WAAW;GACP,WAAW;GACX,aAAa;EACjB,EACJ,CACJ;EACA,yBAAyB;GACrB;GACA;GACA,EAAE,yBAAyB,MAAM;EACrC;EACA,uBAAuB;EACvB,8BAA8B,CAC1B,SACA;GACI,mBAAmB;IACf,eAAe;IACf,WAAW;GACf;GACA,mBAAmB;IACf,eAAe;IACf,WAAW;GACf;GACA,kBAAkB;IACd,eAAe;IACf,WAAW;GACf;GACA,eAAe;IACX,eAAe;IACf,WAAW;GACf;EACJ,CACJ;EACA,4BAA4B;GACxB;GACA;GACA,EAAE,WAAW,EAAE,KAAK,QAAQ,EAAE;EAClC;EACA,yCAAyC;GACrC;GACA;IACI,WAAW;IACX,MAAM;KACF;KACA;KACA;IACJ;IACA,MAAM;GACV;GACA;IACI,WAAW;IACX,MAAM;IACN,MAAM,CACF,SACA,UACJ;GACJ;EACJ;EACA,cAAc,CACV,SACA,QACJ;CACJ;AACJ"}
|
|
1
|
+
{"version":3,"file":"base.js","names":[],"sources":["../src/base.ts"],"sourcesContent":["import type {\n Rules,\n TypedFlatConfigItem,\n} from '@antfu/eslint-config';\n// @ts-expect-error No declare file.\nimport promise from 'eslint-plugin-promise';\n\nimport { customPlugins } from './internals/plugins';\n\n// Constants/Variables\nconst basePerfectionistSortOptions = {\n ignoreCase: false,\n type: 'natural',\n} as const;\n\n// Functions\nexport function createBaseConfigs(environment: 'bun' | 'node' = 'node'): TypedFlatConfigItem[] {\n return [\n // All files\n {\n rules: {\n 'e18e/ban-dependencies': [\n 'error',\n {\n allowed: [\n 'axios',\n 'rimraf',\n ],\n },\n ],\n 'e18e/prefer-static-regex': ['off'],\n },\n },\n // JavaScript\n {\n files: ['**/*.{cjs,js,mjs}'],\n plugins: {\n kikiutils: customPlugins,\n promise,\n },\n rules: {\n ...createBaseRules(environment),\n 'node/prefer-global/process': [\n 'error',\n 'always',\n ],\n },\n },\n // TypeScript\n {\n files: ['**/*.{ts,tsx}'],\n plugins: {\n kikiutils: customPlugins,\n promise,\n },\n rules: {\n ...createBaseRules(environment),\n 'node/prefer-global/process': [\n 'error',\n 'always',\n ],\n 'ts/consistent-generic-constructors': [\n 'error',\n 'constructor',\n ],\n 'ts/no-redeclare': 'off',\n },\n },\n // VsCode jsonc\n {\n files: ['**/.vscode/*.json'],\n rules: {\n 'jsonc/sort-array-values': [\n 'error',\n {\n order: {\n natural: true,\n type: 'asc',\n },\n pathPattern: '^.*$',\n },\n ],\n 'jsonc/sort-keys': [\n 'error',\n 'asc',\n {\n caseSensitive: true,\n natural: true,\n },\n ],\n },\n },\n ];\n}\n\nexport function createBaseRules(environment: 'bun' | 'node' = 'node'): Rules {\n return {\n 'antfu/consistent-list-newline': [\n 'error',\n {\n ArrayExpression: false,\n ArrayPattern: false,\n },\n ],\n 'antfu/curly': 'off',\n 'antfu/if-newline': 'off',\n 'antfu/no-top-level-await': 'off',\n 'arrow-body-style': [\n 'error',\n 'as-needed',\n ],\n 'curly': [\n 'error',\n 'multi-line',\n ],\n 'kikiutils/compact-iteration-layout': 'error',\n 'kikiutils/consistent-condition-layout': 'error',\n 'kikiutils/consistent-parameter-layout': 'error',\n 'kikiutils/statement-padding': 'error',\n 'max-classes-per-file': [\n 'error',\n 1,\n ],\n 'no-promise-executor-return': [\n 'error',\n { allowVoid: true },\n ],\n 'perfectionist/sort-array-includes': [\n 'error',\n basePerfectionistSortOptions,\n ],\n 'perfectionist/sort-enums': [\n 'error',\n {\n ...basePerfectionistSortOptions,\n sortByValue: 'never',\n },\n ],\n 'perfectionist/sort-heritage-clauses': [\n 'error',\n {\n ignoreCase: false,\n type: 'natural',\n },\n ],\n 'perfectionist/sort-imports': [\n 'error',\n {\n environment,\n groups: [\n 'side-effect',\n 'side-effect-style',\n 'style',\n [\n 'value-builtin',\n 'type-builtin',\n ],\n [\n 'value-external',\n 'type-external',\n ],\n [\n 'value-internal',\n 'type-internal',\n ],\n [\n 'value-parent',\n 'type-parent',\n ],\n [\n 'value-sibling',\n 'type-sibling',\n ],\n [\n 'value-index',\n 'type-index',\n ],\n 'unknown',\n ],\n ignoreCase: false,\n internalPattern: [\n '^#.*',\n '^@/.*',\n '^~/.*',\n ],\n type: 'natural',\n },\n ],\n 'perfectionist/sort-interfaces': [\n 'error',\n basePerfectionistSortOptions,\n ],\n 'perfectionist/sort-intersection-types': [\n 'error',\n basePerfectionistSortOptions,\n ],\n 'perfectionist/sort-maps': [\n 'error',\n basePerfectionistSortOptions,\n ],\n 'perfectionist/sort-modules': [\n 'error',\n {\n ...basePerfectionistSortOptions,\n groups: [\n 'declare-type',\n [\n 'export-type',\n 'type',\n ],\n 'declare-interface',\n [\n 'export-interface',\n 'interface',\n ],\n 'declare-enum',\n [\n 'enum',\n 'export-enum',\n ],\n 'declare-class',\n [\n 'class',\n 'export-class',\n ],\n 'declare-function',\n [\n 'export-function',\n 'function',\n ],\n ],\n },\n ],\n 'perfectionist/sort-object-types': [\n 'error',\n basePerfectionistSortOptions,\n ],\n 'perfectionist/sort-objects': [\n 'error',\n basePerfectionistSortOptions,\n ],\n 'perfectionist/sort-sets': [\n 'error',\n basePerfectionistSortOptions,\n ],\n 'perfectionist/sort-switch-case': [\n 'error',\n {\n ignoreCase: false,\n type: 'natural',\n },\n ],\n 'perfectionist/sort-union-types': [\n 'error',\n basePerfectionistSortOptions,\n ],\n 'perfectionist/sort-variable-declarations': [\n 'error',\n basePerfectionistSortOptions,\n ],\n 'promise/no-multiple-resolved': 'error',\n 'promise/no-return-in-finally': 'error',\n 'promise/no-return-wrap': 'error',\n 'require-await': 'error',\n 'style/array-bracket-newline': [\n 'error',\n { multiline: true },\n ],\n 'style/array-element-newline': [\n 'error',\n {\n ArrayExpression: {\n consistent: true,\n minItems: 2,\n },\n ArrayPattern: { minItems: 3 },\n },\n ],\n 'style/arrow-parens': [\n 'error',\n 'always',\n ],\n 'style/brace-style': [\n 'error',\n '1tbs',\n { allowSingleLine: false },\n ],\n 'style/function-call-spacing': [\n 'error',\n 'never',\n ],\n 'style/indent': [\n 'error',\n 4,\n ],\n 'style/max-len': [\n 'warn',\n {\n code: 120,\n comments: 120,\n },\n ],\n 'style/member-delimiter-style': [\n 'error',\n {\n multiline: {\n delimiter: 'semi',\n requireLast: true,\n },\n },\n ],\n 'style/no-extra-parens': [\n 'error',\n 'all',\n { nestedBinaryExpressions: false },\n ],\n 'style/no-extra-semi': 'error',\n 'style/object-curly-newline': [\n 'error',\n {\n ExportDeclaration: {\n minProperties: 2,\n multiline: true,\n },\n ImportDeclaration: {\n minProperties: 2,\n multiline: true,\n },\n ObjectExpression: {\n minProperties: 2,\n multiline: true,\n },\n ObjectPattern: {\n minProperties: 3,\n multiline: true,\n },\n },\n ],\n 'style/operator-linebreak': [\n 'error',\n 'before',\n { overrides: { '=': 'after' } },\n ],\n 'style/padding-line-between-statements': [\n 'error',\n {\n blankLine: 'always',\n next: [\n 'class',\n 'enum',\n 'function',\n ],\n prev: '*',\n },\n {\n blankLine: 'always',\n next: '*',\n prev: [\n 'class',\n 'function',\n ],\n },\n ],\n 'style/semi': [\n 'error',\n 'always',\n ],\n };\n}\n"],"mappings":";;;AAUA,MAAM,+BAA+B;CACjC,YAAY;CACZ,MAAM;AACV;AAGA,SAAgB,kBAAkB,cAA8B,QAA+B;CAC3F,OAAO;EAEH,EACI,OAAO;GACH,yBAAyB,CACrB,SACA,EACI,SAAS,CACL,SACA,QACJ,EACJ,CACJ;GACA,4BAA4B,CAAC,KAAK;EACtC,EACJ;EAEA;GACI,OAAO,CAAC,mBAAmB;GAC3B,SAAS;IACL,WAAW;IACX;GACJ;GACA,OAAO;IACH,GAAG,gBAAgB,WAAW;IAC9B,8BAA8B,CAC1B,SACA,QACJ;GACJ;EACJ;EAEA;GACI,OAAO,CAAC,eAAe;GACvB,SAAS;IACL,WAAW;IACX;GACJ;GACA,OAAO;IACH,GAAG,gBAAgB,WAAW;IAC9B,8BAA8B,CAC1B,SACA,QACJ;IACA,sCAAsC,CAClC,SACA,aACJ;IACA,mBAAmB;GACvB;EACJ;EAEA;GACI,OAAO,CAAC,mBAAmB;GAC3B,OAAO;IACH,2BAA2B,CACvB,SACA;KACI,OAAO;MACH,SAAS;MACT,MAAM;KACV;KACA,aAAa;IACjB,CACJ;IACA,mBAAmB;KACf;KACA;KACA;MACI,eAAe;MACf,SAAS;KACb;IACJ;GACJ;EACJ;CACJ;AACJ;AAEA,SAAgB,gBAAgB,cAA8B,QAAe;CACzE,OAAO;EACH,iCAAiC,CAC7B,SACA;GACI,iBAAiB;GACjB,cAAc;EAClB,CACJ;EACA,eAAe;EACf,oBAAoB;EACpB,4BAA4B;EAC5B,oBAAoB,CAChB,SACA,WACJ;EACA,SAAS,CACL,SACA,YACJ;EACA,sCAAsC;EACtC,yCAAyC;EACzC,yCAAyC;EACzC,+BAA+B;EAC/B,wBAAwB,CACpB,SACA,CACJ;EACA,8BAA8B,CAC1B,SACA,EAAE,WAAW,KAAK,CACtB;EACA,qCAAqC,CACjC,SACA,4BACJ;EACA,4BAA4B,CACxB,SACA;GACI,GAAG;GACH,aAAa;EACjB,CACJ;EACA,uCAAuC,CACnC,SACA;GACI,YAAY;GACZ,MAAM;EACV,CACJ;EACA,8BAA8B,CAC1B,SACA;GACI;GACA,QAAQ;IACJ;IACA;IACA;IACA,CACI,iBACA,cACJ;IACA,CACI,kBACA,eACJ;IACA,CACI,kBACA,eACJ;IACA,CACI,gBACA,aACJ;IACA,CACI,iBACA,cACJ;IACA,CACI,eACA,YACJ;IACA;GACJ;GACA,YAAY;GACZ,iBAAiB;IACb;IACA;IACA;GACJ;GACA,MAAM;EACV,CACJ;EACA,iCAAiC,CAC7B,SACA,4BACJ;EACA,yCAAyC,CACrC,SACA,4BACJ;EACA,2BAA2B,CACvB,SACA,4BACJ;EACA,8BAA8B,CAC1B,SACA;GACI,GAAG;GACH,QAAQ;IACJ;IACA,CACI,eACA,MACJ;IACA;IACA,CACI,oBACA,WACJ;IACA;IACA,CACI,QACA,aACJ;IACA;IACA,CACI,SACA,cACJ;IACA;IACA,CACI,mBACA,UACJ;GACJ;EACJ,CACJ;EACA,mCAAmC,CAC/B,SACA,4BACJ;EACA,8BAA8B,CAC1B,SACA,4BACJ;EACA,2BAA2B,CACvB,SACA,4BACJ;EACA,kCAAkC,CAC9B,SACA;GACI,YAAY;GACZ,MAAM;EACV,CACJ;EACA,kCAAkC,CAC9B,SACA,4BACJ;EACA,4CAA4C,CACxC,SACA,4BACJ;EACA,gCAAgC;EAChC,gCAAgC;EAChC,0BAA0B;EAC1B,iBAAiB;EACjB,+BAA+B,CAC3B,SACA,EAAE,WAAW,KAAK,CACtB;EACA,+BAA+B,CAC3B,SACA;GACI,iBAAiB;IACb,YAAY;IACZ,UAAU;GACd;GACA,cAAc,EAAE,UAAU,EAAE;EAChC,CACJ;EACA,sBAAsB,CAClB,SACA,QACJ;EACA,qBAAqB;GACjB;GACA;GACA,EAAE,iBAAiB,MAAM;EAC7B;EACA,+BAA+B,CAC3B,SACA,OACJ;EACA,gBAAgB,CACZ,SACA,CACJ;EACA,iBAAiB,CACb,QACA;GACI,MAAM;GACN,UAAU;EACd,CACJ;EACA,gCAAgC,CAC5B,SACA,EACI,WAAW;GACP,WAAW;GACX,aAAa;EACjB,EACJ,CACJ;EACA,yBAAyB;GACrB;GACA;GACA,EAAE,yBAAyB,MAAM;EACrC;EACA,uBAAuB;EACvB,8BAA8B,CAC1B,SACA;GACI,mBAAmB;IACf,eAAe;IACf,WAAW;GACf;GACA,mBAAmB;IACf,eAAe;IACf,WAAW;GACf;GACA,kBAAkB;IACd,eAAe;IACf,WAAW;GACf;GACA,eAAe;IACX,eAAe;IACf,WAAW;GACf;EACJ,CACJ;EACA,4BAA4B;GACxB;GACA;GACA,EAAE,WAAW,EAAE,KAAK,QAAQ,EAAE;EAClC;EACA,yCAAyC;GACrC;GACA;IACI,WAAW;IACX,MAAM;KACF;KACA;KACA;IACJ;IACA,MAAM;GACV;GACA;IACI,WAAW;IACX,MAAM;IACN,MAAM,CACF,SACA,UACJ;GACJ;EACJ;EACA,cAAc,CACV,SACA,QACJ;CACJ;AACJ"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/internals/plugins.d.ts
|
|
2
|
+
export declare const customPlugins: {
|
|
3
|
+
rules: {
|
|
4
|
+
'compact-iteration-layout': import("eslint").Rule.RuleModule;
|
|
5
|
+
'consistent-condition-layout': import("eslint").Rule.RuleModule;
|
|
6
|
+
'consistent-parameter-layout': import("eslint").Rule.RuleModule;
|
|
7
|
+
'statement-padding': import("eslint").Rule.RuleModule;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
11
|
+
//# sourceMappingURL=plugins.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugins.d.ts","names":[],"sources":["../../src/internals/plugins.ts"],"mappings":";qBAKa"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { compactIterationLayout } from "./rules/compact-iteration-layout.js";
|
|
2
|
+
import { consistentConditionLayout } from "./rules/consistent-condition-layout.js";
|
|
3
|
+
import { consistentParameterLayout } from "./rules/consistent-parameter-layout.js";
|
|
4
|
+
import { statementPadding } from "./rules/statement-padding.js";
|
|
5
|
+
//#region src/internals/plugins.ts
|
|
6
|
+
const customPlugins = { rules: {
|
|
7
|
+
"compact-iteration-layout": compactIterationLayout,
|
|
8
|
+
"consistent-condition-layout": consistentConditionLayout,
|
|
9
|
+
"consistent-parameter-layout": consistentParameterLayout,
|
|
10
|
+
"statement-padding": statementPadding
|
|
11
|
+
} };
|
|
12
|
+
//#endregion
|
|
13
|
+
export { customPlugins };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=plugins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugins.js","names":[],"sources":["../../src/internals/plugins.ts"],"sourcesContent":["import { compactIterationLayout } from './rules/compact-iteration-layout';\nimport { consistentConditionLayout } from './rules/consistent-condition-layout';\nimport { consistentParameterLayout } from './rules/consistent-parameter-layout';\nimport { statementPadding } from './rules/statement-padding';\n\nexport const customPlugins = {\n rules: {\n 'compact-iteration-layout': compactIterationLayout,\n 'consistent-condition-layout': consistentConditionLayout,\n 'consistent-parameter-layout': consistentParameterLayout,\n 'statement-padding': statementPadding,\n },\n};\n"],"mappings":";;;;;AAKA,MAAa,gBAAgB,EACzB,OAAO;CACH,4BAA4B;CAC5B,+BAA+B;CAC/B,+BAA+B;CAC/B,qBAAqB;AACzB,EACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compact-iteration-layout.d.ts","names":[],"sources":["../../../src/internals/rules/compact-iteration-layout.ts"],"mappings":";;qBAIa,wBAAwB,KAAK"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/internals/rules/compact-iteration-layout.ts
|
|
2
|
+
const compactIterationLayout = {
|
|
3
|
+
create(context) {
|
|
4
|
+
const { sourceCode } = context;
|
|
5
|
+
function checkParentheses(node) {
|
|
6
|
+
const openingParen = sourceCode.getFirstToken(node, (token) => token.value === "(");
|
|
7
|
+
const closingParen = sourceCode.getTokenBefore(node.body);
|
|
8
|
+
const next = sourceCode.getTokenAfter(openingParen);
|
|
9
|
+
const previous = sourceCode.getTokenBefore(closingParen);
|
|
10
|
+
const ranges = [];
|
|
11
|
+
if (openingParen.loc.end.line !== next.loc.start.line && !sourceCode.commentsExistBetween(openingParen, next)) ranges.push([openingParen.range[1], next.range[0]]);
|
|
12
|
+
if (previous.loc.end.line !== closingParen.loc.start.line && !sourceCode.commentsExistBetween(previous, closingParen)) ranges.push([previous.range[1], closingParen.range[0]]);
|
|
13
|
+
if (ranges.length) context.report({
|
|
14
|
+
fix: (fixer) => ranges.map((range) => fixer.replaceTextRange(range, "")),
|
|
15
|
+
messageId: "compact",
|
|
16
|
+
node
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
ForInStatement: checkParentheses,
|
|
21
|
+
ForOfStatement: checkParentheses
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
meta: {
|
|
25
|
+
docs: { description: "Keep for-in and for-of parentheses beside their header contents." },
|
|
26
|
+
fixable: "whitespace",
|
|
27
|
+
messages: { compact: "Keep iteration parentheses on the same lines as their adjacent header contents." },
|
|
28
|
+
schema: [],
|
|
29
|
+
type: "layout"
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
//#endregion
|
|
33
|
+
export { compactIterationLayout };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=compact-iteration-layout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compact-iteration-layout.js","names":[],"sources":["../../../src/internals/rules/compact-iteration-layout.ts"],"sourcesContent":["import type { Rule } from 'eslint';\n\ntype IterationNode = Extract<Rule.Node, { type: 'ForInStatement' | 'ForOfStatement' }>;\n\nexport const compactIterationLayout: Rule.RuleModule = {\n create(context) {\n const { sourceCode } = context;\n\n function checkParentheses(node: IterationNode): void {\n const openingParen = sourceCode.getFirstToken(node, (token) => token.value === '(')!;\n const closingParen = sourceCode.getTokenBefore(node.body)!;\n const next = sourceCode.getTokenAfter(openingParen)!;\n const previous = sourceCode.getTokenBefore(closingParen)!;\n const ranges: Array<[number, number]> = [];\n\n if (\n openingParen.loc.end.line !== next.loc.start.line\n && !sourceCode.commentsExistBetween(openingParen, next)\n ) {\n ranges.push([\n openingParen.range[1],\n next.range[0],\n ]);\n }\n\n if (\n previous.loc.end.line !== closingParen.loc.start.line\n && !sourceCode.commentsExistBetween(previous, closingParen)\n ) {\n ranges.push([\n previous.range[1],\n closingParen.range[0],\n ]);\n }\n\n if (ranges.length) {\n context.report({\n fix: (fixer) => ranges.map((range) => fixer.replaceTextRange(range, '')),\n messageId: 'compact',\n node,\n });\n }\n }\n\n return {\n ForInStatement: checkParentheses,\n ForOfStatement: checkParentheses,\n };\n },\n meta: {\n docs: { description: 'Keep for-in and for-of parentheses beside their header contents.' },\n fixable: 'whitespace',\n messages: { compact: 'Keep iteration parentheses on the same lines as their adjacent header contents.' },\n schema: [],\n type: 'layout',\n },\n};\n"],"mappings":";AAIA,MAAa,yBAA0C;CACnD,OAAO,SAAS;EACZ,MAAM,EAAE,eAAe;EAEvB,SAAS,iBAAiB,MAA2B;GACjD,MAAM,eAAe,WAAW,cAAc,OAAO,UAAU,MAAM,UAAU,GAAG;GAClF,MAAM,eAAe,WAAW,eAAe,KAAK,IAAI;GACxD,MAAM,OAAO,WAAW,cAAc,YAAY;GAClD,MAAM,WAAW,WAAW,eAAe,YAAY;GACvD,MAAM,SAAkC,CAAC;GAEzC,IACI,aAAa,IAAI,IAAI,SAAS,KAAK,IAAI,MAAM,QAC1C,CAAC,WAAW,qBAAqB,cAAc,IAAI,GAEtD,OAAO,KAAK,CACR,aAAa,MAAM,IACnB,KAAK,MAAM,EACf,CAAC;GAGL,IACI,SAAS,IAAI,IAAI,SAAS,aAAa,IAAI,MAAM,QAC9C,CAAC,WAAW,qBAAqB,UAAU,YAAY,GAE1D,OAAO,KAAK,CACR,SAAS,MAAM,IACf,aAAa,MAAM,EACvB,CAAC;GAGL,IAAI,OAAO,QACP,QAAQ,OAAO;IACX,MAAM,UAAU,OAAO,KAAK,UAAU,MAAM,iBAAiB,OAAO,EAAE,CAAC;IACvE,WAAW;IACX;GACJ,CAAC;EAET;EAEA,OAAO;GACH,gBAAgB;GAChB,gBAAgB;EACpB;CACJ;CACA,MAAM;EACF,MAAM,EAAE,aAAa,mEAAmE;EACxF,SAAS;EACT,UAAU,EAAE,SAAS,kFAAkF;EACvG,QAAQ,CAAC;EACT,MAAM;CACV;AACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consistent-condition-layout.d.ts","names":[],"sources":["../../../src/internals/rules/consistent-condition-layout.ts"],"mappings":";;qBAUa,2BAA2B,KAAK"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { defineScriptAndTemplateVisitors } from "../utils.js";
|
|
2
|
+
//#region src/internals/rules/consistent-condition-layout.ts
|
|
3
|
+
const consistentConditionLayout = {
|
|
4
|
+
create(context) {
|
|
5
|
+
function createVisitor(tokenStore) {
|
|
6
|
+
const checkedOpeningOffsets = /* @__PURE__ */ new Set();
|
|
7
|
+
function collectOperators(node, operators) {
|
|
8
|
+
if (node.type !== "LogicalExpression" || node.operator !== "&&" && node.operator !== "||") return;
|
|
9
|
+
const operator = tokenStore.getTokensBetween(node.left, node.right).find((token) => token.type === "Punctuator" && token.value === node.operator);
|
|
10
|
+
function collectChild(child) {
|
|
11
|
+
const before = tokenStore.getTokenBefore(child);
|
|
12
|
+
const after = tokenStore.getTokenAfter(child);
|
|
13
|
+
if (before?.value === "(" && after?.value === ")" && before.range[0] >= node.range[0] && after.range[1] <= node.range[1]) return;
|
|
14
|
+
collectOperators(child, operators);
|
|
15
|
+
}
|
|
16
|
+
collectChild(node.left);
|
|
17
|
+
operators.push(operator);
|
|
18
|
+
collectChild(node.right);
|
|
19
|
+
}
|
|
20
|
+
function checkParentheses(node) {
|
|
21
|
+
let openingParen = tokenStore.getTokenBefore(node);
|
|
22
|
+
let closingParen = tokenStore.getTokenAfter(node);
|
|
23
|
+
let operators;
|
|
24
|
+
const newlineOffsets = [];
|
|
25
|
+
while (openingParen?.value === "(" && closingParen?.value === ")") {
|
|
26
|
+
if (!checkedOpeningOffsets.has(openingParen.range[0]) && openingParen.loc.start.line !== closingParen.loc.end.line) {
|
|
27
|
+
checkedOpeningOffsets.add(openingParen.range[0]);
|
|
28
|
+
if (!operators) {
|
|
29
|
+
operators = [];
|
|
30
|
+
collectOperators(node, operators);
|
|
31
|
+
}
|
|
32
|
+
const next = tokenStore.getTokenAfter(openingParen);
|
|
33
|
+
if (openingParen.loc.end.line === next.loc.start.line) newlineOffsets.push(openingParen.range[1]);
|
|
34
|
+
for (const operator of operators) if (tokenStore.getTokenBefore(operator).loc.end.line === operator.loc.start.line) newlineOffsets.push(operator.range[0]);
|
|
35
|
+
if (tokenStore.getTokenBefore(closingParen).loc.end.line === closingParen.loc.start.line) newlineOffsets.push(closingParen.range[0]);
|
|
36
|
+
}
|
|
37
|
+
openingParen = tokenStore.getTokenBefore(openingParen);
|
|
38
|
+
closingParen = tokenStore.getTokenAfter(closingParen);
|
|
39
|
+
operators = [];
|
|
40
|
+
}
|
|
41
|
+
if (newlineOffsets.length) context.report({
|
|
42
|
+
fix: (fixer) => newlineOffsets.map((offset) => fixer.insertTextBeforeRange([offset, offset], "\n")),
|
|
43
|
+
messageId: "newline",
|
|
44
|
+
node
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
BinaryExpression: (node) => {
|
|
49
|
+
if ([
|
|
50
|
+
"!=",
|
|
51
|
+
"!==",
|
|
52
|
+
"<",
|
|
53
|
+
"<=",
|
|
54
|
+
"==",
|
|
55
|
+
"===",
|
|
56
|
+
">",
|
|
57
|
+
">=",
|
|
58
|
+
"in",
|
|
59
|
+
"instanceof"
|
|
60
|
+
].includes(node.operator)) checkParentheses(node);
|
|
61
|
+
},
|
|
62
|
+
DoWhileStatement: (node) => checkParentheses(node.test),
|
|
63
|
+
IfStatement: (node) => checkParentheses(node.test),
|
|
64
|
+
LogicalExpression: (node) => {
|
|
65
|
+
if (node.operator === "&&" || node.operator === "||") checkParentheses(node);
|
|
66
|
+
},
|
|
67
|
+
UnaryExpression: (node) => {
|
|
68
|
+
if (node.operator === "!") checkParentheses(node);
|
|
69
|
+
},
|
|
70
|
+
WhileStatement: (node) => checkParentheses(node.test)
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return defineScriptAndTemplateVisitors(context.sourceCode, createVisitor);
|
|
74
|
+
},
|
|
75
|
+
meta: {
|
|
76
|
+
docs: { description: "Expand multiline parenthesized conditions one logical item per line." },
|
|
77
|
+
fixable: "whitespace",
|
|
78
|
+
messages: { newline: "Put each logical item and both parentheses on separate lines in a multiline condition." },
|
|
79
|
+
schema: [],
|
|
80
|
+
type: "layout"
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
//#endregion
|
|
84
|
+
export { consistentConditionLayout };
|
|
85
|
+
|
|
86
|
+
//# sourceMappingURL=consistent-condition-layout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consistent-condition-layout.js","names":[],"sources":["../../../src/internals/rules/consistent-condition-layout.ts"],"sourcesContent":["import type {\n AST,\n Rule,\n} from 'eslint';\n\nimport type { TokenStore } from '../utils';\nimport { defineScriptAndTemplateVisitors } from '../utils';\n\ntype LogicalNode = Extract<Rule.Node, { type: 'LogicalExpression' }>;\n\nexport const consistentConditionLayout: Rule.RuleModule = {\n create(context) {\n function createVisitor(tokenStore: TokenStore): Rule.RuleListener {\n const checkedOpeningOffsets = new Set<number>();\n\n function collectOperators(node: LogicalNode['left'], operators: AST.Token[]): void {\n if (node.type !== 'LogicalExpression' || (node.operator !== '&&' && node.operator !== '||')) return;\n const operator = tokenStore.getTokensBetween(node.left, node.right)\n .find((token) => token.type === 'Punctuator' && token.value === node.operator)!;\n\n function collectChild(child: LogicalNode['left']): void {\n const before = tokenStore.getTokenBefore(child);\n const after = tokenStore.getTokenAfter(child);\n if (\n before?.value === '('\n && after?.value === ')'\n && before.range[0] >= node.range![0]\n && after.range[1] <= node.range![1]\n ) return;\n\n collectOperators(child, operators);\n }\n\n collectChild(node.left);\n operators.push(operator);\n collectChild(node.right);\n }\n\n function checkParentheses(node: LogicalNode['left']): void {\n let openingParen = tokenStore.getTokenBefore(node);\n let closingParen = tokenStore.getTokenAfter(node);\n let operators: AST.Token[] | undefined;\n const newlineOffsets: number[] = [];\n while (openingParen?.value === '(' && closingParen?.value === ')') {\n if (\n !checkedOpeningOffsets.has(openingParen.range[0])\n && openingParen.loc.start.line !== closingParen.loc.end.line\n ) {\n checkedOpeningOffsets.add(openingParen.range[0]);\n if (!operators) {\n operators = [];\n collectOperators(node, operators);\n }\n\n const next = tokenStore.getTokenAfter(openingParen)!;\n if (openingParen.loc.end.line === next.loc.start.line) {\n newlineOffsets.push(openingParen.range[1]);\n }\n\n for (const operator of operators) {\n if (tokenStore.getTokenBefore(operator)!.loc.end.line === operator.loc.start.line) {\n newlineOffsets.push(operator.range[0]);\n }\n }\n\n if (tokenStore.getTokenBefore(closingParen)!.loc.end.line === closingParen.loc.start.line) {\n newlineOffsets.push(closingParen.range[0]);\n }\n }\n\n openingParen = tokenStore.getTokenBefore(openingParen);\n closingParen = tokenStore.getTokenAfter(closingParen);\n // An outer pair contains one grouped item, not the inner logical chain.\n operators = [];\n }\n\n if (newlineOffsets.length) {\n context.report({\n fix: (fixer) => newlineOffsets.map((offset) => fixer.insertTextBeforeRange(\n [\n offset,\n offset,\n ],\n '\\n',\n )),\n messageId: 'newline',\n node,\n });\n }\n }\n\n return {\n BinaryExpression: (node) => {\n if (\n [\n '!=',\n '!==',\n '<',\n '<=',\n '==',\n '===',\n '>',\n '>=',\n 'in',\n 'instanceof',\n ].includes(node.operator)\n ) checkParentheses(node);\n },\n DoWhileStatement: (node) => checkParentheses(node.test),\n IfStatement: (node) => checkParentheses(node.test),\n LogicalExpression: (node) => {\n if (node.operator === '&&' || node.operator === '||') checkParentheses(node);\n },\n UnaryExpression: (node) => {\n if (node.operator === '!') checkParentheses(node);\n },\n WhileStatement: (node) => checkParentheses(node.test),\n };\n }\n\n return defineScriptAndTemplateVisitors(context.sourceCode, createVisitor);\n },\n meta: {\n docs: { description: 'Expand multiline parenthesized conditions one logical item per line.' },\n fixable: 'whitespace',\n messages: { newline: 'Put each logical item and both parentheses on separate lines in a multiline condition.' },\n schema: [],\n type: 'layout',\n },\n};\n"],"mappings":";;AAUA,MAAa,4BAA6C;CACtD,OAAO,SAAS;EACZ,SAAS,cAAc,YAA2C;GAC9D,MAAM,wCAAwB,IAAI,IAAY;GAE9C,SAAS,iBAAiB,MAA2B,WAA8B;IAC/E,IAAI,KAAK,SAAS,uBAAwB,KAAK,aAAa,QAAQ,KAAK,aAAa,MAAO;IAC7F,MAAM,WAAW,WAAW,iBAAiB,KAAK,MAAM,KAAK,KAAK,CAAC,CAC9D,MAAM,UAAU,MAAM,SAAS,gBAAgB,MAAM,UAAU,KAAK,QAAQ;IAEjF,SAAS,aAAa,OAAkC;KACpD,MAAM,SAAS,WAAW,eAAe,KAAK;KAC9C,MAAM,QAAQ,WAAW,cAAc,KAAK;KAC5C,IACI,QAAQ,UAAU,OACf,OAAO,UAAU,OACjB,OAAO,MAAM,MAAM,KAAK,MAAO,MAC/B,MAAM,MAAM,MAAM,KAAK,MAAO,IACnC;KAEF,iBAAiB,OAAO,SAAS;IACrC;IAEA,aAAa,KAAK,IAAI;IACtB,UAAU,KAAK,QAAQ;IACvB,aAAa,KAAK,KAAK;GAC3B;GAEA,SAAS,iBAAiB,MAAiC;IACvD,IAAI,eAAe,WAAW,eAAe,IAAI;IACjD,IAAI,eAAe,WAAW,cAAc,IAAI;IAChD,IAAI;IACJ,MAAM,iBAA2B,CAAC;IAClC,OAAO,cAAc,UAAU,OAAO,cAAc,UAAU,KAAK;KAC/D,IACI,CAAC,sBAAsB,IAAI,aAAa,MAAM,EAAE,KAC7C,aAAa,IAAI,MAAM,SAAS,aAAa,IAAI,IAAI,MAC1D;MACE,sBAAsB,IAAI,aAAa,MAAM,EAAE;MAC/C,IAAI,CAAC,WAAW;OACZ,YAAY,CAAC;OACb,iBAAiB,MAAM,SAAS;MACpC;MAEA,MAAM,OAAO,WAAW,cAAc,YAAY;MAClD,IAAI,aAAa,IAAI,IAAI,SAAS,KAAK,IAAI,MAAM,MAC7C,eAAe,KAAK,aAAa,MAAM,EAAE;MAG7C,KAAK,MAAM,YAAY,WACnB,IAAI,WAAW,eAAe,QAAQ,CAAC,CAAE,IAAI,IAAI,SAAS,SAAS,IAAI,MAAM,MACzE,eAAe,KAAK,SAAS,MAAM,EAAE;MAI7C,IAAI,WAAW,eAAe,YAAY,CAAC,CAAE,IAAI,IAAI,SAAS,aAAa,IAAI,MAAM,MACjF,eAAe,KAAK,aAAa,MAAM,EAAE;KAEjD;KAEA,eAAe,WAAW,eAAe,YAAY;KACrD,eAAe,WAAW,cAAc,YAAY;KAEpD,YAAY,CAAC;IACjB;IAEA,IAAI,eAAe,QACf,QAAQ,OAAO;KACX,MAAM,UAAU,eAAe,KAAK,WAAW,MAAM,sBACjD,CACI,QACA,MACJ,GACA,IACJ,CAAC;KACD,WAAW;KACX;IACJ,CAAC;GAET;GAEA,OAAO;IACH,mBAAmB,SAAS;KACxB,IACI;MACI;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;KACJ,CAAC,CAAC,SAAS,KAAK,QAAQ,GAC1B,iBAAiB,IAAI;IAC3B;IACA,mBAAmB,SAAS,iBAAiB,KAAK,IAAI;IACtD,cAAc,SAAS,iBAAiB,KAAK,IAAI;IACjD,oBAAoB,SAAS;KACzB,IAAI,KAAK,aAAa,QAAQ,KAAK,aAAa,MAAM,iBAAiB,IAAI;IAC/E;IACA,kBAAkB,SAAS;KACvB,IAAI,KAAK,aAAa,KAAK,iBAAiB,IAAI;IACpD;IACA,iBAAiB,SAAS,iBAAiB,KAAK,IAAI;GACxD;EACJ;EAEA,OAAO,gCAAgC,QAAQ,YAAY,aAAa;CAC5E;CACA,MAAM;EACF,MAAM,EAAE,aAAa,uEAAuE;EAC5F,SAAS;EACT,UAAU,EAAE,SAAS,yFAAyF;EAC9G,QAAQ,CAAC;EACT,MAAM;CACV;AACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consistent-parameter-layout.d.ts","names":[],"sources":["../../../src/internals/rules/consistent-parameter-layout.ts"],"mappings":";;qBAaa,2BAA2B,KAAK"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { defineScriptAndTemplateVisitors } from "../utils.js";
|
|
2
|
+
//#region src/internals/rules/consistent-parameter-layout.ts
|
|
3
|
+
const consistentParameterLayout = {
|
|
4
|
+
create(context) {
|
|
5
|
+
const isTestFile = /\.test\.[jt]sx?$/.test(context.filename);
|
|
6
|
+
function checkParameterLayout(node, items, tokenStore, isTemplate) {
|
|
7
|
+
const first = items[0];
|
|
8
|
+
if (!first) return;
|
|
9
|
+
const isSingleParameter = items.length === 1;
|
|
10
|
+
const firstType = first.type;
|
|
11
|
+
if (isSingleParameter && (firstType === "JSXElement" || firstType === "JSXFragment")) return;
|
|
12
|
+
let openingParen;
|
|
13
|
+
if (node.type === "CallExpression" || node.type === "NewExpression") {
|
|
14
|
+
const call = node;
|
|
15
|
+
openingParen = tokenStore.getTokenAfter(call.typeArguments ?? call.callee, (token) => token.type === "Punctuator" && token.value === "(");
|
|
16
|
+
} else openingParen = tokenStore.getTokenBefore(first);
|
|
17
|
+
if (!openingParen || openingParen.value !== "(") return;
|
|
18
|
+
if (openingParen.range[0] < node.range[0]) return;
|
|
19
|
+
const closingParen = node.type === "CallExpression" || node.type === "NewExpression" ? tokenStore.getLastToken(node) : tokenStore.getTokenAfter(items.at(-1), (token) => token.value === ")");
|
|
20
|
+
const next = tokenStore.getTokenAfter(openingParen);
|
|
21
|
+
if (isSingleParameter) {
|
|
22
|
+
if (!closingParen || closingParen.value !== ")") return;
|
|
23
|
+
let previous = tokenStore.getTokenBefore(closingParen);
|
|
24
|
+
if (previous.value === ",") previous = tokenStore.getTokenBefore(previous);
|
|
25
|
+
if (tokenStore.commentsExistBetween(openingParen, next) || tokenStore.commentsExistBetween(previous, closingParen)) return;
|
|
26
|
+
const hasOpeningNewline = openingParen.loc.end.line !== next.loc.start.line;
|
|
27
|
+
if (hasOpeningNewline === (tokenStore.getTokenBefore(closingParen).loc.end.line !== closingParen.loc.start.line)) return;
|
|
28
|
+
context.report({
|
|
29
|
+
fix: (fixer) => hasOpeningNewline ? fixer.insertTextBefore(closingParen, "\n") : fixer.insertTextAfter(openingParen, "\n"),
|
|
30
|
+
messageId: "singleBoundary",
|
|
31
|
+
node
|
|
32
|
+
});
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (!closingParen || openingParen.loc.start.line === closingParen.loc.end.line) return;
|
|
36
|
+
if (isTemplate) {
|
|
37
|
+
const newlineOffsets = [];
|
|
38
|
+
if (openingParen.loc.end.line === next.loc.start.line) newlineOffsets.push(openingParen.range[1]);
|
|
39
|
+
for (let index = 1; index < items.length; index++) {
|
|
40
|
+
const item = items[index];
|
|
41
|
+
const comma = tokenStore.getTokensBetween(items[index - 1], item).find((token) => token.value === ",");
|
|
42
|
+
if (comma && comma.loc.end.line === tokenStore.getTokenAfter(comma).loc.start.line) newlineOffsets.push(comma.range[1]);
|
|
43
|
+
}
|
|
44
|
+
if (closingParen.value === ")" && tokenStore.getTokenBefore(closingParen).loc.end.line === closingParen.loc.start.line) newlineOffsets.push(closingParen.range[0]);
|
|
45
|
+
if (newlineOffsets.length) context.report({
|
|
46
|
+
fix: (fixer) => newlineOffsets.map((offset) => fixer.insertTextAfterRange([offset, offset], "\n")),
|
|
47
|
+
messageId: "newline",
|
|
48
|
+
node: first
|
|
49
|
+
});
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (openingParen.loc.end.line !== next.loc.start.line) return;
|
|
53
|
+
context.report({
|
|
54
|
+
fix: (fixer) => fixer.insertTextAfter(openingParen, "\n"),
|
|
55
|
+
messageId: "newline",
|
|
56
|
+
node: first
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function createVisitor(tokenStore, isTemplate) {
|
|
60
|
+
return {
|
|
61
|
+
ArrowFunctionExpression: (node) => checkParameterLayout(node, node.params, tokenStore, isTemplate),
|
|
62
|
+
CallExpression: (node) => {
|
|
63
|
+
const { callee } = node;
|
|
64
|
+
if (isTestFile) {
|
|
65
|
+
const target = callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier" && callee.property.name === "concurrent" ? callee.object : callee;
|
|
66
|
+
if (target.type === "Identifier" && (target.name === "describe" || target.name === "it")) return;
|
|
67
|
+
}
|
|
68
|
+
checkParameterLayout(node, node.arguments, tokenStore, isTemplate);
|
|
69
|
+
},
|
|
70
|
+
FunctionDeclaration: (node) => checkParameterLayout(node, node.params, tokenStore, isTemplate),
|
|
71
|
+
FunctionExpression: (node) => checkParameterLayout(node, node.params, tokenStore, isTemplate),
|
|
72
|
+
NewExpression: (node) => checkParameterLayout(node, node.arguments, tokenStore, isTemplate)
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return defineScriptAndTemplateVisitors(context.sourceCode, createVisitor);
|
|
76
|
+
},
|
|
77
|
+
meta: {
|
|
78
|
+
docs: { description: "Preserve consistent single-parameter boundaries and expand multiline parameter lists." },
|
|
79
|
+
fixable: "whitespace",
|
|
80
|
+
messages: {
|
|
81
|
+
newline: "Start a multiline parameter list on a new line.",
|
|
82
|
+
singleBoundary: "Use matching newline boundaries around a single parameter."
|
|
83
|
+
},
|
|
84
|
+
schema: [],
|
|
85
|
+
type: "layout"
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
//#endregion
|
|
89
|
+
export { consistentParameterLayout };
|
|
90
|
+
|
|
91
|
+
//# sourceMappingURL=consistent-parameter-layout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consistent-parameter-layout.js","names":[],"sources":["../../../src/internals/rules/consistent-parameter-layout.ts"],"sourcesContent":["import type { Rule } from 'eslint';\n\nimport type { TokenStore } from '../utils';\nimport { defineScriptAndTemplateVisitors } from '../utils';\n\ntype CallNode = Extract<Rule.Node, { type: 'CallExpression' | 'NewExpression' }> & { typeArguments?: Rule.Node };\ntype FunctionNode = Extract<\n Rule.Node,\n { type: 'ArrowFunctionExpression' | 'FunctionDeclaration' | 'FunctionExpression' }\n>;\n\ntype ListItem = CallNode['arguments'][number] | FunctionNode['params'][number];\n\nexport const consistentParameterLayout: Rule.RuleModule = {\n create(context) {\n const isTestFile = /\\.test\\.[jt]sx?$/.test(context.filename);\n\n function checkParameterLayout(\n node: Rule.Node,\n items: readonly ListItem[],\n tokenStore: TokenStore,\n isTemplate: boolean,\n ): void {\n const first = items[0];\n if (!first) return;\n const isSingleParameter = items.length === 1;\n\n // JSX argument layout belongs to the JSX formatting rules.\n const firstType: string = first.type;\n if (isSingleParameter && (firstType === 'JSXElement' || firstType === 'JSXFragment')) return;\n let openingParen;\n if (node.type === 'CallExpression' || node.type === 'NewExpression') {\n const call = node as CallNode;\n openingParen = tokenStore.getTokenAfter(\n call.typeArguments ?? call.callee,\n (token) => token.type === 'Punctuator' && token.value === '(',\n );\n } else {\n openingParen = tokenStore.getTokenBefore(first);\n }\n\n if (!openingParen || openingParen.value !== '(') return;\n // An unparenthesized arrow must not borrow its parent's delimiters.\n if (openingParen.range[0] < node.range![0]) return;\n const closingParen = node.type === 'CallExpression' || node.type === 'NewExpression'\n ? tokenStore.getLastToken(node)\n : tokenStore.getTokenAfter(items.at(-1)!, (token) => token.value === ')');\n\n const next = tokenStore.getTokenAfter(openingParen)!;\n\n if (isSingleParameter) {\n if (!closingParen || closingParen.value !== ')') return;\n let previous = tokenStore.getTokenBefore(closingParen)!;\n if (previous.value === ',') previous = tokenStore.getTokenBefore(previous)!;\n if (\n tokenStore.commentsExistBetween(openingParen, next)\n || tokenStore.commentsExistBetween(previous, closingParen)\n ) return;\n\n const hasOpeningNewline = openingParen.loc.end.line !== next.loc.start.line;\n const hasClosingNewline = tokenStore.getTokenBefore(closingParen)!.loc.end.line\n !== closingParen.loc.start.line;\n\n if (hasOpeningNewline === hasClosingNewline) return;\n\n context.report({\n fix: (fixer) => hasOpeningNewline\n ? fixer.insertTextBefore(closingParen, '\\n')\n : fixer.insertTextAfter(openingParen, '\\n'),\n messageId: 'singleBoundary',\n node,\n });\n\n return;\n }\n\n if (!closingParen || openingParen.loc.start.line === closingParen.loc.end.line) return;\n\n if (isTemplate) {\n // Script list formatters do not traverse Vue template expressions.\n const newlineOffsets: number[] = [];\n if (openingParen.loc.end.line === next.loc.start.line) newlineOffsets.push(openingParen.range[1]);\n for (let index = 1; index < items.length; index++) {\n const item = items[index]!;\n const comma = tokenStore.getTokensBetween(items[index - 1]!, item)\n .find((token) => token.value === ',');\n\n if (comma && comma.loc.end.line === tokenStore.getTokenAfter(comma)!.loc.start.line) {\n newlineOffsets.push(comma.range[1]);\n }\n }\n\n if (\n closingParen.value === ')'\n && tokenStore.getTokenBefore(closingParen)!.loc.end.line === closingParen.loc.start.line\n ) newlineOffsets.push(closingParen.range[0]);\n\n if (newlineOffsets.length) {\n context.report({\n fix: (fixer) => newlineOffsets.map((offset) => fixer.insertTextAfterRange(\n [\n offset,\n offset,\n ],\n '\\n',\n )),\n messageId: 'newline',\n node: first,\n });\n }\n\n return;\n }\n\n if (openingParen.loc.end.line !== next.loc.start.line) return;\n\n context.report({\n fix: (fixer) => fixer.insertTextAfter(openingParen, '\\n'),\n messageId: 'newline',\n node: first,\n });\n }\n\n function createVisitor(tokenStore: TokenStore, isTemplate: boolean): Rule.RuleListener {\n return {\n ArrowFunctionExpression: (node) => checkParameterLayout(node, node.params, tokenStore, isTemplate),\n CallExpression: (node) => {\n const { callee } = node;\n if (isTestFile) {\n const target = callee.type === 'MemberExpression'\n && !callee.computed\n && callee.property.type === 'Identifier'\n && callee.property.name === 'concurrent'\n ? callee.object\n : callee;\n\n if (\n target.type === 'Identifier'\n && (target.name === 'describe' || target.name === 'it')\n ) return;\n }\n\n checkParameterLayout(node, node.arguments, tokenStore, isTemplate);\n },\n FunctionDeclaration: (node) => checkParameterLayout(node, node.params, tokenStore, isTemplate),\n FunctionExpression: (node) => checkParameterLayout(node, node.params, tokenStore, isTemplate),\n NewExpression: (node) => checkParameterLayout(node, node.arguments, tokenStore, isTemplate),\n };\n }\n\n return defineScriptAndTemplateVisitors(context.sourceCode, createVisitor);\n },\n meta: {\n docs: { description: 'Preserve consistent single-parameter boundaries and expand multiline parameter lists.' },\n fixable: 'whitespace',\n messages: {\n newline: 'Start a multiline parameter list on a new line.',\n singleBoundary: 'Use matching newline boundaries around a single parameter.',\n },\n schema: [],\n type: 'layout',\n },\n};\n"],"mappings":";;AAaA,MAAa,4BAA6C;CACtD,OAAO,SAAS;EACZ,MAAM,aAAa,mBAAmB,KAAK,QAAQ,QAAQ;EAE3D,SAAS,qBACL,MACA,OACA,YACA,YACI;GACJ,MAAM,QAAQ,MAAM;GACpB,IAAI,CAAC,OAAO;GACZ,MAAM,oBAAoB,MAAM,WAAW;GAG3C,MAAM,YAAoB,MAAM;GAChC,IAAI,sBAAsB,cAAc,gBAAgB,cAAc,gBAAgB;GACtF,IAAI;GACJ,IAAI,KAAK,SAAS,oBAAoB,KAAK,SAAS,iBAAiB;IACjE,MAAM,OAAO;IACb,eAAe,WAAW,cACtB,KAAK,iBAAiB,KAAK,SAC1B,UAAU,MAAM,SAAS,gBAAgB,MAAM,UAAU,GAC9D;GACJ,OACI,eAAe,WAAW,eAAe,KAAK;GAGlD,IAAI,CAAC,gBAAgB,aAAa,UAAU,KAAK;GAEjD,IAAI,aAAa,MAAM,KAAK,KAAK,MAAO,IAAI;GAC5C,MAAM,eAAe,KAAK,SAAS,oBAAoB,KAAK,SAAS,kBAC/D,WAAW,aAAa,IAAI,IAC5B,WAAW,cAAc,MAAM,GAAG,EAAE,IAAK,UAAU,MAAM,UAAU,GAAG;GAE5E,MAAM,OAAO,WAAW,cAAc,YAAY;GAElD,IAAI,mBAAmB;IACnB,IAAI,CAAC,gBAAgB,aAAa,UAAU,KAAK;IACjD,IAAI,WAAW,WAAW,eAAe,YAAY;IACrD,IAAI,SAAS,UAAU,KAAK,WAAW,WAAW,eAAe,QAAQ;IACzE,IACI,WAAW,qBAAqB,cAAc,IAAI,KAC/C,WAAW,qBAAqB,UAAU,YAAY,GAC3D;IAEF,MAAM,oBAAoB,aAAa,IAAI,IAAI,SAAS,KAAK,IAAI,MAAM;IAIvE,IAAI,uBAHsB,WAAW,eAAe,YAAY,CAAC,CAAE,IAAI,IAAI,SACrE,aAAa,IAAI,MAAM,OAEgB;IAE7C,QAAQ,OAAO;KACX,MAAM,UAAU,oBACV,MAAM,iBAAiB,cAAc,IAAI,IACzC,MAAM,gBAAgB,cAAc,IAAI;KAC9C,WAAW;KACX;IACJ,CAAC;IAED;GACJ;GAEA,IAAI,CAAC,gBAAgB,aAAa,IAAI,MAAM,SAAS,aAAa,IAAI,IAAI,MAAM;GAEhF,IAAI,YAAY;IAEZ,MAAM,iBAA2B,CAAC;IAClC,IAAI,aAAa,IAAI,IAAI,SAAS,KAAK,IAAI,MAAM,MAAM,eAAe,KAAK,aAAa,MAAM,EAAE;IAChG,KAAK,IAAI,QAAQ,GAAG,QAAQ,MAAM,QAAQ,SAAS;KAC/C,MAAM,OAAO,MAAM;KACnB,MAAM,QAAQ,WAAW,iBAAiB,MAAM,QAAQ,IAAK,IAAI,CAAC,CAC7D,MAAM,UAAU,MAAM,UAAU,GAAG;KAExC,IAAI,SAAS,MAAM,IAAI,IAAI,SAAS,WAAW,cAAc,KAAK,CAAC,CAAE,IAAI,MAAM,MAC3E,eAAe,KAAK,MAAM,MAAM,EAAE;IAE1C;IAEA,IACI,aAAa,UAAU,OACpB,WAAW,eAAe,YAAY,CAAC,CAAE,IAAI,IAAI,SAAS,aAAa,IAAI,MAAM,MACtF,eAAe,KAAK,aAAa,MAAM,EAAE;IAE3C,IAAI,eAAe,QACf,QAAQ,OAAO;KACX,MAAM,UAAU,eAAe,KAAK,WAAW,MAAM,qBACjD,CACI,QACA,MACJ,GACA,IACJ,CAAC;KACD,WAAW;KACX,MAAM;IACV,CAAC;IAGL;GACJ;GAEA,IAAI,aAAa,IAAI,IAAI,SAAS,KAAK,IAAI,MAAM,MAAM;GAEvD,QAAQ,OAAO;IACX,MAAM,UAAU,MAAM,gBAAgB,cAAc,IAAI;IACxD,WAAW;IACX,MAAM;GACV,CAAC;EACL;EAEA,SAAS,cAAc,YAAwB,YAAwC;GACnF,OAAO;IACH,0BAA0B,SAAS,qBAAqB,MAAM,KAAK,QAAQ,YAAY,UAAU;IACjG,iBAAiB,SAAS;KACtB,MAAM,EAAE,WAAW;KACnB,IAAI,YAAY;MACZ,MAAM,SAAS,OAAO,SAAS,sBAC1B,CAAC,OAAO,YACR,OAAO,SAAS,SAAS,gBACzB,OAAO,SAAS,SAAS,eACxB,OAAO,SACP;MAEN,IACI,OAAO,SAAS,iBACZ,OAAO,SAAS,cAAc,OAAO,SAAS,OACpD;KACN;KAEA,qBAAqB,MAAM,KAAK,WAAW,YAAY,UAAU;IACrE;IACA,sBAAsB,SAAS,qBAAqB,MAAM,KAAK,QAAQ,YAAY,UAAU;IAC7F,qBAAqB,SAAS,qBAAqB,MAAM,KAAK,QAAQ,YAAY,UAAU;IAC5F,gBAAgB,SAAS,qBAAqB,MAAM,KAAK,WAAW,YAAY,UAAU;GAC9F;EACJ;EAEA,OAAO,gCAAgC,QAAQ,YAAY,aAAa;CAC5E;CACA,MAAM;EACF,MAAM,EAAE,aAAa,wFAAwF;EAC7G,SAAS;EACT,UAAU;GACN,SAAS;GACT,gBAAgB;EACpB;EACA,QAAQ,CAAC;EACT,MAAM;CACV;AACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"statement-padding.d.ts","names":[],"sources":["../../../src/internals/rules/statement-padding.ts"],"mappings":";;qBAIa,kBAAkB,KAAK"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
//#region src/internals/rules/statement-padding.ts
|
|
2
|
+
const statementPadding = {
|
|
3
|
+
create(context) {
|
|
4
|
+
const { sourceCode } = context;
|
|
5
|
+
function checkStatements(statements) {
|
|
6
|
+
for (let index = 1; index < statements.length; index++) {
|
|
7
|
+
const previous = statements[index - 1];
|
|
8
|
+
const next = statements[index];
|
|
9
|
+
const lastToken = sourceCode.getLastToken(previous);
|
|
10
|
+
const firstToken = sourceCode.getFirstToken(next);
|
|
11
|
+
const closingLine = sourceCode.lines[lastToken.loc.end.line - 1];
|
|
12
|
+
const openingLine = sourceCode.lines[firstToken.loc.start.line - 1];
|
|
13
|
+
const hasDifferentIndent = /^\s*/.exec(closingLine)[0] !== /^\s*/.exec(openingLine)[0];
|
|
14
|
+
const hasStandaloneClosing = /^[)\]}]+;?$/.test(closingLine.slice(0, lastToken.loc.end.column).trim());
|
|
15
|
+
const blockNode = previous.type === "ExportDefaultDeclaration" || previous.type === "ExportNamedDeclaration" ? previous.declaration : previous;
|
|
16
|
+
const hasBlockClosing = lastToken.value === "}" && blockNode && [
|
|
17
|
+
"BlockStatement",
|
|
18
|
+
"ClassDeclaration",
|
|
19
|
+
"ForInStatement",
|
|
20
|
+
"ForOfStatement",
|
|
21
|
+
"ForStatement",
|
|
22
|
+
"FunctionDeclaration",
|
|
23
|
+
"IfStatement",
|
|
24
|
+
"LabeledStatement",
|
|
25
|
+
"SwitchStatement",
|
|
26
|
+
"TryStatement",
|
|
27
|
+
"WhileStatement",
|
|
28
|
+
"WithStatement"
|
|
29
|
+
].includes(blockNode.type);
|
|
30
|
+
if (!hasDifferentIndent && !hasStandaloneClosing && !hasBlockClosing) continue;
|
|
31
|
+
const comments = sourceCode.getCommentsBefore(next);
|
|
32
|
+
if (sourceCode.lines.slice(lastToken.loc.end.line, firstToken.loc.start.line - 1).some((line, index) => !line.trim() && !comments.some((comment) => comment.loc.start.line <= lastToken.loc.end.line + index + 1 && comment.loc.end.line >= lastToken.loc.end.line + index + 1))) continue;
|
|
33
|
+
const boundary = comments.find((comment) => comment.loc.start.line > lastToken.loc.end.line) ?? firstToken;
|
|
34
|
+
const offset = boundary.loc.start.line > lastToken.loc.end.line ? boundary.range[0] - boundary.loc.start.column : boundary.range[0];
|
|
35
|
+
context.report({
|
|
36
|
+
fix: (fixer) => fixer.insertTextBeforeRange([offset, offset], boundary.loc.start.line === lastToken.loc.end.line ? "\n\n" : "\n"),
|
|
37
|
+
messageId: "blankLine",
|
|
38
|
+
node: next
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
BlockStatement: (node) => checkStatements(node.body),
|
|
44
|
+
Program: (node) => checkStatements(node.body),
|
|
45
|
+
StaticBlock: (node) => checkStatements(node.body),
|
|
46
|
+
SwitchCase: (node) => checkStatements(node.consequent)
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
meta: {
|
|
50
|
+
docs: { description: "Separate statements after closing lines, blocks, or indentation changes." },
|
|
51
|
+
fixable: "whitespace",
|
|
52
|
+
messages: { blankLine: "Add a blank line between these complete statements." },
|
|
53
|
+
schema: [],
|
|
54
|
+
type: "layout"
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
//#endregion
|
|
58
|
+
export { statementPadding };
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=statement-padding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"statement-padding.js","names":[],"sources":["../../../src/internals/rules/statement-padding.ts"],"sourcesContent":["import type { Rule } from 'eslint';\n\ntype StatementNode = Extract<Rule.Node, { type: 'Program' }>['body'][number];\n\nexport const statementPadding: Rule.RuleModule = {\n create(context) {\n const { sourceCode } = context;\n\n function checkStatements(statements: readonly StatementNode[]): void {\n for (let index = 1; index < statements.length; index++) {\n const previous = statements[index - 1]!;\n const next = statements[index]!;\n const lastToken = sourceCode.getLastToken(previous)!;\n const firstToken = sourceCode.getFirstToken(next)!;\n const closingLine = sourceCode.lines[lastToken.loc.end.line - 1]!;\n const openingLine = sourceCode.lines[firstToken.loc.start.line - 1]!;\n const hasDifferentIndent = /^\\s*/.exec(closingLine)![0] !== /^\\s*/.exec(openingLine)![0];\n const hasStandaloneClosing = /^[)\\]}]+;?$/.test(closingLine.slice(0, lastToken.loc.end.column).trim());\n const blockNode = previous.type === 'ExportDefaultDeclaration'\n || previous.type === 'ExportNamedDeclaration'\n ? previous.declaration\n : previous;\n\n const hasBlockClosing = lastToken.value === '}' && blockNode && [\n 'BlockStatement',\n 'ClassDeclaration',\n 'ForInStatement',\n 'ForOfStatement',\n 'ForStatement',\n 'FunctionDeclaration',\n 'IfStatement',\n 'LabeledStatement',\n 'SwitchStatement',\n 'TryStatement',\n 'WhileStatement',\n 'WithStatement',\n ].includes(blockNode.type);\n\n if (!hasDifferentIndent && !hasStandaloneClosing && !hasBlockClosing) continue;\n const comments = sourceCode.getCommentsBefore(next);\n if (\n sourceCode\n .lines\n .slice(lastToken.loc.end.line, firstToken.loc.start.line - 1)\n .some((line, index) => !line.trim() && !comments.some((comment) =>\n comment.loc!.start.line <= lastToken.loc.end.line + index + 1\n && comment.loc!.end.line >= lastToken.loc.end.line + index + 1))\n ) continue;\n\n // Keep leading comments attached to the next statement and trailing comments in place.\n const boundary = comments\n .find((comment) => comment.loc!.start.line > lastToken.loc.end.line) ?? firstToken;\n\n const offset = boundary.loc!.start.line > lastToken.loc.end.line\n ? boundary.range![0] - boundary.loc!.start.column\n : boundary.range![0];\n\n context.report({\n fix: (fixer) => fixer.insertTextBeforeRange(\n [\n offset,\n offset,\n ],\n boundary.loc!.start.line === lastToken.loc.end.line ? '\\n\\n' : '\\n',\n ),\n messageId: 'blankLine',\n node: next,\n });\n }\n }\n\n return {\n BlockStatement: (node) => checkStatements(node.body),\n Program: (node) => checkStatements(node.body),\n StaticBlock: (node) => checkStatements(node.body),\n SwitchCase: (node) => checkStatements(node.consequent),\n };\n },\n meta: {\n docs: { description: 'Separate statements after closing lines, blocks, or indentation changes.' },\n fixable: 'whitespace',\n messages: { blankLine: 'Add a blank line between these complete statements.' },\n schema: [],\n type: 'layout',\n },\n};\n"],"mappings":";AAIA,MAAa,mBAAoC;CAC7C,OAAO,SAAS;EACZ,MAAM,EAAE,eAAe;EAEvB,SAAS,gBAAgB,YAA4C;GACjE,KAAK,IAAI,QAAQ,GAAG,QAAQ,WAAW,QAAQ,SAAS;IACpD,MAAM,WAAW,WAAW,QAAQ;IACpC,MAAM,OAAO,WAAW;IACxB,MAAM,YAAY,WAAW,aAAa,QAAQ;IAClD,MAAM,aAAa,WAAW,cAAc,IAAI;IAChD,MAAM,cAAc,WAAW,MAAM,UAAU,IAAI,IAAI,OAAO;IAC9D,MAAM,cAAc,WAAW,MAAM,WAAW,IAAI,MAAM,OAAO;IACjE,MAAM,qBAAqB,OAAO,KAAK,WAAW,CAAC,CAAE,OAAO,OAAO,KAAK,WAAW,CAAC,CAAE;IACtF,MAAM,uBAAuB,cAAc,KAAK,YAAY,MAAM,GAAG,UAAU,IAAI,IAAI,MAAM,CAAC,CAAC,KAAK,CAAC;IACrG,MAAM,YAAY,SAAS,SAAS,8BAC/B,SAAS,SAAS,2BACjB,SAAS,cACT;IAEN,MAAM,kBAAkB,UAAU,UAAU,OAAO,aAAa;KAC5D;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;IACJ,CAAC,CAAC,SAAS,UAAU,IAAI;IAEzB,IAAI,CAAC,sBAAsB,CAAC,wBAAwB,CAAC,iBAAiB;IACtE,MAAM,WAAW,WAAW,kBAAkB,IAAI;IAClD,IACI,WACK,MACA,MAAM,UAAU,IAAI,IAAI,MAAM,WAAW,IAAI,MAAM,OAAO,CAAC,CAAC,CAC5D,MAAM,MAAM,UAAU,CAAC,KAAK,KAAK,KAAK,CAAC,SAAS,MAAM,YACnD,QAAQ,IAAK,MAAM,QAAQ,UAAU,IAAI,IAAI,OAAO,QAAQ,KACzD,QAAQ,IAAK,IAAI,QAAQ,UAAU,IAAI,IAAI,OAAO,QAAQ,CAAC,CAAC,GACzE;IAGF,MAAM,WAAW,SACZ,MAAM,YAAY,QAAQ,IAAK,MAAM,OAAO,UAAU,IAAI,IAAI,IAAI,KAAK;IAE5E,MAAM,SAAS,SAAS,IAAK,MAAM,OAAO,UAAU,IAAI,IAAI,OACtD,SAAS,MAAO,KAAK,SAAS,IAAK,MAAM,SACzC,SAAS,MAAO;IAEtB,QAAQ,OAAO;KACX,MAAM,UAAU,MAAM,sBAClB,CACI,QACA,MACJ,GACA,SAAS,IAAK,MAAM,SAAS,UAAU,IAAI,IAAI,OAAO,SAAS,IACnE;KACA,WAAW;KACX,MAAM;IACV,CAAC;GACL;EACJ;EAEA,OAAO;GACH,iBAAiB,SAAS,gBAAgB,KAAK,IAAI;GACnD,UAAU,SAAS,gBAAgB,KAAK,IAAI;GAC5C,cAAc,SAAS,gBAAgB,KAAK,IAAI;GAChD,aAAa,SAAS,gBAAgB,KAAK,UAAU;EACzD;CACJ;CACA,MAAM;EACF,MAAM,EAAE,aAAa,2EAA2E;EAChG,SAAS;EACT,UAAU,EAAE,WAAW,sDAAsD;EAC7E,QAAQ,CAAC;EACT,MAAM;CACV;AACJ"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Rule, SourceCode } from "eslint";
|
|
2
|
+
//#region src/internals/utils.d.ts
|
|
3
|
+
export type TokenStore = Pick<SourceCode, 'commentsExistBetween' | 'getLastToken' | 'getTokenAfter' | 'getTokenBefore' | 'getTokensBetween'>;
|
|
4
|
+
export declare function defineScriptAndTemplateVisitors(sourceCode: SourceCode, createVisitor: (tokenStore: TokenStore, isTemplate: boolean) => Rule.RuleListener): Rule.RuleListener;
|
|
5
|
+
//#endregion
|
|
6
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","names":[],"sources":["../../src/internals/utils.ts"],"mappings":";;YAKY,aAAa,KACrB;wBAaY,gCACZ,YAAY,YACZ,gBAAgB,YAAY,YAAY,wBAAwB,KAAK,eACtE,KAAK"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/internals/utils.ts
|
|
2
|
+
function defineScriptAndTemplateVisitors(sourceCode, createVisitor) {
|
|
3
|
+
const scriptVisitor = createVisitor(sourceCode, false);
|
|
4
|
+
const parserServices = sourceCode.parserServices;
|
|
5
|
+
if (!parserServices.defineTemplateBodyVisitor || !parserServices.getTemplateBodyTokenStore) return scriptVisitor;
|
|
6
|
+
return parserServices.defineTemplateBodyVisitor(createVisitor(parserServices.getTemplateBodyTokenStore(), true), scriptVisitor);
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { defineScriptAndTemplateVisitors };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["../../src/internals/utils.ts"],"sourcesContent":["import type {\n Rule,\n SourceCode,\n} from 'eslint';\n\nexport type TokenStore = Pick<\n SourceCode,\n 'commentsExistBetween' | 'getLastToken' | 'getTokenAfter' | 'getTokenBefore' | 'getTokensBetween'\n>;\n\ninterface TemplateParserServices {\n defineTemplateBodyVisitor?: (\n templateVisitor: Rule.RuleListener,\n scriptVisitor: Rule.RuleListener,\n ) => Rule.RuleListener;\n\n getTemplateBodyTokenStore?: () => TokenStore;\n}\n\nexport function defineScriptAndTemplateVisitors(\n sourceCode: SourceCode,\n createVisitor: (tokenStore: TokenStore, isTemplate: boolean) => Rule.RuleListener,\n): Rule.RuleListener {\n const scriptVisitor = createVisitor(sourceCode, false);\n const parserServices = sourceCode.parserServices as TemplateParserServices;\n if (!parserServices.defineTemplateBodyVisitor || !parserServices.getTemplateBodyTokenStore) return scriptVisitor;\n\n return parserServices.defineTemplateBodyVisitor(\n createVisitor(parserServices.getTemplateBodyTokenStore(), true),\n scriptVisitor,\n );\n}\n"],"mappings":";AAmBA,SAAgB,gCACZ,YACA,eACiB;CACjB,MAAM,gBAAgB,cAAc,YAAY,KAAK;CACrD,MAAM,iBAAiB,WAAW;CAClC,IAAI,CAAC,eAAe,6BAA6B,CAAC,eAAe,2BAA2B,OAAO;CAEnG,OAAO,eAAe,0BAClB,cAAc,eAAe,0BAA0B,GAAG,IAAI,GAC9D,aACJ;AACJ"}
|
package/dist/style.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { TypedFlatConfigItem } from "@antfu/eslint-config";
|
|
2
|
-
|
|
3
2
|
//#region src/style.d.ts
|
|
4
|
-
declare function createStyleFilesConfigs(): TypedFlatConfigItem[];
|
|
3
|
+
export declare function createStyleFilesConfigs(): TypedFlatConfigItem[];
|
|
5
4
|
//#endregion
|
|
6
|
-
export { createStyleFilesConfigs };
|
|
7
5
|
//# sourceMappingURL=style.d.ts.map
|
package/dist/style.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style.d.ts","names":[],"sources":["../src/style.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"style.d.ts","names":[],"sources":["../src/style.ts"],"mappings":";;wBAsBgB,2BAA2B"}
|
package/dist/vue.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { TypedFlatConfigItem } from "@antfu/eslint-config";
|
|
2
|
-
|
|
3
2
|
//#region src/vue.d.ts
|
|
4
|
-
declare function createVueConfig(environment?: 'bun' | 'node'): TypedFlatConfigItem;
|
|
3
|
+
export declare function createVueConfig(environment?: 'bun' | 'node'): TypedFlatConfigItem;
|
|
5
4
|
//#endregion
|
|
6
|
-
export { createVueConfig };
|
|
7
5
|
//# sourceMappingURL=vue.d.ts.map
|
package/dist/vue.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vue.d.ts","names":[],"sources":["../src/vue.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"vue.d.ts","names":[],"sources":["../src/vue.ts"],"mappings":";;wBASgB,gBAAgB,+BAAuC"}
|