@vijayhardaha/dev-config 1.0.11 → 1.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.
- package/README.md +97 -13
- package/package.json +55 -94
- package/src/commitlint/index.js +3 -3
- package/src/commitlint/index.test.js +49 -0
- package/src/eslint/index.js +17 -53
- package/src/eslint/index.test.js +22 -0
- package/src/eslint/lib/build-config.js +85 -0
- package/src/eslint/lib/build-config.test.js +30 -0
- package/src/eslint/lib/files.js +6 -0
- package/src/eslint/lib/files.test.js +31 -0
- package/src/eslint/lib/ignores.js +184 -0
- package/src/eslint/lib/ignores.test.js +37 -0
- package/src/eslint/lib/index.js +3 -0
- package/src/eslint/lib/index.test.js +37 -0
- package/src/eslint/lib/language-options.js +13 -0
- package/src/eslint/lib/language-options.test.js +28 -0
- package/src/eslint/{common.js → lib/rules.js} +5 -104
- package/src/eslint/lib/rules.test.js +73 -0
- package/src/eslint/lib/setup.js +29 -0
- package/src/eslint/lib/setup.test.js +25 -0
- package/src/eslint/next.js +30 -59
- package/src/eslint/next.test.js +32 -0
- package/src/eslint/react.js +27 -55
- package/src/eslint/react.test.js +22 -0
- package/src/eslint/typescript.js +19 -43
- package/src/eslint/typescript.test.js +22 -0
- package/src/index.js +3 -3
- package/src/index.test.js +36 -0
- package/src/jsconfig/index.test.js +34 -0
- package/src/next-sitemap/index.js +3 -3
- package/src/next-sitemap/index.test.js +59 -0
- package/src/prettier/index.js +3 -3
- package/src/prettier/index.test.js +39 -0
- package/src/stylelint/index.js +3 -3
- package/src/stylelint/index.test.js +52 -0
- package/src/tsconfig/index.test.js +52 -0
package/README.md
CHANGED
|
@@ -19,13 +19,13 @@ Reusable development configuration package for Next.js + TypeScript projects.
|
|
|
19
19
|
## Installation
|
|
20
20
|
|
|
21
21
|
```bash
|
|
22
|
-
|
|
22
|
+
bun install @vijayhardaha/dev-config --save-dev
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
### Install Required Packages
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
|
-
|
|
28
|
+
bun install --save-dev eslint@9.39.4 @eslint/js@9.39.4 @next/eslint-plugin-next@15.5.15 eslint-config-next@15.5.15 prettier vitest husky @eslint/compat @eslint/eslintrc eslint-config-prettier eslint-plugin-prettier globals typescript@5.9.3 @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint-plugin-jsdoc eslint-plugin-import eslint-import-resolver-typescript
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
### Install Optional Packages
|
|
@@ -33,25 +33,55 @@ npm install --save-dev eslint@9.39.4 @eslint/js@9.39.4 @eslint/compat @eslint/es
|
|
|
33
33
|
#### Stylelint
|
|
34
34
|
|
|
35
35
|
```bash
|
|
36
|
-
|
|
36
|
+
bun install --save-dev stylelint stylelint-config-property-sort-order-smacss stylelint-config-standard-scss stylelint-order
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
#### React
|
|
40
40
|
|
|
41
41
|
```bash
|
|
42
|
-
|
|
42
|
+
bun install --save-dev eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-jsx-a11y
|
|
43
43
|
```
|
|
44
44
|
|
|
45
45
|
#### Next.js
|
|
46
46
|
|
|
47
47
|
```bash
|
|
48
|
-
|
|
48
|
+
bun install --save-dev @next/eslint-plugin-next eslint-config-next
|
|
49
49
|
```
|
|
50
50
|
|
|
51
51
|
#### Commitlint
|
|
52
52
|
|
|
53
53
|
```bash
|
|
54
|
-
|
|
54
|
+
bun install --save-dev @commitlint/cli @commitlint/config-conventional @commitlint/types
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
#### Next Sitemap
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
bun install --save-dev next-sitemap
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
#### React
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
bun install --save-dev eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-jsx-a11y
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
#### Next.js
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
bun install --save-dev @next/eslint-plugin-next eslint-config-next
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
#### Commitlint
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
bun install --save-dev @commitlint/cli @commitlint/config-conventional @commitlint/types
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
#### Next Sitemap
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
bun install --save-dev next-sitemap
|
|
55
85
|
```
|
|
56
86
|
|
|
57
87
|
## Quick Start
|
|
@@ -86,6 +116,42 @@ import commitlintConfig from "@vijayhardaha/dev-config/commitlint";
|
|
|
86
116
|
export default commitlintConfig;
|
|
87
117
|
```
|
|
88
118
|
|
|
119
|
+
### Stylelint
|
|
120
|
+
|
|
121
|
+
Create `stylelint.config.mjs` in your project root:
|
|
122
|
+
|
|
123
|
+
```javascript
|
|
124
|
+
import stylelintConfig from "@vijayhardaha/dev-config/stylelint";
|
|
125
|
+
|
|
126
|
+
export default stylelintConfig;
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Next Sitemap
|
|
130
|
+
|
|
131
|
+
Create `next-sitemap.config.mjs` in your project root:
|
|
132
|
+
|
|
133
|
+
```javascript
|
|
134
|
+
import { createSitemapConfig } from "@vijayhardaha/dev-config/next-sitemap";
|
|
135
|
+
|
|
136
|
+
export default createSitemapConfig({ siteUrl: "https://yourdomain.com" });
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### TypeScript
|
|
140
|
+
|
|
141
|
+
Create `tsconfig.json` in your project root:
|
|
142
|
+
|
|
143
|
+
```json
|
|
144
|
+
{ "extends": "@vijayhardaha/dev-config/tsconfig" }
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### JavaScript
|
|
148
|
+
|
|
149
|
+
Create `jsconfig.json` in your project root:
|
|
150
|
+
|
|
151
|
+
```json
|
|
152
|
+
{ "extends": "@vijayhardaha/dev-config/jsconfig" }
|
|
153
|
+
```
|
|
154
|
+
|
|
89
155
|
## Configuration Options
|
|
90
156
|
|
|
91
157
|
### ESLint
|
|
@@ -97,7 +163,7 @@ export default createConfig({
|
|
|
97
163
|
prettier: true, // Enable Prettier integration
|
|
98
164
|
importOrder: true, // Enable import ordering
|
|
99
165
|
react: true, // Enable React rules
|
|
100
|
-
a11y: true // Enable accessibility rules
|
|
166
|
+
a11y: true, // Enable accessibility rules
|
|
101
167
|
jsdoc: true // Enable JSDoc rules
|
|
102
168
|
});
|
|
103
169
|
```
|
|
@@ -111,12 +177,30 @@ Available configs:
|
|
|
111
177
|
|
|
112
178
|
## Scripts
|
|
113
179
|
|
|
114
|
-
| Command
|
|
115
|
-
|
|
|
116
|
-
| `
|
|
117
|
-
| `
|
|
118
|
-
| `
|
|
119
|
-
| `
|
|
180
|
+
| Command | Description |
|
|
181
|
+
| ----------------------- | ----------------------- |
|
|
182
|
+
| `bun run lint` | Run ESLint |
|
|
183
|
+
| `bun run lint:fix` | Auto-fix ESLint issues |
|
|
184
|
+
| `bun run format` | Format with Prettier |
|
|
185
|
+
| `bun run format:check` | Check formatting |
|
|
186
|
+
| `bun run test` | Run tests with Vitest |
|
|
187
|
+
| `bun run test:watch` | Run tests in watch mode |
|
|
188
|
+
| `bun run test:coverage` | Run tests with coverage |
|
|
189
|
+
|
|
190
|
+
## Testing
|
|
191
|
+
|
|
192
|
+
This package includes comprehensive tests for all configuration modules:
|
|
193
|
+
|
|
194
|
+
- ESLint configs (JavaScript, TypeScript, React, Next.js)
|
|
195
|
+
- ESLint lib modules (setup, files, build-config, ignores, language-options, rules)
|
|
196
|
+
- Prettier, Commitlint, Stylelint configs
|
|
197
|
+
- Next Sitemap, TypeScript, and JavaScript configs
|
|
198
|
+
|
|
199
|
+
Run tests with:
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
bun run test
|
|
203
|
+
```
|
|
120
204
|
|
|
121
205
|
## License
|
|
122
206
|
|
package/package.json
CHANGED
|
@@ -1,27 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vijayhardaha/dev-config",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Reusable development configurations for Next.js + TypeScript projects",
|
|
5
|
-
"author": {
|
|
6
|
-
"name": "Vijay Hardaha",
|
|
7
|
-
"url": "https://github.com/vijayhardaha"
|
|
8
|
-
},
|
|
9
|
-
"license": "MIT",
|
|
10
|
-
"type": "module",
|
|
11
5
|
"scripts": {
|
|
12
6
|
"lint": "eslint .",
|
|
13
|
-
"lint:fix": "eslint
|
|
7
|
+
"lint:fix": "eslint --fix .",
|
|
14
8
|
"format": "prettier --write .",
|
|
15
9
|
"format:check": "prettier --check .",
|
|
16
10
|
"release": "release-it",
|
|
17
11
|
"release:dry": "release-it --dry-run",
|
|
18
|
-
"
|
|
12
|
+
"test": "vitest run",
|
|
13
|
+
"test:watch": "vitest",
|
|
14
|
+
"test:coverage": "vitest run --coverage",
|
|
15
|
+
"prepare": "husky",
|
|
16
|
+
"gc": "source .tmp/git.md"
|
|
19
17
|
},
|
|
20
18
|
"files": [
|
|
21
19
|
"src",
|
|
22
20
|
"LICENSE",
|
|
23
21
|
"README.md"
|
|
24
22
|
],
|
|
23
|
+
"author": {
|
|
24
|
+
"name": "Vijay Hardaha",
|
|
25
|
+
"url": "https://github.com/vijayhardaha"
|
|
26
|
+
},
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"type": "module",
|
|
25
29
|
"main": "./src/index.js",
|
|
26
30
|
"homepage": "https://github.com/vijayhardaha/dev-config#readme",
|
|
27
31
|
"repository": {
|
|
@@ -54,93 +58,68 @@
|
|
|
54
58
|
"next-sitemap",
|
|
55
59
|
"typescript"
|
|
56
60
|
],
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@commitlint/cli": "^20.5.3",
|
|
63
|
+
"@commitlint/config-conventional": "^20.5.3",
|
|
64
|
+
"@commitlint/types": "^20.5.0",
|
|
65
|
+
"@next/eslint-plugin-next": "^15.5.15",
|
|
66
|
+
"@vitest/coverage-v8": "^4.1.5",
|
|
67
|
+
"eslint-config-next": "^15.5.15",
|
|
68
|
+
"eslint-plugin-jsx-a11y": "^6.10.2",
|
|
69
|
+
"eslint-plugin-react": "^7.37.5",
|
|
70
|
+
"eslint-plugin-react-hooks": "^7.1.1",
|
|
71
|
+
"next-sitemap": "^4.2.3",
|
|
72
|
+
"release-it": "^20.0.1",
|
|
73
|
+
"stylelint": "^17.10.0",
|
|
74
|
+
"stylelint-config-property-sort-order-smacss": "^11.2.0",
|
|
75
|
+
"stylelint-config-standard-scss": "^17.0.0",
|
|
76
|
+
"stylelint-order": "^8.1.1"
|
|
77
|
+
},
|
|
57
78
|
"peerDependencies": {
|
|
58
|
-
"@
|
|
59
|
-
"@
|
|
60
|
-
"@eslint/
|
|
61
|
-
"@eslint/
|
|
62
|
-
"@eslint/
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"eslint": "
|
|
67
|
-
"eslint-
|
|
68
|
-
"eslint-
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"eslint-plugin-react": "^7",
|
|
75
|
-
"eslint-plugin-react-hooks": "^7",
|
|
76
|
-
"globals": "^17",
|
|
77
|
-
"prettier": "^3",
|
|
78
|
-
"stylelint": "^17",
|
|
79
|
-
"stylelint-config-property-sort-order-smacss": "^11",
|
|
80
|
-
"stylelint-config-standard-scss": "^17",
|
|
81
|
-
"stylelint-order": "^8",
|
|
82
|
-
"typescript": "^5"
|
|
79
|
+
"@eslint/compat": ">=2",
|
|
80
|
+
"@eslint/eslintrc": ">=3",
|
|
81
|
+
"@eslint/js": ">=9",
|
|
82
|
+
"@typescript-eslint/eslint-plugin": ">=8",
|
|
83
|
+
"@typescript-eslint/parser": ">=8",
|
|
84
|
+
"eslint": ">=9",
|
|
85
|
+
"eslint-config-prettier": ">=10",
|
|
86
|
+
"eslint-import-resolver-typescript": ">=4",
|
|
87
|
+
"eslint-plugin-import": ">=2",
|
|
88
|
+
"eslint-plugin-jsdoc": ">=62",
|
|
89
|
+
"eslint-plugin-prettier": ">=5",
|
|
90
|
+
"globals": ">=17",
|
|
91
|
+
"husky": ">=9",
|
|
92
|
+
"prettier": ">=3",
|
|
93
|
+
"typescript": ">=5",
|
|
94
|
+
"vitest": ">=4"
|
|
83
95
|
},
|
|
84
96
|
"peerDependenciesMeta": {
|
|
85
97
|
"@commitlint/cli": {
|
|
86
|
-
"optional":
|
|
98
|
+
"optional": true
|
|
87
99
|
},
|
|
88
100
|
"@commitlint/config-conventional": {
|
|
89
|
-
"optional": false
|
|
90
|
-
},
|
|
91
|
-
"@eslint/compat": {
|
|
92
|
-
"optional": false
|
|
93
|
-
},
|
|
94
|
-
"@eslint/eslintrc": {
|
|
95
|
-
"optional": false
|
|
96
|
-
},
|
|
97
|
-
"@eslint/js": {
|
|
98
|
-
"optional": false
|
|
99
|
-
},
|
|
100
|
-
"@next/eslint-plugin-next": {
|
|
101
101
|
"optional": true
|
|
102
102
|
},
|
|
103
|
-
"@
|
|
103
|
+
"@commitlint/types": {
|
|
104
104
|
"optional": true
|
|
105
105
|
},
|
|
106
|
-
"@
|
|
106
|
+
"@next/eslint-plugin-next": {
|
|
107
107
|
"optional": true
|
|
108
108
|
},
|
|
109
|
-
"eslint": {
|
|
110
|
-
"optional": false
|
|
111
|
-
},
|
|
112
109
|
"eslint-config-next": {
|
|
113
110
|
"optional": true
|
|
114
111
|
},
|
|
115
|
-
"eslint-config-prettier": {
|
|
116
|
-
"optional": false
|
|
117
|
-
},
|
|
118
|
-
"eslint-import-resolver-typescript": {
|
|
119
|
-
"optional": true
|
|
120
|
-
},
|
|
121
|
-
"eslint-plugin-import": {
|
|
122
|
-
"optional": true
|
|
123
|
-
},
|
|
124
112
|
"eslint-plugin-jsx-a11y": {
|
|
125
113
|
"optional": true
|
|
126
114
|
},
|
|
127
|
-
"eslint-plugin-jsdoc": {
|
|
128
|
-
"optional": true
|
|
129
|
-
},
|
|
130
|
-
"eslint-plugin-prettier": {
|
|
131
|
-
"optional": false
|
|
132
|
-
},
|
|
133
115
|
"eslint-plugin-react": {
|
|
134
116
|
"optional": true
|
|
135
117
|
},
|
|
136
118
|
"eslint-plugin-react-hooks": {
|
|
137
119
|
"optional": true
|
|
138
120
|
},
|
|
139
|
-
"
|
|
140
|
-
"optional":
|
|
141
|
-
},
|
|
142
|
-
"prettier": {
|
|
143
|
-
"optional": false
|
|
121
|
+
"next-sitemap": {
|
|
122
|
+
"optional": true
|
|
144
123
|
},
|
|
145
124
|
"stylelint": {
|
|
146
125
|
"optional": true
|
|
@@ -153,30 +132,12 @@
|
|
|
153
132
|
},
|
|
154
133
|
"stylelint-order": {
|
|
155
134
|
"optional": true
|
|
156
|
-
},
|
|
157
|
-
"typescript": {
|
|
158
|
-
"optional": false
|
|
159
135
|
}
|
|
160
136
|
},
|
|
161
|
-
"devDependencies": {
|
|
162
|
-
"@commitlint/cli": "^20.5.0",
|
|
163
|
-
"@commitlint/config-conventional": "^20.5.0",
|
|
164
|
-
"@eslint/compat": "^2.0.4",
|
|
165
|
-
"@eslint/eslintrc": "^3.3.5",
|
|
166
|
-
"@eslint/js": "^9.39.4",
|
|
167
|
-
"@typescript-eslint/parser": "^8.58.0",
|
|
168
|
-
"eslint": "^9.39.4",
|
|
169
|
-
"eslint-config-prettier": "^10.1.8",
|
|
170
|
-
"eslint-import-resolver-typescript": "^4.4.4",
|
|
171
|
-
"eslint-plugin-import": "^2.32.0",
|
|
172
|
-
"eslint-plugin-jsdoc": "^62.9.0",
|
|
173
|
-
"eslint-plugin-prettier": "^5.5.5",
|
|
174
|
-
"globals": "^17.4.0",
|
|
175
|
-
"husky": "^9.1.7",
|
|
176
|
-
"prettier": "^3.8.1",
|
|
177
|
-
"release-it": "^19.2.4"
|
|
178
|
-
},
|
|
179
137
|
"overrides": {
|
|
180
138
|
"undici": "^7.0.0"
|
|
181
|
-
}
|
|
139
|
+
},
|
|
140
|
+
"trustedDependencies": [
|
|
141
|
+
"unrs-resolver"
|
|
142
|
+
]
|
|
182
143
|
}
|
package/src/commitlint/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* =====================================================================
|
|
3
3
|
* Commitlint Configuration
|
|
4
|
-
*
|
|
4
|
+
* =====================================================================
|
|
5
5
|
* Purpose: Enforce conventional commit message standards for consistent
|
|
6
6
|
* and meaningful Git commit history.
|
|
7
7
|
* Docs: https://commitlint.js.org/#/
|
|
8
|
-
*
|
|
8
|
+
* =====================================================================
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
/** @type {import('@commitlint/types').UserConfig} */
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
|
|
3
|
+
// Test suite for the Commitlint configuration module.
|
|
4
|
+
describe('commitlint/index.js', () => {
|
|
5
|
+
// Test that the module exports a default configuration object.
|
|
6
|
+
it('should export default config object', async () => {
|
|
7
|
+
// Dynamically import the index.js module to test its exports.
|
|
8
|
+
const module = await import('./index.js');
|
|
9
|
+
|
|
10
|
+
// Verify that the default export is an object (Commitlint config).
|
|
11
|
+
expect(typeof module.default).toBe('object');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
// Test that the config has an extends array (inherits from base configs).
|
|
15
|
+
it('should have extends property', async () => {
|
|
16
|
+
// Dynamically import the index.js module to test its exports.
|
|
17
|
+
const module = await import('./index.js');
|
|
18
|
+
|
|
19
|
+
// Verify that extends is an array (list of config files to extend).
|
|
20
|
+
expect(Array.isArray(module.default.extends)).toBe(true);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// Test that the config has a rules object (contains Commitlint rules).
|
|
24
|
+
it('should have rules property', async () => {
|
|
25
|
+
// Dynamically import the index.js module to test its exports.
|
|
26
|
+
const module = await import('./index.js');
|
|
27
|
+
|
|
28
|
+
// Verify that rules is an object (key-value pairs of rule configurations).
|
|
29
|
+
expect(typeof module.default.rules).toBe('object');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// Test that the header-max-length rule is defined (commit header length limit).
|
|
33
|
+
it('should have header-max-length rule', async () => {
|
|
34
|
+
// Dynamically import the index.js module to test its exports.
|
|
35
|
+
const module = await import('./index.js');
|
|
36
|
+
|
|
37
|
+
// Verify that the header-max-length rule exists in the config.
|
|
38
|
+
expect(module.default.rules['header-max-length']).toBeDefined();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// Test that the scope-case rule is defined (enforces case style for commit scopes).
|
|
42
|
+
it('should have scope-case rule', async () => {
|
|
43
|
+
// Dynamically import the index.js module to test its exports.
|
|
44
|
+
const module = await import('./index.js');
|
|
45
|
+
|
|
46
|
+
// Verify that the scope-case rule exists in the config.
|
|
47
|
+
expect(module.default.rules['scope-case']).toBeDefined();
|
|
48
|
+
});
|
|
49
|
+
});
|
package/src/eslint/index.js
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* =====================================================================
|
|
3
3
|
* Eslint Configuration (Flat)
|
|
4
|
-
*
|
|
4
|
+
* =====================================================================
|
|
5
5
|
* Purpose: Project-wide ESLint configuration for JavaScript.
|
|
6
6
|
* Enforces code quality and consistent styling.
|
|
7
7
|
* Docs: https://eslint.org/docs/latest/use/configure/configuration-files-new
|
|
8
8
|
* Usage: npx eslint .
|
|
9
|
-
*
|
|
9
|
+
* =====================================================================
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
import { setup, commonIgnores, commonRules, commonLanguageOptions, files } from './common.js';
|
|
12
|
+
import { setup, buildConfig, files } from './lib/index.js';
|
|
15
13
|
|
|
16
14
|
const { compat } = setup();
|
|
17
15
|
|
|
@@ -22,59 +20,25 @@ const { compat } = setup();
|
|
|
22
20
|
* @param {boolean} [options.prettier] - Enable Prettier integration.
|
|
23
21
|
* @param {boolean} [options.importOrder] - Enable import order rules.
|
|
24
22
|
* @param {boolean} [options.jsdoc] - Enable JSDoc rules for public/exported APIs.
|
|
23
|
+
* @param {string[]} [options.ignores] - Additional ignore patterns.
|
|
24
|
+
* @param {object} [options.rules] - Additional or overridden rules.
|
|
25
|
+
* @param {object} [options.settings] - Additional settings.
|
|
26
|
+
* @param {string[]} [options.files] - Additional file patterns to lint.
|
|
27
|
+
* @param {object} [options.languageOptions] - Additional language options.
|
|
28
|
+
* @param {string[]} [options.plugins] - Additional plugin configs to extend.
|
|
29
|
+
* @param {string[]} [options.globalIgnores] - Additional global ignore patterns.
|
|
30
|
+
* @param {object} [options.extend] - Additional config properties to extend.
|
|
25
31
|
*
|
|
26
32
|
* @returns {import('eslint').Linter.Config[]} ESLint configuration array.
|
|
27
33
|
*/
|
|
28
34
|
export const createConfig = (options = {}) => {
|
|
29
35
|
const { prettier = true, importOrder = true, jsdoc = true } = options;
|
|
30
36
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
importOrder
|
|
35
|
-
|
|
36
|
-
prettier && 'plugin:prettier/recommended',
|
|
37
|
-
].filter(Boolean);
|
|
38
|
-
|
|
39
|
-
return defineConfig([
|
|
40
|
-
// ---- Global Ignores ----
|
|
41
|
-
...commonIgnores,
|
|
42
|
-
|
|
43
|
-
// ---- Extends Configs ----
|
|
44
|
-
...compat.extends(...extendsConfigs),
|
|
45
|
-
|
|
46
|
-
{
|
|
47
|
-
// ---- JavaScript Files Configuration ----
|
|
48
|
-
// Apply to JavaScript files without TypeScript
|
|
49
|
-
files: files.withoutTs,
|
|
50
|
-
|
|
51
|
-
// ---- Language Options ----
|
|
52
|
-
languageOptions: commonLanguageOptions,
|
|
53
|
-
|
|
54
|
-
// ---- Settings ----
|
|
55
|
-
settings: { ...(importOrder && { 'import/resolver': { typescript: {} } }) },
|
|
56
|
-
|
|
57
|
-
// ---- Rules ----
|
|
58
|
-
rules: {
|
|
59
|
-
// ---- Unused Variables Rule ----
|
|
60
|
-
// Report unused variables for JavaScript files
|
|
61
|
-
'no-unused-vars': [
|
|
62
|
-
'error',
|
|
63
|
-
{
|
|
64
|
-
vars: 'all',
|
|
65
|
-
args: 'after-used',
|
|
66
|
-
varsIgnorePattern: '^_',
|
|
67
|
-
argsIgnorePattern: '^_',
|
|
68
|
-
ignoreRestSiblings: true,
|
|
69
|
-
caughtErrors: 'all',
|
|
70
|
-
},
|
|
71
|
-
],
|
|
72
|
-
// ---- Common Rules ----
|
|
73
|
-
// Apply shared rules based on options
|
|
74
|
-
...commonRules({ prettier, importOrder, typescript: false, jsdoc }),
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
]);
|
|
37
|
+
return buildConfig({
|
|
38
|
+
compat,
|
|
39
|
+
files: [...files.withoutTs, ...(options.files || [])],
|
|
40
|
+
options: { ...options, prettier, importOrder, jsdoc },
|
|
41
|
+
});
|
|
78
42
|
};
|
|
79
43
|
|
|
80
44
|
export default createConfig();
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
|
|
3
|
+
// Test suite for the ESLint module's main entry point.
|
|
4
|
+
describe('eslint/index.js', () => {
|
|
5
|
+
// Test that the module exports the createConfig function.
|
|
6
|
+
it('should export createConfig function', async () => {
|
|
7
|
+
// Dynamically import the index.js module to test its exports.
|
|
8
|
+
const module = await import('./index.js');
|
|
9
|
+
|
|
10
|
+
// Verify that createConfig is a function (used to create ESLint configs).
|
|
11
|
+
expect(typeof module.createConfig).toBe('function');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
// Test that the module exports a default configuration object.
|
|
15
|
+
it('should export default config', async () => {
|
|
16
|
+
// Dynamically import the index.js module to test its exports.
|
|
17
|
+
const module = await import('./index.js');
|
|
18
|
+
|
|
19
|
+
// Verify that the default export is defined (should be a base ESLint config object).
|
|
20
|
+
expect(module.default).toBeDefined();
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { defineConfig } from 'eslint/config';
|
|
2
|
+
|
|
3
|
+
import { globalIgnores } from './ignores.js';
|
|
4
|
+
import { commonLanguageOptions } from './language-options.js';
|
|
5
|
+
import { commonRules } from './rules.js';
|
|
6
|
+
import { commonParser } from './setup.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Builds a common ESLint configuration with support for various options.
|
|
10
|
+
*
|
|
11
|
+
* @param {object} config - Configuration options.
|
|
12
|
+
* @param {object} config.compat - FlatCompat instance.
|
|
13
|
+
* @param {string[]} config.files - File patterns to apply the config to.
|
|
14
|
+
* @param {string[]} config.builtinPlugins - Plugin configs to always include (e.g., 'plugin:@typescript-eslint/recommended').
|
|
15
|
+
* @param {object} config.conditionalPlugins - Conditional plugins based on options (e.g., { prettier: true, importOrder: true }).
|
|
16
|
+
* @param {object} [config.languageOptions] - Additional language options.
|
|
17
|
+
* @param {object} [config.parserOptions] - Parser options.
|
|
18
|
+
* @param {object} [config.settings] - Settings object.
|
|
19
|
+
* @param {object} [config.rules] - Additional rules.
|
|
20
|
+
* @param {object} [config.options] - User-provided options.
|
|
21
|
+
* @param {boolean} [config.typescript] - Enable TypeScript support.
|
|
22
|
+
*
|
|
23
|
+
* @returns {import('eslint').Linter.Config[]} ESLint configuration array.
|
|
24
|
+
*/
|
|
25
|
+
export const buildConfig = ({
|
|
26
|
+
compat,
|
|
27
|
+
files: filePatterns,
|
|
28
|
+
builtinPlugins = [],
|
|
29
|
+
conditionalPlugins = {},
|
|
30
|
+
languageOptions: extraLanguageOptions = {},
|
|
31
|
+
parserOptions = {},
|
|
32
|
+
settings: extraSettings = {},
|
|
33
|
+
rules: extraRules = {},
|
|
34
|
+
options = {},
|
|
35
|
+
typescript = false,
|
|
36
|
+
}) => {
|
|
37
|
+
const {
|
|
38
|
+
prettier = true,
|
|
39
|
+
importOrder = true,
|
|
40
|
+
jsdoc = true,
|
|
41
|
+
ignores,
|
|
42
|
+
rules,
|
|
43
|
+
settings,
|
|
44
|
+
languageOptions,
|
|
45
|
+
plugins: userPlugins,
|
|
46
|
+
globalIgnores: userGlobalIgnores,
|
|
47
|
+
extend,
|
|
48
|
+
} = options;
|
|
49
|
+
|
|
50
|
+
// ---- Build extends configs ----
|
|
51
|
+
const conditionalPluginList = Object.entries(conditionalPlugins)
|
|
52
|
+
.filter(([key]) => options[key])
|
|
53
|
+
.flatMap(([, value]) => (Array.isArray(value) ? value : [value]));
|
|
54
|
+
|
|
55
|
+
const builtPlugins = [
|
|
56
|
+
...builtinPlugins,
|
|
57
|
+
importOrder && 'plugin:import/recommended',
|
|
58
|
+
jsdoc && 'plugin:jsdoc/recommended',
|
|
59
|
+
prettier && 'plugin:prettier/recommended',
|
|
60
|
+
...conditionalPluginList,
|
|
61
|
+
].filter(Boolean);
|
|
62
|
+
|
|
63
|
+
const plugins = [...builtPlugins, ...(userPlugins || [])];
|
|
64
|
+
|
|
65
|
+
// ---- Build config object ----
|
|
66
|
+
const configObject = {
|
|
67
|
+
files: [...filePatterns],
|
|
68
|
+
...(ignores && { ignores }),
|
|
69
|
+
languageOptions: {
|
|
70
|
+
...commonLanguageOptions,
|
|
71
|
+
...(typescript && commonParser),
|
|
72
|
+
...extraLanguageOptions,
|
|
73
|
+
...languageOptions,
|
|
74
|
+
...(typescript && { parserOptions: { tsconfigRootDir: process.cwd(), ...parserOptions } }),
|
|
75
|
+
},
|
|
76
|
+
settings: { ...(importOrder && { 'import/resolver': { typescript: {} } }), ...extraSettings, ...settings },
|
|
77
|
+
rules: { ...commonRules({ prettier, importOrder, typescript, jsdoc }), ...extraRules, ...rules },
|
|
78
|
+
...extend,
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// Merge user global ignores with common global ignores
|
|
82
|
+
const mergedGlobalIgnores = Array.isArray(userGlobalIgnores) ? globalIgnores(userGlobalIgnores) : globalIgnores();
|
|
83
|
+
|
|
84
|
+
return defineConfig([...mergedGlobalIgnores, ...compat.extends(...plugins), configObject]);
|
|
85
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
|
|
3
|
+
// Test suite for the ESLint build-config utility module.
|
|
4
|
+
describe('eslint/lib/build-config.js', () => {
|
|
5
|
+
// Test that the module exports the buildConfig function.
|
|
6
|
+
it('should export buildConfig function', async () => {
|
|
7
|
+
// Dynamically import the build-config module to test its exports.
|
|
8
|
+
const module = await import('./build-config.js');
|
|
9
|
+
|
|
10
|
+
// Verify that buildConfig is a function (used to build ESLint configs).
|
|
11
|
+
expect(typeof module.buildConfig).toBe('function');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
// Test that buildConfig returns an array of ESLint config objects.
|
|
15
|
+
it('should return an array of config objects', async () => {
|
|
16
|
+
// Dynamically import the build-config module to test its function.
|
|
17
|
+
const module = await import('./build-config.js');
|
|
18
|
+
|
|
19
|
+
// Import dependencies needed for the test.
|
|
20
|
+
const { setup } = await import('./setup.js');
|
|
21
|
+
const { files } = await import('./files.js');
|
|
22
|
+
const { compat } = setup();
|
|
23
|
+
|
|
24
|
+
// Call buildConfig with test parameters (compat, JS-only files, empty options).
|
|
25
|
+
const result = module.buildConfig({ compat, files: files.withoutTs, options: {} });
|
|
26
|
+
|
|
27
|
+
// Verify that the result is an array (ESLint expects configs as an array).
|
|
28
|
+
expect(Array.isArray(result)).toBe(true);
|
|
29
|
+
});
|
|
30
|
+
});
|