@kikiutils/eslint-config 11.5.0 → 12.0.1
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/README.md +41 -23
- package/dist/_internals/configs/base-rules.d.ts.map +1 -1
- package/dist/_internals/configs/base-rules.js +37 -37
- package/dist/_internals/configs/base-rules.js.map +1 -1
- package/dist/_internals/configs/jsdoc.d.ts +0 -36
- package/dist/_internals/configs/jsdoc.d.ts.map +1 -1
- package/dist/_internals/configs/jsdoc.js +1 -42
- package/dist/_internals/configs/jsdoc.js.map +1 -1
- package/dist/_internals/configs/type-aware.d.ts.map +1 -1
- package/dist/_internals/configs/type-aware.js +26 -1
- package/dist/_internals/configs/type-aware.js.map +1 -1
- package/dist/_internals/configs/typescript.d.ts +42 -0
- package/dist/_internals/configs/typescript.d.ts.map +1 -0
- package/dist/_internals/configs/typescript.js +49 -0
- package/dist/_internals/configs/typescript.js.map +1 -0
- package/dist/_internals/eslint-plugin-promise.d.ts +7 -0
- package/dist/_internals/eslint-plugin-promise.d.ts.map +1 -0
- package/dist/_internals/rules/consistent-condition-layout.d.ts.map +1 -1
- package/dist/_internals/rules/consistent-condition-layout.js +15 -14
- package/dist/_internals/rules/consistent-condition-layout.js.map +1 -1
- package/dist/_internals/rules/consistent-parameter-layout.d.ts.map +1 -1
- package/dist/_internals/rules/consistent-parameter-layout.js +17 -11
- package/dist/_internals/rules/consistent-parameter-layout.js.map +1 -1
- package/dist/_internals/rules/index.d.ts +7 -1
- package/dist/_internals/rules/index.d.ts.map +1 -1
- package/dist/_internals/rules/index.js +11 -2
- package/dist/_internals/rules/index.js.map +1 -1
- package/dist/_internals/rules/no-composable-in-head-getter.d.ts.map +1 -1
- package/dist/_internals/rules/no-composable-in-head-getter.js +97 -19
- package/dist/_internals/rules/no-composable-in-head-getter.js.map +1 -1
- package/dist/_internals/rules/no-reactive-composable-return.d.ts +3 -0
- package/dist/_internals/rules/no-reactive-composable-return.d.ts.map +1 -0
- package/dist/_internals/rules/no-reactive-composable-return.js +43 -0
- package/dist/_internals/rules/no-reactive-composable-return.js.map +1 -0
- package/dist/_internals/rules/no-reactive-destructure.d.ts +3 -0
- package/dist/_internals/rules/no-reactive-destructure.d.ts.map +1 -0
- package/dist/_internals/rules/no-reactive-destructure.js +44 -0
- package/dist/_internals/rules/no-reactive-destructure.js.map +1 -0
- package/dist/_internals/rules/no-silent-catch.d.ts.map +1 -1
- package/dist/_internals/rules/no-silent-catch.js +3 -2
- package/dist/_internals/rules/no-silent-catch.js.map +1 -1
- package/dist/_internals/rules/no-thenable-zod-refinement.d.ts.map +1 -1
- package/dist/_internals/rules/no-thenable-zod-refinement.js +9 -3
- package/dist/_internals/rules/no-thenable-zod-refinement.js.map +1 -1
- package/dist/_internals/rules/prefer-enhanced-date.d.ts +3 -0
- package/dist/_internals/rules/prefer-enhanced-date.d.ts.map +1 -0
- package/dist/_internals/rules/prefer-enhanced-date.js +307 -0
- package/dist/_internals/rules/prefer-enhanced-date.js.map +1 -0
- package/dist/_internals/rules/promise-function-async.d.ts.map +1 -1
- package/dist/_internals/rules/promise-function-async.js.map +1 -1
- package/dist/_internals/rules/statement-padding.d.ts.map +1 -1
- package/dist/_internals/rules/statement-padding.js +19 -15
- package/dist/_internals/rules/statement-padding.js.map +1 -1
- package/dist/_internals/rules/utils.d.ts +23 -0
- package/dist/_internals/rules/utils.d.ts.map +1 -0
- package/dist/_internals/rules/utils.js +17 -0
- package/dist/_internals/rules/utils.js.map +1 -0
- package/dist/_internals/rules/vue-reactivity.d.ts +3 -0
- package/dist/_internals/rules/vue-reactivity.d.ts.map +1 -0
- package/dist/_internals/rules/vue-reactivity.js +30 -0
- package/dist/_internals/rules/vue-reactivity.js.map +1 -0
- package/dist/base.d.ts.map +1 -1
- package/dist/base.js +57 -29
- package/dist/base.js.map +1 -1
- package/dist/nuxt.d.ts +3 -1
- package/dist/nuxt.d.ts.map +1 -1
- package/dist/nuxt.js +53 -3
- package/dist/nuxt.js.map +1 -1
- package/dist/style.d.ts.map +1 -1
- package/dist/style.js +1 -0
- package/dist/style.js.map +1 -1
- package/dist/vue.d.ts +1 -1
- package/dist/vue.d.ts.map +1 -1
- package/dist/vue.js +17 -19
- package/dist/vue.js.map +1 -1
- package/package.json +6 -5
- package/src/_internals/configs/base-rules.ts +29 -44
- package/src/_internals/configs/jsdoc.ts +0 -51
- package/src/_internals/configs/type-aware.ts +29 -1
- package/src/_internals/configs/typescript.ts +62 -0
- package/src/_internals/eslint-plugin-promise.d.ts +6 -0
- package/src/_internals/rules/consistent-condition-layout.ts +20 -23
- package/src/_internals/rules/consistent-parameter-layout.ts +30 -34
- package/src/_internals/rules/index.ts +10 -1
- package/src/_internals/rules/no-composable-in-head-getter.ts +132 -26
- package/src/_internals/rules/no-reactive-composable-return.ts +55 -0
- package/src/_internals/rules/no-reactive-destructure.ts +64 -0
- package/src/_internals/rules/no-silent-catch.ts +4 -10
- package/src/_internals/rules/no-thenable-zod-refinement.ts +14 -9
- package/src/_internals/rules/prefer-enhanced-date.ts +448 -0
- package/src/_internals/rules/promise-function-async.ts +2 -6
- package/src/_internals/rules/statement-padding.ts +23 -24
- package/src/_internals/{utils.ts → rules/utils.ts} +31 -0
- package/src/_internals/rules/vue-reactivity.ts +42 -0
- package/src/base.ts +55 -47
- package/src/nuxt.ts +90 -5
- package/src/style.ts +1 -0
- package/src/vue.ts +24 -26
- package/dist/_internals/configs/restricted-syntax.d.ts +0 -5
- package/dist/_internals/configs/restricted-syntax.d.ts.map +0 -1
- package/dist/_internals/configs/restricted-syntax.js +0 -12
- package/dist/_internals/configs/restricted-syntax.js.map +0 -1
- package/dist/_internals/configs/typefest.d.ts +0 -3
- package/dist/_internals/configs/typefest.d.ts.map +0 -1
- package/dist/_internals/configs/typefest.js +0 -21
- package/dist/_internals/configs/typefest.js.map +0 -1
- package/dist/_internals/utils.d.ts +0 -4
- package/dist/_internals/utils.d.ts.map +0 -1
- package/dist/_internals/utils.js +0 -10
- package/dist/_internals/utils.js.map +0 -1
- package/src/_internals/configs/restricted-syntax.ts +0 -8
- package/src/_internals/configs/typefest.ts +0 -19
package/src/base.ts
CHANGED
|
@@ -6,21 +6,16 @@ import {
|
|
|
6
6
|
GLOB_TS,
|
|
7
7
|
GLOB_TSX,
|
|
8
8
|
} from '@antfu/eslint-config';
|
|
9
|
-
// @ts-expect-error No declare file.
|
|
10
9
|
import promise from 'eslint-plugin-promise';
|
|
11
10
|
|
|
12
11
|
import { createBaseRules } from './_internals/configs/base-rules';
|
|
13
|
-
import {
|
|
14
|
-
jsdocSettings,
|
|
15
|
-
typescriptJsdocConfig,
|
|
16
|
-
} from './_internals/configs/jsdoc';
|
|
12
|
+
import { jsdocSettings } from './_internals/configs/jsdoc';
|
|
17
13
|
import { createTypeAwareConfig } from './_internals/configs/type-aware';
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
14
|
+
import { typescriptConfig } from './_internals/configs/typescript';
|
|
15
|
+
import { kikiutilsPlugin } from './_internals/rules';
|
|
20
16
|
|
|
21
17
|
export { createBaseRules };
|
|
22
18
|
|
|
23
|
-
// Constants/Variables
|
|
24
19
|
const vscodeOrderSensitiveArrayProperties = [
|
|
25
20
|
'args',
|
|
26
21
|
'autoAttachSmartPattern',
|
|
@@ -33,11 +28,12 @@ const vscodeOrderSensitiveArrayProperties = [
|
|
|
33
28
|
'skipFiles',
|
|
34
29
|
].join('|');
|
|
35
30
|
|
|
36
|
-
|
|
31
|
+
const testSleepMessage = 'A fixed wait makes tests slow and flaky. Use fake timers for timer-driven code, or wait for the event or condition itself, such as with `vi.waitFor()`. To assert that something has not happened yet, await one event loop turn with `setImmediate` from `node:timers/promises`.';
|
|
32
|
+
|
|
37
33
|
export function createBaseConfigs(environment: 'bun' | 'node' = 'node'): TypedFlatConfigItem[] {
|
|
38
34
|
return [
|
|
39
|
-
// All files
|
|
40
35
|
{
|
|
36
|
+
name: 'kikiutils/base',
|
|
41
37
|
rules: {
|
|
42
38
|
'e18e/ban-dependencies': [
|
|
43
39
|
'error',
|
|
@@ -50,8 +46,8 @@ export function createBaseConfigs(environment: 'bun' | 'node' = 'node'): TypedFl
|
|
|
50
46
|
],
|
|
51
47
|
},
|
|
52
48
|
},
|
|
53
|
-
// JavaScript and TypeScript
|
|
54
49
|
{
|
|
50
|
+
name: 'kikiutils/javascript',
|
|
55
51
|
files: [
|
|
56
52
|
GLOB_JS,
|
|
57
53
|
GLOB_JSX,
|
|
@@ -59,7 +55,7 @@ export function createBaseConfigs(environment: 'bun' | 'node' = 'node'): TypedFl
|
|
|
59
55
|
GLOB_TSX,
|
|
60
56
|
],
|
|
61
57
|
plugins: {
|
|
62
|
-
kikiutils:
|
|
58
|
+
kikiutils: kikiutilsPlugin,
|
|
63
59
|
promise,
|
|
64
60
|
},
|
|
65
61
|
rules: {
|
|
@@ -71,46 +67,25 @@ export function createBaseConfigs(environment: 'bun' | 'node' = 'node'): TypedFl
|
|
|
71
67
|
},
|
|
72
68
|
settings: jsdocSettings,
|
|
73
69
|
},
|
|
74
|
-
// TypeScript
|
|
75
70
|
{
|
|
71
|
+
...typescriptConfig,
|
|
72
|
+
name: 'kikiutils/typescript',
|
|
76
73
|
files: [
|
|
77
74
|
GLOB_TS,
|
|
78
75
|
GLOB_TSX,
|
|
79
76
|
],
|
|
80
|
-
rules: {
|
|
81
|
-
...typescriptJsdocConfig.rules,
|
|
82
|
-
'ts/array-type': [
|
|
83
|
-
'error',
|
|
84
|
-
{ default: 'array-simple' },
|
|
85
|
-
],
|
|
86
|
-
'ts/consistent-generic-constructors': [
|
|
87
|
-
'error',
|
|
88
|
-
'constructor',
|
|
89
|
-
],
|
|
90
|
-
'ts/no-redeclare': 'off',
|
|
91
|
-
},
|
|
92
|
-
settings: typescriptJsdocConfig.settings,
|
|
93
77
|
},
|
|
94
|
-
// Type-aware TypeScript
|
|
95
78
|
{
|
|
96
79
|
...createTypeAwareConfig(),
|
|
80
|
+
name: 'kikiutils/type-aware',
|
|
97
81
|
files: [
|
|
98
82
|
GLOB_TS,
|
|
99
83
|
GLOB_TSX,
|
|
100
84
|
],
|
|
101
85
|
ignores: ['**/*.config.?([cm])ts'],
|
|
102
86
|
},
|
|
103
|
-
// Type-fest and ts-extras
|
|
104
|
-
{
|
|
105
|
-
...createTypefestConfig(),
|
|
106
|
-
files: [
|
|
107
|
-
GLOB_TS,
|
|
108
|
-
GLOB_TSX,
|
|
109
|
-
],
|
|
110
|
-
ignores: ['**/*.config.?([cm])ts'],
|
|
111
|
-
},
|
|
112
|
-
// Tests
|
|
113
87
|
{
|
|
88
|
+
name: 'kikiutils/tests',
|
|
114
89
|
files: GLOB_TESTS,
|
|
115
90
|
rules: {
|
|
116
91
|
'kikiutils/consistent-parameter-layout': [
|
|
@@ -126,9 +101,33 @@ export function createBaseConfigs(environment: 'bun' | 'node' = 'node'): TypedFl
|
|
|
126
101
|
message: 'Use `expect` from the test context.',
|
|
127
102
|
name: 'vitest',
|
|
128
103
|
},
|
|
104
|
+
...[
|
|
105
|
+
'node:timers/promises',
|
|
106
|
+
'timers/promises',
|
|
107
|
+
].map((name) => ({
|
|
108
|
+
importNames: ['setTimeout'],
|
|
109
|
+
message: testSleepMessage,
|
|
110
|
+
name,
|
|
111
|
+
})),
|
|
129
112
|
],
|
|
130
113
|
},
|
|
131
114
|
],
|
|
115
|
+
'kikiutils/no-restricted-test-syntax': [
|
|
116
|
+
'error',
|
|
117
|
+
{
|
|
118
|
+
message: testSleepMessage,
|
|
119
|
+
selector: [
|
|
120
|
+
'NewExpression[callee.name="Promise"] > :function > CallExpression.body[callee.name="setTimeout"]',
|
|
121
|
+
'NewExpression[callee.name="Promise"] > :function > BlockStatement > ExpressionStatement > CallExpression[callee.name="setTimeout"]',
|
|
122
|
+
'CallExpression[callee.object.name="Bun"][callee.property.name=/^sleep(Sync)?$/]',
|
|
123
|
+
].join(', '),
|
|
124
|
+
},
|
|
125
|
+
// An implementation types the mock; only an empty one falls back to `(...args: any[]) => any`.
|
|
126
|
+
{
|
|
127
|
+
message: 'An empty `vi.fn()` is typed `(...args: any[]) => any`; pass a type parameter or an implementation.',
|
|
128
|
+
selector: 'CallExpression[callee.object.name="vi"][callee.property.name="fn"][arguments.length=0]:not([typeArguments])',
|
|
129
|
+
},
|
|
130
|
+
],
|
|
132
131
|
'test/consistent-each-for': [
|
|
133
132
|
'error',
|
|
134
133
|
{
|
|
@@ -136,6 +135,11 @@ export function createBaseConfigs(environment: 'bun' | 'node' = 'node'): TypedFl
|
|
|
136
135
|
test: 'for',
|
|
137
136
|
},
|
|
138
137
|
],
|
|
138
|
+
'test/expect-expect': 'error',
|
|
139
|
+
'test/no-commented-out-tests': 'error',
|
|
140
|
+
'test/no-conditional-expect': 'error',
|
|
141
|
+
'test/no-disabled-tests': 'error',
|
|
142
|
+
'test/no-standalone-expect': 'error',
|
|
139
143
|
'test/prefer-each': 'error',
|
|
140
144
|
'test/prefer-hooks-on-top': 'error',
|
|
141
145
|
'test/prefer-lowercase-title': [
|
|
@@ -146,20 +150,18 @@ export function createBaseConfigs(environment: 'bun' | 'node' = 'node'): TypedFl
|
|
|
146
150
|
},
|
|
147
151
|
],
|
|
148
152
|
'test/prefer-to-be': 'error',
|
|
153
|
+
'test/prefer-vi-mocked': 'error',
|
|
154
|
+
'test/require-to-throw-message': 'error',
|
|
149
155
|
'test/valid-describe-callback': 'error',
|
|
150
156
|
'test/valid-expect': 'error',
|
|
151
157
|
'test/valid-expect-in-promise': 'error',
|
|
152
|
-
'test/valid-title':
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
mustMatch: { it: '^should ' },
|
|
156
|
-
mustNotMatch: { it: String.raw`\.$` },
|
|
157
|
-
},
|
|
158
|
-
],
|
|
158
|
+
'test/valid-title': 'error',
|
|
159
|
+
// Mocks and partial fixtures often need `any`.
|
|
160
|
+
'ts/no-explicit-any': 'off',
|
|
159
161
|
},
|
|
160
162
|
},
|
|
161
|
-
// VS Code JSONC
|
|
162
163
|
{
|
|
164
|
+
name: 'kikiutils/vscode',
|
|
163
165
|
files: ['**/.vscode/*.json'],
|
|
164
166
|
rules: {
|
|
165
167
|
'jsonc/sort-array-values': [
|
|
@@ -184,8 +186,14 @@ export function createBaseConfigs(environment: 'bun' | 'node' = 'node'): TypedFl
|
|
|
184
186
|
},
|
|
185
187
|
},
|
|
186
188
|
// Ignore all extracted Markdown code blocks, but keep linting Markdown itself.
|
|
187
|
-
{
|
|
189
|
+
{
|
|
190
|
+
name: 'kikiutils/ignores/markdown-code-blocks',
|
|
191
|
+
ignores: ['**/*.md/**'],
|
|
192
|
+
},
|
|
188
193
|
// Serena's project files (`project.yml`, memories) are tool-generated and may be tracked.
|
|
189
|
-
{
|
|
194
|
+
{
|
|
195
|
+
name: 'kikiutils/ignores/serena',
|
|
196
|
+
ignores: ['**/.serena/**'],
|
|
197
|
+
},
|
|
190
198
|
];
|
|
191
199
|
}
|
package/src/nuxt.ts
CHANGED
|
@@ -7,10 +7,11 @@ import {
|
|
|
7
7
|
GLOB_TESTS,
|
|
8
8
|
GLOB_VUE,
|
|
9
9
|
} from '@antfu/eslint-config';
|
|
10
|
+
import type { PackageJson } from 'type-fest';
|
|
11
|
+
import ts from 'typescript';
|
|
10
12
|
|
|
11
|
-
import {
|
|
13
|
+
import { kikiutilsPlugin } from './_internals/rules';
|
|
12
14
|
|
|
13
|
-
// Server helpers that `nuxt/server` provides since Nuxt 4.6.
|
|
14
15
|
const nuxtServerHelpers = [
|
|
15
16
|
'clearSession',
|
|
16
17
|
'createError',
|
|
@@ -44,7 +45,7 @@ const nuxtServerHelpers = [
|
|
|
44
45
|
'useSession',
|
|
45
46
|
];
|
|
46
47
|
|
|
47
|
-
export function createNuxtConfigs(): TypedFlatConfigItem[] {
|
|
48
|
+
export function createNuxtConfigs({ ssr = !isSsrDisabled() }: { ssr?: boolean } = {}): TypedFlatConfigItem[] {
|
|
48
49
|
const nuxtRestrictedSyntax = [
|
|
49
50
|
{
|
|
50
51
|
message: 'Do not redirect with a top-level `await navigateTo()` in setup: under KeepAlive it interrupts a pending Suspense and leaves the page stuck. Use `definePageMeta({ redirect })` or a route middleware.',
|
|
@@ -60,13 +61,40 @@ export function createNuxtConfigs(): TypedFlatConfigItem[] {
|
|
|
60
61
|
: [],
|
|
61
62
|
];
|
|
62
63
|
|
|
64
|
+
const ssrConfigs: TypedFlatConfigItem[] = ssr
|
|
65
|
+
? [
|
|
66
|
+
{
|
|
67
|
+
name: 'kikiutils/nuxt/app',
|
|
68
|
+
files: ['**/app/**/*.?([cm])[jt]s'],
|
|
69
|
+
ignores: [
|
|
70
|
+
...GLOB_TESTS,
|
|
71
|
+
// Nuxt registers `.client` plugins only in the browser; other `.client` modules still load wherever they are imported.
|
|
72
|
+
'**/plugins/**/*.client.?([cm])[jt]s',
|
|
73
|
+
],
|
|
74
|
+
rules: {
|
|
75
|
+
'kikiutils/no-restricted-nuxt-app-syntax': [
|
|
76
|
+
'error',
|
|
77
|
+
{
|
|
78
|
+
message: 'Module-level state in `app/` is shared by every SSR request and leaks between users. Use `useState()` for state the server writes or the client reuses after hydration, or create it inside a composable.',
|
|
79
|
+
selector: [
|
|
80
|
+
'CallExpression.init',
|
|
81
|
+
':matches(TSAsExpression, TSSatisfiesExpression) > CallExpression.expression',
|
|
82
|
+
].map((target) => `:matches(Program, Program > ExportNamedDeclaration) > VariableDeclaration > VariableDeclarator > ${target}[callee.name=/^(computed|reactive|ref|shallowReactive|shallowRef)$/]`).join(', '),
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
]
|
|
88
|
+
: [];
|
|
89
|
+
|
|
63
90
|
return [
|
|
64
91
|
{
|
|
92
|
+
name: 'kikiutils/nuxt',
|
|
65
93
|
files: [
|
|
66
94
|
GLOB_SRC,
|
|
67
95
|
GLOB_VUE,
|
|
68
96
|
],
|
|
69
|
-
plugins: { kikiutils:
|
|
97
|
+
plugins: { kikiutils: kikiutilsPlugin },
|
|
70
98
|
rules: {
|
|
71
99
|
'kikiutils/no-composable-in-head-getter': 'error',
|
|
72
100
|
'kikiutils/no-restricted-nuxt-syntax': [
|
|
@@ -76,6 +104,31 @@ export function createNuxtConfigs(): TypedFlatConfigItem[] {
|
|
|
76
104
|
},
|
|
77
105
|
},
|
|
78
106
|
{
|
|
107
|
+
name: 'kikiutils/nuxt/components',
|
|
108
|
+
files: [
|
|
109
|
+
GLOB_VUE,
|
|
110
|
+
'**/composables/**/*.?([cm])[jt]s',
|
|
111
|
+
],
|
|
112
|
+
ignores: GLOB_TESTS,
|
|
113
|
+
rules: {
|
|
114
|
+
'kikiutils/no-restricted-nuxt-component-syntax': [
|
|
115
|
+
'error',
|
|
116
|
+
{
|
|
117
|
+
message: 'Use `useEventListener()` from VueUse; it removes the listener when the component or effect scope is disposed and re-binds when a target ref changes.',
|
|
118
|
+
selector: 'CallExpression[callee.property.name="addEventListener"]',
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
name: 'kikiutils/nuxt/composables',
|
|
125
|
+
files: ['**/composables/**/*.?([cm])[jt]s'],
|
|
126
|
+
ignores: GLOB_TESTS,
|
|
127
|
+
rules: { 'kikiutils/no-reactive-composable-return': 'error' },
|
|
128
|
+
},
|
|
129
|
+
...ssrConfigs,
|
|
130
|
+
{
|
|
131
|
+
name: 'kikiutils/nuxt/pages',
|
|
79
132
|
files: ['**/pages/**/*.{ts,vue}'],
|
|
80
133
|
rules: {
|
|
81
134
|
'kikiutils/no-restricted-nuxt-page-syntax': [
|
|
@@ -88,11 +141,13 @@ export function createNuxtConfigs(): TypedFlatConfigItem[] {
|
|
|
88
141
|
},
|
|
89
142
|
},
|
|
90
143
|
{
|
|
144
|
+
name: 'kikiutils/nuxt/server-routes',
|
|
91
145
|
files: ['**/server/{api,routes}/**/*.?([cm])[jt]s'],
|
|
92
146
|
ignores: GLOB_TESTS,
|
|
93
147
|
rules: { 'kikiutils/nitro-route-method-suffix': 'error' },
|
|
94
148
|
},
|
|
95
149
|
{
|
|
150
|
+
name: 'kikiutils/nuxt/server',
|
|
96
151
|
files: ['**/server/**/*.?([cm])[jt]s'],
|
|
97
152
|
rules: {
|
|
98
153
|
'kikiutils/no-restricted-nuxt-server-imports': [
|
|
@@ -116,7 +171,7 @@ export function createNuxtConfigs(): TypedFlatConfigItem[] {
|
|
|
116
171
|
|
|
117
172
|
function hasSeoUtils(): boolean {
|
|
118
173
|
try {
|
|
119
|
-
const { dependencies, devDependencies } = JSON.parse(readFileSync(join(process.cwd(), 'package.json'), 'utf8'));
|
|
174
|
+
const { dependencies, devDependencies } = JSON.parse(readFileSync(join(process.cwd(), 'package.json'), 'utf8')) as PackageJson;
|
|
120
175
|
return [
|
|
121
176
|
'@nuxtjs/seo',
|
|
122
177
|
'nuxt-seo-utils',
|
|
@@ -129,3 +184,33 @@ function hasSeoUtils(): boolean {
|
|
|
129
184
|
return false;
|
|
130
185
|
}
|
|
131
186
|
}
|
|
187
|
+
|
|
188
|
+
// Loading the Nuxt config would run its imports, so only a literal `ssr: false` on the exported config object counts.
|
|
189
|
+
function isSsrDisabled(): boolean {
|
|
190
|
+
for (const extension of [
|
|
191
|
+
'js',
|
|
192
|
+
'mjs',
|
|
193
|
+
'mts',
|
|
194
|
+
'ts',
|
|
195
|
+
]) {
|
|
196
|
+
const path = join(process.cwd(), `nuxt.config.${extension}`);
|
|
197
|
+
let text: string;
|
|
198
|
+
try {
|
|
199
|
+
text = readFileSync(path, 'utf8');
|
|
200
|
+
} catch {
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const source = ts.createSourceFile(path, text, ts.ScriptTarget.Latest);
|
|
205
|
+
const exported = source.statements.find((statement) => ts.isExportAssignment(statement))?.expression;
|
|
206
|
+
const config = exported && ts.isCallExpression(exported) ? exported.arguments[0] : exported;
|
|
207
|
+
return !!config
|
|
208
|
+
&& ts.isObjectLiteralExpression(config)
|
|
209
|
+
&& config.properties.some((property) => ts.isPropertyAssignment(property)
|
|
210
|
+
&& ts.isIdentifier(property.name)
|
|
211
|
+
&& property.name.text === 'ssr'
|
|
212
|
+
&& property.initializer.kind === ts.SyntaxKind.FalseKeyword);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return false;
|
|
216
|
+
}
|
package/src/style.ts
CHANGED
|
@@ -3,6 +3,7 @@ import format from 'eslint-plugin-format';
|
|
|
3
3
|
|
|
4
4
|
function createPrettierCssConfig(parser: 'css' | 'scss'): TypedFlatConfigItem {
|
|
5
5
|
return {
|
|
6
|
+
name: `kikiutils/style/${parser}`,
|
|
6
7
|
files: [`**/*.${parser}`],
|
|
7
8
|
languageOptions: { parser: format.parserPlain },
|
|
8
9
|
plugins: { format },
|
package/src/vue.ts
CHANGED
|
@@ -1,33 +1,44 @@
|
|
|
1
1
|
import type { TypedFlatConfigItem } from '@antfu/eslint-config';
|
|
2
|
+
import {
|
|
3
|
+
jsdoc,
|
|
4
|
+
node,
|
|
5
|
+
unicorn,
|
|
6
|
+
} from '@antfu/eslint-config';
|
|
2
7
|
import kikiutilsEslintPluginVue from '@kikiutils/eslint-plugin-vue';
|
|
3
8
|
import betterTailwindcss from 'eslint-plugin-better-tailwindcss';
|
|
4
|
-
// @ts-expect-error No declare file.
|
|
5
9
|
import promise from 'eslint-plugin-promise';
|
|
10
|
+
import { objectEntries } from 'ts-extras';
|
|
6
11
|
|
|
7
12
|
import { createBaseRules } from './_internals/configs/base-rules';
|
|
8
|
-
import { typescriptJsdocConfig } from './_internals/configs/jsdoc';
|
|
9
13
|
import { createTypeAwareConfig } from './_internals/configs/type-aware';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
14
|
+
import { typescriptConfig } from './_internals/configs/typescript';
|
|
15
|
+
import { kikiutilsPlugin } from './_internals/rules';
|
|
16
|
+
|
|
17
|
+
export async function createVueConfig(environment: 'bun' | 'node' = 'node'): Promise<TypedFlatConfigItem> {
|
|
18
|
+
// antfu scopes these rule sets to JS and TS files; `<script>` blocks need them too.
|
|
19
|
+
const scriptConfigs = await Promise.all([
|
|
20
|
+
jsdoc(),
|
|
21
|
+
node(),
|
|
22
|
+
unicorn(),
|
|
23
|
+
]);
|
|
12
24
|
|
|
13
|
-
export function createVueConfig(environment: 'bun' | 'node' = 'node'): TypedFlatConfigItem {
|
|
14
25
|
const typeAwareConfig = createTypeAwareConfig();
|
|
15
|
-
const typefestConfig = createTypefestConfig();
|
|
16
26
|
return {
|
|
27
|
+
name: 'kikiutils/vue',
|
|
17
28
|
files: ['**/*.vue'],
|
|
18
29
|
languageOptions: typeAwareConfig.languageOptions,
|
|
19
30
|
plugins: {
|
|
20
|
-
...
|
|
31
|
+
...typeAwareConfig.plugins,
|
|
21
32
|
'@kikiutils/vue': kikiutilsEslintPluginVue,
|
|
22
33
|
'better-tailwindcss': betterTailwindcss,
|
|
23
|
-
'kikiutils':
|
|
34
|
+
'kikiutils': kikiutilsPlugin,
|
|
24
35
|
promise,
|
|
25
36
|
},
|
|
26
37
|
rules: {
|
|
38
|
+
...Object.fromEntries(scriptConfigs.flat().flatMap((config) => objectEntries(config.rules ?? {}))),
|
|
27
39
|
...createBaseRules(environment),
|
|
28
|
-
...
|
|
40
|
+
...typescriptConfig.rules,
|
|
29
41
|
...typeAwareConfig.rules,
|
|
30
|
-
...typefestConfig.rules,
|
|
31
42
|
'@kikiutils/vue/attributes-order': [
|
|
32
43
|
'error',
|
|
33
44
|
{
|
|
@@ -44,11 +55,8 @@ export function createVueConfig(environment: 'bun' | 'node' = 'node'): TypedFlat
|
|
|
44
55
|
'better-tailwindcss/no-deprecated-classes': 'warn',
|
|
45
56
|
'better-tailwindcss/no-duplicate-classes': 'error',
|
|
46
57
|
'better-tailwindcss/no-unnecessary-whitespace': 'error',
|
|
47
|
-
'
|
|
48
|
-
'
|
|
49
|
-
'error',
|
|
50
|
-
{ default: 'array-simple' },
|
|
51
|
-
],
|
|
58
|
+
// Keeps antfu's Vue setting, which the spread node rules above would re-enable.
|
|
59
|
+
'node/prefer-global/process': 'off',
|
|
52
60
|
'vue/attribute-hyphenation': 'error',
|
|
53
61
|
'vue/attributes-order': 'off',
|
|
54
62
|
'vue/block-order': [
|
|
@@ -78,16 +86,6 @@ export function createVueConfig(environment: 'bun' | 'node' = 'node'): TypedFlat
|
|
|
78
86
|
singleline: 1,
|
|
79
87
|
},
|
|
80
88
|
],
|
|
81
|
-
'vue/max-len': [
|
|
82
|
-
'warn',
|
|
83
|
-
{
|
|
84
|
-
code: 120,
|
|
85
|
-
comments: 120,
|
|
86
|
-
ignoreStrings: true,
|
|
87
|
-
ignoreTemplateLiterals: true,
|
|
88
|
-
template: 120,
|
|
89
|
-
},
|
|
90
|
-
],
|
|
91
89
|
'vue/no-dupe-keys': 'error',
|
|
92
90
|
'vue/no-import-compiler-macros': 'error',
|
|
93
91
|
'vue/no-lone-template': 'error',
|
|
@@ -105,6 +103,6 @@ export function createVueConfig(environment: 'bun' | 'node' = 'node'): TypedFlat
|
|
|
105
103
|
'vue/require-macro-variable-name': 'error',
|
|
106
104
|
'vue/require-typed-ref': 'error',
|
|
107
105
|
},
|
|
108
|
-
settings:
|
|
106
|
+
settings: typescriptConfig.settings,
|
|
109
107
|
};
|
|
110
108
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"restricted-syntax.d.ts","names":[],"sources":["../../../src/_internals/configs/restricted-syntax.ts"],"mappings":"A,qBAAa"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// src/_internals/configs/restricted-syntax.ts
|
|
2
|
-
const restrictedSyntax = [
|
|
3
|
-
"TSEnumDeclaration[const=true]",
|
|
4
|
-
"TSExportAssignment",
|
|
5
|
-
{
|
|
6
|
-
message: "Use `axios.isAxiosError(error)`; `instanceof` fails when the error comes from another copy of axios.",
|
|
7
|
-
selector: "BinaryExpression[operator=\"instanceof\"][right.name=\"AxiosError\"]"
|
|
8
|
-
}
|
|
9
|
-
];
|
|
10
|
-
export { restrictedSyntax };
|
|
11
|
-
|
|
12
|
-
//# sourceMappingURL=restricted-syntax.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"restricted-syntax.js","names":[],"sources":["../../../src/_internals/configs/restricted-syntax.ts"],"sourcesContent":["export const restrictedSyntax = [\n 'TSEnumDeclaration[const=true]',\n 'TSExportAssignment',\n {\n message: 'Use `axios.isAxiosError(error)`; `instanceof` fails when the error comes from another copy of axios.',\n selector: 'BinaryExpression[operator=\"instanceof\"][right.name=\"AxiosError\"]',\n },\n];\n"],"mappings":";AAAA,MAAa,mBAAmB;CAC5B;CACA;CACA;EACI,SAAS;EACT,UAAU;CACd;AACJ"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"typefest.d.ts","names":[],"sources":["../../../src/_internals/configs/typefest.ts"],"mappings":";wBAGgB,wBAAwB"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import typefest from "eslint-plugin-typefest";
|
|
2
|
-
// src/_internals/configs/typefest.ts
|
|
3
|
-
function createTypefestConfig() {
|
|
4
|
-
return {
|
|
5
|
-
plugins: { typefest },
|
|
6
|
-
rules: {
|
|
7
|
-
"typefest/prefer-ts-extras-is-present-filter": "error",
|
|
8
|
-
"typefest/prefer-ts-extras-object-entries": "error",
|
|
9
|
-
"typefest/prefer-ts-extras-object-has-own": "error",
|
|
10
|
-
"typefest/prefer-ts-extras-object-keys": "error",
|
|
11
|
-
"typefest/prefer-ts-extras-object-values": "error",
|
|
12
|
-
"typefest/prefer-type-fest-array-values": "error",
|
|
13
|
-
"typefest/prefer-type-fest-arrayable": "error",
|
|
14
|
-
"typefest/prefer-type-fest-unknown-record": "error",
|
|
15
|
-
"typefest/prefer-type-fest-value-of": "error"
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
export { createTypefestConfig };
|
|
20
|
-
|
|
21
|
-
//# sourceMappingURL=typefest.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"typefest.js","names":[],"sources":["../../../src/_internals/configs/typefest.ts"],"sourcesContent":["import type { TypedFlatConfigItem } from '@antfu/eslint-config';\nimport typefest from 'eslint-plugin-typefest';\n\nexport function createTypefestConfig(): TypedFlatConfigItem {\n return {\n plugins: { typefest },\n rules: {\n 'typefest/prefer-ts-extras-is-present-filter': 'error',\n 'typefest/prefer-ts-extras-object-entries': 'error',\n 'typefest/prefer-ts-extras-object-has-own': 'error',\n 'typefest/prefer-ts-extras-object-keys': 'error',\n 'typefest/prefer-ts-extras-object-values': 'error',\n 'typefest/prefer-type-fest-array-values': 'error',\n 'typefest/prefer-type-fest-arrayable': 'error',\n 'typefest/prefer-type-fest-unknown-record': 'error',\n 'typefest/prefer-type-fest-value-of': 'error',\n },\n };\n}\n"],"mappings":";;AAGA,SAAgB,uBAA4C;CACxD,OAAO;EACH,SAAS,EAAE,SAAS;EACpB,OAAO;GACH,+CAA+C;GAC/C,4CAA4C;GAC5C,4CAA4C;GAC5C,yCAAyC;GACzC,2CAA2C;GAC3C,0CAA0C;GAC1C,uCAAuC;GACvC,4CAA4C;GAC5C,sCAAsC;EAC1C;CACJ;AACJ"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { Rule, SourceCode } from "eslint";
|
|
2
|
-
export type TokenStore = Pick<SourceCode, 'commentsExistBetween' | 'getLastToken' | 'getTokenAfter' | 'getTokenBefore' | 'getTokensBetween'>;
|
|
3
|
-
export declare function defineScriptAndTemplateVisitors(sourceCode: SourceCode, createVisitor: (tokenStore: TokenStore, isTemplate: boolean) => Rule.RuleListener): Rule.RuleListener;
|
|
4
|
-
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/_internals/utils.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
// 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
|
-
export { defineScriptAndTemplateVisitors };
|
|
9
|
-
|
|
10
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export const restrictedSyntax = [
|
|
2
|
-
'TSEnumDeclaration[const=true]',
|
|
3
|
-
'TSExportAssignment',
|
|
4
|
-
{
|
|
5
|
-
message: 'Use `axios.isAxiosError(error)`; `instanceof` fails when the error comes from another copy of axios.',
|
|
6
|
-
selector: 'BinaryExpression[operator="instanceof"][right.name="AxiosError"]',
|
|
7
|
-
},
|
|
8
|
-
];
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { TypedFlatConfigItem } from '@antfu/eslint-config';
|
|
2
|
-
import typefest from 'eslint-plugin-typefest';
|
|
3
|
-
|
|
4
|
-
export function createTypefestConfig(): TypedFlatConfigItem {
|
|
5
|
-
return {
|
|
6
|
-
plugins: { typefest },
|
|
7
|
-
rules: {
|
|
8
|
-
'typefest/prefer-ts-extras-is-present-filter': 'error',
|
|
9
|
-
'typefest/prefer-ts-extras-object-entries': 'error',
|
|
10
|
-
'typefest/prefer-ts-extras-object-has-own': 'error',
|
|
11
|
-
'typefest/prefer-ts-extras-object-keys': 'error',
|
|
12
|
-
'typefest/prefer-ts-extras-object-values': 'error',
|
|
13
|
-
'typefest/prefer-type-fest-array-values': 'error',
|
|
14
|
-
'typefest/prefer-type-fest-arrayable': 'error',
|
|
15
|
-
'typefest/prefer-type-fest-unknown-record': 'error',
|
|
16
|
-
'typefest/prefer-type-fest-value-of': 'error',
|
|
17
|
-
},
|
|
18
|
-
};
|
|
19
|
-
}
|