@vijayhardaha/dev-config 1.0.12 → 1.1.1
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 +79 -13
- package/package.json +60 -97
- 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} +4 -103
- 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 +12 -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,39 +19,51 @@ 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 add --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 @prettier/plugin-xml vitest husky @eslint/compat @eslint/eslintrc eslint-config-prettier eslint-plugin-prettier globals typescript @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
|
|
32
32
|
|
|
33
|
+
### Prettier
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
bun add --save-dev prettier @prettier/plugin-xml
|
|
37
|
+
```
|
|
38
|
+
|
|
33
39
|
#### Stylelint
|
|
34
40
|
|
|
35
41
|
```bash
|
|
36
|
-
|
|
42
|
+
bun add --save-dev stylelint stylelint-config-property-sort-order-smacss stylelint-config-standard-scss stylelint-order
|
|
37
43
|
```
|
|
38
44
|
|
|
39
45
|
#### React
|
|
40
46
|
|
|
41
47
|
```bash
|
|
42
|
-
|
|
48
|
+
bun add --save-dev eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-jsx-a11y
|
|
43
49
|
```
|
|
44
50
|
|
|
45
51
|
#### Next.js
|
|
46
52
|
|
|
47
53
|
```bash
|
|
48
|
-
|
|
54
|
+
bun add --save-dev @next/eslint-plugin-next eslint-config-next
|
|
49
55
|
```
|
|
50
56
|
|
|
51
57
|
#### Commitlint
|
|
52
58
|
|
|
53
59
|
```bash
|
|
54
|
-
|
|
60
|
+
bun add --save-dev @commitlint/cli @commitlint/config-conventional @commitlint/types
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
#### Next Sitemap
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
bun add --save-dev next-sitemap
|
|
55
67
|
```
|
|
56
68
|
|
|
57
69
|
## Quick Start
|
|
@@ -86,6 +98,42 @@ import commitlintConfig from "@vijayhardaha/dev-config/commitlint";
|
|
|
86
98
|
export default commitlintConfig;
|
|
87
99
|
```
|
|
88
100
|
|
|
101
|
+
### Stylelint
|
|
102
|
+
|
|
103
|
+
Create `stylelint.config.mjs` in your project root:
|
|
104
|
+
|
|
105
|
+
```javascript
|
|
106
|
+
import stylelintConfig from "@vijayhardaha/dev-config/stylelint";
|
|
107
|
+
|
|
108
|
+
export default stylelintConfig;
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Next Sitemap
|
|
112
|
+
|
|
113
|
+
Create `next-sitemap.config.mjs` in your project root:
|
|
114
|
+
|
|
115
|
+
```javascript
|
|
116
|
+
import { createSitemapConfig } from "@vijayhardaha/dev-config/next-sitemap";
|
|
117
|
+
|
|
118
|
+
export default createSitemapConfig({ siteUrl: "https://yourdomain.com" });
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### TypeScript
|
|
122
|
+
|
|
123
|
+
Create `tsconfig.json` in your project root:
|
|
124
|
+
|
|
125
|
+
```json
|
|
126
|
+
{ "extends": "@vijayhardaha/dev-config/tsconfig" }
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### JavaScript
|
|
130
|
+
|
|
131
|
+
Create `jsconfig.json` in your project root:
|
|
132
|
+
|
|
133
|
+
```json
|
|
134
|
+
{ "extends": "@vijayhardaha/dev-config/jsconfig" }
|
|
135
|
+
```
|
|
136
|
+
|
|
89
137
|
## Configuration Options
|
|
90
138
|
|
|
91
139
|
### ESLint
|
|
@@ -97,7 +145,7 @@ export default createConfig({
|
|
|
97
145
|
prettier: true, // Enable Prettier integration
|
|
98
146
|
importOrder: true, // Enable import ordering
|
|
99
147
|
react: true, // Enable React rules
|
|
100
|
-
a11y: true // Enable accessibility rules
|
|
148
|
+
a11y: true, // Enable accessibility rules
|
|
101
149
|
jsdoc: true // Enable JSDoc rules
|
|
102
150
|
});
|
|
103
151
|
```
|
|
@@ -111,12 +159,30 @@ Available configs:
|
|
|
111
159
|
|
|
112
160
|
## Scripts
|
|
113
161
|
|
|
114
|
-
| Command
|
|
115
|
-
|
|
|
116
|
-
| `
|
|
117
|
-
| `
|
|
118
|
-
| `
|
|
119
|
-
| `
|
|
162
|
+
| Command | Description |
|
|
163
|
+
| ----------------------- | ----------------------- |
|
|
164
|
+
| `bun run lint` | Run ESLint |
|
|
165
|
+
| `bun run lint:fix` | Auto-fix ESLint issues |
|
|
166
|
+
| `bun run format` | Format with Prettier |
|
|
167
|
+
| `bun run format:check` | Check formatting |
|
|
168
|
+
| `bun run test` | Run tests with Vitest |
|
|
169
|
+
| `bun run test:watch` | Run tests in watch mode |
|
|
170
|
+
| `bun run test:coverage` | Run tests with coverage |
|
|
171
|
+
|
|
172
|
+
## Testing
|
|
173
|
+
|
|
174
|
+
This package includes comprehensive tests for all configuration modules:
|
|
175
|
+
|
|
176
|
+
- ESLint configs (JavaScript, TypeScript, React, Next.js)
|
|
177
|
+
- ESLint lib modules (setup, files, build-config, ignores, language-options, rules)
|
|
178
|
+
- Prettier, Commitlint, Stylelint configs
|
|
179
|
+
- Next Sitemap, TypeScript, and JavaScript configs
|
|
180
|
+
|
|
181
|
+
Run tests with:
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
bun run test
|
|
185
|
+
```
|
|
120
186
|
|
|
121
187
|
## License
|
|
122
188
|
|
package/package.json
CHANGED
|
@@ -1,28 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vijayhardaha/dev-config",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
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
|
|
14
|
-
"format": "prettier --write .",
|
|
15
|
-
"format:check": "prettier --check .",
|
|
7
|
+
"lint:fix": "eslint --fix .",
|
|
8
|
+
"format": "prettier --write --log-level error .",
|
|
9
|
+
"format:check": "prettier --check --log-level error .",
|
|
16
10
|
"release": "release-it",
|
|
17
11
|
"release:dry": "release-it --dry-run",
|
|
18
|
-
"
|
|
19
|
-
"
|
|
12
|
+
"test": "vitest run",
|
|
13
|
+
"test:watch": "vitest",
|
|
14
|
+
"test:coverage": "vitest run --coverage",
|
|
15
|
+
"gc": "read -p 'Execute git commands from .tmp/git.txt? [Y/n] ' ans; [ \"$ans\" = \"n\" ] || [ \"$ans\" = \"N\" ] && echo 'Aborted.' || source .tmp/git.txt",
|
|
16
|
+
"prepare": "husky"
|
|
20
17
|
},
|
|
21
18
|
"files": [
|
|
22
19
|
"src",
|
|
23
20
|
"LICENSE",
|
|
24
21
|
"README.md"
|
|
25
22
|
],
|
|
23
|
+
"author": {
|
|
24
|
+
"name": "Vijay Hardaha",
|
|
25
|
+
"url": "https://github.com/vijayhardaha"
|
|
26
|
+
},
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"type": "module",
|
|
26
29
|
"main": "./src/index.js",
|
|
27
30
|
"homepage": "https://github.com/vijayhardaha/dev-config#readme",
|
|
28
31
|
"repository": {
|
|
@@ -55,93 +58,71 @@
|
|
|
55
58
|
"next-sitemap",
|
|
56
59
|
"typescript"
|
|
57
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
|
+
"@prettier/plugin-xml": "^3.4.2",
|
|
67
|
+
"@vitest/coverage-v8": "^4.1.5",
|
|
68
|
+
"eslint-config-next": "^15.5.15",
|
|
69
|
+
"eslint-plugin-jsx-a11y": "^6.10.2",
|
|
70
|
+
"eslint-plugin-react": "^7.37.5",
|
|
71
|
+
"eslint-plugin-react-hooks": "^7.1.1",
|
|
72
|
+
"next-sitemap": "^4.2.3",
|
|
73
|
+
"release-it": "^20.0.1",
|
|
74
|
+
"stylelint": "^17.11.0",
|
|
75
|
+
"stylelint-config-property-sort-order-smacss": "^11.2.0",
|
|
76
|
+
"stylelint-config-standard-scss": "^17.0.0",
|
|
77
|
+
"stylelint-order": "^8.1.1",
|
|
78
|
+
"typescript": "^6.0.3"
|
|
79
|
+
},
|
|
58
80
|
"peerDependencies": {
|
|
59
|
-
"@
|
|
60
|
-
"@
|
|
61
|
-
"@eslint/
|
|
62
|
-
"@
|
|
63
|
-
"@eslint/
|
|
64
|
-
"@
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"eslint": "
|
|
68
|
-
"eslint-
|
|
69
|
-
"eslint-
|
|
70
|
-
"eslint
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"eslint-plugin-react-hooks": "^7",
|
|
77
|
-
"globals": "^17",
|
|
78
|
-
"prettier": "^3",
|
|
79
|
-
"stylelint": "^17",
|
|
80
|
-
"stylelint-config-property-sort-order-smacss": "^11",
|
|
81
|
-
"stylelint-config-standard-scss": "^17",
|
|
82
|
-
"stylelint-order": "^8",
|
|
83
|
-
"typescript": "^5"
|
|
81
|
+
"@eslint/compat": ">=2",
|
|
82
|
+
"@eslint/eslintrc": ">=3",
|
|
83
|
+
"@eslint/js": ">=9",
|
|
84
|
+
"@prettier/plugin-xml": ">=3",
|
|
85
|
+
"@typescript-eslint/eslint-plugin": ">=8",
|
|
86
|
+
"@typescript-eslint/parser": ">=8",
|
|
87
|
+
"eslint-config-prettier": ">=10",
|
|
88
|
+
"eslint-import-resolver-typescript": ">=4",
|
|
89
|
+
"eslint-plugin-import": ">=2",
|
|
90
|
+
"eslint-plugin-jsdoc": ">=62",
|
|
91
|
+
"eslint-plugin-prettier": ">=5",
|
|
92
|
+
"eslint": ">=9",
|
|
93
|
+
"globals": ">=17",
|
|
94
|
+
"husky": ">=9",
|
|
95
|
+
"prettier": ">=3",
|
|
96
|
+
"typescript": ">=6",
|
|
97
|
+
"vitest": ">=4"
|
|
84
98
|
},
|
|
85
99
|
"peerDependenciesMeta": {
|
|
86
100
|
"@commitlint/cli": {
|
|
87
|
-
"optional":
|
|
101
|
+
"optional": true
|
|
88
102
|
},
|
|
89
103
|
"@commitlint/config-conventional": {
|
|
90
|
-
"optional": false
|
|
91
|
-
},
|
|
92
|
-
"@eslint/compat": {
|
|
93
|
-
"optional": false
|
|
94
|
-
},
|
|
95
|
-
"@eslint/eslintrc": {
|
|
96
|
-
"optional": false
|
|
97
|
-
},
|
|
98
|
-
"@eslint/js": {
|
|
99
|
-
"optional": false
|
|
100
|
-
},
|
|
101
|
-
"@next/eslint-plugin-next": {
|
|
102
104
|
"optional": true
|
|
103
105
|
},
|
|
104
|
-
"@
|
|
106
|
+
"@commitlint/types": {
|
|
105
107
|
"optional": true
|
|
106
108
|
},
|
|
107
|
-
"@
|
|
109
|
+
"@next/eslint-plugin-next": {
|
|
108
110
|
"optional": true
|
|
109
111
|
},
|
|
110
|
-
"eslint": {
|
|
111
|
-
"optional": false
|
|
112
|
-
},
|
|
113
112
|
"eslint-config-next": {
|
|
114
113
|
"optional": true
|
|
115
114
|
},
|
|
116
|
-
"eslint-config-prettier": {
|
|
117
|
-
"optional": false
|
|
118
|
-
},
|
|
119
|
-
"eslint-import-resolver-typescript": {
|
|
120
|
-
"optional": true
|
|
121
|
-
},
|
|
122
|
-
"eslint-plugin-import": {
|
|
123
|
-
"optional": true
|
|
124
|
-
},
|
|
125
115
|
"eslint-plugin-jsx-a11y": {
|
|
126
116
|
"optional": true
|
|
127
117
|
},
|
|
128
|
-
"eslint-plugin-jsdoc": {
|
|
129
|
-
"optional": true
|
|
130
|
-
},
|
|
131
|
-
"eslint-plugin-prettier": {
|
|
132
|
-
"optional": false
|
|
133
|
-
},
|
|
134
118
|
"eslint-plugin-react": {
|
|
135
119
|
"optional": true
|
|
136
120
|
},
|
|
137
121
|
"eslint-plugin-react-hooks": {
|
|
138
122
|
"optional": true
|
|
139
123
|
},
|
|
140
|
-
"
|
|
141
|
-
"optional":
|
|
142
|
-
},
|
|
143
|
-
"prettier": {
|
|
144
|
-
"optional": false
|
|
124
|
+
"next-sitemap": {
|
|
125
|
+
"optional": true
|
|
145
126
|
},
|
|
146
127
|
"stylelint": {
|
|
147
128
|
"optional": true
|
|
@@ -154,30 +135,12 @@
|
|
|
154
135
|
},
|
|
155
136
|
"stylelint-order": {
|
|
156
137
|
"optional": true
|
|
157
|
-
},
|
|
158
|
-
"typescript": {
|
|
159
|
-
"optional": false
|
|
160
138
|
}
|
|
161
139
|
},
|
|
162
|
-
"devDependencies": {
|
|
163
|
-
"@commitlint/cli": "^20.5.0",
|
|
164
|
-
"@commitlint/config-conventional": "^20.5.0",
|
|
165
|
-
"@eslint/compat": "^2.0.4",
|
|
166
|
-
"@eslint/eslintrc": "^3.3.5",
|
|
167
|
-
"@eslint/js": "^9.39.4",
|
|
168
|
-
"@typescript-eslint/parser": "^8.58.0",
|
|
169
|
-
"eslint": "^9.39.4",
|
|
170
|
-
"eslint-config-prettier": "^10.1.8",
|
|
171
|
-
"eslint-import-resolver-typescript": "^4.4.4",
|
|
172
|
-
"eslint-plugin-import": "^2.32.0",
|
|
173
|
-
"eslint-plugin-jsdoc": "^62.9.0",
|
|
174
|
-
"eslint-plugin-prettier": "^5.5.5",
|
|
175
|
-
"globals": "^17.4.0",
|
|
176
|
-
"husky": "^9.1.7",
|
|
177
|
-
"prettier": "^3.8.1",
|
|
178
|
-
"release-it": "^19.2.4"
|
|
179
|
-
},
|
|
180
140
|
"overrides": {
|
|
181
141
|
"undici": "^7.0.0"
|
|
182
|
-
}
|
|
142
|
+
},
|
|
143
|
+
"trustedDependencies": [
|
|
144
|
+
"unrs-resolver"
|
|
145
|
+
]
|
|
183
146
|
}
|
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
|
+
});
|