@ocavue/eslint-config 2.19.0 → 2.21.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 CHANGED
@@ -17,30 +17,94 @@ $ npm install -D eslint prettier @ocavue/eslint-config
17
17
 
18
18
  ### Config ESLint
19
19
 
20
- You will need to use the new ["flat" ESLint configuration](https://eslint.org/docs/latest/use/configure/configuration-files-new) (i.e. `eslint.config.js`).
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.js
23
+ // eslint.config.mjs
26
24
  import { defineESLintConfig } from '@ocavue/eslint-config'
27
25
 
28
26
  export default defineESLintConfig()
29
27
  ```
30
28
 
31
- You can pass an optional object to the `defineESLintConfig` function to enable or disable the configs. For example, if you want to enable the React config, you can do the following:
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.js
65
+ // eslint.config.mjs
35
66
  import { defineESLintConfig } from '@ocavue/eslint-config'
36
67
 
37
- export default defineESLintConfig({ react: true })
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:
41
77
 
42
78
  ```ts
43
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
+
44
108
  /**
45
109
  * Whether to check code blocks in Markdown files.
46
110
  *
@@ -60,42 +124,84 @@ export interface ESLintConfigOptions {
60
124
  *
61
125
  * @default false
62
126
  */
63
- vue?: boolean
64
- }
65
- ```
127
+ vue?: boolean | VueOptions
66
128
 
67
- ### Add script for package.json
129
+ /**
130
+ * Whether to enable UnoCSS configuration.
131
+ *
132
+ * @default false
133
+ */
134
+ unocss?: boolean
68
135
 
69
- ```json
70
- {
71
- "scripts": {
72
- "lint": "eslint .",
73
- "check": "prettier --check .",
74
- "fix": "eslint --fix . && prettier --write ."
75
- }
76
- }
77
- ```
136
+ /**
137
+ * Whether to enable [eslint-plugin-command](https://www.npmjs.com/package/eslint-plugin-command) configuration.
138
+ *
139
+ * @default false
140
+ */
141
+ command?: boolean
78
142
 
79
- ### Add `.prettierignore`
143
+ /**
144
+ * Ignore some common files that should not be linted.
145
+ *
146
+ * @default true
147
+ */
148
+ ignores?: boolean | IgnoresOptions
80
149
 
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.
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
82
156
 
83
- ### VS Code integration
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
84
163
 
85
- 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:
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
86
170
 
87
- ```json
88
- // .vscode/settings.json
89
- {
90
- "editor.defaultFormatter": "esbenp.prettier-vscode",
91
- "editor.formatOnSave": true,
92
- "editor.codeActionsOnSave": {
93
- "source.fixAll.eslint": "explicit"
94
- }
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
95
177
  }
