@ocavue/eslint-config 2.20.0 → 3.0.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/README.md +63 -0
- package/dist/gitignore.d.ts +3 -0
- package/dist/gitignore.js +4 -0
- package/dist/ignores.d.ts +2 -1
- package/dist/ignores.js +4 -7
- package/dist/index.d.ts +0 -6
- package/dist/index.js +37 -11
- package/dist/markdown.js +13 -27
- package/dist/options.d.ts +68 -1
- package/dist/options.js +14 -2
- package/dist/shared.d.ts +4 -0
- package/dist/shared.js +10 -0
- package/dist/types.d.ts +1 -0
- package/dist/typescript.js +133 -102
- package/package.json +3 -3
- package/dist/basic.d.ts +0 -2
- package/dist/basic.js +0 -20
package/README.md
CHANGED
|
@@ -77,6 +77,34 @@ The full type definition for the options is as follows:
|
|
|
77
77
|
|
|
78
78
|
```ts
|
|
79
79
|
export interface ESLintConfigOptions {
|
|
80
|
+
/**
|
|
81
|
+
* Whether to enable [typescript-eslint](https://github.com/typescript-eslint/typescript-eslint) configuration.
|
|
82
|
+
*
|
|
83
|
+
* @default true
|
|
84
|
+
*/
|
|
85
|
+
typescript?: boolean
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Whether to enable [eslint-plugin-unicorn](https://www.npmjs.com/package/eslint-plugin-unicorn) configuration.
|
|
89
|
+
*
|
|
90
|
+
* @default true
|
|
91
|
+
*/
|
|
92
|
+
unicorn?: boolean
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Whether to enable [eslint-plugin-package-json](https://www.npmjs.com/package/eslint-plugin-package-json) configuration.
|
|
96
|
+
*
|
|
97
|
+
* @default true
|
|
98
|
+
*/
|
|
99
|
+
packageJson?: boolean
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Whether to enable [eslint-plugin-import-x](https://www.npmjs.com/package/eslint-plugin-import-x) configuration.
|
|
103
|
+
*
|
|
104
|
+
* @default true
|
|
105
|
+
*/
|
|
106
|
+
imports?: boolean
|
|
107
|
+
|
|
80
108
|
/**
|
|
81
109
|
* Whether to check code blocks in Markdown files.
|
|
82
110
|
*
|
|
@@ -111,6 +139,41 @@ export interface ESLintConfigOptions {
|
|
|
111
139
|
* @default false
|
|
112
140
|
*/
|
|
113
141
|
command?: boolean
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Ignore some common files that should not be linted.
|
|
145
|
+
*
|
|
146
|
+
* @default true
|
|
147
|
+
*/
|
|
148
|
+
ignores?: boolean | IgnoresOptions
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Whether to enable [eslint-config-flat-gitignore](https://www.npmjs.com/package/eslint-config-flat-gitignore) configuration.
|
|
152
|
+
*
|
|
153
|
+
* @default true
|
|
154
|
+
*/
|
|
155
|
+
gitignore?: boolean | GitignoreOptions
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Whether to enable [eslint-plugin-antfu](https://www.npmjs.com/package/eslint-plugin-antfu) configuration.
|
|
159
|
+
*
|
|
160
|
+
* @default true
|
|
161
|
+
*/
|
|
162
|
+
antfu?: boolean
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Whether to enable [eslint-plugin-no-only-tests](https://www.npmjs.com/package/eslint-plugin-no-only-tests) configuration.
|
|
166
|
+
*
|
|
167
|
+
* @default true
|
|
168
|
+
*/
|
|
169
|
+
noOnlyTests?: boolean
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Whether to enable [eslint-config-prettier](https://www.npmjs.com/package/eslint-config-prettier) configuration.
|
|
173
|
+
*
|
|
174
|
+
* @default true
|
|
175
|
+
*/
|
|
176
|
+
prettier?: boolean
|
|
114
177
|
}
|
|
115
178
|
```
|
|
116
179
|
|
package/dist/ignores.d.ts
CHANGED
package/dist/ignores.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
return [
|
|
5
|
-
{ ignores: [...GLOB_EXCLUDE], name: 'basic-global-ignores' },
|
|
6
|
-
gitignore(),
|
|
7
|
-
];
|
|
1
|
+
import { resolveIgnoresOptions } from './options.js';
|
|
2
|
+
export function ignores(options) {
|
|
3
|
+
const { ignores } = resolveIgnoresOptions(options);
|
|
4
|
+
return [{ name: 'ocavue/ignores', ignores }];
|
|
8
5
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
import { type ESLintConfigOptions } from './options.js';
|
|
2
2
|
import type { Config } from './types.js';
|
|
3
|
-
export * from './basic.js';
|
|
4
|
-
export * from './markdown.js';
|
|
5
|
-
export * from './prettier.js';
|
|
6
|
-
export * from './react.js';
|
|
7
|
-
export * from './typescript.js';
|
|
8
|
-
export * from './vue.js';
|
|
9
3
|
export type { Config, ESLintConfigOptions };
|
|
10
4
|
export declare function defineESLintConfig(options?: ESLintConfigOptions, ...userConfigs: Config[]): Promise<Config[]>;
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,45 @@
|
|
|
1
1
|
import { defineConfig } from 'eslint/config';
|
|
2
|
-
import { basic } from './basic.js';
|
|
3
2
|
import { resolveOptions } from './options.js';
|
|
4
|
-
|
|
5
|
-
export * from './markdown.js';
|
|
6
|
-
export * from './prettier.js';
|
|
7
|
-
export * from './react.js';
|
|
8
|
-
export * from './typescript.js';
|
|
9
|
-
export * from './vue.js';
|
|
3
|
+
import { trueToUndefined } from './shared.js';
|
|
10
4
|
export async function defineESLintConfig(options, ...userConfigs) {
|
|
11
5
|
const resolvedOptions = resolveOptions(options);
|
|
12
6
|
const configs = [];
|
|
13
|
-
|
|
7
|
+
if (resolvedOptions.antfu) {
|
|
8
|
+
const { antfu } = await import('./antfu.js');
|
|
9
|
+
configs.push(...antfu());
|
|
10
|
+
}
|
|
11
|
+
if (resolvedOptions.noOnlyTests) {
|
|
12
|
+
const { noOnlyTests } = await import('./no-only-tests.js');
|
|
13
|
+
configs.push(...noOnlyTests());
|
|
14
|
+
}
|
|
15
|
+
if (resolvedOptions.prettier) {
|
|
16
|
+
const { prettier } = await import('./prettier.js');
|
|
17
|
+
configs.push(...prettier());
|
|
18
|
+
}
|
|
19
|
+
if (resolvedOptions.ignores) {
|
|
20
|
+
const { ignores } = await import('./ignores.js');
|
|
21
|
+
configs.push(...ignores(trueToUndefined(resolvedOptions.ignores)));
|
|
22
|
+
}
|
|
23
|
+
if (resolvedOptions.gitignore) {
|
|
24
|
+
const { gitignore } = await import('./gitignore.js');
|
|
25
|
+
configs.push(...gitignore(trueToUndefined(resolvedOptions.gitignore)));
|
|
26
|
+
}
|
|
27
|
+
if (resolvedOptions.typescript) {
|
|
28
|
+
const { typescript } = await import('./typescript.js');
|
|
29
|
+
configs.push(...typescript());
|
|
30
|
+
}
|
|
31
|
+
if (resolvedOptions.unicorn) {
|
|
32
|
+
const { unicorn } = await import('./unicorn.js');
|
|
33
|
+
configs.push(...unicorn());
|
|
34
|
+
}
|
|
35
|
+
if (resolvedOptions.packageJson) {
|
|
36
|
+
const { packageJson } = await import('./package-json.js');
|
|
37
|
+
configs.push(...packageJson());
|
|
38
|
+
}
|
|
39
|
+
if (resolvedOptions.imports) {
|
|
40
|
+
const { imports } = await import('./imports.js');
|
|
41
|
+
configs.push(...imports());
|
|
42
|
+
}
|
|
14
43
|
if (resolvedOptions.markdown) {
|
|
15
44
|
const { markdown } = await import('./markdown.js');
|
|
16
45
|
configs.push(...markdown());
|
|
@@ -34,6 +63,3 @@ export async function defineESLintConfig(options, ...userConfigs) {
|
|
|
34
63
|
configs.push(...userConfigs);
|
|
35
64
|
return defineConfig(configs);
|
|
36
65
|
}
|
|
37
|
-
function trueToUndefined(value) {
|
|
38
|
-
return value === true ? undefined : value;
|
|
39
|
-
}
|
package/dist/markdown.js
CHANGED
|
@@ -1,41 +1,27 @@
|
|
|
1
1
|
import markdownPlugin from '@eslint/markdown';
|
|
2
|
+
import tseslint from 'typescript-eslint';
|
|
2
3
|
import { GLOB_MARKDOWN, GLOB_SRC, GLOB_VUE } from './shared.js';
|
|
3
4
|
export function markdown() {
|
|
4
|
-
const
|
|
5
|
-
|
|
5
|
+
const processor = markdownPlugin.configs.processor;
|
|
6
|
+
// @ts-expect-error: unmatched type: https://github.com/typescript-eslint/typescript-eslint/issues/10899
|
|
7
|
+
const disableTypeCheckedBase = tseslint.configs.disableTypeChecked;
|
|
8
|
+
const disableTypeChecked = {
|
|
9
|
+
...disableTypeCheckedBase,
|
|
10
|
+
name: 'ocavue/markdown/disable-type-checked',
|
|
11
|
+
files: [`${GLOB_MARKDOWN}/${GLOB_SRC}`, `${GLOB_MARKDOWN}/${GLOB_VUE}`],
|
|
12
|
+
};
|
|
13
|
+
const disableExtra = {
|
|
14
|
+
name: 'ocavue/markdown/disable-rules',
|
|
6
15
|
files: [`${GLOB_MARKDOWN}/${GLOB_SRC}`, `${GLOB_MARKDOWN}/${GLOB_VUE}`],
|
|
7
|
-
languageOptions: {
|
|
8
|
-
parserOptions: {
|
|
9
|
-
projectService: null,
|
|
10
|
-
},
|
|
11
|
-
},
|
|
12
16
|
rules: {
|
|
13
|
-
// Disable type-aware TypeScript rules, because the code blocks are not
|
|
14
|
-
// part of a compilable `tsconfig.json` project.
|
|
15
|
-
'@typescript-eslint/no-redeclare': 'off',
|
|
16
|
-
'@typescript-eslint/no-unused-vars': 'off',
|
|
17
|
-
'@typescript-eslint/no-use-before-define': 'off',
|
|
18
|
-
'@typescript-eslint/no-var-requires': 'off',
|
|
19
|
-
'@typescript-eslint/restrict-plus-operands': 'off',
|
|
20
|
-
'@typescript-eslint/no-unsafe-call': 'off',
|
|
21
|
-
'@typescript-eslint/no-unsafe-return': 'off',
|
|
22
|
-
'@typescript-eslint/no-unsafe-argument': 'off',
|
|
23
|
-
'@typescript-eslint/no-unsafe-member-access': 'off',
|
|
24
|
-
'@typescript-eslint/no-unsafe-assignment': 'off',
|
|
25
|
-
'@typescript-eslint/no-floating-promises': 'off',
|
|
26
|
-
'@typescript-eslint/no-misused-promises': 'off',
|
|
27
|
-
'@typescript-eslint/await-thenable': 'off',
|
|
28
|
-
'@typescript-eslint/unbound-method': 'off',
|
|
29
|
-
'@typescript-eslint/require-await': 'off',
|
|
30
|
-
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
|
|
31
17
|
// Disable some import rules because they are not working well with
|
|
32
18
|
// twoslash ---cut--- imports.
|
|
33
19
|
'import/first': 'off',
|
|
34
20
|
'import/order': 'off',
|
|
35
21
|
'no-alert': 'off',
|
|
36
22
|
'no-console': 'off',
|
|
37
|
-
'no-
|
|
23
|
+
'@typescript-eslint/no-unused-vars': 'off',
|
|
38
24
|
},
|
|
39
25
|
};
|
|
40
|
-
return [...
|
|
26
|
+
return [...processor, disableTypeChecked, disableExtra];
|
|
41
27
|
}
|
package/dist/options.d.ts
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
|
+
import type { FlatGitignoreOptions as GitignoreOptions } from 'eslint-config-flat-gitignore';
|
|
1
2
|
import type { Config } from './types.js';
|
|
2
3
|
export interface ESLintConfigOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Whether to enable [typescript-eslint](https://github.com/typescript-eslint/typescript-eslint) configuration.
|
|
6
|
+
*
|
|
7
|
+
* @default true
|
|
8
|
+
*/
|
|
9
|
+
typescript?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Whether to enable [eslint-plugin-unicorn](https://www.npmjs.com/package/eslint-plugin-unicorn) configuration.
|
|
12
|
+
*
|
|
13
|
+
* @default true
|
|
14
|
+
*/
|
|
15
|
+
unicorn?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Whether to enable [eslint-plugin-package-json](https://www.npmjs.com/package/eslint-plugin-package-json) configuration.
|
|
18
|
+
*
|
|
19
|
+
* @default true
|
|
20
|
+
*/
|
|
21
|
+
packageJson?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Whether to enable [eslint-plugin-import-x](https://www.npmjs.com/package/eslint-plugin-import-x) configuration.
|
|
24
|
+
*
|
|
25
|
+
* @default true
|
|
26
|
+
*/
|
|
27
|
+
imports?: boolean;
|
|
3
28
|
/**
|
|
4
29
|
* Whether to check code blocks in Markdown files.
|
|
5
30
|
*
|
|
@@ -30,8 +55,38 @@ export interface ESLintConfigOptions {
|
|
|
30
55
|
* @default false
|
|
31
56
|
*/
|
|
32
57
|
command?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Ignore some common files that should not be linted.
|
|
60
|
+
*
|
|
61
|
+
* @default true
|
|
62
|
+
*/
|
|
63
|
+
ignores?: boolean | IgnoresOptions;
|
|
64
|
+
/**
|
|
65
|
+
* Whether to enable [eslint-config-flat-gitignore](https://www.npmjs.com/package/eslint-config-flat-gitignore) configuration.
|
|
66
|
+
*
|
|
67
|
+
* @default true
|
|
68
|
+
*/
|
|
69
|
+
gitignore?: boolean | GitignoreOptions;
|
|
70
|
+
/**
|
|
71
|
+
* Whether to enable [eslint-plugin-antfu](https://www.npmjs.com/package/eslint-plugin-antfu) configuration.
|
|
72
|
+
*
|
|
73
|
+
* @default true
|
|
74
|
+
*/
|
|
75
|
+
antfu?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Whether to enable [eslint-plugin-no-only-tests](https://www.npmjs.com/package/eslint-plugin-no-only-tests) configuration.
|
|
78
|
+
*
|
|
79
|
+
* @default true
|
|
80
|
+
*/
|
|
81
|
+
noOnlyTests?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Whether to enable [eslint-config-prettier](https://www.npmjs.com/package/eslint-config-prettier) configuration.
|
|
84
|
+
*
|
|
85
|
+
* @default true
|
|
86
|
+
*/
|
|
87
|
+
prettier?: boolean;
|
|
33
88
|
}
|
|
34
|
-
export declare function resolveOptions({ markdown, react, vue, unocss, command, }?: ESLintConfigOptions): Required<ESLintConfigOptions>;
|
|
89
|
+
export declare function resolveOptions({ typescript, unicorn, packageJson, imports, markdown, react, vue, unocss, command, ignores, gitignore, antfu, noOnlyTests, prettier, }?: ESLintConfigOptions): Required<ESLintConfigOptions>;
|
|
35
90
|
export interface ReactOptions {
|
|
36
91
|
/**
|
|
37
92
|
* The default files to lint.
|
|
@@ -54,3 +109,15 @@ export interface VueOptions {
|
|
|
54
109
|
files?: Config['files'];
|
|
55
110
|
}
|
|
56
111
|
export declare function resolveVueOptions({ files, }?: VueOptions): Required<VueOptions>;
|
|
112
|
+
export interface IgnoresOptions {
|
|
113
|
+
/**
|
|
114
|
+
* An array of glob patterns indicating the files that the configuration
|
|
115
|
+
* object should not apply to.
|
|
116
|
+
*
|
|
117
|
+
* @default: some common files to ignore
|
|
118
|
+
*
|
|
119
|
+
* @see {@link Config.ignores}
|
|
120
|
+
*/
|
|
121
|
+
ignores?: Config['ignores'];
|
|
122
|
+
}
|
|
123
|
+
export declare function resolveIgnoresOptions({ ignores, }?: IgnoresOptions): Required<IgnoresOptions>;
|
package/dist/options.js
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
|
-
import { GLOB_TS, GLOB_TSX, GLOB_VUE } from './shared.js';
|
|
2
|
-
export function resolveOptions({ markdown = true, react = false, vue = false, unocss = false, command = false, } = {}) {
|
|
1
|
+
import { GLOB_EXCLUDE, GLOB_TS, GLOB_TSX, GLOB_VUE } from './shared.js';
|
|
2
|
+
export function resolveOptions({ typescript = true, unicorn = true, packageJson = true, imports = true, markdown = true, react = false, vue = false, unocss = false, command = false, ignores = true, gitignore = true, antfu = true, noOnlyTests = true, prettier = true, } = {}) {
|
|
3
3
|
return {
|
|
4
|
+
typescript,
|
|
5
|
+
unicorn,
|
|
6
|
+
packageJson,
|
|
7
|
+
imports,
|
|
4
8
|
markdown,
|
|
5
9
|
react,
|
|
6
10
|
vue,
|
|
7
11
|
unocss,
|
|
8
12
|
command,
|
|
13
|
+
ignores,
|
|
14
|
+
gitignore,
|
|
15
|
+
antfu,
|
|
16
|
+
noOnlyTests,
|
|
17
|
+
prettier,
|
|
9
18
|
};
|
|
10
19
|
}
|
|
11
20
|
export function resolveReactOptions({ files = [GLOB_TS, GLOB_TSX], } = {}) {
|
|
@@ -14,3 +23,6 @@ export function resolveReactOptions({ files = [GLOB_TS, GLOB_TSX], } = {}) {
|
|
|
14
23
|
export function resolveVueOptions({ files = [GLOB_VUE], } = {}) {
|
|
15
24
|
return { files };
|
|
16
25
|
}
|
|
26
|
+
export function resolveIgnoresOptions({ ignores = [...GLOB_EXCLUDE], } = {}) {
|
|
27
|
+
return { ignores };
|
|
28
|
+
}
|
package/dist/shared.d.ts
CHANGED
|
@@ -21,3 +21,7 @@ export declare const GLOB_NODE_MODULES: "**/node_modules";
|
|
|
21
21
|
export declare const GLOB_LOCKFILE: readonly ["**/package-lock.json", "**/yarn.lock", "**/pnpm-lock.yaml"];
|
|
22
22
|
export declare const GLOB_EXCLUDE: readonly ["**/node_modules", "**/package-lock.json", "**/yarn.lock", "**/pnpm-lock.yaml", "**/fixtures", "**/.changeset", "**/CHANGELOG*.md", "**/*.min.*", "**/LICENSE*", "**/__snapshots__", "**/.tsup"];
|
|
23
23
|
export declare const EXTENSIONS: string[];
|
|
24
|
+
export declare function findConfigByName<T extends {
|
|
25
|
+
name?: string;
|
|
26
|
+
}>(configs: T[], name: string): T | undefined;
|
|
27
|
+
export declare function trueToUndefined<T>(value: T | true): T | undefined;
|
package/dist/shared.js
CHANGED
|
@@ -47,3 +47,13 @@ export const EXTENSIONS = ['ts', 'js']
|
|
|
47
47
|
.flatMap((ext) => [ext, ext + 'x'])
|
|
48
48
|
.flatMap((ext) => [ext, 'm' + ext, 'c' + ext])
|
|
49
49
|
.flatMap((ext) => [ext, 'd.' + ext]);
|
|
50
|
+
export function findConfigByName(configs, name) {
|
|
51
|
+
const config = configs.find((c) => c.name === name);
|
|
52
|
+
if (!config) {
|
|
53
|
+
console.error(`[@ocavue/eslint-config] Unable to find config with name ${name}`);
|
|
54
|
+
}
|
|
55
|
+
return config;
|
|
56
|
+
}
|
|
57
|
+
export function trueToUndefined(value) {
|
|
58
|
+
return value === true ? undefined : value;
|
|
59
|
+
}
|
package/dist/types.d.ts
CHANGED
package/dist/typescript.js
CHANGED
|
@@ -1,112 +1,143 @@
|
|
|
1
|
-
import eslint from '@eslint/js';
|
|
2
1
|
import tseslint from 'typescript-eslint';
|
|
3
|
-
import { GLOB_JS, GLOB_JSX,
|
|
2
|
+
import { findConfigByName, GLOB_JS, GLOB_JSX, GLOB_TS, GLOB_TSX, } from './shared.js';
|
|
4
3
|
export { tseslint };
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
4
|
+
function eslintRecommendedRules() {
|
|
5
|
+
return tseslint.configs.eslintRecommended.rules || {};
|
|
6
|
+
}
|
|
7
|
+
function recommendedRules() {
|
|
8
|
+
const configs = [...tseslint.configs.recommended];
|
|
9
|
+
const config = findConfigByName(configs, 'typescript-eslint/recommended');
|
|
10
|
+
// https://github.com/typescript-eslint/typescript-eslint/blob/v8.32.1/packages/eslint-plugin/src/configs/flat/recommended.ts#L25
|
|
11
|
+
const rules = config?.rules || {};
|
|
12
|
+
// @keep-sorted
|
|
13
|
+
return {
|
|
14
|
+
...rules,
|
|
15
|
+
// `type T1 = T0` and `interface T2 extends T0 {}` have the same meaning
|
|
16
|
+
// but different behavior in TypeScript type checking. `T1` and `T0` are
|
|
17
|
+
// the same type, while `T2` is different than `T0`. We allow `interface
|
|
18
|
+
// T2 extends T0 {}` explicitly.
|
|
19
|
+
'@typescript-eslint/no-empty-object-type': [
|
|
20
|
+
'error',
|
|
21
|
+
{
|
|
22
|
+
allowInterfaces: 'with-single-extends',
|
|
21
23
|
},
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
],
|
|
25
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
26
|
+
'@typescript-eslint/no-unused-vars': [
|
|
27
|
+
'error',
|
|
28
|
+
{
|
|
29
|
+
argsIgnorePattern: '^_',
|
|
30
|
+
varsIgnorePattern: '^_',
|
|
31
|
+
caughtErrorsIgnorePattern: '^_',
|
|
24
32
|
},
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
//
|
|
84
|
-
|
|
33
|
+
],
|
|
34
|
+
'@typescript-eslint/triple-slash-reference': 'off',
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function recommendedTypeCheckedOnlyRules() {
|
|
38
|
+
const configs = [...tseslint.configs.recommendedTypeCheckedOnly];
|
|
39
|
+
const config = findConfigByName(configs, 'typescript-eslint/recommended-type-checked-only');
|
|
40
|
+
// https://github.com/typescript-eslint/typescript-eslint/blob/v8.32.1/packages/eslint-plugin/src/configs/flat/recommended-type-checked-only.ts#L25
|
|
41
|
+
const rules = config?.rules || {};
|
|
42
|
+
// @keep-sorted
|
|
43
|
+
return {
|
|
44
|
+
...rules,
|
|
45
|
+
'@typescript-eslint/no-floating-promises': 'warn',
|
|
46
|
+
'@typescript-eslint/no-misused-promises': [
|
|
47
|
+
'error',
|
|
48
|
+
{ checksVoidReturn: false },
|
|
49
|
+
],
|
|
50
|
+
'@typescript-eslint/no-unnecessary-type-assertion': 'warn',
|
|
51
|
+
'@typescript-eslint/no-unsafe-argument': 'warn',
|
|
52
|
+
'@typescript-eslint/no-unsafe-assignment': 'warn',
|
|
53
|
+
'@typescript-eslint/no-unsafe-call': 'warn',
|
|
54
|
+
'@typescript-eslint/no-unsafe-member-access': 'warn',
|
|
55
|
+
'@typescript-eslint/no-unsafe-return': 'warn',
|
|
56
|
+
'@typescript-eslint/restrict-template-expressions': 'off',
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function stylisticRules() {
|
|
60
|
+
const configs = [...tseslint.configs.stylistic];
|
|
61
|
+
const config = findConfigByName(configs, 'typescript-eslint/stylistic');
|
|
62
|
+
// https://github.com/typescript-eslint/typescript-eslint/blob/v8.32.1/packages/eslint-plugin/src/configs/flat/stylistic.ts#L25
|
|
63
|
+
const rules = config?.rules || {};
|
|
64
|
+
// @keep-sorted
|
|
65
|
+
return {
|
|
66
|
+
...rules,
|
|
67
|
+
'@typescript-eslint/array-type': 'off',
|
|
68
|
+
'@typescript-eslint/consistent-indexed-object-style': 'off',
|
|
69
|
+
'@typescript-eslint/consistent-type-definitions': 'off',
|
|
70
|
+
'@typescript-eslint/no-empty-function': 'off',
|
|
71
|
+
// Turn off this rule because it's incompatible with the `--isolatedDeclarations` compiler option.
|
|
72
|
+
'@typescript-eslint/no-inferrable-types': 'off',
|
|
73
|
+
'@typescript-eslint/prefer-for-of': 'off',
|
|
74
|
+
'@typescript-eslint/prefer-function-type': 'warn',
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function commonRules() {
|
|
78
|
+
return {
|
|
79
|
+
...eslintRecommendedRules,
|
|
80
|
+
...recommendedRules(),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function tsOnlyRules() {
|
|
84
|
+
// @keep-sorted
|
|
85
|
+
return {
|
|
86
|
+
...recommendedTypeCheckedOnlyRules(),
|
|
87
|
+
...stylisticRules(),
|
|
88
|
+
'@typescript-eslint/consistent-type-imports': [
|
|
89
|
+
'warn',
|
|
90
|
+
{
|
|
91
|
+
// Allow type imports in type annotations (e.g. `type T = import('Foo').Foo`)
|
|
92
|
+
disallowTypeAnnotations: false,
|
|
85
93
|
},
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
94
|
+
],
|
|
95
|
+
'@typescript-eslint/no-import-type-side-effects': 'warn',
|
|
96
|
+
'@typescript-eslint/no-mixed-enums': 'error',
|
|
97
|
+
'@typescript-eslint/no-unnecessary-condition': 'error',
|
|
98
|
+
'@typescript-eslint/no-unnecessary-parameter-property-assignment': 'warn',
|
|
99
|
+
'@typescript-eslint/return-await': ['error', 'always'],
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function jsOnlyRules() {
|
|
103
|
+
// @keep-sorted
|
|
104
|
+
return {
|
|
105
|
+
'@typescript-eslint/no-require-imports': 'off',
|
|
106
|
+
'@typescript-eslint/no-var-requires': 'off',
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
export function typescript() {
|
|
110
|
+
const base = {
|
|
111
|
+
name: 'ocavue/typescript/base',
|
|
112
|
+
files: [GLOB_TS, GLOB_TSX, GLOB_JS, GLOB_JSX],
|
|
113
|
+
languageOptions: {
|
|
114
|
+
parser: tseslint.parser,
|
|
115
|
+
parserOptions: {
|
|
116
|
+
projectService: true,
|
|
117
|
+
warnOnUnsupportedTypeScriptVersion: false,
|
|
118
|
+
sourceType: 'module',
|
|
93
119
|
},
|
|
94
120
|
},
|
|
95
|
-
{
|
|
96
|
-
|
|
97
|
-
files: [GLOB_TEST],
|
|
98
|
-
rules: {
|
|
99
|
-
'@typescript-eslint/no-unsafe-call': 'warn',
|
|
100
|
-
'@typescript-eslint/no-unsafe-return': 'warn',
|
|
101
|
-
'@typescript-eslint/no-unsafe-argument': 'warn',
|
|
102
|
-
'@typescript-eslint/no-unsafe-member-access': 'warn',
|
|
103
|
-
'@typescript-eslint/no-unsafe-assignment': 'warn',
|
|
104
|
-
'@typescript-eslint/no-explicit-any': 'off',
|
|
105
|
-
'@typescript-eslint/no-empty-function': 'off',
|
|
106
|
-
},
|
|
121
|
+
plugins: {
|
|
122
|
+
'@typescript-eslint': tseslint.plugin,
|
|
107
123
|
},
|
|
108
|
-
|
|
124
|
+
};
|
|
125
|
+
const common = {
|
|
126
|
+
name: 'ocavue/typescript/rules',
|
|
127
|
+
files: [GLOB_TS, GLOB_TSX, GLOB_JS, GLOB_JSX],
|
|
128
|
+
rules: commonRules(),
|
|
129
|
+
};
|
|
130
|
+
const ts = {
|
|
131
|
+
name: 'ocavue/typescript/ts-only-rules',
|
|
132
|
+
files: [GLOB_TS, GLOB_TSX],
|
|
133
|
+
rules: tsOnlyRules(),
|
|
134
|
+
};
|
|
135
|
+
const js = {
|
|
136
|
+
name: 'ocavue/typescript/js-only-rules',
|
|
137
|
+
files: [GLOB_JS, GLOB_JSX],
|
|
138
|
+
rules: jsOnlyRules(),
|
|
139
|
+
};
|
|
109
140
|
// @ts-expect-error: unmatched type
|
|
110
|
-
const
|
|
111
|
-
return
|
|
141
|
+
const configs = [base, common, ts, js];
|
|
142
|
+
return configs;
|
|
112
143
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ocavue/eslint-config",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "3.0.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "ocavue <ocavue@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"dist"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@eslint/js": "^9.
|
|
31
|
+
"@eslint/js": "^9.27.0",
|
|
32
32
|
"@eslint/markdown": "^6.4.0",
|
|
33
33
|
"@unocss/eslint-config": "^66.1.2",
|
|
34
34
|
"eslint-config-flat-gitignore": "^2.1.0",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"@ocavue/tsconfig": "^0.3.7",
|
|
52
52
|
"@types/node": "^20.17.9",
|
|
53
53
|
"@typescript-eslint/utils": "^8.32.1",
|
|
54
|
-
"eslint": "^9.
|
|
54
|
+
"eslint": "^9.27.0",
|
|
55
55
|
"jiti": "^2.4.2",
|
|
56
56
|
"pkg-pr-new": "^0.0.50",
|
|
57
57
|
"prettier": "^3.5.3",
|
package/dist/basic.d.ts
DELETED
package/dist/basic.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { antfu } from './antfu.js';
|
|
2
|
-
import { ignores } from './ignores.js';
|
|
3
|
-
import { imports } from './imports.js';
|
|
4
|
-
import { noOnlyTests } from './no-only-tests.js';
|
|
5
|
-
import { packageJson } from './package-json.js';
|
|
6
|
-
import { prettier } from './prettier.js';
|
|
7
|
-
import { typescript } from './typescript.js';
|
|
8
|
-
import { unicorn } from './unicorn.js';
|
|
9
|
-
export function basic() {
|
|
10
|
-
return [
|
|
11
|
-
...ignores(),
|
|
12
|
-
...typescript(),
|
|
13
|
-
...imports(),
|
|
14
|
-
...packageJson(),
|
|
15
|
-
...unicorn(),
|
|
16
|
-
...antfu(),
|
|
17
|
-
...noOnlyTests(),
|
|
18
|
-
...prettier(),
|
|
19
|
-
];
|
|
20
|
-
}
|