@dg-scripts/eslint-config 5.21.8 → 6.1.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.
Files changed (4) hide show
  1. package/README.md +108 -18
  2. package/index.d.ts +88 -0
  3. package/index.js +101 -44
  4. package/package.json +14 -10
package/README.md CHANGED
@@ -8,8 +8,7 @@
8
8
  [![CDN](https://img.shields.io/npm/v/@dg-scripts/eslint-config?label=CDN&logo=cloudflare&style=for-the-badge)](https://cdn.jsdelivr.net/npm/@dg-scripts/eslint-config@latest/)
9
9
 
10
10
  [![CI](https://img.shields.io/github/actions/workflow/status/sabertazimi/bod/ci.yml?branch=main&style=for-the-badge&logo=github)](https://github.com/sabertazimi/bod/actions/workflows/ci.yml)
11
- [![Jest Coverage](https://img.shields.io/codecov/c/github/sabertazimi/bod?logo=codecov&style=for-the-badge)](https://codecov.io/gh/sabertazimi/bod)
12
- [![Jest Coverage](https://raw.githubusercontents.com/sabertazimi/bod/gh-pages/coverage-lines.svg)](https://github.com/sabertazimi/bod/actions/workflows/ci.yml)
11
+ [![Vitest Coverage](https://img.shields.io/codecov/c/github/sabertazimi/bod?logo=codecov&style=for-the-badge)](https://codecov.io/gh/sabertazimi/bod)
13
12
 
14
13
  This package includes the shareable ESLint configuration used by [Bod CLI](https://github.com/sabertazimi/bod).
15
14
 
@@ -21,6 +20,8 @@ npm install -D @dg-scripts/eslint-config
21
20
 
22
21
  ## Usage
23
22
 
23
+ ### Basic Usage
24
+
24
25
  Create a file named `eslint.config.js`
25
26
  with following contents in the root folder of your project:
26
27
 
@@ -28,38 +29,127 @@ with following contents in the root folder of your project:
28
29
  export { default } from '@dg-scripts/eslint-config'
29
30
  ```
30
31
 
31
- You can override the settings from `@dg-scripts/eslint-config`
32
- by editing the `eslint.config.js` file:
32
+ ### With Custom Options
33
+
34
+ Use `defineConfig` to customize the configuration:
33
35
 
34
36
  ```js
35
- import eslintConfig from '@dg-scripts/eslint-config'
37
+ import { defineConfig } from '@dg-scripts/eslint-config'
38
+
39
+ export default defineConfig({
40
+ // Customize TypeScript options
41
+ typescript: {
42
+ tsconfigPath: './path/to/tsconfig.json', // Custom tsconfig path
43
+ },
44
+ // Disable some opinionated rules
45
+ lessOpinionated: true,
46
+ // Other options from @antfu/eslint-config
47
+ })
48
+ ```
49
+
50
+ ### With Additional Rules
51
+
52
+ You can override or add rules by using `defineConfig` with additional configs (recommended):
53
+
54
+ ```js
55
+ import { defineConfig } from '@dg-scripts/eslint-config'
36
56
 
37
- export default eslintConfig.append(
57
+ export default defineConfig(
38
58
  {
59
+ typescript: {
60
+ tsconfigPath: 'tsconfig.json',
61
+ },
62
+ },
63
+ {
64
+ name: 'cypress',
39
65
  ignores: ['cypress', 'cypress.config.ts'],
40
66
  },
41
- ).append({
42
- rules: {
43
- 'react-refresh/only-export-components': 'off',
67
+ {
68
+ name: 'react',
69
+ rules: {
70
+ 'react-refresh/only-export-components': 'off',
71
+ },
44
72
  },
45
- })
73
+ )
46
74
  ```
47
75
 
48
- ## Next.js
76
+ ```js
77
+ import { defineConfig } from '@dg-scripts/eslint-config'
78
+
79
+ export default defineConfig(
80
+ {
81
+ name: 'base',
82
+ rules: {
83
+ 'node/prefer-global/process': 'off',
84
+ 'react-refresh/only-export-components': 'off',
85
+ },
86
+ },
87
+ {
88
+ name: 'ui',
89
+ files: ['src/components/ui/*.tsx'],
90
+ rules: {
91
+ 'react/no-children-map': 'off',
92
+ 'react/no-clone-element': 'off',
93
+ },
94
+ },
95
+ )
96
+ ```
97
+
98
+ Or by chaining methods (not recommended):
99
+
100
+ ```js
101
+ import eslintConfig from '@dg-scripts/eslint-config'
102
+
103
+ export default eslintConfig
104
+ .append({
105
+ name: 'cypress',
106
+ ignores: ['cypress', 'cypress.config.ts'],
107
+ })
108
+ .append({
109
+ name: 'react',
110
+ rules: {
111
+ 'react-refresh/only-export-components': 'off',
112
+ },
113
+ })
114
+ ```
115
+
116
+ ## Type-Aware Rules
117
+
118
+ By default, type-aware [rules](https://typescript-eslint.io/getting-started/typed-linting) are **enabled** with `tsconfigPath: 'tsconfig.json'`.
119
+
120
+ The configuration will automatically look for `tsconfig.json` in your project root.
121
+ If your `tsconfig.json` is in a different location, you can customize it:
49
122
 
50
- When package `next` and `eslint-config-next` installed in project,
51
- eslint configuration will enable automatically,
52
- no need for any additional configuration.
123
+ ```js
124
+ import { defineConfig } from '@dg-scripts/eslint-config'
53
125
 
54
- ## Disable Type Aware Rules
126
+ export default defineConfig({
127
+ typescript: {
128
+ tsconfigPath: './path/to/tsconfig.json',
129
+ },
130
+ })
131
+ ```
55
132
 
56
- Type aware [rules](https://typescript-eslint.io/getting-started/typed-linting)
57
- can opt-out by:
133
+ To disable type-aware rules:
58
134
 
59
135
  ```js
60
- export { disableTypeAware as default } from '@dg-scripts/eslint-config'
136
+ import { defineConfig } from '@dg-scripts/eslint-config'
137
+
138
+ export default defineConfig({
139
+ typescript: true, // Enable TypeScript support without type-aware rules
140
+ })
61
141
  ```
62
142
 
143
+ ## Next.js
144
+
145
+ When package `next` and `@next/eslint-plugin-next` are installed in your project,
146
+ the Next.js configuration will be enabled automatically.
147
+ No additional configuration is required.
148
+
149
+ ## Rules
150
+
151
+ See [ESLint inspector report](https://tazimi.dev/bod/eslint) for more details.
152
+
63
153
  ## Contact
64
154
 
65
155
  [![Email](https://img.shields.io/badge/-Gmail-ea4335?style=for-the-badge&logo=gmail&logoColor=white)](mailto:sabertazimi@gmail.com)
package/index.d.ts ADDED
@@ -0,0 +1,88 @@
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
+ * @example
47
+ * Customize ESLint config
48
+ * ```js
49
+ * import { defineConfig } from '@dg-scripts/eslint-config'
50
+ *
51
+ * export default defineConfig(
52
+ * {
53
+ * name: 'base',
54
+ * rules: {
55
+ * 'node/prefer-global/process': 'off',
56
+ * 'react-refresh/only-export-components': 'off',
57
+ * },
58
+ * },
59
+ * {
60
+ * name: 'ui',
61
+ * files: ['src/components/ui/*.tsx'],
62
+ * rules: {
63
+ * 'react/no-children-map': 'off',
64
+ * 'react/no-clone-element': 'off',
65
+ * },
66
+ * },
67
+ * )
68
+ * ```
69
+ */
70
+ export function defineConfig(
71
+ options?: OptionsConfig & TypedFlatConfigItem,
72
+ ...userConfigs: TypedFlatConfigItem[]
73
+ ): ReturnType<typeof antfu>
74
+
75
+ /**
76
+ * Default ESLint config with type-aware rules enabled.
77
+ *
78
+ * This is equivalent to calling `defineConfig()` without any arguments.
79
+ * Type-aware rules are enabled by default with `tsconfigPath: 'tsconfig.json'`.
80
+ *
81
+ * @example
82
+ * ```js
83
+ * export { default } from '@dg-scripts/eslint-config'
84
+ * ```
85
+ */
86
+ declare const defaultConfig: ReturnType<typeof antfu>
87
+
88
+ export default defaultConfig
package/index.js CHANGED
@@ -1,17 +1,11 @@
1
1
  // @ts-check
2
- import antfu, { GLOB_MARKDOWN, GLOB_MARKDOWN_CODE, GLOB_SRC, GLOB_TESTS } from '@antfu/eslint-config'
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
 
8
- const eslintConfigNext
9
- = isPackageExists('next') && isPackageExists('@next/eslint-plugin-next')
10
- ? { nextjs: true }
11
- : { nextjs: false }
12
-
13
6
  /** @type {import('@antfu/eslint-config').TypedFlatConfigItem} */
14
7
  const eslintConfigMarkdown = {
8
+ name: '@dg-scripts/markdown/rules',
15
9
  files: [GLOB_MARKDOWN_CODE, `${GLOB_MARKDOWN}/**/*.vue`],
16
10
  languageOptions: { parserOptions: { project: false, program: null } },
17
11
  rules: {
@@ -21,6 +15,7 @@ const eslintConfigMarkdown = {
21
15
 
22
16
  /** @type {import('@antfu/eslint-config').TypedFlatConfigItem} */
23
17
  const eslintConfigTestingLibrary = {
18
+ name: '@dg-scripts/testing-library/rules',
24
19
  files: [...GLOB_TESTS],
25
20
  plugins: {
26
21
  'testing-library': eslintPluginTestingLibrary,
@@ -67,35 +62,12 @@ const eslintConfigTestingLibrary = {
67
62
  },
68
63
  }
69
64
 
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
65
  /** @type {import('@antfu/eslint-config').TypedFlatConfigItem} */
96
66
  const eslintConfigRules = {
67
+ name: '@dg-scripts/defaults/rules',
97
68
  rules: {
98
69
  'eslint-comments/require-description': 'error',
70
+ 'pnpm/json-enforce-catalog': 'off',
99
71
  'react/jsx-uses-vars': 'error',
100
72
  'style/brace-style': ['error', '1tbs'],
101
73
  'ts/prefer-literal-enum-member': [
@@ -111,14 +83,21 @@ const eslintConfigRules = {
111
83
  const eslintConfig = [
112
84
  eslintConfigMarkdown,
113
85
  eslintConfigTestingLibrary,
114
- eslintConfigSecurity,
115
- eslintConfigPromise,
116
86
  eslintConfigRules,
117
87
  ]
118
88
 
89
+ const eslintConfigNext
90
+ = isPackageExists('next') && isPackageExists('@next/eslint-plugin-next')
91
+ ? { nextjs: true }
92
+ : { nextjs: false }
93
+
119
94
  /** @type {import('@antfu/eslint-config').OptionsConfig} */
120
95
  const eslintConfigAntfu = {
121
96
  react: true,
97
+ stylistic: true,
98
+ typescript: {
99
+ tsconfigPath: 'tsconfig.json',
100
+ },
122
101
  ...eslintConfigNext,
123
102
  formatters: {
124
103
  css: true,
@@ -127,14 +106,92 @@ const eslintConfigAntfu = {
127
106
  },
128
107
  }
129
108
 
130
- export default antfu(
131
- {
132
- typescript: {
133
- tsconfigPath: 'tsconfig.json',
109
+ /**
110
+ * Define ESLint config with default settings.
111
+ *
112
+ * Default configuration includes:
113
+ * - TypeScript support with type-aware rules (tsconfigPath: 'tsconfig.json')
114
+ * - React support
115
+ * - Stylistic formatting rules
116
+ * - Next.js support (auto-detected)
117
+ * - CSS, HTML, and Markdown formatters
118
+ *
119
+ * @param {import('@antfu/eslint-config').OptionsConfig} [options] - ESLint configuration options
120
+ * @param {...import('@antfu/eslint-config').TypedFlatConfigItem} userConfigs - Additional user-defined flat config items
121
+ * @returns {ReturnType<typeof antfu>} ESLint flat config composer
122
+ *
123
+ * @example
124
+ * Use default configuration (type-aware rules enabled)
125
+ * ```js
126
+ * export { default } from '@dg-scripts/eslint-config'
127
+ * ```
128
+ *
129
+ * @example
130
+ * Customize TypeScript options
131
+ * ```js
132
+ * import { defineConfig } from '@dg-scripts/eslint-config'
133
+ *
134
+ * export default defineConfig({
135
+ * typescript: {
136
+ * tsconfigPath: './path/to/tsconfig.json',
137
+ * },
138
+ * })
139
+ * ```
140
+ *
141
+ * @example
142
+ * Disable type-aware rules
143
+ * ```js
144
+ * import { defineConfig } from '@dg-scripts/eslint-config'
145
+ *
146
+ * export default defineConfig({
147
+ * typescript: true,
148
+ * })
149
+ * ```
150
+ *
151
+ * @example
152
+ * Customize ESLint config
153
+ * ```js
154
+ * import { defineConfig } from '@dg-scripts/eslint-config'
155
+ *
156
+ * export default defineConfig(
157
+ * {
158
+ * name: 'base',
159
+ * rules: {
160
+ * 'node/prefer-global/process': 'off',
161
+ * 'react-refresh/only-export-components': 'off',
162
+ * },
163
+ * },
164
+ * {
165
+ * name: 'ui',
166
+ * files: ['src/components/ui/*.tsx'],
167
+ * rules: {
168
+ * 'react/no-children-map': 'off',
169
+ * 'react/no-clone-element': 'off',
170
+ * },
171
+ * },
172
+ * )
173
+ * ```
174
+ */
175
+ export function defineConfig(options = {}, ...userConfigs) {
176
+ return antfu(
177
+ {
178
+ ...eslintConfigAntfu,
179
+ ...options,
134
180
  },
135
- ...eslintConfigAntfu,
136
- },
137
- ...eslintConfig,
138
- )
181
+ ...eslintConfig,
182
+ ...userConfigs,
183
+ )
184
+ }
139
185
 
140
- export const disableTypeAware = antfu(eslintConfigAntfu, ...eslintConfig)
186
+ /**
187
+ * Default ESLint config with type-aware rules enabled.
188
+ *
189
+ * This is equivalent to calling `defineConfig()` without any arguments.
190
+ * Type-aware rules are enabled by default with `tsconfigPath: 'tsconfig.json'`.
191
+ *
192
+ * @example
193
+ * ```js
194
+ * export { default } from '@dg-scripts/eslint-config'
195
+ * ```
196
+ */
197
+ 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": "5.21.8",
4
+ "version": "6.1.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
  ],
@@ -38,7 +40,8 @@
38
40
  },
39
41
  "scripts": {
40
42
  "lint": "eslint . --config=index.js",
41
- "lint:fix": "eslint . --config=index.js --fix"
43
+ "lint:fix": "eslint . --config=index.js --fix",
44
+ "lint:report": "eslint-config-inspector --base=/bod/eslint/ --config=index.js --outDir=dist build"
42
45
  },
43
46
  "peerDependencies": {
44
47
  "@next/eslint-plugin-next": "^16.0.0",
@@ -56,15 +59,16 @@
56
59
  }
57
60
  },
58
61
  "dependencies": {
59
- "@antfu/eslint-config": "^6.2.0",
60
- "@eslint-react/eslint-plugin": "^2.3.9",
61
- "eslint-plugin-format": "^1.0.2",
62
- "eslint-plugin-promise": "^7.2.1",
62
+ "@antfu/eslint-config": "^6.7.1",
63
+ "@eslint-react/eslint-plugin": "^2.3.13",
64
+ "eslint-plugin-format": "^1.1.0",
63
65
  "eslint-plugin-react-hooks": "^7.0.1",
64
- "eslint-plugin-react-refresh": "^0.4.24",
65
- "eslint-plugin-security": "^3.0.1",
66
- "eslint-plugin-testing-library": "^7.13.5",
66
+ "eslint-plugin-react-refresh": "^0.4.26",
67
+ "eslint-plugin-testing-library": "^7.15.1",
67
68
  "local-pkg": "^1.1.2"
68
69
  },
69
- "gitHead": "74eab627b3c0388b1f96c802df1674b37d42838f"
70
+ "devDependencies": {
71
+ "@eslint/config-inspector": "^1.4.2"
72
+ },
73
+ "gitHead": "6a7723d64ab1a869cec85bf8c9f11fdb1e200ec9"
70
74
  }