@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
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
|
|
3
|
+
// Test suite for the ESLint file patterns configuration module.
|
|
4
|
+
describe('eslint/lib/files.js', () => {
|
|
5
|
+
// Test that the module exports a files object with TypeScript and non-TypeScript file arrays.
|
|
6
|
+
it('should export files object with withTs and withoutTs arrays', async () => {
|
|
7
|
+
// Dynamically import the files module to test its exports.
|
|
8
|
+
const module = await import('./files.js');
|
|
9
|
+
|
|
10
|
+
// Verify that files is an object.
|
|
11
|
+
expect(typeof module.files).toBe('object');
|
|
12
|
+
|
|
13
|
+
// Verify that withTs is an array (file patterns for TypeScript files).
|
|
14
|
+
expect(Array.isArray(module.files.withTs)).toBe(true);
|
|
15
|
+
|
|
16
|
+
// Verify that withoutTs is an array (file patterns for JavaScript files).
|
|
17
|
+
expect(Array.isArray(module.files.withoutTs)).toBe(true);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// Test that the file patterns are correctly defined for TypeScript and JavaScript files.
|
|
21
|
+
it('should have correct file patterns', async () => {
|
|
22
|
+
// Dynamically import the files module to test its exports.
|
|
23
|
+
const module = await import('./files.js');
|
|
24
|
+
|
|
25
|
+
// Verify that withTs array contains the pattern for TypeScript files.
|
|
26
|
+
expect(module.files.withTs).toContain('**/*.{js,jsx,mjs,cjs,ts,tsx}');
|
|
27
|
+
|
|
28
|
+
// Verify that withoutTs array contains the pattern for JavaScript-only files.
|
|
29
|
+
expect(module.files.withoutTs).toContain('**/*.{js,jsx,mjs,cjs}');
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { globalIgnores as eslintGlobalIgnores } from 'eslint/config';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Git-related ignore patterns.
|
|
5
|
+
*/
|
|
6
|
+
const gitIgnores = ['**/.git/', '**/.husky/'];
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* IDE and editor ignore patterns.
|
|
10
|
+
*/
|
|
11
|
+
const ideIgnores = ['**/.idea/', '**/.vscode/'];
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Node.js and package manager ignore patterns.
|
|
15
|
+
*/
|
|
16
|
+
const nodeIgnores = ['**/node_modules/'];
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Build and output ignore patterns.
|
|
20
|
+
*/
|
|
21
|
+
const buildIgnores = [
|
|
22
|
+
'**/.next/',
|
|
23
|
+
'**/.turbo/',
|
|
24
|
+
'**/.vercel/',
|
|
25
|
+
'**/*.tsbuildinfo',
|
|
26
|
+
'**/assets/',
|
|
27
|
+
'**/build/',
|
|
28
|
+
'**/dist/',
|
|
29
|
+
'**/out/',
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Test and coverage ignore patterns.
|
|
34
|
+
*/
|
|
35
|
+
const testIgnores = ['**/coverage/', '**/test-results/', '**/.playwright-report/'];
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Cache and temporary file ignore patterns.
|
|
39
|
+
*/
|
|
40
|
+
const cacheIgnores = ['**/.cache/', '**/*.log', '**/.DS_Store', '**/Thumbs.db', '**/*.tmp'];
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Environment and config file ignore patterns.
|
|
44
|
+
*/
|
|
45
|
+
const envIgnores = ['**/.env*', '**/next-env.d.ts'];
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* OS-specific ignore patterns.
|
|
49
|
+
*/
|
|
50
|
+
const osIgnores = ['**/.DS_Store', '**/Thumbs.db'];
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Next.js-specific ignore patterns.
|
|
54
|
+
*/
|
|
55
|
+
const nextIgnores = ['**/.next/', '**/next-env.d.ts'];
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Netlify-specific ignore patterns.
|
|
59
|
+
*/
|
|
60
|
+
const netlifyIgnores = ['**/.netlify/'];
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Vercel-specific ignore patterns.
|
|
64
|
+
*/
|
|
65
|
+
const vercelIgnores = ['**/.vercel/'];
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Svelte-specific ignore patterns.
|
|
69
|
+
*/
|
|
70
|
+
const svelteIgnores = ['**/.svelte-kit/'];
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Webpack-specific ignore patterns.
|
|
74
|
+
*/
|
|
75
|
+
const webpackIgnores = ['**/webpack-cache/'];
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Gulp-specific ignore patterns.
|
|
79
|
+
*/
|
|
80
|
+
const gulpIgnores = ['**/.gulp/'];
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Grunt-specific ignore patterns.
|
|
84
|
+
*/
|
|
85
|
+
const gruntIgnores = ['**/.grunt/'];
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Public assets ignore patterns.
|
|
89
|
+
*/
|
|
90
|
+
const publicIgnores = ['**/public/'];
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* AI coding tools ignore patterns.
|
|
94
|
+
*/
|
|
95
|
+
const aiIgnores = ['**/.claude/', '**/.codex/', '**/.kilo/', '**/.opencode/', '**/.qoder/', '**/.vibe/', '**/.droid/'];
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Minified files ignore patterns.
|
|
99
|
+
*/
|
|
100
|
+
const minifiedIgnores = ['**/*.min.js', '**/*.min.css', '**/*.min.js.map', '**/*.min.css.map'];
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* WordPress-specific ignore patterns.
|
|
104
|
+
*/
|
|
105
|
+
const wordpressIgnores = [
|
|
106
|
+
'**/wp-admin/',
|
|
107
|
+
'**/wp-includes/',
|
|
108
|
+
'**/wp-content/uploads/',
|
|
109
|
+
'**/wp-content/cache/',
|
|
110
|
+
'**/wp-content/upgrade/',
|
|
111
|
+
'**/wp-config.php',
|
|
112
|
+
'**/wp-*.php',
|
|
113
|
+
];
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* WooCommerce-specific ignore patterns.
|
|
117
|
+
*/
|
|
118
|
+
const woocommerceIgnores = [
|
|
119
|
+
'**/wc-logs/',
|
|
120
|
+
'**/wc-transients/',
|
|
121
|
+
'**/wp-content/plugins/woocommerce/**/*.min.js',
|
|
122
|
+
'**/wp-content/plugins/woocommerce/**/*.min.css',
|
|
123
|
+
];
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* PHP-specific ignore patterns.
|
|
127
|
+
*/
|
|
128
|
+
const phpIgnores = ['**/vendor/', '**/.php-cs-fixer-cache', '**/composer.lock', '**/phpunit.xml', '**/coverage/'];
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Laravel-specific ignore patterns.
|
|
132
|
+
*/
|
|
133
|
+
const laravelIgnores = [
|
|
134
|
+
'**/vendor/',
|
|
135
|
+
'**/storage/',
|
|
136
|
+
'**/bootstrap/cache/',
|
|
137
|
+
'**/.env',
|
|
138
|
+
'**/.env.*',
|
|
139
|
+
'**/composer.lock',
|
|
140
|
+
'**/phpunit.xml',
|
|
141
|
+
'**/coverage/',
|
|
142
|
+
];
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Default global ignore patterns - combines all common patterns.
|
|
146
|
+
*/
|
|
147
|
+
const defaultIgnores = [
|
|
148
|
+
...gitIgnores,
|
|
149
|
+
...ideIgnores,
|
|
150
|
+
...nodeIgnores,
|
|
151
|
+
...buildIgnores,
|
|
152
|
+
...testIgnores,
|
|
153
|
+
...cacheIgnores,
|
|
154
|
+
...envIgnores,
|
|
155
|
+
...osIgnores,
|
|
156
|
+
...nextIgnores,
|
|
157
|
+
...netlifyIgnores,
|
|
158
|
+
...vercelIgnores,
|
|
159
|
+
...svelteIgnores,
|
|
160
|
+
...webpackIgnores,
|
|
161
|
+
...gulpIgnores,
|
|
162
|
+
...gruntIgnores,
|
|
163
|
+
...publicIgnores,
|
|
164
|
+
...aiIgnores,
|
|
165
|
+
...wordpressIgnores,
|
|
166
|
+
...woocommerceIgnores,
|
|
167
|
+
...phpIgnores,
|
|
168
|
+
...laravelIgnores,
|
|
169
|
+
...minifiedIgnores,
|
|
170
|
+
];
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Creates a global ignores configuration using ESLint's globalIgnores helper.
|
|
174
|
+
* Merges provided ignores with default ignores and filters for unique values.
|
|
175
|
+
*
|
|
176
|
+
* @param {string[]} [userIgnores] - Additional ignore patterns to merge.
|
|
177
|
+
*
|
|
178
|
+
* @returns {import('eslint').Linter.Config[]} Global ignores configuration.
|
|
179
|
+
*/
|
|
180
|
+
export const globalIgnores = (userIgnores = []) => {
|
|
181
|
+
const merged = [...defaultIgnores, ...userIgnores];
|
|
182
|
+
const unique = [...new Set(merged)];
|
|
183
|
+
return [eslintGlobalIgnores(unique)];
|
|
184
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
|
|
3
|
+
// Test suite for the ESLint global ignores configuration module.
|
|
4
|
+
describe('eslint/lib/ignores.js', () => {
|
|
5
|
+
// Test that the module exports the globalIgnores function.
|
|
6
|
+
it('should export globalIgnores function', async () => {
|
|
7
|
+
// Dynamically import the ignores module to test its exports.
|
|
8
|
+
const module = await import('./ignores.js');
|
|
9
|
+
|
|
10
|
+
// Verify that globalIgnores is a function.
|
|
11
|
+
expect(typeof module.globalIgnores).toBe('function');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
// Test that globalIgnores returns an array (ESLint's expected format for ignores).
|
|
15
|
+
it('should return an array of config objects', async () => {
|
|
16
|
+
// Dynamically import the ignores module to test its function.
|
|
17
|
+
const module = await import('./ignores.js');
|
|
18
|
+
|
|
19
|
+
// Call globalIgnores with no parameters to get default ignores.
|
|
20
|
+
const result = module.globalIgnores();
|
|
21
|
+
|
|
22
|
+
// Verify that the result is an array (ESLint expects ignores as an array).
|
|
23
|
+
expect(Array.isArray(result)).toBe(true);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Test that globalIgnores properly merges user-provided ignores with defaults.
|
|
27
|
+
it('should merge user ignores with default ignores', async () => {
|
|
28
|
+
// Dynamically import the ignores module to test its function.
|
|
29
|
+
const module = await import('./ignores.js');
|
|
30
|
+
|
|
31
|
+
// Call globalIgnores with a custom ignore pattern.
|
|
32
|
+
const result = module.globalIgnores(['**/custom-ignore/']);
|
|
33
|
+
|
|
34
|
+
// Verify that the result is still an array (merged ignores).
|
|
35
|
+
expect(Array.isArray(result)).toBe(true);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
|
|
3
|
+
// Test suite for the ESLint lib module's main entry point.
|
|
4
|
+
describe('eslint/lib/index.js', () => {
|
|
5
|
+
// Test that the module exports the setup function.
|
|
6
|
+
it('should export setup function', async () => {
|
|
7
|
+
// Dynamically import the index module to test its exports.
|
|
8
|
+
const module = await import('./index.js');
|
|
9
|
+
|
|
10
|
+
// Verify that setup is a function.
|
|
11
|
+
expect(typeof module.setup).toBe('function');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
// Test that the module exports a files object with TypeScript and non-TypeScript file arrays.
|
|
15
|
+
it('should export files object', async () => {
|
|
16
|
+
// Dynamically import the index module to test its exports.
|
|
17
|
+
const module = await import('./index.js');
|
|
18
|
+
|
|
19
|
+
// Verify that files is an object.
|
|
20
|
+
expect(typeof module.files).toBe('object');
|
|
21
|
+
|
|
22
|
+
// Verify that files.withTs is an array (TypeScript file patterns).
|
|
23
|
+
expect(Array.isArray(module.files.withTs)).toBe(true);
|
|
24
|
+
|
|
25
|
+
// Verify that files.withoutTs is an array (JavaScript file patterns).
|
|
26
|
+
expect(Array.isArray(module.files.withoutTs)).toBe(true);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Test that the module exports the buildConfig function.
|
|
30
|
+
it('should export buildConfig function', async () => {
|
|
31
|
+
// Dynamically import the index module to test its exports.
|
|
32
|
+
const module = await import('./index.js');
|
|
33
|
+
|
|
34
|
+
// Verify that buildConfig is a function.
|
|
35
|
+
expect(typeof module.buildConfig).toBe('function');
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import globals from 'globals';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Common language options for ESLint including ECMAScript version,
|
|
5
|
+
* source type, and global variables.
|
|
6
|
+
*
|
|
7
|
+
* @type {import('eslint').Linter.LanguageOptions}
|
|
8
|
+
*/
|
|
9
|
+
export const commonLanguageOptions = {
|
|
10
|
+
ecmaVersion: 'latest',
|
|
11
|
+
sourceType: 'module',
|
|
12
|
+
globals: { ...globals.browser, ...globals.node },
|
|
13
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
|
|
3
|
+
// Test suite for the ESLint language options configuration module.
|
|
4
|
+
describe('eslint/lib/language-options.js', () => {
|
|
5
|
+
// Test that the module exports the commonLanguageOptions object.
|
|
6
|
+
it('should export commonLanguageOptions object', async () => {
|
|
7
|
+
// Dynamically import the language-options module to test its exports.
|
|
8
|
+
const module = await import('./language-options.js');
|
|
9
|
+
|
|
10
|
+
// Verify that commonLanguageOptions is an object.
|
|
11
|
+
expect(typeof module.commonLanguageOptions).toBe('object');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
// Test that the exported language options have the correct properties.
|
|
15
|
+
it('should have correct language options properties', async () => {
|
|
16
|
+
// Dynamically import the language-options module to test its exports.
|
|
17
|
+
const module = await import('./language-options.js');
|
|
18
|
+
|
|
19
|
+
// Verify that ecmaVersion is set to 'latest' (ESLint's latest ECMAScript version).
|
|
20
|
+
expect(module.commonLanguageOptions.ecmaVersion).toBe('latest');
|
|
21
|
+
|
|
22
|
+
// Verify that sourceType is set to 'module' (ES modules).
|
|
23
|
+
expect(module.commonLanguageOptions.sourceType).toBe('module');
|
|
24
|
+
|
|
25
|
+
// Verify that globals is an object (containing global variable definitions).
|
|
26
|
+
expect(typeof module.commonLanguageOptions.globals).toBe('object');
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -1,94 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* =====================================================================.
|
|
3
|
-
* Eslint Common Configuration
|
|
4
|
-
* =====================================================================.
|
|
5
|
-
* Purpose: Shared setup for all ESLint configurations including common
|
|
6
|
-
* ignores, parser setup, and rule definitions.
|
|
7
|
-
* Docs: https://eslint.org/docs/latest/use/configure/configuration-files-new
|
|
8
|
-
* =====================================================================.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import path from 'node:path';
|
|
12
|
-
import { fileURLToPath } from 'node:url';
|
|
13
|
-
|
|
14
|
-
import { FlatCompat } from '@eslint/eslintrc';
|
|
15
|
-
import js from '@eslint/js';
|
|
16
|
-
import tsParser from '@typescript-eslint/parser';
|
|
17
|
-
import { globalIgnores } from 'eslint/config';
|
|
18
|
-
import globals from 'globals';
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Global ignore patterns for ESLint to skip build artifacts, dependencies,
|
|
22
|
-
* and generated files during linting.
|
|
23
|
-
*/
|
|
24
|
-
export const ignores = [
|
|
25
|
-
'**/.git/',
|
|
26
|
-
'**/.idea/',
|
|
27
|
-
'**/.vscode/',
|
|
28
|
-
'**/.husky/',
|
|
29
|
-
'**/node_modules/',
|
|
30
|
-
'**/.next/',
|
|
31
|
-
'**/dist/',
|
|
32
|
-
'**/build/',
|
|
33
|
-
'**/out/',
|
|
34
|
-
'**/.vercel/',
|
|
35
|
-
'**/.cache/',
|
|
36
|
-
'**/.turbo/',
|
|
37
|
-
'**/*.tsbuildinfo',
|
|
38
|
-
'**/coverage/',
|
|
39
|
-
'**/test-results/',
|
|
40
|
-
'**/.playwright-report/',
|
|
41
|
-
'**/public/',
|
|
42
|
-
'**/.env*',
|
|
43
|
-
'**/next-env.d.ts',
|
|
44
|
-
'**/*.log',
|
|
45
|
-
'**/.DS_Store',
|
|
46
|
-
'**/Thumbs.db',
|
|
47
|
-
'**/*.tmp',
|
|
48
|
-
];
|
|
49
|
-
|
|
50
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
51
|
-
const __dirname = path.dirname(__filename);
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Creates a FlatCompat instance for using flat config format with older
|
|
55
|
-
* ESLint configurations.
|
|
56
|
-
*/
|
|
57
|
-
const compat = new FlatCompat({ baseDirectory: __dirname, recommendedConfig: js.configs.recommended });
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Returns the setup object containing shared utilities for ESLint configs.
|
|
61
|
-
*
|
|
62
|
-
* @returns {{ compat: FlatCompat, tsParser: typeof tsParser, __dirname: string }} Reusable setup utilities for ESLint configurations.
|
|
63
|
-
*/
|
|
64
|
-
export const setup = () => ({ compat, tsParser, __dirname });
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Global ignores configuration using ESLint's globalIgnores helper.
|
|
68
|
-
*
|
|
69
|
-
* @type {import('eslint').Linter.Config}
|
|
70
|
-
*/
|
|
71
|
-
export const commonIgnores = [globalIgnores(ignores)];
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Common parser configuration for TypeScript files.
|
|
75
|
-
*
|
|
76
|
-
* @type {{ parser: typeof tsParser }}
|
|
77
|
-
*/
|
|
78
|
-
export const commonParser = { parser: tsParser };
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Common language options for ESLint including ECMAScript version,
|
|
82
|
-
* source type, and global variables.
|
|
83
|
-
*
|
|
84
|
-
* @type {import('eslint').Linter.LanguageOptions}
|
|
85
|
-
*/
|
|
86
|
-
export const commonLanguageOptions = {
|
|
87
|
-
ecmaVersion: 'latest',
|
|
88
|
-
sourceType: 'module',
|
|
89
|
-
globals: { ...globals.browser, ...globals.node },
|
|
90
|
-
};
|
|
91
|
-
|
|
92
1
|
/**
|
|
93
2
|
* Creates JSDoc rules for enforcing documentation on public/exported APIs.
|
|
94
3
|
*
|
|
@@ -96,7 +5,7 @@ export const commonLanguageOptions = {
|
|
|
96
5
|
*
|
|
97
6
|
* @returns {object} JSDoc ESLint rules object.
|
|
98
7
|
*/
|
|
99
|
-
|
|
8
|
+
const jsdocRules = (jsdoc = true) =>
|
|
100
9
|
jsdoc
|
|
101
10
|
? {
|
|
102
11
|
// ---- JSDoc Rules for PUBLIC / EXPORTED APIs ----
|
|
@@ -115,7 +24,6 @@ export const jsdocRules = (jsdoc = true) =>
|
|
|
115
24
|
|
|
116
25
|
// Descriptions must exist and be meaningful
|
|
117
26
|
'jsdoc/require-description': 'error',
|
|
118
|
-
'jsdoc/require-description-complete-sentence': ['error', { tags: ['param', 'returns'] }],
|
|
119
27
|
|
|
120
28
|
// Params must be fully documented
|
|
121
29
|
'jsdoc/require-param': 'error',
|
|
@@ -150,7 +58,7 @@ export const jsdocRules = (jsdoc = true) =>
|
|
|
150
58
|
|
|
151
59
|
// Avoid useless docs
|
|
152
60
|
'jsdoc/no-types': 'off',
|
|
153
|
-
'jsdoc/informative-docs': '
|
|
61
|
+
'jsdoc/informative-docs': 'off',
|
|
154
62
|
|
|
155
63
|
// Enforce property docs in typedef-style (optional)
|
|
156
64
|
'jsdoc/require-property-description': 'warn',
|
|
@@ -164,7 +72,7 @@ export const jsdocRules = (jsdoc = true) =>
|
|
|
164
72
|
*
|
|
165
73
|
* @returns {object} TypeScript ESLint rules object.
|
|
166
74
|
*/
|
|
167
|
-
|
|
75
|
+
const tsRules = (typescript = true) =>
|
|
168
76
|
typescript
|
|
169
77
|
? {
|
|
170
78
|
'@typescript-eslint/no-unused-vars': [
|
|
@@ -188,7 +96,7 @@ export const tsRules = (typescript = true) =>
|
|
|
188
96
|
*
|
|
189
97
|
* @returns {object} Prettier ESLint rules object.
|
|
190
98
|
*/
|
|
191
|
-
|
|
99
|
+
const prettierRules = (prettier = true) => (prettier ? { 'prettier/prettier': 'warn' } : {});
|
|
192
100
|
|
|
193
101
|
/**
|
|
194
102
|
* Creates import order rules.
|
|
@@ -197,7 +105,7 @@ export const prettierRules = (prettier = true) => (prettier ? { 'prettier/pretti
|
|
|
197
105
|
*
|
|
198
106
|
* @returns {object} Import order ESLint rules object.
|
|
199
107
|
*/
|
|
200
|
-
|
|
108
|
+
const importOrderRules = (importOrder = true) =>
|
|
201
109
|
importOrder
|
|
202
110
|
? {
|
|
203
111
|
'import/order': [
|
|
@@ -245,10 +153,3 @@ export const commonRules = (options = {}) => {
|
|
|
245
153
|
...jsdocRules(jsdoc),
|
|
246
154
|
};
|
|
247
155
|
};
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* File patterns for ESLint configuration.
|
|
251
|
-
*
|
|
252
|
-
* @type {{ withTs: string[], withoutTs: string[] }}
|
|
253
|
-
*/
|
|
254
|
-
export const files = { withTs: ['**/*.{js,jsx,mjs,cjs,ts,tsx}'], withoutTs: ['**/*.{js,jsx,mjs,cjs}'] };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
|
|
3
|
+
// Test suite for the ESLint rules configuration module.
|
|
4
|
+
describe('eslint/lib/rules.js', () => {
|
|
5
|
+
// Test that the module exports the commonRules function.
|
|
6
|
+
it('should export commonRules function', async () => {
|
|
7
|
+
// Dynamically import the rules module to test its exports.
|
|
8
|
+
const module = await import('./rules.js');
|
|
9
|
+
|
|
10
|
+
// Verify that commonRules is a function.
|
|
11
|
+
expect(typeof module.commonRules).toBe('function');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
// Test that commonRules returns an object containing ESLint rules.
|
|
15
|
+
it('should return an object with rules', async () => {
|
|
16
|
+
// Dynamically import the rules module to test its function.
|
|
17
|
+
const module = await import('./rules.js');
|
|
18
|
+
|
|
19
|
+
// Call commonRules with no options to get base rules.
|
|
20
|
+
const result = module.commonRules();
|
|
21
|
+
|
|
22
|
+
// Verify that the result is an object (ESLint rules config).
|
|
23
|
+
expect(typeof result).toBe('object');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Test that TypeScript rules are included when typescript option is true.
|
|
27
|
+
it('should include TypeScript rules when typescript is true', async () => {
|
|
28
|
+
// Dynamically import the rules module to test its function.
|
|
29
|
+
const module = await import('./rules.js');
|
|
30
|
+
|
|
31
|
+
// Call commonRules with typescript option enabled.
|
|
32
|
+
const result = module.commonRules({ typescript: true });
|
|
33
|
+
|
|
34
|
+
// Verify that a TypeScript-specific rule is present in the config.
|
|
35
|
+
expect(result['@typescript-eslint/no-unused-vars']).toBeDefined();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Test that import order rules are included when importOrder option is true.
|
|
39
|
+
it('should include import order rules when importOrder is true', async () => {
|
|
40
|
+
// Dynamically import the rules module to test its function.
|
|
41
|
+
const module = await import('./rules.js');
|
|
42
|
+
|
|
43
|
+
// Call commonRules with importOrder option enabled.
|
|
44
|
+
const result = module.commonRules({ importOrder: true });
|
|
45
|
+
|
|
46
|
+
// Verify that the import/order rule is present in the config.
|
|
47
|
+
expect(result['import/order']).toBeDefined();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// Test that Prettier rules are included when prettier option is true.
|
|
51
|
+
it('should include Prettier rules when prettier is true', async () => {
|
|
52
|
+
// Dynamically import the rules module to test its function.
|
|
53
|
+
const module = await import('./rules.js');
|
|
54
|
+
|
|
55
|
+
// Call commonRules with prettier option enabled.
|
|
56
|
+
const result = module.commonRules({ prettier: true });
|
|
57
|
+
|
|
58
|
+
// Verify that the prettier/prettier rule is present in the config.
|
|
59
|
+
expect(result['prettier/prettier']).toBeDefined();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Test that JSDoc rules are included when jsdoc option is true.
|
|
63
|
+
it('should include JSDoc rules when jsdoc is true', async () => {
|
|
64
|
+
// Dynamically import the rules module to test its function.
|
|
65
|
+
const module = await import('./rules.js');
|
|
66
|
+
|
|
67
|
+
// Call commonRules with jsdoc option enabled.
|
|
68
|
+
const result = module.commonRules({ jsdoc: true });
|
|
69
|
+
|
|
70
|
+
// Verify that the jsdoc/require-jsdoc rule is present in the config.
|
|
71
|
+
expect(result['jsdoc/require-jsdoc']).toBeDefined();
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
|
|
4
|
+
import { FlatCompat } from '@eslint/eslintrc';
|
|
5
|
+
import js from '@eslint/js';
|
|
6
|
+
import tsParser from '@typescript-eslint/parser';
|
|
7
|
+
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = path.dirname(__filename);
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Creates a FlatCompat instance for using flat config format with older
|
|
13
|
+
* ESLint configurations.
|
|
14
|
+
*/
|
|
15
|
+
const compat = new FlatCompat({ baseDirectory: __dirname, recommendedConfig: js.configs.recommended });
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Returns the setup object containing shared utilities for ESLint configs.
|
|
19
|
+
*
|
|
20
|
+
* @returns {{ compat: FlatCompat, tsParser: typeof tsParser, __dirname: string }} Reusable setup utilities for ESLint configurations.
|
|
21
|
+
*/
|
|
22
|
+
export const setup = () => ({ compat, tsParser, __dirname });
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Common parser configuration for TypeScript files.
|
|
26
|
+
*
|
|
27
|
+
* @type {{ parser: typeof tsParser }}
|
|
28
|
+
*/
|
|
29
|
+
export const commonParser = { parser: tsParser };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
|
|
3
|
+
// Test suite for the ESLint setup utilities module.
|
|
4
|
+
describe('eslint/lib/setup.js', () => {
|
|
5
|
+
// Test that the module exports the setup function.
|
|
6
|
+
it('should export setup function', async () => {
|
|
7
|
+
// Dynamically import the setup module to test its exports.
|
|
8
|
+
const module = await import('./setup.js');
|
|
9
|
+
|
|
10
|
+
// Verify that setup is a function.
|
|
11
|
+
expect(typeof module.setup).toBe('function');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
// Test that the module exports the commonParser object with a parser property.
|
|
15
|
+
it('should export commonParser object', async () => {
|
|
16
|
+
// Dynamically import the setup module to test its exports.
|
|
17
|
+
const module = await import('./setup.js');
|
|
18
|
+
|
|
19
|
+
// Verify that commonParser is an object.
|
|
20
|
+
expect(typeof module.commonParser).toBe('object');
|
|
21
|
+
|
|
22
|
+
// Verify that commonParser has a parser property defined.
|
|
23
|
+
expect(module.commonParser.parser).toBeDefined();
|
|
24
|
+
});
|
|
25
|
+
});
|