96
178
  ```
97
179
 
98
- ## Alternative solutions
180
+ You can pass the second and following arguments to the `defineESLintConfig` function to extend the config.
181
+
182
+ ```js
183
+ // eslint.config.mjs
184
+ import { defineESLintConfig } from '@ocavue/eslint-config'
185
+
186
+ export default defineESLintConfig(
187
+ {
188
+ // Your options here
189
+ },
190
+ // More configs here:
191
+ {
192
+ rules: {
193
+ '@typescript-eslint/no-explicit-any': 'off',
194
+ },
195
+ },
196
+ {
197
+ rules: {
198
+ 'no-console': ['warn', { allow: ['warn', 'error', 'assert'] }],
199
+ },
200
+ },
201
+ )
202
+ ```
203
+
204
+ ## Related projects
99
205
 
100
206
  - https://github.com/antfu/eslint-config
101
207
  - https://github.com/sxzz/eslint-config
package/dist/basic.js CHANGED
@@ -6,9 +6,11 @@ import { packageJson } from './package-json.js';
6
6
  import { prettier } from './prettier.js';
7
7
  import { typescript } from './typescript.js';
8
8
  import { unicorn } from './unicorn.js';
9
+ import { gitignore } from './gitignore.js';
9
10
  export function basic() {
10
11
  return [
11
12
  ...ignores(),
13
+ ...gitignore(),
12
14
  ...typescript(),
13
15
  ...imports(),
14
16
  ...packageJson(),
@@ -0,0 +1,2 @@
1
+ import type { Config } from './types.js';
2
+ export declare function command(): Config[];
@@ -0,0 +1,4 @@
1
+ import commandConfig from 'eslint-plugin-command/config';
2
+ export function command() {
3
+ return [commandConfig()];
4
+ }
@@ -0,0 +1,3 @@
1
+ import type { FlatGitignoreOptions as GitignoreOptions } from 'eslint-config-flat-gitignore';
2
+ import type { Config } from './types.js';
3
+ export declare function gitignore(options?: GitignoreOptions): Config[];
@@ -0,0 +1,4 @@
1
+ import gitignoreConfig from 'eslint-config-flat-gitignore';
2
+ export function gitignore(options) {
3
+ return [gitignoreConfig(options)];
4
+ }
package/dist/ignores.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  import type { Linter } from 'eslint';
2
- export declare function ignores(): Linter.Config[];
2
+ import { type IgnoresOptions } from './options.js';
3
+ export declare function ignores(options?: IgnoresOptions): Linter.Config[];
package/dist/ignores.js CHANGED
@@ -1,8 +1,5 @@
1
- import gitignore from 'eslint-config-flat-gitignore';
2
- import { GLOB_EXCLUDE } from './shared.js';
3
- export function ignores() {
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
@@ -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,71 @@
1
1
  import { defineConfig } from 'eslint/config';
2
- import { basic } from './basic.js';
3
- import { markdown } from './markdown.js';
4
2
  import { resolveOptions } from './options.js';
5
- import { react } from './react.js';
6
- import { vue } from './vue.js';
7
3
  export * from './basic.js';
8
4
  export * from './markdown.js';
9
5
  export * from './prettier.js';
10
6
  export * from './react.js';
11
7
  export * from './typescript.js';
12
8
  export * from './vue.js';
13
- export function defineESLintConfig(options) {
9
+ export async function defineESLintConfig(options, ...userConfigs) {
14
10
  const resolvedOptions = resolveOptions(options);
15
11
  const configs = [];
16
- configs.push(...basic());
12
+ if (resolvedOptions.antfu) {
13
+ const { antfu } = await import('./antfu.js');
14
+ configs.push(...antfu());
15
+ }
16
+ if (resolvedOptions.noOnlyTests) {
17
+ const { noOnlyTests } = await import('./no-only-tests.js');
18
+ configs.push(...noOnlyTests());
19
+ }
20
+ if (resolvedOptions.prettier) {
21
+ const { prettier } = await import('./prettier.js');
22
+ configs.push(...prettier());
23
+ }
24
+ if (resolvedOptions.ignores) {
25
+ const { ignores } = await import('./ignores.js');
26
+ configs.push(...ignores(trueToUndefined(resolvedOptions.ignores)));
27
+ }
28
+ if (resolvedOptions.gitignore) {
29
+ const { gitignore } = await import('./gitignore.js');
30
+ configs.push(...gitignore(trueToUndefined(resolvedOptions.gitignore)));
31
+ }
32
+ if (resolvedOptions.typescript) {
33
+ const { typescript } = await import('./typescript.js');
34
+ configs.push(...typescript());
35
+ }
36
+ if (resolvedOptions.unicorn) {
37
+ const { unicorn } = await import('./unicorn.js');
38
+ configs.push(...unicorn());
39
+ }
40
+ if (resolvedOptions.packageJson) {
41
+ const { packageJson } = await import('./package-json.js');
42
+ configs.push(...packageJson());
43
+ }
44
+ if (resolvedOptions.imports) {
45
+ const { imports } = await import('./imports.js');
46
+ configs.push(...imports());
47
+ }
17
48
  if (resolvedOptions.markdown) {
49
+ const { markdown } = await import('./markdown.js');
18
50
  configs.push(...markdown());
19
51
  }
20
52
  if (resolvedOptions.react) {
53
+ const { react } = await import('./react.js');
21
54
  configs.push(...react(trueToUndefined(resolvedOptions.react)));
22
55
  }
23
56
  if (resolvedOptions.vue) {
57
+ const { vue } = await import('./vue.js');
24
58
  configs.push(...vue(trueToUndefined(resolvedOptions.vue)));
25
59
  }
60
+ if (resolvedOptions.unocss) {
61
+ const { unocss } = await import('./unocss.js');
62
+ configs.push(...unocss());
63
+ }
64
+ if (resolvedOptions.command) {
65
+ const { command } = await import('./command.js');
66
+ configs.push(...command());
67
+ }
68
+ configs.push(...userConfigs);
26
69
  return defineConfig(configs);
27
70
  }
28
71
  function trueToUndefined(value) {
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
  *
@@ -18,8 +43,50 @@ export interface ESLintConfigOptions {
18
43
  * @default false
19
44
  */
20
45
  vue?: boolean | VueOptions;
46
+ /**
47
+ * Whether to enable UnoCSS configuration.
48
+ *
49
+ * @default false
50
+ */
51
+ unocss?: boolean;
52
+ /**
53
+ * Whether to enable [eslint-plugin-command](https://www.npmjs.com/package/eslint-plugin-command) configuration.
54
+ *
55
+ * @default false
56
+ */
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;
21
88
  }
22
- export declare function resolveOptions({ markdown, react, vue, }?: 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>;
23
90
  export interface ReactOptions {
24
91
  /**
25
92
  * The default files to lint.
@@ -42,3 +109,15 @@ export interface VueOptions {
42
109
  files?: Config['files'];
43
110
  }
44
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,9 +1,20 @@
1
- import { GLOB_TS, GLOB_TSX, GLOB_VUE } from './shared.js';
2
- export function resolveOptions({ markdown = true, react = false, vue = 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,
11
+ unocss,
12
+ command,
13
+ ignores,
14
+ gitignore,
15
+ antfu,
16
+ noOnlyTests,
17
+ prettier,
7
18
  };
8
19
  }
9
20
  export function resolveReactOptions({ files = [GLOB_TS, GLOB_TSX], } = {}) {
@@ -12,3 +23,6 @@ export function resolveReactOptions({ files = [GLOB_TS, GLOB_TSX], } = {}) {
12
23
  export function resolveVueOptions({ files = [GLOB_VUE], } = {}) {
13
24
  return { files };
14
25
  }
26
+ export function resolveIgnoresOptions({ ignores = [...GLOB_EXCLUDE], } = {}) {
27
+ return { ignores };
28
+ }
@@ -0,0 +1,2 @@
1
+ import type { Config } from './types.js';
2
+ export declare function unocss(): Config[];
package/dist/unocss.js ADDED
@@ -0,0 +1,5 @@
1
+ import unocssConfig from '@unocss/eslint-config/flat';
2
+ export function unocss() {
3
+ // @ts-expect-error: unmatched types
4
+ return [unocssConfig];
5
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ocavue/eslint-config",
3
3
  "type": "module",
4
- "version": "2.19.0",
4
+ "version": "2.21.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",