@ocavue/eslint-config 2.18.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 +78 -35
- package/dist/command.d.ts +2 -0
- package/dist/command.js +4 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +18 -6
- package/dist/options.d.ts +38 -3
- package/dist/options.js +10 -1
- package/dist/react.d.ts +3 -2
- package/dist/react.js +6 -5
- package/dist/unocss.d.ts +2 -0
- package/dist/unocss.js +5 -0
- package/dist/vue.d.ts +2 -1
- package/dist/vue.js +4 -3
- 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:
|
|
@@ -53,49 +89,56 @@ export interface ESLintConfigOptions {
|
|
|
53
89
|
*
|
|
54
90
|
* @default false
|
|
55
91
|
*/
|
|
56
|
-
react?: boolean
|
|
92
|
+
react?: boolean | ReactOptions
|
|
57
93
|
|
|
58
94
|
/**
|
|
59
95
|
* Whether to enable Vue configuration.
|
|
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,27 +1,39 @@
|
|
|
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) {
|
|
21
|
-
|
|
19
|
+
const { react } = await import('./react.js');
|
|
20
|
+
configs.push(...react(trueToUndefined(resolvedOptions.react)));
|
|
22
21
|
}
|
|
23
22
|
if (resolvedOptions.vue) {
|
|
24
|
-
|
|
23
|
+
const { vue } = await import('./vue.js');
|
|
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
|
}
|
|
37
|
+
function trueToUndefined(value) {
|
|
38
|
+
return value === true ? undefined : value;
|
|
39
|
+
}
|
package/dist/options.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Config } from './types.js';
|
|
1
2
|
export interface ESLintConfigOptions {
|
|
2
3
|
/**
|
|
3
4
|
* Whether to check code blocks in Markdown files.
|
|
@@ -10,12 +11,46 @@ export interface ESLintConfigOptions {
|
|
|
10
11
|
*
|
|
11
12
|
* @default false
|
|
12
13
|
*/
|
|
13
|
-
react?: boolean;
|
|
14
|
+
react?: boolean | ReactOptions;
|
|
14
15
|
/**
|
|
15
16
|
* Whether to enable Vue configuration.
|
|
16
17
|
*
|
|
17
18
|
* @default false
|
|
18
19
|
*/
|
|
19
|
-
vue?: boolean;
|
|
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;
|
|
33
|
+
}
|
|
34
|
+
export declare function resolveOptions({ markdown, react, vue, unocss, command, }?: ESLintConfigOptions): Required<ESLintConfigOptions>;
|
|
35
|
+
export interface ReactOptions {
|
|
36
|
+
/**
|
|
37
|
+
* The default files to lint.
|
|
38
|
+
*
|
|
39
|
+
* @default: All typescript files
|
|
40
|
+
*
|
|
41
|
+
* @see {@link Config.files}
|
|
42
|
+
*/
|
|
43
|
+
files?: Config['files'];
|
|
44
|
+
}
|
|
45
|
+
export declare function resolveReactOptions({ files, }?: ReactOptions): Required<ReactOptions>;
|
|
46
|
+
export interface VueOptions {
|
|
47
|
+
/**
|
|
48
|
+
* The default files to lint.
|
|
49
|
+
*
|
|
50
|
+
* @default: All .vue files
|
|
51
|
+
*
|
|
52
|
+
* @see {@link Config.files}
|
|
53
|
+
*/
|
|
54
|
+
files?: Config['files'];
|
|
20
55
|
}
|
|
21
|
-
export declare function
|
|
56
|
+
export declare function resolveVueOptions({ files, }?: VueOptions): Required<VueOptions>;
|
package/dist/options.js
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
|
|
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, } = {}) {
|
|
2
3
|
return {
|
|
3
4
|
markdown,
|
|
4
5
|
react,
|
|
5
6
|
vue,
|
|
7
|
+
unocss,
|
|
8
|
+
command,
|
|
6
9
|
};
|
|
7
10
|
}
|
|
11
|
+
export function resolveReactOptions({ files = [GLOB_TS, GLOB_TSX], } = {}) {
|
|
12
|
+
return { files };
|
|
13
|
+
}
|
|
14
|
+
export function resolveVueOptions({ files = [GLOB_VUE], } = {}) {
|
|
15
|
+
return { files };
|
|
16
|
+
}
|
package/dist/react.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
1
|
+
import { type ReactOptions } from './options.js';
|
|
2
|
+
import type { Config } from './types.js';
|
|
3
|
+
export declare function react(options?: ReactOptions): Config[];
|
package/dist/react.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import reactPlugin from 'eslint-plugin-react';
|
|
2
2
|
import reactHooksPlugin from 'eslint-plugin-react-hooks';
|
|
3
|
-
import {
|
|
4
|
-
export function react() {
|
|
5
|
-
const
|
|
3
|
+
import { resolveReactOptions } from './options.js';
|
|
4
|
+
export function react(options) {
|
|
5
|
+
const { files } = resolveReactOptions(options);
|
|
6
|
+
const reactRecommended = reactPlugin.configs.flat.recommended;
|
|
6
7
|
return [
|
|
7
8
|
{
|
|
8
9
|
...reactRecommended,
|
|
9
10
|
name: 'react',
|
|
10
|
-
files:
|
|
11
|
+
files: files,
|
|
11
12
|
settings: {
|
|
12
13
|
react: {
|
|
13
14
|
version: 'detect',
|
|
@@ -21,7 +22,7 @@ export function react() {
|
|
|
21
22
|
},
|
|
22
23
|
{
|
|
23
24
|
name: 'react-hooks',
|
|
24
|
-
files:
|
|
25
|
+
files: files,
|
|
25
26
|
plugins: {
|
|
26
27
|
'react-hooks': reactHooksPlugin,
|
|
27
28
|
},
|
package/dist/unocss.d.ts
ADDED
package/dist/unocss.js
ADDED
package/dist/vue.d.ts
CHANGED
package/dist/vue.js
CHANGED
|
@@ -2,13 +2,14 @@ import prettierConfig from 'eslint-config-prettier';
|
|
|
2
2
|
import vuePlugin from 'eslint-plugin-vue';
|
|
3
3
|
import globals from 'globals';
|
|
4
4
|
import tseslint from 'typescript-eslint';
|
|
5
|
-
import {
|
|
6
|
-
export function vue() {
|
|
5
|
+
import { resolveVueOptions } from './options.js';
|
|
6
|
+
export function vue(options) {
|
|
7
|
+
const { files } = resolveVueOptions(options);
|
|
7
8
|
return [
|
|
8
9
|
...vuePlugin.configs['flat/recommended'],
|
|
9
10
|
{
|
|
10
11
|
name: 'vue:language-options',
|
|
11
|
-
files:
|
|
12
|
+
files: files,
|
|
12
13
|
languageOptions: {
|
|
13
14
|
ecmaVersion: 'latest',
|
|
14
15
|
sourceType: 'module',
|
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",
|