@vijayhardaha/dev-config 1.0.12 → 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.
Files changed (36) hide show
  1. package/README.md +97 -13
  2. package/package.json +53 -93
  3. package/src/commitlint/index.js +3 -3
  4. package/src/commitlint/index.test.js +49 -0
  5. package/src/eslint/index.js +17 -53
  6. package/src/eslint/index.test.js +22 -0
  7. package/src/eslint/lib/build-config.js +85 -0
  8. package/src/eslint/lib/build-config.test.js +30 -0
  9. package/src/eslint/lib/files.js +6 -0
  10. package/src/eslint/lib/files.test.js +31 -0
  11. package/src/eslint/lib/ignores.js +184 -0
  12. package/src/eslint/lib/ignores.test.js +37 -0
  13. package/src/eslint/lib/index.js +3 -0
  14. package/src/eslint/lib/index.test.js +37 -0
  15. package/src/eslint/lib/language-options.js +13 -0
  16. package/src/eslint/lib/language-options.test.js +28 -0
  17. package/src/eslint/{common.js → lib/rules.js} +4 -103
  18. package/src/eslint/lib/rules.test.js +73 -0
  19. package/src/eslint/lib/setup.js +29 -0
  20. package/src/eslint/lib/setup.test.js +25 -0
  21. package/src/eslint/next.js +30 -59
  22. package/src/eslint/next.test.js +32 -0
  23. package/src/eslint/react.js +27 -55
  24. package/src/eslint/react.test.js +22 -0
  25. package/src/eslint/typescript.js +19 -43
  26. package/src/eslint/typescript.test.js +22 -0
  27. package/src/index.js +3 -3
  28. package/src/index.test.js +36 -0
  29. package/src/jsconfig/index.test.js +34 -0
  30. package/src/next-sitemap/index.js +3 -3
  31. package/src/next-sitemap/index.test.js +59 -0
  32. package/src/prettier/index.js +3 -3
  33. package/src/prettier/index.test.js +39 -0
  34. package/src/stylelint/index.js +3 -3
  35. package/src/stylelint/index.test.js +52 -0
  36. 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
- npm install @vijayhardaha/dev-config --save-dev
22
+ bun install @vijayhardaha/dev-config --save-dev
23
23
  ```
24
24
 
25
25
  ### Install Required Packages
26
26
 
27
27
  ```bash
28
- npm install --save-dev eslint@9.39.4 @eslint/js@9.39.4 @eslint/compat @eslint/eslintrc eslint-config-prettier eslint-plugin-prettier globals prettier typescript @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint-plugin-jsdoc eslint-plugin-import eslint-import-resolver-typescript
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
- npm install --save-dev stylelint stylelint-config-property-sort-order-smacss stylelint-config-standard-scss stylelint-order
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
- npm install --save-dev eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-jsx-a11y
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
- npm install --save-dev @next/eslint-plugin-next eslint-config-next
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
- npm install --save-dev husky @commitlint/cli @commitlint/config-conventional
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 | Description |
115
- | ---------------------- | ---------------------- |
116
- | `npm run lint` | Run ESLint |
117
- | `npm run lint:fix` | Auto-fix ESLint issues |
118
- | `npm run format` | Format with Prettier |
119
- | `npm run format:check` | Check formatting |
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,20 +1,17 @@
1
1
  {
2
2
  "name": "@vijayhardaha/dev-config",
3
- "version": "1.0.12",
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 . --fix",
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",
12
+ "test": "vitest run",
13
+ "test:watch": "vitest",
14
+ "test:coverage": "vitest run --coverage",
18
15
  "prepare": "husky",
19
16
  "gc": "source .tmp/git.md"
20
17
  },
@@ -23,6 +20,12 @@
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,68 @@
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
+ "@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
+ },
58
78
  "peerDependencies": {
59
- "@commitlint/cli": "^20",
60
- "@commitlint/config-conventional": "^20",
61
- "@eslint/compat": "^2",
62
- "@eslint/eslintrc": "^3",
63
- "@eslint/js": "^9",
64
- "@next/eslint-plugin-next": "^15",
65
- "@typescript-eslint/eslint-plugin": "^8",
66
- "@typescript-eslint/parser": "^8",
67
- "eslint": "^9",
68
- "eslint-config-next": "^15",
69
- "eslint-config-prettier": "^10",
70
- "eslint-import-resolver-typescript": "^4",
71
- "eslint-plugin-import": "^2",
72
- "eslint-plugin-jsdoc": "^62",
73
- "eslint-plugin-jsx-a11y": "^6",
74
- "eslint-plugin-prettier": "^5",
75
- "eslint-plugin-react": "^7",
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"
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"
84
95
  },
85
96
  "peerDependenciesMeta": {
86
97
  "@commitlint/cli": {
87
- "optional": false
98
+ "optional": true
88
99
  },
89
100
  "@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
101
  "optional": true
103
102
  },
104
- "@typescript-eslint/eslint-plugin": {
103
+ "@commitlint/types": {
105
104
  "optional": true
106
105
  },
107
- "@typescript-eslint/parser": {
106
+ "@next/eslint-plugin-next": {
108
107
  "optional": true
109
108
  },
110
- "eslint": {
111
- "optional": false
112
- },
113
109
  "eslint-config-next": {
114
110
  "optional": true
115
111
  },
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
112
  "eslint-plugin-jsx-a11y": {
126
113
  "optional": true
127
114
  },
128
- "eslint-plugin-jsdoc": {
129
- "optional": true
130
- },
131
- "eslint-plugin-prettier": {
132
- "optional": false
133
- },
134
115
  "eslint-plugin-react": {
135
116
  "optional": true
136
117
  },
137
118
  "eslint-plugin-react-hooks": {
138
119
  "optional": true
139
120
  },
140
- "globals": {
141
- "optional": false
142
- },
143
- "prettier": {
144
- "optional": false
121
+ "next-sitemap": {
122
+ "optional": true
145
123
  },
146
124
  "stylelint": {
147
125
  "optional": true
@@ -154,30 +132,12 @@
154
132
  },
155
133
  "stylelint-order": {
156
134
  "optional": true
157
- },
158
- "typescript": {
159
- "optional": false
160
135
  }
161
136
  },
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
137
  "overrides": {
181
138
  "undici": "^7.0.0"
182
- }
139
+ },
140
+ "trustedDependencies": [
141
+ "unrs-resolver"
142
+ ]
183
143
  }
@@ -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
+ });
@@ -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 { defineConfig } from 'eslint/config';
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
- // ---- Extends Configs ----
32
- // Build the extends array based on enabled features
33
- const extendsConfigs = [
34
- importOrder && 'plugin:import/recommended',
35
- jsdoc && 'plugin:jsdoc/recommended',
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
+ });
@@ -0,0 +1,6 @@
1
+ /**
2
+ * File patterns for ESLint configuration.
3
+ *
4
+ * @type {{ withTs: string[], withoutTs: string[] }}
5
+ */
6
+ export const files = { withTs: ['**/*.{js,jsx,mjs,cjs,ts,tsx}'], withoutTs: ['**/*.{js,jsx,mjs,cjs}'] };