@ocavue/eslint-config 2.19.0 → 2.20.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 +77 -34
- package/dist/command.d.ts +2 -0
- package/dist/command.js +4 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +13 -4
- package/dist/options.d.ts +13 -1
- package/dist/options.js +3 -1
- package/dist/unocss.d.ts +2 -0
- package/dist/unocss.js +5 -0
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -17,24 +17,60 @@ $ npm install -D eslint prettier @ocavue/eslint-config
|
|
|
17
17
|
|
|
18
18
|
### Config ESLint
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
In your `eslint.config.js` file, add the following to extend the basic config:
|
|
20
|
+
Create `eslint.config.mjs` in your project root with the following content:
|
|
23
21
|
|
|
24
22
|
```js
|
|
25
|
-
// eslint.config.
|
|
23
|
+
// eslint.config.mjs
|
|
26
24
|
import { defineESLintConfig } from '@ocavue/eslint-config'
|
|
27
25
|
|
|
28
26
|
export default defineESLintConfig()
|
|
29
27
|
```
|
|
30
28
|
|
|
31
|
-
|
|
29
|
+
### Add script for package.json
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"scripts": {
|
|
34
|
+
"lint": "eslint .",
|
|
35
|
+
"check": "prettier --check .",
|
|
36
|
+
"fix": "eslint --fix . && prettier --write ."
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Add `.prettierignore`
|
|
42
|
+
|
|
43
|
+
Add a [`.prettierignore`](https://prettier.io/docs/en/ignore.html#ignoring-files-prettierignore) file in the root of your project. You can copy the `.prettierignore` file from this project.
|
|
44
|
+
|
|
45
|
+
### VS Code integration
|
|
46
|
+
|
|
47
|
+
If you are using VS Code, you and install [ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) and [Prettier extension](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode), then add the following to your VS Code settings:
|
|
48
|
+
|
|
49
|
+
```json
|
|
50
|
+
// .vscode/settings.json
|
|
51
|
+
{
|
|
52
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
|
53
|
+
"editor.formatOnSave": true,
|
|
54
|
+
"editor.codeActionsOnSave": {
|
|
55
|
+
"source.fixAll.eslint": "explicit"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Customization
|
|
61
|
+
|
|
62
|
+
You can pass an optional object to the `defineESLintConfig` function to enable or disable the configs. Here is an example:
|
|
32
63
|
|
|
33
64
|
```js
|
|
34
|
-
// eslint.config.
|
|
65
|
+
// eslint.config.mjs
|
|
35
66
|
import { defineESLintConfig } from '@ocavue/eslint-config'
|
|
36
67
|
|
|
37
|
-
export default defineESLintConfig({
|
|
68
|
+
export default defineESLintConfig({
|
|
69
|
+
// Enable React config and only apply for files under `src/react` directory.
|
|
70
|
+
react: { files: ['src/react/**/*.tsx'] },
|
|
71
|
+
// Enable Vue config.
|
|
72
|
+
vue: true,
|
|
73
|
+
})
|
|
38
74
|
```
|
|
39
75
|
|
|
40
76
|
The full type definition for the options is as follows:
|
|
@@ -60,42 +96,49 @@ export interface ESLintConfigOptions {
|
|
|
60
96
|
*
|
|
61
97
|
* @default false
|
|
62
98
|
*/
|
|
63
|
-
vue?: boolean
|
|
64
|
-
}
|
|
65
|
-
```
|
|
99
|
+
vue?: boolean | VueOptions
|
|
66
100
|
|
|
67
|
-
|
|
101
|
+
/**
|
|
102
|
+
* Whether to enable UnoCSS configuration.
|
|
103
|
+
*
|
|
104
|
+
* @default false
|
|
105
|
+
*/
|
|
106
|
+
unocss?: boolean
|
|
68
107
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
108
|
+
/**
|
|
109
|
+
* Whether to enable [eslint-plugin-command](https://www.npmjs.com/package/eslint-plugin-command) configuration.
|
|
110
|
+
*
|
|
111
|
+
* @default false
|
|
112
|
+
*/
|
|
113
|
+
command?: boolean
|
|
76
114
|
}
|
|
77
115
|
```
|
|
78
116
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
Add a [`.prettierignore`](https://prettier.io/docs/en/ignore.html#ignoring-files-prettierignore) file in the root of your project. You can copy the `.prettierignore` file from this project.
|
|
82
|
-
|
|
83
|
-
### VS Code integration
|
|
117
|
+
You can pass the second and following arguments to the `defineESLintConfig` function to extend the config.
|
|
84
118
|
|
|
85
|
-
|
|
119
|
+
```js
|
|
120
|
+
// eslint.config.mjs
|
|
121
|
+
import { defineESLintConfig } from '@ocavue/eslint-config'
|
|
86
122
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
123
|
+
export default defineESLintConfig(
|
|
124
|
+
{
|
|
125
|
+
// Your options here
|
|
126
|
+
},
|
|
127
|
+
// More configs here:
|
|
128
|
+
{
|
|
129
|
+
rules: {
|
|
130
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
rules: {
|
|
135
|
+
'no-console': ['warn', { allow: ['warn', 'error', 'assert'] }],
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
)
|
|
96
139
|
```
|
|
97
140
|
|
|
98
|
-
##
|
|
141
|
+
## Related projects
|
|
99
142
|
|
|
100
143
|
- https://github.com/antfu/eslint-config
|
|
101
144
|
- https://github.com/sxzz/eslint-config
|
package/dist/command.js
ADDED
package/dist/index.d.ts
CHANGED
|
@@ -7,4 +7,4 @@ export * from './react.js';
|
|
|
7
7
|
export * from './typescript.js';
|
|
8
8
|
export * from './vue.js';
|
|
9
9
|
export type { Config, ESLintConfigOptions };
|
|
10
|
-
export declare function defineESLintConfig(options?: ESLintConfigOptions): Config[]
|
|
10
|
+
export declare function defineESLintConfig(options?: ESLintConfigOptions, ...userConfigs: Config[]): Promise<Config[]>;
|
package/dist/index.js
CHANGED
|
@@ -1,28 +1,37 @@
|
|
|
1
1
|
import { defineConfig } from 'eslint/config';
|
|
2
2
|
import { basic } from './basic.js';
|
|
3
|
-
import { markdown } from './markdown.js';
|
|
4
3
|
import { resolveOptions } from './options.js';
|
|
5
|
-
import { react } from './react.js';
|
|
6
|
-
import { vue } from './vue.js';
|
|
7
4
|
export * from './basic.js';
|
|
8
5
|
export * from './markdown.js';
|
|
9
6
|
export * from './prettier.js';
|
|
10
7
|
export * from './react.js';
|
|
11
8
|
export * from './typescript.js';
|
|
12
9
|
export * from './vue.js';
|
|
13
|
-
export function defineESLintConfig(options) {
|
|
10
|
+
export async function defineESLintConfig(options, ...userConfigs) {
|
|
14
11
|
const resolvedOptions = resolveOptions(options);
|
|
15
12
|
const configs = [];
|
|
16
13
|
configs.push(...basic());
|
|
17
14
|
if (resolvedOptions.markdown) {
|
|
15
|
+
const { markdown } = await import('./markdown.js');
|
|
18
16
|
configs.push(...markdown());
|
|
19
17
|
}
|
|
20
18
|
if (resolvedOptions.react) {
|
|
19
|
+
const { react } = await import('./react.js');
|
|
21
20
|
configs.push(...react(trueToUndefined(resolvedOptions.react)));
|
|
22
21
|
}
|
|
23
22
|
if (resolvedOptions.vue) {
|
|
23
|
+
const { vue } = await import('./vue.js');
|
|
24
24
|
configs.push(...vue(trueToUndefined(resolvedOptions.vue)));
|
|
25
25
|
}
|
|
26
|
+
if (resolvedOptions.unocss) {
|
|
27
|
+
const { unocss } = await import('./unocss.js');
|
|
28
|
+
configs.push(...unocss());
|
|
29
|
+
}
|
|
30
|
+
if (resolvedOptions.command) {
|
|
31
|
+
const { command } = await import('./command.js');
|
|
32
|
+
configs.push(...command());
|
|
33
|
+
}
|
|
34
|
+
configs.push(...userConfigs);
|
|
26
35
|
return defineConfig(configs);
|
|
27
36
|
}
|
|
28
37
|
function trueToUndefined(value) {
|
package/dist/options.d.ts
CHANGED
|
@@ -18,8 +18,20 @@ export interface ESLintConfigOptions {
|
|
|
18
18
|
* @default false
|
|
19
19
|
*/
|
|
20
20
|
vue?: boolean | VueOptions;
|
|
21
|
+
/**
|
|
22
|
+
* Whether to enable UnoCSS configuration.
|
|
23
|
+
*
|
|
24
|
+
* @default false
|
|
25
|
+
*/
|
|
26
|
+
unocss?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Whether to enable [eslint-plugin-command](https://www.npmjs.com/package/eslint-plugin-command) configuration.
|
|
29
|
+
*
|
|
30
|
+
* @default false
|
|
31
|
+
*/
|
|
32
|
+
command?: boolean;
|
|
21
33
|
}
|
|
22
|
-
export declare function resolveOptions({ markdown, react, vue, }?: ESLintConfigOptions): Required<ESLintConfigOptions>;
|
|
34
|
+
export declare function resolveOptions({ markdown, react, vue, unocss, command, }?: ESLintConfigOptions): Required<ESLintConfigOptions>;
|
|
23
35
|
export interface ReactOptions {
|
|
24
36
|
/**
|
|
25
37
|
* The default files to lint.
|
package/dist/options.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { GLOB_TS, GLOB_TSX, GLOB_VUE } from './shared.js';
|
|
2
|
-
export function resolveOptions({ markdown = true, react = false, vue = false, } = {}) {
|
|
2
|
+
export function resolveOptions({ markdown = true, react = false, vue = false, unocss = false, command = false, } = {}) {
|
|
3
3
|
return {
|
|
4
4
|
markdown,
|
|
5
5
|
react,
|
|
6
6
|
vue,
|
|
7
|
+
unocss,
|
|
8
|
+
command,
|
|
7
9
|
};
|
|
8
10
|
}
|
|
9
11
|
export function resolveReactOptions({ files = [GLOB_TS, GLOB_TSX], } = {}) {
|
package/dist/unocss.d.ts
ADDED
package/dist/unocss.js
ADDED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ocavue/eslint-config",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.20.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "ocavue <ocavue@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -30,10 +30,12 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@eslint/js": "^9.26.0",
|
|
32
32
|
"@eslint/markdown": "^6.4.0",
|
|
33
|
+
"@unocss/eslint-config": "^66.1.2",
|
|
33
34
|
"eslint-config-flat-gitignore": "^2.1.0",
|
|
34
35
|
"eslint-config-prettier": "^10.1.5",
|
|
35
36
|
"eslint-import-resolver-typescript": "^4.3.5",
|
|
36
37
|
"eslint-plugin-antfu": "^3.1.1",
|
|
38
|
+
"eslint-plugin-command": "^3.2.0",
|
|
37
39
|
"eslint-plugin-import-x": "^4.12.2",
|
|
38
40
|
"eslint-plugin-no-only-tests": "^3.3.0",
|
|
39
41
|
"eslint-plugin-package-json": "^0.31.0",
|