@webpieces/dev-config 0.2.23 → 0.2.24
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/generators/init/generator.ts +110 -0
- package/package.json +1 -1
- package/plugin/README.md +7 -0
|
@@ -11,6 +11,9 @@ import type { InitGeneratorSchema } from './schema';
|
|
|
11
11
|
* - Creates architecture/ directory if needed
|
|
12
12
|
* - Adds madge as a devDependency (required for circular dep checking)
|
|
13
13
|
* - Adds convenient npm scripts to package.json
|
|
14
|
+
* - Always creates eslint.webpieces.config.mjs with @webpieces rules
|
|
15
|
+
* - Creates eslint.config.mjs (if not exists) that imports eslint.webpieces.config.mjs
|
|
16
|
+
* - If eslint.config.mjs exists, shows user how to import eslint.webpieces.config.mjs
|
|
14
17
|
* - Provides helpful output about available targets
|
|
15
18
|
*/
|
|
16
19
|
export default async function initGenerator(tree: Tree, options: InitGeneratorSchema) {
|
|
@@ -18,6 +21,7 @@ export default async function initGenerator(tree: Tree, options: InitGeneratorSc
|
|
|
18
21
|
const installTask = addMadgeDependency(tree);
|
|
19
22
|
createArchitectureDirectory(tree);
|
|
20
23
|
addNpmScripts(tree);
|
|
24
|
+
createEslintConfig(tree);
|
|
21
25
|
|
|
22
26
|
if (!options.skipFormat) {
|
|
23
27
|
await formatFiles(tree);
|
|
@@ -84,6 +88,112 @@ function addNpmScripts(tree: Tree): void {
|
|
|
84
88
|
console.log('✅ Added npm scripts for architecture validation and circular dependency checking');
|
|
85
89
|
}
|
|
86
90
|
|
|
91
|
+
function createEslintConfig(tree: Tree): void {
|
|
92
|
+
const webpiecesConfigPath = 'eslint.webpieces.config.mjs';
|
|
93
|
+
const mainConfigPath = 'eslint.config.mjs';
|
|
94
|
+
|
|
95
|
+
// Always create eslint.webpieces.config.mjs with our rules
|
|
96
|
+
createWebpiecesEslintConfig(tree, webpiecesConfigPath);
|
|
97
|
+
|
|
98
|
+
// Check if main eslint.config.mjs exists
|
|
99
|
+
if (tree.exists(mainConfigPath)) {
|
|
100
|
+
// Existing config - show them how to import
|
|
101
|
+
console.log('');
|
|
102
|
+
console.log('📋 Existing eslint.config.mjs detected');
|
|
103
|
+
console.log('');
|
|
104
|
+
console.log('To use @webpieces/dev-config ESLint rules, add this import to your eslint.config.mjs:');
|
|
105
|
+
console.log('');
|
|
106
|
+
console.log(' import webpiecesConfig from \'./eslint.webpieces.config.mjs\';');
|
|
107
|
+
console.log('');
|
|
108
|
+
console.log('Then spread it into your config array:');
|
|
109
|
+
console.log('');
|
|
110
|
+
console.log(' export default [');
|
|
111
|
+
console.log(' ...webpiecesConfig, // Add this line');
|
|
112
|
+
console.log(' // ... your existing config');
|
|
113
|
+
console.log(' ];');
|
|
114
|
+
console.log('');
|
|
115
|
+
} else {
|
|
116
|
+
// No existing config - create one that imports webpieces config
|
|
117
|
+
const mainConfig = `// ESLint configuration
|
|
118
|
+
// Imports @webpieces/dev-config rules
|
|
119
|
+
|
|
120
|
+
import webpiecesConfig from './eslint.webpieces.config.mjs';
|
|
121
|
+
|
|
122
|
+
// Export the webpieces configuration
|
|
123
|
+
// You can add your own rules after spreading webpiecesConfig
|
|
124
|
+
export default [
|
|
125
|
+
...webpiecesConfig,
|
|
126
|
+
// Add your custom ESLint configuration here
|
|
127
|
+
];
|
|
128
|
+
`;
|
|
129
|
+
|
|
130
|
+
tree.write(mainConfigPath, mainConfig);
|
|
131
|
+
console.log('✅ Created eslint.config.mjs with @webpieces/dev-config rules');
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function createWebpiecesEslintConfig(tree: Tree, configPath: string): void {
|
|
136
|
+
const webpiecesConfig = `// @webpieces/dev-config ESLint rules
|
|
137
|
+
// This file contains the ESLint configuration provided by @webpieces/dev-config
|
|
138
|
+
// You can modify or remove rules as needed for your project
|
|
139
|
+
|
|
140
|
+
import webpiecesPlugin from '@webpieces/dev-config/eslint-plugin';
|
|
141
|
+
import tseslint from '@typescript-eslint/eslint-plugin';
|
|
142
|
+
import tsparser from '@typescript-eslint/parser';
|
|
143
|
+
|
|
144
|
+
export default [
|
|
145
|
+
{
|
|
146
|
+
ignores: ['**/dist', '**/node_modules', '**/coverage', '**/.nx'],
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'],
|
|
150
|
+
plugins: {
|
|
151
|
+
'@webpieces': webpiecesPlugin,
|
|
152
|
+
'@typescript-eslint': tseslint,
|
|
153
|
+
},
|
|
154
|
+
languageOptions: {
|
|
155
|
+
parser: tsparser,
|
|
156
|
+
ecmaVersion: 2021,
|
|
157
|
+
sourceType: 'module',
|
|
158
|
+
},
|
|
159
|
+
rules: {
|
|
160
|
+
// WebPieces custom rules
|
|
161
|
+
'@webpieces/catch-error-pattern': 'error',
|
|
162
|
+
'@webpieces/no-unmanaged-exceptions': 'error',
|
|
163
|
+
'@webpieces/max-method-lines': ['error', { max: 70 }],
|
|
164
|
+
'@webpieces/max-file-lines': ['error', { max: 700 }],
|
|
165
|
+
'@webpieces/enforce-architecture': 'error',
|
|
166
|
+
|
|
167
|
+
// TypeScript rules
|
|
168
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
169
|
+
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
170
|
+
'@typescript-eslint/no-unused-vars': 'off',
|
|
171
|
+
'@typescript-eslint/no-empty-interface': 'off',
|
|
172
|
+
'@typescript-eslint/no-empty-function': 'off',
|
|
173
|
+
|
|
174
|
+
// General code quality
|
|
175
|
+
'no-console': 'off',
|
|
176
|
+
'no-debugger': 'off',
|
|
177
|
+
'no-var': 'error',
|
|
178
|
+
'prefer-const': 'off',
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
// Test files - relaxed rules
|
|
183
|
+
files: ['**/*.spec.ts', '**/*.test.ts'],
|
|
184
|
+
rules: {
|
|
185
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
186
|
+
'@typescript-eslint/no-non-null-assertion': 'off',
|
|
187
|
+
'@webpieces/max-method-lines': 'off',
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
];
|
|
191
|
+
`;
|
|
192
|
+
|
|
193
|
+
tree.write(configPath, webpiecesConfig);
|
|
194
|
+
console.log('✅ Created eslint.webpieces.config.mjs with @webpieces/dev-config rules');
|
|
195
|
+
}
|
|
196
|
+
|
|
87
197
|
function createSuccessCallback(installTask: ReturnType<typeof addDependenciesToPackageJson>) {
|
|
88
198
|
return async () => {
|
|
89
199
|
await installTask();
|
package/package.json
CHANGED
package/plugin/README.md
CHANGED
|
@@ -31,8 +31,15 @@ This automatically:
|
|
|
31
31
|
- Adds `madge` as a devDependency (required for circular dependency checking)
|
|
32
32
|
- Creates the `architecture/` directory
|
|
33
33
|
- Adds convenient npm scripts to `package.json`
|
|
34
|
+
- Creates `eslint.webpieces.config.mjs` with @webpieces ESLint rules
|
|
35
|
+
- Creates `eslint.config.mjs` (if you don't have one) that imports the webpieces rules
|
|
36
|
+
- If you already have `eslint.config.mjs`, shows you how to import the webpieces rules (one line)
|
|
34
37
|
- Makes all targets immediately available
|
|
35
38
|
|
|
39
|
+
**For new projects: Zero configuration needed!** All architecture validation, circular dependency checking, and ESLint rules are active.
|
|
40
|
+
|
|
41
|
+
**For existing projects with ESLint:** Just add one import line shown during installation to enable the @webpieces ESLint rules.
|
|
42
|
+
|
|
36
43
|
## Usage
|
|
37
44
|
|
|
38
45
|
### Convenient npm Scripts
|