@kikiutils/eslint-config 11.2.0 → 11.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/_internals/configs/base-rules.d.ts +3 -0
- package/dist/_internals/configs/base-rules.d.ts.map +1 -0
- package/dist/_internals/configs/base-rules.js +190 -0
- package/dist/_internals/configs/base-rules.js.map +1 -0
- package/dist/_internals/configs/jsdoc.d.ts.map +1 -0
- package/dist/_internals/{jsdoc.js → configs/jsdoc.js} +1 -1
- package/dist/_internals/configs/jsdoc.js.map +1 -0
- package/dist/_internals/configs/restricted-syntax.d.ts.map +1 -0
- package/dist/_internals/configs/restricted-syntax.js +12 -0
- package/dist/_internals/configs/restricted-syntax.js.map +1 -0
- package/dist/_internals/configs/type-aware.d.ts.map +1 -0
- package/dist/_internals/configs/type-aware.js +48 -0
- package/dist/_internals/configs/type-aware.js.map +1 -0
- package/dist/_internals/configs/typefest.d.ts.map +1 -0
- package/dist/_internals/{typefest.js → configs/typefest.js} +1 -1
- package/dist/_internals/configs/typefest.js.map +1 -0
- package/dist/_internals/rules/comment-indent.d.ts +3 -0
- package/dist/_internals/rules/comment-indent.d.ts.map +1 -0
- package/dist/_internals/rules/comment-indent.js +58 -0
- package/dist/_internals/rules/comment-indent.js.map +1 -0
- package/dist/_internals/rules/index.d.ts +18 -0
- package/dist/_internals/rules/index.d.ts.map +1 -0
- package/dist/_internals/rules/index.js +32 -0
- package/dist/_internals/rules/index.js.map +1 -0
- package/dist/_internals/rules/nitro-route-method-suffix.d.ts +3 -0
- package/dist/_internals/rules/nitro-route-method-suffix.d.ts.map +1 -0
- package/dist/_internals/rules/nitro-route-method-suffix.js +25 -0
- package/dist/_internals/rules/nitro-route-method-suffix.js.map +1 -0
- package/dist/_internals/rules/no-composable-in-head-getter.d.ts +3 -0
- package/dist/_internals/rules/no-composable-in-head-getter.d.ts.map +1 -0
- package/dist/_internals/rules/no-composable-in-head-getter.js +41 -0
- package/dist/_internals/rules/no-composable-in-head-getter.js.map +1 -0
- package/dist/_internals/rules/no-silent-catch.d.ts +3 -0
- package/dist/_internals/rules/no-silent-catch.d.ts.map +1 -0
- package/dist/_internals/rules/no-silent-catch.js +37 -0
- package/dist/_internals/rules/no-silent-catch.js.map +1 -0
- package/dist/_internals/rules/promise-function-async.d.ts +3 -0
- package/dist/_internals/rules/promise-function-async.d.ts.map +1 -0
- package/dist/_internals/rules/promise-function-async.js +32 -0
- package/dist/_internals/rules/promise-function-async.js.map +1 -0
- package/dist/_internals/rules/statement-padding.js +2 -1
- package/dist/_internals/rules/statement-padding.js.map +1 -1
- package/dist/base.d.ts +3 -2
- package/dist/base.d.ts.map +1 -1
- package/dist/base.js +6 -183
- package/dist/base.js.map +1 -1
- package/dist/nuxt.d.ts +3 -0
- package/dist/nuxt.d.ts.map +1 -0
- package/dist/nuxt.js +94 -0
- package/dist/nuxt.js.map +1 -0
- package/dist/vue.d.ts.map +1 -1
- package/dist/vue.js +12 -15
- package/dist/vue.js.map +1 -1
- package/package.json +13 -11
- package/src/_internals/configs/base-rules.ts +335 -0
- package/src/_internals/{restricted-syntax.ts → configs/restricted-syntax.ts} +0 -4
- package/src/_internals/configs/type-aware.ts +70 -0
- package/src/_internals/rules/comment-indent.ts +87 -0
- package/src/_internals/rules/index.ts +36 -0
- package/src/_internals/rules/nitro-route-method-suffix.ts +27 -0
- package/src/_internals/rules/no-composable-in-head-getter.ts +52 -0
- package/src/_internals/rules/no-silent-catch.ts +51 -0
- package/src/_internals/rules/promise-function-async.ts +56 -0
- package/src/_internals/rules/statement-padding.ts +1 -0
- package/src/base.ts +9 -334
- package/src/nuxt.ts +131 -0
- package/src/vue.ts +11 -14
- package/dist/_internals/jsdoc.d.ts.map +0 -1
- package/dist/_internals/jsdoc.js.map +0 -1
- package/dist/_internals/plugins.d.ts +0 -9
- package/dist/_internals/plugins.d.ts.map +0 -1
- package/dist/_internals/plugins.js +0 -14
- package/dist/_internals/plugins.js.map +0 -1
- package/dist/_internals/restricted-syntax.d.ts.map +0 -1
- package/dist/_internals/restricted-syntax.js +0 -16
- package/dist/_internals/restricted-syntax.js.map +0 -1
- package/dist/_internals/type-aware.d.ts.map +0 -1
- package/dist/_internals/type-aware.js +0 -29
- package/dist/_internals/type-aware.js.map +0 -1
- package/dist/_internals/typefest.d.ts.map +0 -1
- package/dist/_internals/typefest.js.map +0 -1
- package/src/_internals/plugins.ts +0 -13
- package/src/_internals/type-aware.ts +0 -42
- /package/dist/_internals/{jsdoc.d.ts → configs/jsdoc.d.ts} +0 -0
- /package/dist/_internals/{restricted-syntax.d.ts → configs/restricted-syntax.d.ts} +0 -0
- /package/dist/_internals/{type-aware.d.ts → configs/type-aware.d.ts} +0 -0
- /package/dist/_internals/{typefest.d.ts → configs/typefest.d.ts} +0 -0
- /package/src/_internals/{jsdoc.ts → configs/jsdoc.ts} +0 -0
- /package/src/_internals/{typefest.ts → configs/typefest.ts} +0 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
|
|
3
|
+
const headComposables = new Set([
|
|
4
|
+
'useHead',
|
|
5
|
+
'useHeadSafe',
|
|
6
|
+
'useSeoMeta',
|
|
7
|
+
'useServerHead',
|
|
8
|
+
'useServerHeadSafe',
|
|
9
|
+
'useServerSeoMeta',
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
const composablePattern = /^use[A-Z]/;
|
|
13
|
+
|
|
14
|
+
export const noComposableInHeadGetter: Rule.RuleModule = {
|
|
15
|
+
create(context) {
|
|
16
|
+
return {
|
|
17
|
+
CallExpression(node) {
|
|
18
|
+
if (node.callee.type !== 'Identifier' || !composablePattern.test(node.callee.name)) return;
|
|
19
|
+
let insideFunction = false;
|
|
20
|
+
for (const parent of context.sourceCode.getAncestors(node).reverse()) {
|
|
21
|
+
if (parent.type === 'ArrowFunctionExpression' || parent.type === 'FunctionExpression') {
|
|
22
|
+
insideFunction = true;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (
|
|
26
|
+
insideFunction
|
|
27
|
+
&& parent.type === 'CallExpression'
|
|
28
|
+
&& parent.callee.type === 'Identifier'
|
|
29
|
+
&& headComposables.has(parent.callee.name)
|
|
30
|
+
) {
|
|
31
|
+
context.report({
|
|
32
|
+
data: {
|
|
33
|
+
composable: node.callee.name,
|
|
34
|
+
head: parent.callee.name,
|
|
35
|
+
},
|
|
36
|
+
messageId: 'getter',
|
|
37
|
+
node,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
meta: {
|
|
47
|
+
docs: { description: 'Disallow calling composables inside `useHead`/`useSeoMeta` getters.' },
|
|
48
|
+
messages: { getter: '`{{ composable }}()` runs when the `{{ head }}` getter is evaluated after setup, outside the component context. Call it in setup and use its result in the getter.' },
|
|
49
|
+
schema: [],
|
|
50
|
+
type: 'problem',
|
|
51
|
+
},
|
|
52
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
|
|
3
|
+
type CallArgument = Extract<Rule.Node, { type: 'CallExpression' }>['arguments'][number];
|
|
4
|
+
type Expression = Exclude<CallArgument, { type: 'SpreadElement' }>;
|
|
5
|
+
|
|
6
|
+
function isNothing(node: Expression | null | undefined): boolean {
|
|
7
|
+
if (!node) return true;
|
|
8
|
+
if (node.type === 'Identifier') return node.name === 'undefined';
|
|
9
|
+
if (node.type === 'Literal') return node.raw === 'null';
|
|
10
|
+
return node.type === 'UnaryExpression' && node.operator === 'void' && node.argument.type === 'Literal';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function isSilent(callback: CallArgument): boolean {
|
|
14
|
+
if (callback.type !== 'ArrowFunctionExpression' && callback.type !== 'FunctionExpression') return false;
|
|
15
|
+
const { body } = callback;
|
|
16
|
+
if (body.type !== 'BlockStatement') return isNothing(body);
|
|
17
|
+
const [statement, ...rest] = body.body;
|
|
18
|
+
return !statement || (!rest.length && statement.type === 'ReturnStatement' && isNothing(statement.argument));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const noSilentCatch: Rule.RuleModule = {
|
|
22
|
+
create(context) {
|
|
23
|
+
return {
|
|
24
|
+
CallExpression(node) {
|
|
25
|
+
const { callee } = node;
|
|
26
|
+
const callback = node.arguments[0];
|
|
27
|
+
if (
|
|
28
|
+
callee.type !== 'MemberExpression'
|
|
29
|
+
|| callee.computed
|
|
30
|
+
|| callee.property.type !== 'Identifier'
|
|
31
|
+
|| callee.property.name !== 'catch'
|
|
32
|
+
|| !callback
|
|
33
|
+
|| !isSilent(callback)
|
|
34
|
+
) return;
|
|
35
|
+
|
|
36
|
+
// A comment inside the callback is the reason the rejection can be ignored.
|
|
37
|
+
if (context.sourceCode.getCommentsInside(callback).length) return;
|
|
38
|
+
context.report({
|
|
39
|
+
messageId: 'silent',
|
|
40
|
+
node: callback,
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
meta: {
|
|
46
|
+
docs: { description: 'Disallow `.catch()` callbacks that silently swallow the rejection.' },
|
|
47
|
+
messages: { silent: 'Do not swallow the rejection silently: log it, or add a comment in the callback explaining why it can be ignored.' },
|
|
48
|
+
schema: [],
|
|
49
|
+
type: 'problem',
|
|
50
|
+
},
|
|
51
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import tseslint from '@typescript-eslint/eslint-plugin';
|
|
2
|
+
import type { Rule } from 'eslint';
|
|
3
|
+
import type {
|
|
4
|
+
Node,
|
|
5
|
+
SignatureDeclaration,
|
|
6
|
+
Type,
|
|
7
|
+
TypeChecker,
|
|
8
|
+
} from 'typescript';
|
|
9
|
+
|
|
10
|
+
interface ParserServices {
|
|
11
|
+
esTreeNodeToTSNodeMap: { get: (node: unknown) => Node };
|
|
12
|
+
program: { getTypeChecker: () => TypeChecker };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const upstream = tseslint.rules['promise-function-async'] as unknown as Rule.RuleModule;
|
|
16
|
+
const promiseMembers = new Set([
|
|
17
|
+
'catch',
|
|
18
|
+
'finally',
|
|
19
|
+
'then',
|
|
20
|
+
]);
|
|
21
|
+
|
|
22
|
+
// A thenable with extra members, such as Nuxt's `AsyncData`, loses those members once the function becomes async.
|
|
23
|
+
function hasNonPromiseMembers(checker: TypeChecker, type: Type): boolean {
|
|
24
|
+
return (type.isUnion() ? type.types : [type]).some((part) => {
|
|
25
|
+
const names = checker.getPropertiesOfType(part).map((symbol) => symbol.getName());
|
|
26
|
+
return names.includes('then') && names.some((name) => !promiseMembers.has(name) && !name.startsWith('__@'));
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const promiseFunctionAsync: Rule.RuleModule = {
|
|
31
|
+
create(context) {
|
|
32
|
+
const report = (descriptor: Rule.ReportDescriptor) => {
|
|
33
|
+
if ('node' in descriptor) {
|
|
34
|
+
const services = context.sourceCode.parserServices as ParserServices;
|
|
35
|
+
const checker = services.program.getTypeChecker();
|
|
36
|
+
const tsNode = services.esTreeNodeToTSNodeMap.get(descriptor.node) as SignatureDeclaration;
|
|
37
|
+
// Overloads are what callers see, so they count alongside the implementation signature.
|
|
38
|
+
const signatures = [
|
|
39
|
+
checker.getSignatureFromDeclaration(tsNode),
|
|
40
|
+
...checker.getTypeAtLocation(tsNode).getCallSignatures(),
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
if (
|
|
44
|
+
signatures.some((signature) => signature
|
|
45
|
+
&& hasNonPromiseMembers(checker, checker.getReturnTypeOfSignature(signature)))
|
|
46
|
+
) return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
context.report(descriptor);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// The upstream rule validates that type information is available.
|
|
53
|
+
return upstream.create(Object.create(context, { report: { value: report } }));
|
|
54
|
+
},
|
|
55
|
+
meta: upstream.meta,
|
|
56
|
+
};
|
|
@@ -85,6 +85,7 @@ export const statementPadding: Rule.RuleModule = {
|
|
|
85
85
|
Program: (node) => checkStatements(node.body),
|
|
86
86
|
StaticBlock: (node) => checkStatements(node.body),
|
|
87
87
|
SwitchCase: (node) => checkStatements(node.consequent),
|
|
88
|
+
TSModuleBlock: (node: Rule.Node & { body: StatementNode[] }) => checkStatements(node.body),
|
|
88
89
|
};
|
|
89
90
|
},
|
|
90
91
|
meta: {
|
package/src/base.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Rules,
|
|
3
|
-
TypedFlatConfigItem,
|
|
4
|
-
} from '@antfu/eslint-config';
|
|
1
|
+
import type { TypedFlatConfigItem } from '@antfu/eslint-config';
|
|
5
2
|
import {
|
|
6
3
|
GLOB_JS,
|
|
7
4
|
GLOB_JSX,
|
|
@@ -12,21 +9,18 @@ import {
|
|
|
12
9
|
// @ts-expect-error No declare file.
|
|
13
10
|
import promise from 'eslint-plugin-promise';
|
|
14
11
|
|
|
12
|
+
import { createBaseRules } from './_internals/configs/base-rules';
|
|
15
13
|
import {
|
|
16
14
|
jsdocSettings,
|
|
17
15
|
typescriptJsdocConfig,
|
|
18
|
-
} from './_internals/jsdoc';
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import { createTypefestConfig } from './_internals/typefest';
|
|
16
|
+
} from './_internals/configs/jsdoc';
|
|
17
|
+
import { createTypeAwareConfig } from './_internals/configs/type-aware';
|
|
18
|
+
import { createTypefestConfig } from './_internals/configs/typefest';
|
|
19
|
+
import { customPlugins } from './_internals/rules';
|
|
23
20
|
|
|
24
|
-
|
|
25
|
-
const basePerfectionistSortOptions = {
|
|
26
|
-
ignoreCase: false,
|
|
27
|
-
type: 'natural',
|
|
28
|
-
} as const;
|
|
21
|
+
export { createBaseRules };
|
|
29
22
|
|
|
23
|
+
// Constants/Variables
|
|
30
24
|
const vscodeOrderSensitiveArrayProperties = [
|
|
31
25
|
'args',
|
|
32
26
|
'autoAttachSmartPattern',
|
|
@@ -123,7 +117,7 @@ export function createBaseConfigs(environment: 'bun' | 'node' = 'node'): TypedFl
|
|
|
123
117
|
'error',
|
|
124
118
|
{ compactTestCalls: true },
|
|
125
119
|
],
|
|
126
|
-
'no-restricted-imports': [
|
|
120
|
+
'kikiutils/no-restricted-test-imports': [
|
|
127
121
|
'error',
|
|
128
122
|
{
|
|
129
123
|
paths: [
|
|
@@ -195,322 +189,3 @@ export function createBaseConfigs(environment: 'bun' | 'node' = 'node'): TypedFl
|
|
|
195
189
|
{ ignores: ['**/.serena/**'] },
|
|
196
190
|
];
|
|
197
191
|
}
|
|
198
|
-
|
|
199
|
-
export function createBaseRules(environment: 'bun' | 'node' = 'node'): Rules {
|
|
200
|
-
return {
|
|
201
|
-
'antfu/consistent-list-newline': [
|
|
202
|
-
'error',
|
|
203
|
-
{
|
|
204
|
-
ArrayExpression: false,
|
|
205
|
-
ArrayPattern: false,
|
|
206
|
-
},
|
|
207
|
-
],
|
|
208
|
-
'antfu/curly': 'off',
|
|
209
|
-
'antfu/if-newline': 'off',
|
|
210
|
-
'antfu/no-top-level-await': 'off',
|
|
211
|
-
'antfu/reasonable-newline': 'off',
|
|
212
|
-
'arrow-body-style': [
|
|
213
|
-
'error',
|
|
214
|
-
'as-needed',
|
|
215
|
-
],
|
|
216
|
-
'curly': [
|
|
217
|
-
'error',
|
|
218
|
-
'multi-line',
|
|
219
|
-
],
|
|
220
|
-
'jsdoc/check-tag-names': 'error',
|
|
221
|
-
'jsdoc/multiline-blocks': [
|
|
222
|
-
'error',
|
|
223
|
-
{
|
|
224
|
-
noSingleLineBlocks: true,
|
|
225
|
-
singleLineTags: [
|
|
226
|
-
'type',
|
|
227
|
-
'import',
|
|
228
|
-
],
|
|
229
|
-
},
|
|
230
|
-
],
|
|
231
|
-
'jsdoc/no-blank-blocks': [
|
|
232
|
-
'error',
|
|
233
|
-
{ enableFixer: true },
|
|
234
|
-
],
|
|
235
|
-
'jsdoc/require-asterisk-prefix': 'error',
|
|
236
|
-
'jsdoc/require-hyphen-before-param-description': [
|
|
237
|
-
'error',
|
|
238
|
-
'always',
|
|
239
|
-
{ tags: { typeParam: 'always' } },
|
|
240
|
-
],
|
|
241
|
-
'kikiutils/compact-iteration-layout': 'error',
|
|
242
|
-
'kikiutils/consistent-condition-layout': 'error',
|
|
243
|
-
'kikiutils/consistent-parameter-layout': 'error',
|
|
244
|
-
'kikiutils/statement-padding': 'error',
|
|
245
|
-
'max-classes-per-file': [
|
|
246
|
-
'error',
|
|
247
|
-
1,
|
|
248
|
-
],
|
|
249
|
-
'no-constant-binary-expression': 'error',
|
|
250
|
-
// An ignored error needs at least a comment in the block saying why.
|
|
251
|
-
'no-empty': [
|
|
252
|
-
'error',
|
|
253
|
-
{ allowEmptyCatch: false },
|
|
254
|
-
],
|
|
255
|
-
'no-promise-executor-return': [
|
|
256
|
-
'error',
|
|
257
|
-
{ allowVoid: true },
|
|
258
|
-
],
|
|
259
|
-
'no-restricted-imports': [
|
|
260
|
-
'error',
|
|
261
|
-
{
|
|
262
|
-
patterns: [
|
|
263
|
-
{
|
|
264
|
-
message: '`_internals` modules are private to their own directory; import the public module instead.',
|
|
265
|
-
regex: String.raw`^[^.].*/_internals(/|$)`,
|
|
266
|
-
},
|
|
267
|
-
],
|
|
268
|
-
},
|
|
269
|
-
],
|
|
270
|
-
'no-restricted-syntax': [
|
|
271
|
-
'error',
|
|
272
|
-
...restrictedSyntax,
|
|
273
|
-
],
|
|
274
|
-
'no-useless-assignment': 'error',
|
|
275
|
-
'perfectionist/sort-array-includes': [
|
|
276
|
-
'error',
|
|
277
|
-
basePerfectionistSortOptions,
|
|
278
|
-
],
|
|
279
|
-
'perfectionist/sort-enums': [
|
|
280
|
-
'error',
|
|
281
|
-
{
|
|
282
|
-
...basePerfectionistSortOptions,
|
|
283
|
-
sortByValue: 'never',
|
|
284
|
-
},
|
|
285
|
-
],
|
|
286
|
-
'perfectionist/sort-heritage-clauses': [
|
|
287
|
-
'error',
|
|
288
|
-
basePerfectionistSortOptions,
|
|
289
|
-
],
|
|
290
|
-
'perfectionist/sort-imports': [
|
|
291
|
-
'error',
|
|
292
|
-
{
|
|
293
|
-
environment,
|
|
294
|
-
groups: [
|
|
295
|
-
'side-effect',
|
|
296
|
-
'side-effect-style',
|
|
297
|
-
'style',
|
|
298
|
-
[
|
|
299
|
-
'value-builtin',
|
|
300
|
-
'type-builtin',
|
|
301
|
-
],
|
|
302
|
-
[
|
|
303
|
-
'value-external',
|
|
304
|
-
'type-external',
|
|
305
|
-
],
|
|
306
|
-
[
|
|
307
|
-
'value-internal',
|
|
308
|
-
'type-internal',
|
|
309
|
-
],
|
|
310
|
-
[
|
|
311
|
-
'value-parent',
|
|
312
|
-
'type-parent',
|
|
313
|
-
],
|
|
314
|
-
[
|
|
315
|
-
'value-sibling',
|
|
316
|
-
'type-sibling',
|
|
317
|
-
],
|
|
318
|
-
[
|
|
319
|
-
'value-index',
|
|
320
|
-
'type-index',
|
|
321
|
-
],
|
|
322
|
-
'unknown',
|
|
323
|
-
],
|
|
324
|
-
ignoreCase: false,
|
|
325
|
-
internalPattern: [
|
|
326
|
-
'^#.*',
|
|
327
|
-
'^@/.*',
|
|
328
|
-
'^~/.*',
|
|
329
|
-
],
|
|
330
|
-
type: 'natural',
|
|
331
|
-
},
|
|
332
|
-
],
|
|
333
|
-
'perfectionist/sort-interfaces': [
|
|
334
|
-
'error',
|
|
335
|
-
basePerfectionistSortOptions,
|
|
336
|
-
],
|
|
337
|
-
'perfectionist/sort-intersection-types': [
|
|
338
|
-
'error',
|
|
339
|
-
basePerfectionistSortOptions,
|
|
340
|
-
],
|
|
341
|
-
'perfectionist/sort-maps': [
|
|
342
|
-
'error',
|
|
343
|
-
basePerfectionistSortOptions,
|
|
344
|
-
],
|
|
345
|
-
'perfectionist/sort-modules': [
|
|
346
|
-
'error',
|
|
347
|
-
{
|
|
348
|
-
...basePerfectionistSortOptions,
|
|
349
|
-
groups: [
|
|
350
|
-
'declare-type',
|
|
351
|
-
[
|
|
352
|
-
'export-type',
|
|
353
|
-
'type',
|
|
354
|
-
],
|
|
355
|
-
'declare-interface',
|
|
356
|
-
[
|
|
357
|
-
'export-interface',
|
|
358
|
-
'interface',
|
|
359
|
-
],
|
|
360
|
-
'declare-enum',
|
|
361
|
-
[
|
|
362
|
-
'enum',
|
|
363
|
-
'export-enum',
|
|
364
|
-
],
|
|
365
|
-
'declare-class',
|
|
366
|
-
[
|
|
367
|
-
'class',
|
|
368
|
-
'export-class',
|
|
369
|
-
],
|
|
370
|
-
'declare-function',
|
|
371
|
-
[
|
|
372
|
-
'export-function',
|
|
373
|
-
'function',
|
|
374
|
-
],
|
|
375
|
-
],
|
|
376
|
-
},
|
|
377
|
-
],
|
|
378
|
-
'perfectionist/sort-object-types': [
|
|
379
|
-
'error',
|
|
380
|
-
basePerfectionistSortOptions,
|
|
381
|
-
],
|
|
382
|
-
'perfectionist/sort-objects': [
|
|
383
|
-
'error',
|
|
384
|
-
basePerfectionistSortOptions,
|
|
385
|
-
],
|
|
386
|
-
'perfectionist/sort-sets': [
|
|
387
|
-
'error',
|
|
388
|
-
basePerfectionistSortOptions,
|
|
389
|
-
],
|
|
390
|
-
'perfectionist/sort-switch-case': [
|
|
391
|
-
'error',
|
|
392
|
-
{
|
|
393
|
-
ignoreCase: false,
|
|
394
|
-
type: 'natural',
|
|
395
|
-
},
|
|
396
|
-
],
|
|
397
|
-
'perfectionist/sort-union-types': [
|
|
398
|
-
'error',
|
|
399
|
-
basePerfectionistSortOptions,
|
|
400
|
-
],
|
|
401
|
-
'perfectionist/sort-variable-declarations': [
|
|
402
|
-
'error',
|
|
403
|
-
basePerfectionistSortOptions,
|
|
404
|
-
],
|
|
405
|
-
'preserve-caught-error': 'error',
|
|
406
|
-
'promise/no-multiple-resolved': 'error',
|
|
407
|
-
'promise/no-return-in-finally': 'error',
|
|
408
|
-
'promise/no-return-wrap': 'error',
|
|
409
|
-
'require-await': 'off',
|
|
410
|
-
'style/array-bracket-newline': [
|
|
411
|
-
'error',
|
|
412
|
-
{ multiline: true },
|
|
413
|
-
],
|
|
414
|
-
'style/array-element-newline': [
|
|
415
|
-
'error',
|
|
416
|
-
{
|
|
417
|
-
ArrayExpression: {
|
|
418
|
-
consistent: true,
|
|
419
|
-
minItems: 2,
|
|
420
|
-
},
|
|
421
|
-
ArrayPattern: { minItems: 3 },
|
|
422
|
-
},
|
|
423
|
-
],
|
|
424
|
-
'style/arrow-parens': [
|
|
425
|
-
'error',
|
|
426
|
-
'always',
|
|
427
|
-
],
|
|
428
|
-
'style/brace-style': [
|
|
429
|
-
'error',
|
|
430
|
-
'1tbs',
|
|
431
|
-
{ allowSingleLine: false },
|
|
432
|
-
],
|
|
433
|
-
'style/function-call-spacing': [
|
|
434
|
-
'error',
|
|
435
|
-
'never',
|
|
436
|
-
],
|
|
437
|
-
'style/indent': [
|
|
438
|
-
'error',
|
|
439
|
-
4,
|
|
440
|
-
],
|
|
441
|
-
'style/max-len': [
|
|
442
|
-
'warn',
|
|
443
|
-
{
|
|
444
|
-
code: 120,
|
|
445
|
-
comments: 120,
|
|
446
|
-
ignoreStrings: true,
|
|
447
|
-
ignoreTemplateLiterals: true,
|
|
448
|
-
},
|
|
449
|
-
],
|
|
450
|
-
'style/member-delimiter-style': [
|
|
451
|
-
'error',
|
|
452
|
-
{
|
|
453
|
-
multiline: {
|
|
454
|
-
delimiter: 'semi',
|
|
455
|
-
requireLast: true,
|
|
456
|
-
},
|
|
457
|
-
},
|
|
458
|
-
],
|
|
459
|
-
'style/no-extra-parens': [
|
|
460
|
-
'error',
|
|
461
|
-
'all',
|
|
462
|
-
{ nestedBinaryExpressions: false },
|
|
463
|
-
],
|
|
464
|
-
'style/no-extra-semi': 'error',
|
|
465
|
-
'style/object-curly-newline': [
|
|
466
|
-
'error',
|
|
467
|
-
{
|
|
468
|
-
ExportDeclaration: {
|
|
469
|
-
minProperties: 2,
|
|
470
|
-
multiline: true,
|
|
471
|
-
},
|
|
472
|
-
ImportDeclaration: {
|
|
473
|
-
minProperties: 2,
|
|
474
|
-
multiline: true,
|
|
475
|
-
},
|
|
476
|
-
ObjectExpression: {
|
|
477
|
-
minProperties: 2,
|
|
478
|
-
multiline: true,
|
|
479
|
-
},
|
|
480
|
-
ObjectPattern: {
|
|
481
|
-
minProperties: 3,
|
|
482
|
-
multiline: true,
|
|
483
|
-
},
|
|
484
|
-
},
|
|
485
|
-
],
|
|
486
|
-
'style/operator-linebreak': [
|
|
487
|
-
'error',
|
|
488
|
-
'before',
|
|
489
|
-
{ overrides: { '=': 'after' } },
|
|
490
|
-
],
|
|
491
|
-
'style/padding-line-between-statements': [
|
|
492
|
-
'error',
|
|
493
|
-
{
|
|
494
|
-
blankLine: 'always',
|
|
495
|
-
next: [
|
|
496
|
-
'class',
|
|
497
|
-
'enum',
|
|
498
|
-
'function',
|
|
499
|
-
],
|
|
500
|
-
prev: '*',
|
|
501
|
-
},
|
|
502
|
-
{
|
|
503
|
-
blankLine: 'always',
|
|
504
|
-
next: '*',
|
|
505
|
-
prev: [
|
|
506
|
-
'class',
|
|
507
|
-
'function',
|
|
508
|
-
],
|
|
509
|
-
},
|
|
510
|
-
],
|
|
511
|
-
'style/semi': [
|
|
512
|
-
'error',
|
|
513
|
-
'always',
|
|
514
|
-
],
|
|
515
|
-
};
|
|
516
|
-
}
|
package/src/nuxt.ts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
|
|
4
|
+
import type { TypedFlatConfigItem } from '@antfu/eslint-config';
|
|
5
|
+
import {
|
|
6
|
+
GLOB_SRC,
|
|
7
|
+
GLOB_TESTS,
|
|
8
|
+
GLOB_VUE,
|
|
9
|
+
} from '@antfu/eslint-config';
|
|
10
|
+
|
|
11
|
+
import { customPlugins } from './_internals/rules';
|
|
12
|
+
|
|
13
|
+
// Server helpers that `nuxt/server` provides since Nuxt 4.6.
|
|
14
|
+
const nuxtServerHelpers = [
|
|
15
|
+
'clearSession',
|
|
16
|
+
'createError',
|
|
17
|
+
'defineEventHandler',
|
|
18
|
+
'defineHandler',
|
|
19
|
+
'deleteCookie',
|
|
20
|
+
'eventHandler',
|
|
21
|
+
'getCookie',
|
|
22
|
+
'getQuery',
|
|
23
|
+
'getRequestHeader',
|
|
24
|
+
'getRequestHeaders',
|
|
25
|
+
'getRequestHost',
|
|
26
|
+
'getRequestIP',
|
|
27
|
+
'getRequestProtocol',
|
|
28
|
+
'getRequestURL',
|
|
29
|
+
'getRouteRules',
|
|
30
|
+
'getRouterParam',
|
|
31
|
+
'getRouterParams',
|
|
32
|
+
'getSession',
|
|
33
|
+
'getValidatedQuery',
|
|
34
|
+
'handleCors',
|
|
35
|
+
'parseCookies',
|
|
36
|
+
'readBody',
|
|
37
|
+
'readValidatedBody',
|
|
38
|
+
'sendRedirect',
|
|
39
|
+
'setCookie',
|
|
40
|
+
'setResponseStatus',
|
|
41
|
+
'updateSession',
|
|
42
|
+
'useAppConfig',
|
|
43
|
+
'useRuntimeConfig',
|
|
44
|
+
'useSession',
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
export function createNuxtConfigs(): TypedFlatConfigItem[] {
|
|
48
|
+
const nuxtRestrictedSyntax = [
|
|
49
|
+
{
|
|
50
|
+
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.',
|
|
51
|
+
selector: 'Program > ExpressionStatement > AwaitExpression > CallExpression[callee.name="navigateTo"]',
|
|
52
|
+
},
|
|
53
|
+
...hasSeoUtils()
|
|
54
|
+
? [
|
|
55
|
+
{
|
|
56
|
+
message: 'nuxt-seo-utils infers og:title and og:description from `title` and `description`, X falls back to them for its title and description, and the seo layer sets `twitter:card`. Setting these keys stops the inference; set `title` and `description` instead.',
|
|
57
|
+
selector: 'CallExpression[callee.name=/^use(Server)?SeoMeta$/] > ObjectExpression > Property[key.name=/^(ogDescription|ogTitle|twitterCard|twitterDescription|twitterTitle)$/]',
|
|
58
|
+
},
|
|
59
|
+
]
|
|
60
|
+
: [],
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
return [
|
|
64
|
+
{
|
|
65
|
+
files: [
|
|
66
|
+
GLOB_SRC,
|
|
67
|
+
GLOB_VUE,
|
|
68
|
+
],
|
|
69
|
+
plugins: { kikiutils: customPlugins },
|
|
70
|
+
rules: {
|
|
71
|
+
'kikiutils/no-composable-in-head-getter': 'error',
|
|
72
|
+
'kikiutils/no-restricted-nuxt-syntax': [
|
|
73
|
+
'error',
|
|
74
|
+
...nuxtRestrictedSyntax,
|
|
75
|
+
],
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
files: ['**/pages/**/*.{ts,vue}'],
|
|
80
|
+
rules: {
|
|
81
|
+
'kikiutils/no-restricted-nuxt-page-syntax': [
|
|
82
|
+
'error',
|
|
83
|
+
{
|
|
84
|
+
message: '`<html lang>` follows the current locale through the i18n layer, or `app.head` in `nuxt.config.ts` without i18n; setting it in a page overrides it.',
|
|
85
|
+
selector: 'CallExpression[callee.name=/^use(Server)?Head(Safe)?$/] Property[key.name="htmlAttrs"] > ObjectExpression > Property[key.name="lang"]',
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
files: ['**/server/{api,routes}/**/*.?([cm])[jt]s'],
|
|
92
|
+
ignores: GLOB_TESTS,
|
|
93
|
+
rules: { 'kikiutils/nitro-route-method-suffix': 'error' },
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
files: ['**/server/**/*.?([cm])[jt]s'],
|
|
97
|
+
rules: {
|
|
98
|
+
'kikiutils/no-restricted-nuxt-server-imports': [
|
|
99
|
+
'error',
|
|
100
|
+
{
|
|
101
|
+
paths: [
|
|
102
|
+
'#imports',
|
|
103
|
+
'h3',
|
|
104
|
+
'nitropack/runtime',
|
|
105
|
+
].map((name) => ({
|
|
106
|
+
importNames: nuxtServerHelpers,
|
|
107
|
+
message: 'Import this helper from `nuxt/server`, which runs on Nuxt 4.6 and Nuxt 5; the h3 and Nitro versions expect a different event. Keep h3 or `nitropack/runtime` only for helpers `nuxt/server` does not provide.',
|
|
108
|
+
name,
|
|
109
|
+
})),
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
];
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function hasSeoUtils(): boolean {
|
|
118
|
+
try {
|
|
119
|
+
const { dependencies, devDependencies } = JSON.parse(readFileSync(join(process.cwd(), 'package.json'), 'utf8'));
|
|
120
|
+
return [
|
|
121
|
+
'@nuxtjs/seo',
|
|
122
|
+
'nuxt-seo-utils',
|
|
123
|
+
].some((name) => name in {
|
|
124
|
+
...dependencies,
|
|
125
|
+
...devDependencies,
|
|
126
|
+
});
|
|
127
|
+
} catch {
|
|
128
|
+
// Without a readable package.json, skip the rules that depend on the SEO modules.
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
}
|