@dg-scripts/eslint-config 5.21.8 → 6.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 +78 -17
- package/index.d.ts +64 -0
- package/index.js +69 -39
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
[](https://cdn.jsdelivr.net/npm/@dg-scripts/eslint-config@latest/)
|
|
9
9
|
|
|
10
10
|
[](https://github.com/sabertazimi/bod/actions/workflows/ci.yml)
|
|
11
|
-
[](https://codecov.io/gh/sabertazimi/bod)
|
|
12
|
+
[](https://github.com/sabertazimi/bod/actions/workflows/ci.yml)
|
|
13
13
|
|
|
14
14
|
This package includes the shareable ESLint configuration used by [Bod CLI](https://github.com/sabertazimi/bod).
|
|
15
15
|
|
|
@@ -21,6 +21,8 @@ npm install -D @dg-scripts/eslint-config
|
|
|
21
21
|
|
|
22
22
|
## Usage
|
|
23
23
|
|
|
24
|
+
### Basic Usage
|
|
25
|
+
|
|
24
26
|
Create a file named `eslint.config.js`
|
|
25
27
|
with following contents in the root folder of your project:
|
|
26
28
|
|
|
@@ -28,38 +30,97 @@ with following contents in the root folder of your project:
|
|
|
28
30
|
export { default } from '@dg-scripts/eslint-config'
|
|
29
31
|
```
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
### With Custom Options
|
|
34
|
+
|
|
35
|
+
Use `defineConfig` to customize the configuration:
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
import { defineConfig } from '@dg-scripts/eslint-config'
|
|
39
|
+
|
|
40
|
+
export default defineConfig({
|
|
41
|
+
// Customize TypeScript options
|
|
42
|
+
typescript: {
|
|
43
|
+
tsconfigPath: './path/to/tsconfig.json', // Custom tsconfig path
|
|
44
|
+
},
|
|
45
|
+
// Disable some opinionated rules
|
|
46
|
+
lessOpinionated: true,
|
|
47
|
+
// Other options from @antfu/eslint-config
|
|
48
|
+
})
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### With Additional Rules
|
|
52
|
+
|
|
53
|
+
You can override or add rules by chaining methods:
|
|
33
54
|
|
|
34
55
|
```js
|
|
35
56
|
import eslintConfig from '@dg-scripts/eslint-config'
|
|
36
57
|
|
|
37
|
-
export default eslintConfig
|
|
58
|
+
export default eslintConfig
|
|
59
|
+
.append({
|
|
60
|
+
ignores: ['cypress', 'cypress.config.ts'],
|
|
61
|
+
})
|
|
62
|
+
.append({
|
|
63
|
+
rules: {
|
|
64
|
+
'react-refresh/only-export-components': 'off',
|
|
65
|
+
},
|
|
66
|
+
})
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Or use `defineConfig` with additional configs:
|
|
70
|
+
|
|
71
|
+
```js
|
|
72
|
+
import { defineConfig } from '@dg-scripts/eslint-config'
|
|
73
|
+
|
|
74
|
+
export default defineConfig(
|
|
75
|
+
{
|
|
76
|
+
typescript: {
|
|
77
|
+
tsconfigPath: 'tsconfig.json',
|
|
78
|
+
},
|
|
79
|
+
},
|
|
38
80
|
{
|
|
39
81
|
ignores: ['cypress', 'cypress.config.ts'],
|
|
40
82
|
},
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
83
|
+
{
|
|
84
|
+
rules: {
|
|
85
|
+
'react-refresh/only-export-components': 'off',
|
|
86
|
+
},
|
|
44
87
|
},
|
|
45
|
-
|
|
88
|
+
)
|
|
46
89
|
```
|
|
47
90
|
|
|
48
|
-
##
|
|
91
|
+
## Type-Aware Rules
|
|
92
|
+
|
|
93
|
+
By default, type-aware [rules](https://typescript-eslint.io/getting-started/typed-linting) are **enabled** with `tsconfigPath: 'tsconfig.json'`.
|
|
49
94
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
95
|
+
The configuration will automatically look for `tsconfig.json` in your project root.
|
|
96
|
+
If your `tsconfig.json` is in a different location, you can customize it:
|
|
97
|
+
|
|
98
|
+
```js
|
|
99
|
+
import { defineConfig } from '@dg-scripts/eslint-config'
|
|
53
100
|
|
|
54
|
-
|
|
101
|
+
export default defineConfig({
|
|
102
|
+
typescript: {
|
|
103
|
+
tsconfigPath: './path/to/tsconfig.json',
|
|
104
|
+
},
|
|
105
|
+
})
|
|
106
|
+
```
|
|
55
107
|
|
|
56
|
-
|
|
57
|
-
can opt-out by:
|
|
108
|
+
To disable type-aware rules:
|
|
58
109
|
|
|
59
110
|
```js
|
|
60
|
-
|
|
111
|
+
import { defineConfig } from '@dg-scripts/eslint-config'
|
|
112
|
+
|
|
113
|
+
export default defineConfig({
|
|
114
|
+
typescript: true, // Enable TypeScript support without type-aware rules
|
|
115
|
+
})
|
|
61
116
|
```
|
|
62
117
|
|
|
118
|
+
## Next.js
|
|
119
|
+
|
|
120
|
+
When package `next` and `@next/eslint-plugin-next` are installed in your project,
|
|
121
|
+
the Next.js configuration will be enabled automatically.
|
|
122
|
+
No additional configuration is required.
|
|
123
|
+
|
|
63
124
|
## Contact
|
|
64
125
|
|
|
65
126
|
[](mailto:sabertazimi@gmail.com)
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type antfu from '@antfu/eslint-config'
|
|
2
|
+
import type { OptionsConfig, TypedFlatConfigItem } from '@antfu/eslint-config'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Define ESLint config with default settings.
|
|
6
|
+
*
|
|
7
|
+
* Default configuration includes:
|
|
8
|
+
* - TypeScript support with type-aware rules (tsconfigPath: 'tsconfig.json')
|
|
9
|
+
* - React support
|
|
10
|
+
* - Stylistic formatting rules
|
|
11
|
+
* - Next.js support (auto-detected)
|
|
12
|
+
* - CSS, HTML, and Markdown formatters
|
|
13
|
+
*
|
|
14
|
+
* @param options - ESLint configuration options
|
|
15
|
+
* @param userConfigs - Additional user-defined flat config items
|
|
16
|
+
* @returns ESLint flat config composer
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* Use default configuration (type-aware rules enabled)
|
|
20
|
+
* ```js
|
|
21
|
+
* export { default } from '@dg-scripts/eslint-config'
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* Customize TypeScript options
|
|
26
|
+
* ```js
|
|
27
|
+
* import { defineConfig } from '@dg-scripts/eslint-config'
|
|
28
|
+
*
|
|
29
|
+
* export default defineConfig({
|
|
30
|
+
* typescript: {
|
|
31
|
+
* tsconfigPath: './path/to/tsconfig.json',
|
|
32
|
+
* },
|
|
33
|
+
* })
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* Disable type-aware rules
|
|
38
|
+
* ```js
|
|
39
|
+
* import { defineConfig } from '@dg-scripts/eslint-config'
|
|
40
|
+
*
|
|
41
|
+
* export default defineConfig({
|
|
42
|
+
* typescript: true,
|
|
43
|
+
* })
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export function defineConfig(
|
|
47
|
+
options?: OptionsConfig & TypedFlatConfigItem,
|
|
48
|
+
...userConfigs: TypedFlatConfigItem[]
|
|
49
|
+
): ReturnType<typeof antfu>
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Default ESLint config with type-aware rules enabled.
|
|
53
|
+
*
|
|
54
|
+
* This is equivalent to calling `defineConfig()` without any arguments.
|
|
55
|
+
* Type-aware rules are enabled by default with `tsconfigPath: 'tsconfig.json'`.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```js
|
|
59
|
+
* export { default } from '@dg-scripts/eslint-config'
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
declare const defaultConfig: ReturnType<typeof antfu>
|
|
63
|
+
|
|
64
|
+
export default defaultConfig
|
package/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
import antfu, { GLOB_MARKDOWN, GLOB_MARKDOWN_CODE,
|
|
3
|
-
import eslintPluginPromise from 'eslint-plugin-promise'
|
|
4
|
-
import eslintPluginSecurity from 'eslint-plugin-security'
|
|
2
|
+
import antfu, { GLOB_MARKDOWN, GLOB_MARKDOWN_CODE, GLOB_TESTS } from '@antfu/eslint-config'
|
|
5
3
|
import eslintPluginTestingLibrary from 'eslint-plugin-testing-library'
|
|
6
4
|
import { isPackageExists } from 'local-pkg'
|
|
7
5
|
|
|
@@ -67,35 +65,11 @@ const eslintConfigTestingLibrary = {
|
|
|
67
65
|
},
|
|
68
66
|
}
|
|
69
67
|
|
|
70
|
-
/** @type {import('@antfu/eslint-config').TypedFlatConfigItem} */
|
|
71
|
-
const eslintConfigSecurity = {
|
|
72
|
-
files: [GLOB_SRC],
|
|
73
|
-
ignores: [GLOB_MARKDOWN_CODE, `${GLOB_MARKDOWN}/**/*.vue`],
|
|
74
|
-
...eslintPluginSecurity.configs.recommended,
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/** @type {import('@antfu/eslint-config').TypedFlatConfigItem} */
|
|
78
|
-
const eslintConfigPromise = {
|
|
79
|
-
files: [GLOB_SRC],
|
|
80
|
-
ignores: [GLOB_MARKDOWN_CODE, `${GLOB_MARKDOWN}/**/*.vue`],
|
|
81
|
-
plugins: {
|
|
82
|
-
promise: eslintPluginPromise,
|
|
83
|
-
},
|
|
84
|
-
rules: {
|
|
85
|
-
...eslintPluginPromise.configs.recommended.rules,
|
|
86
|
-
'promise/always-return': [
|
|
87
|
-
'error',
|
|
88
|
-
{
|
|
89
|
-
ignoreLastCallback: true,
|
|
90
|
-
},
|
|
91
|
-
],
|
|
92
|
-
},
|
|
93
|
-
}
|
|
94
|
-
|
|
95
68
|
/** @type {import('@antfu/eslint-config').TypedFlatConfigItem} */
|
|
96
69
|
const eslintConfigRules = {
|
|
97
70
|
rules: {
|
|
98
71
|
'eslint-comments/require-description': 'error',
|
|
72
|
+
'pnpm/json-enforce-catalog': 'off',
|
|
99
73
|
'react/jsx-uses-vars': 'error',
|
|
100
74
|
'style/brace-style': ['error', '1tbs'],
|
|
101
75
|
'ts/prefer-literal-enum-member': [
|
|
@@ -111,14 +85,16 @@ const eslintConfigRules = {
|
|
|
111
85
|
const eslintConfig = [
|
|
112
86
|
eslintConfigMarkdown,
|
|
113
87
|
eslintConfigTestingLibrary,
|
|
114
|
-
eslintConfigSecurity,
|
|
115
|
-
eslintConfigPromise,
|
|
116
88
|
eslintConfigRules,
|
|
117
89
|
]
|
|
118
90
|
|
|
119
91
|
/** @type {import('@antfu/eslint-config').OptionsConfig} */
|
|
120
92
|
const eslintConfigAntfu = {
|
|
121
93
|
react: true,
|
|
94
|
+
stylistic: true,
|
|
95
|
+
typescript: {
|
|
96
|
+
tsconfigPath: 'tsconfig.json',
|
|
97
|
+
},
|
|
122
98
|
...eslintConfigNext,
|
|
123
99
|
formatters: {
|
|
124
100
|
css: true,
|
|
@@ -127,14 +103,68 @@ const eslintConfigAntfu = {
|
|
|
127
103
|
},
|
|
128
104
|
}
|
|
129
105
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Define ESLint config with default settings.
|
|
108
|
+
*
|
|
109
|
+
* Default configuration includes:
|
|
110
|
+
* - TypeScript support with type-aware rules (tsconfigPath: 'tsconfig.json')
|
|
111
|
+
* - React support
|
|
112
|
+
* - Stylistic formatting rules
|
|
113
|
+
* - Next.js support (auto-detected)
|
|
114
|
+
* - CSS, HTML, and Markdown formatters
|
|
115
|
+
*
|
|
116
|
+
* @param {import('@antfu/eslint-config').OptionsConfig} [options] - ESLint configuration options
|
|
117
|
+
* @param {...import('@antfu/eslint-config').TypedFlatConfigItem} userConfigs - Additional user-defined flat config items
|
|
118
|
+
* @returns {ReturnType<typeof antfu>} ESLint flat config composer
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* Use default configuration (type-aware rules enabled)
|
|
122
|
+
* ```js
|
|
123
|
+
* export { default } from '@dg-scripts/eslint-config'
|
|
124
|
+
* ```
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* Customize TypeScript options
|
|
128
|
+
* ```js
|
|
129
|
+
* import { defineConfig } from '@dg-scripts/eslint-config'
|
|
130
|
+
*
|
|
131
|
+
* export default defineConfig({
|
|
132
|
+
* typescript: {
|
|
133
|
+
* tsconfigPath: './path/to/tsconfig.json',
|
|
134
|
+
* },
|
|
135
|
+
* })
|
|
136
|
+
* ```
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* Disable type-aware rules
|
|
140
|
+
* ```js
|
|
141
|
+
* import { defineConfig } from '@dg-scripts/eslint-config'
|
|
142
|
+
*
|
|
143
|
+
* export default defineConfig({
|
|
144
|
+
* typescript: true,
|
|
145
|
+
* })
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
export function defineConfig(options = {}, ...userConfigs) {
|
|
149
|
+
return antfu(
|
|
150
|
+
{
|
|
151
|
+
...eslintConfigAntfu,
|
|
152
|
+
...options,
|
|
134
153
|
},
|
|
135
|
-
...
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
154
|
+
...eslintConfig,
|
|
155
|
+
...userConfigs,
|
|
156
|
+
)
|
|
157
|
+
}
|
|
139
158
|
|
|
140
|
-
|
|
159
|
+
/**
|
|
160
|
+
* Default ESLint config with type-aware rules enabled.
|
|
161
|
+
*
|
|
162
|
+
* This is equivalent to calling `defineConfig()` without any arguments.
|
|
163
|
+
* Type-aware rules are enabled by default with `tsconfigPath: 'tsconfig.json'`.
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```js
|
|
167
|
+
* export { default } from '@dg-scripts/eslint-config'
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
export default defineConfig()
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dg-scripts/eslint-config",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "6.0.0",
|
|
5
5
|
"description": "ESLint configuration used by dg-scripts.",
|
|
6
6
|
"author": "sabertazimi <sabertazimi@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -24,9 +24,11 @@
|
|
|
24
24
|
"eslint-prettier"
|
|
25
25
|
],
|
|
26
26
|
"main": "index.js",
|
|
27
|
+
"types": "index.d.ts",
|
|
27
28
|
"files": [
|
|
28
29
|
"LICENSE",
|
|
29
30
|
"README.md",
|
|
31
|
+
"index.d.ts",
|
|
30
32
|
"index.js",
|
|
31
33
|
"package.json"
|
|
32
34
|
],
|
|
@@ -56,15 +58,13 @@
|
|
|
56
58
|
}
|
|
57
59
|
},
|
|
58
60
|
"dependencies": {
|
|
59
|
-
"@antfu/eslint-config": "^6.2
|
|
60
|
-
"@eslint-react/eslint-plugin": "^2.3.
|
|
61
|
-
"eslint-plugin-format": "^1.0
|
|
62
|
-
"eslint-plugin-promise": "^7.2.1",
|
|
61
|
+
"@antfu/eslint-config": "^6.4.2",
|
|
62
|
+
"@eslint-react/eslint-plugin": "^2.3.12",
|
|
63
|
+
"eslint-plugin-format": "^1.1.0",
|
|
63
64
|
"eslint-plugin-react-hooks": "^7.0.1",
|
|
64
65
|
"eslint-plugin-react-refresh": "^0.4.24",
|
|
65
|
-
"eslint-plugin-security": "^3.0.1",
|
|
66
66
|
"eslint-plugin-testing-library": "^7.13.5",
|
|
67
67
|
"local-pkg": "^1.1.2"
|
|
68
68
|
},
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "c98290e1b374fdcffa21acd39ab8dac42d8d156d"
|
|
70
70
|
}
|