code-quality-lib 2.0.2 → 2.6.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 CHANGED
@@ -15,6 +15,9 @@
15
15
  - **CLI + Library** — use from terminal or programmatically
16
16
  - **Detailed reports** — generates `.quality-report.md` with AI-friendly error info
17
17
  - **`--logs` flag** — verbose terminal output for debugging
18
+ - **`--fix` flag** — auto-fix ESLint and Prettier issues automatically
19
+ - **Environment-based configs** — different tools for dev vs CI/CD
20
+ - **Snyk token validation** — validates tokens before running security scans
18
21
  - **TypeScript definitions** — full type safety included
19
22
 
20
23
  ## Installation
@@ -29,73 +32,279 @@ yarn add -D code-quality-lib # yarn
29
32
  ## Quick Start
30
33
 
31
34
  ```bash
32
- npx code-quality # npm
33
- bunx code-quality # bun
34
- pnpm dlx code-quality # pnpm
35
- yarn dlx code-quality # yarn
35
+ # Install and run (first time will auto-start wizard)
36
+ npm install -D code-quality-lib && npx code-quality
37
+
38
+ # Or with bun
39
+ bun add -D code-quality-lib && bunx code-quality
40
+
41
+ # Or with yarn
42
+ yarn add -D code-quality-lib && yarn code-quality
36
43
  ```
37
44
 
38
45
  ## CLI Usage
39
46
 
40
47
  ```bash
41
48
  code-quality # run all quality checks
49
+ code-quality --wizard # run interactive setup wizard
50
+ code-quality --config # generate .code-quality.json config file
42
51
  code-quality --logs # show detailed error output
52
+ code-quality --fix # auto-fix ESLint and Prettier issues
53
+ code-quality --env dev # run development checks (ESLint, TS, Prettier)
54
+ code-quality --env ci # run CI/CD checks (all tools)
55
+ code-quality --env prod # run production checks (all tools)
43
56
  code-quality --help # show help
44
57
  code-quality --version # show version
45
58
  ```
46
59
 
47
- ## Library Usage
60
+ ### Interactive Wizard
61
+
62
+ Use the wizard to configure options before running:
63
+
64
+ ```bash
65
+ code-quality --wizard
66
+ ```
67
+
68
+ The wizard will guide you through:
69
+
70
+ ```
71
+ 🧙‍♂️ Code Quality Setup Wizard
72
+ ──────────────────────────────────────────────────
73
+ Let's configure your quality checks!
74
+
75
+ 📦 Detected package manager: npm
76
+ Use npm? (Y/n):
77
+
78
+ 🔧 Select tools to run (default = all checked):
79
+ [✓] TypeScript? (Y/n):
80
+ [✓] ESLint? (Y/n):
81
+ [✓] Prettier? (Y/n):
82
+ [✓] Knip? (Y/n):
83
+ [✓] Snyk? (Y/n):
84
+
85
+ 🌍 Set up environment-specific tool sets?
86
+ This allows different tools for development vs CI/CD
87
+ Configure environments? (y/N):
88
+
89
+ 📋 Configuration Summary:
90
+ ──────────────────────────────────────────────────
91
+ 📦 Package Manager: npm
92
+ ⚙️ Config: Project configs (detected)
93
+ 🔧 Tools: TypeScript, ESLint, Prettier, Knip, Snyk
94
+ 🌍 Load .env: Yes (always)
95
+ ──────────────────────────────────────────────────
96
+ Run checks with these settings? (Y/n):
97
+ ```
98
+
99
+ **Smart Features:**
100
+
101
+ - **Remember settings** — First run creates `.code-quality.json`, future runs skip questions
102
+ - **Yes/No questions** — Simple Y/n prompts with sensible defaults
103
+ - **Checkbox-style tools** — Each tool can be individually enabled/disabled
104
+ - **Always uses project configs** — Automatically detects and uses your existing ESLint/Prettier configs
105
+ - **Always loads .env** — Environment variables are always available for your tools
106
+
107
+ After confirmation, it runs the quality checks with your selected settings.
108
+
109
+ ### Auto-Wizard on First Run
110
+
111
+ If you run `code-quality` without any configuration file, it automatically starts the wizard:
112
+
113
+ ```bash
114
+ code-quality # First run: no config found → starts wizard
115
+ code-quality # Subsequent runs: uses saved settings
116
+ ```
117
+
118
+ This ensures proper setup on first use while being fast on subsequent runs.
119
+
120
+ ### Terminal Output
121
+
122
+ The CLI provides step-by-step progress like setup wizards:
123
+
124
+ ```
125
+ 🚀 Code Quality Setup
126
+ ──────────────────────────────────────────────────
127
+ 📦 Package Manager: npm
128
+ ⚙️ Config: Project configs
129
+ 🔧 Tools: 5 quality checks
130
+
131
+ 1. TypeScript... ✅ Done
132
+ 2. ESLint... ✅ Done
133
+ 3. Prettier... ✅ Done
134
+ 4. Knip... ✅ Done
135
+ 5. Snyk... ✅ Done
136
+
137
+ ──────────────────────────────────────────────────
138
+ 📊 Quality Check Summary
139
+
140
+ ✅ TypeScript Passed
141
+ ✅ ESLint Passed
142
+ ✅ Prettier Passed
143
+ ✅ Knip Passed
144
+ ✅ Snyk Passed
145
+
146
+ ──────────────────────────────────────────────────
147
+ 🎉 Success! All quality checks passed.
148
+
149
+ ✅ Your code is ready for production!
150
+ ```
151
+
152
+ ### Auto-Fix with --fix
153
+
154
+ Automatically fix ESLint and Prettier issues:
155
+
156
+ ```bash
157
+ code-quality --fix # Fix all issues
158
+ code-quality --env prod --fix # Fix in production mode
159
+ code-quality --ESLint --fix # Fix only ESLint
160
+ code-quality --Prettier --fix # Fix only Prettier
161
+ ```
162
+
163
+ The `--fix` flag will:
164
+
165
+ 1. Run quality checks normally
166
+ 2. If ESLint or Prettier fail, automatically run:
167
+ - `eslint --fix` for ESLint issues
168
+ - `prettier --write` for Prettier issues
169
+ 3. Re-run checks to verify fixes
170
+ 4. Show final results
171
+
172
+ ### Environment-Based Configuration
173
+
174
+ Different tool sets for different environments:
175
+
176
+ ```bash
177
+ code-quality --env development # ESLint, TypeScript, Prettier
178
+ code-quality --env ci # All tools (ESLint, TS, Prettier, Knip, Snyk)
179
+ code-quality --env production # All tools (ESLint, TS, Prettier, Knip, Snyk)
180
+ ```
181
+
182
+ Or configure environments in `.code-quality/config.json`:
183
+
184
+ ```json
185
+ {
186
+ "environments": {
187
+ "development": {
188
+ "tools": ["ESLint", "TypeScript", "Prettier"]
189
+ },
190
+ "ci": {
191
+ "tools": ["ESLint", "TypeScript", "Prettier", "Knip", "Snyk"]
192
+ },
193
+ "production": {
194
+ "tools": ["ESLint", "TypeScript", "Prettier", "Knip", "Snyk"]
195
+ }
196
+ },
197
+ "packageManager": "npm"
198
+ }
199
+ ```
200
+
201
+ ### Configuration Directory
202
+
203
+ Generate a configuration directory with reference configs:
204
+
205
+ ```bash
206
+ code-quality --config
207
+ ```
208
+
209
+ This creates `.code-quality/` directory with:
210
+
211
+ - **config.json** — Main configuration file
212
+ - **tsconfig.json** — TypeScript reference config
213
+ - **eslint.config.mjs** — ESLint reference config
214
+ - **.prettierrc** — Prettier reference config
215
+ - **knip.json** — Knip reference config
216
+ - **README.md** — Usage documentation
217
+
218
+ The CLI automatically loads `.code-quality/config.json` if it exists:
219
+
220
+ ```bash
221
+ code-quality # uses your custom config
222
+ ```
223
+
224
+ Or use it programmatically:
48
225
 
49
226
  ```javascript
50
- const { CodeQualityChecker, runQualityCheck } = require('code-quality-lib');
227
+ const config = require('./.code-quality/config.json')
228
+ const checker = new CodeQualityChecker(config)
229
+ await checker.run()
230
+ ```
231
+
232
+ ### Configuration
233
+
234
+ The library automatically detects and uses your project's existing configuration files (`.eslintrc`, `.prettierrc`, `tsconfig.json`, etc.) if they exist. If no project configs are found, it uses bundled configurations.
235
+
236
+ **Environment variables** from `.env` files are always loaded automatically.
237
+
238
+ ## Library Usage
51
239
 
52
- // Quick — run all checks with defaults (uses project's config files)
53
- const result = await runQualityCheck();
54
- console.log(result.success ? 'All passed' : 'Some failed');
240
+ ```javascript
241
+ const { CodeQualityChecker, runQualityCheck } = require('code-quality-lib')
55
242
 
56
- // Use bundled configs instead of project's configs
57
- const checker = new CodeQualityChecker({
58
- useProjectConfig: false, // use library's bundled .eslintrc, .prettierrc, etc.
59
- });
60
- await checker.run();
243
+ // Quick run all checks with defaults (auto-detects project configs)
244
+ const result = await runQualityCheck()
245
+ console.log(result.success ? 'All passed' : 'Some failed')
61
246
 
62
- // Customselect tools, override commands
247
+ // Advancedcustom configuration
63
248
  const customChecker = new CodeQualityChecker({
64
- tools: ['TypeScript', 'ESLint'],
65
- packageManager: 'pnpm',
249
+ environments: {
250
+ development: { tools: ['ESLint', 'TypeScript'] },
251
+ ci: { tools: ['ESLint', 'TypeScript', 'Prettier', 'Knip', 'Snyk'] },
252
+ },
253
+ packageManager: 'npm',
66
254
  commands: {
67
255
  TypeScript: 'tsc --noEmit',
68
256
  ESLint: 'eslint src/ --ext .ts,.tsx',
69
257
  },
70
- loadEnv: false,
71
- });
258
+ })
72
259
 
73
- const result = await customChecker.run({ showLogs: true });
74
- console.log(result.results); // per-tool results array
260
+ const result = await customChecker.run({ showLogs: true })
261
+ console.log(result.results) // per-tool results array
75
262
  ```
76
263
 
77
264
  ## Configuration Options
78
265
 
79
- | Option | Type | Default | Description |
80
- |--------|------|---------|-------------|
81
- | `useProjectConfig` | `boolean` | `true` | Use project's config files (`.eslintrc.js`, `.prettierrc`, etc.) instead of bundled configs |
82
- | `tools` | `string[]` | All 5 tools | Which tools to run |
83
- | `packageManager` | `'npm' \| 'bun' \| 'pnpm' \| 'yarn'` | auto-detected | Force a specific package manager |
84
- | `commands` | `Record<string, string>` | bundled paths | Custom commands per tool |
85
- | `descriptions` | `Record<string, string>` | built-in | Custom descriptions per tool |
86
- | `loadEnv` | `boolean` | `true` | Load `.env` file |
266
+ | Option | Type | Default | Description |
267
+ | ------------------ | ------------------------------------ | ------------- | ------------------------------------------------------------------------------------------- |
268
+ | `tools` | `string[]` | All 5 tools | Which tools to run (deprecated - use environments instead) |
269
+ | `packageManager` | `'npm' \| 'bun' \| 'pnpm' \| 'yarn'` | auto-detected | Force a specific package manager |
270
+ | `commands` | `Record<string, string>` | bundled paths | Custom commands per tool |
271
+ | `descriptions` | `Record<string, string>` | built-in | Custom descriptions per tool |
272
+ | `environment` | `string` | auto-detected | Override environment (development, ci, production) |
273
+ | `environments` | `Record<string, EnvironmentConfig>` | - | Environment-specific tool configurations |
274
+
275
+ **EnvironmentConfig:**
276
+
277
+ ```typescript
278
+ interface EnvironmentConfig {
279
+ tools: string[]
280
+ }
281
+ ```
282
+
283
+ ## Tool Resolution
87
284
 
88
- ## Bundled Tools
285
+ The library intelligently resolves tools in this order:
89
286
 
90
- All tools are included as dependencies zero extra setup:
287
+ 1. **Project's `node_modules/.bin`** Uses your project's installed versions first
288
+ 2. **Library's bundled tools** — Falls back to bundled versions if not found in project
289
+ 3. **Custom commands** — If you specify custom commands in config, uses them as-is
91
290
 
92
- | Tool | Description |
93
- |------|-------------|
94
- | **TypeScript** | Type checking (`tsc --noEmit`) |
95
- | **ESLint** | Linting with plugins (react, sonarjs, unicorn, import, prettier) |
96
- | **Prettier** | Code formatting validation |
97
- | **Knip** | Dead code and unused export detection |
98
- | **Snyk** | Security vulnerability scanning |
291
+ This means:
292
+
293
+ - Uses your project's tool versions and configurations by default
294
+ - Works out-of-the-box with bundled tools as fallback
295
+ - Custom commands use tools from your project's PATH
296
+
297
+ ### Bundled Tools
298
+
299
+ All tools are included as dependencies for fallback:
300
+
301
+ | Tool | Description |
302
+ | -------------- | ---------------------------------------------------------------- |
303
+ | **TypeScript** | Type checking (`tsc --noEmit`) |
304
+ | **ESLint** | Linting with plugins (react, sonarjs, unicorn, import, prettier) |
305
+ | **Prettier** | Code formatting validation |
306
+ | **Knip** | Dead code and unused export detection |
307
+ | **Snyk** | Security vulnerability scanning |
99
308
 
100
309
  ## Package Manager Detection
101
310
 
@@ -110,12 +319,46 @@ Automatically detected by lock file presence:
110
319
  ## Error Reporting
111
320
 
112
321
  Every run generates `.quality-report.md` with:
322
+
113
323
  - Status of each check (pass/fail)
114
324
  - Full error output for failed checks
115
325
  - AI-friendly structured information for automated fixes
116
326
 
117
327
  Add `.quality-report.md` to your `.gitignore`.
118
328
 
329
+ ## Snyk Token Validation
330
+
331
+ The library validates Snyk tokens before running security scans:
332
+
333
+ ```bash
334
+ # Set your Snyk token
335
+ export SNYK_TOKEN=your_token_here
336
+
337
+ # Or add to .env file
338
+ echo "SNYK_TOKEN=your_token_here" >> .env
339
+
340
+ # Run with validation
341
+ code-quality --env production
342
+ ```
343
+
344
+ **Token Validation Features:**
345
+
346
+ - **Pre-scan validation** - Checks token before running full scan
347
+ - **Clear cache** - Forces token validation by clearing Snyk cache
348
+ - **Detailed errors** - Shows helpful fix instructions for invalid tokens
349
+ - **Fallback handling** - Graceful degradation for token issues
350
+
351
+ **Error Messages:**
352
+
353
+ ```
354
+ ❌ Snyk token validation failed. Token may be expired or invalid.
355
+
356
+ To fix:
357
+ 1. Get a new token at: https://snyk.io/login
358
+ 2. Set SNYK_TOKEN in your .env file
359
+ 3. Or run: npx snyk auth
360
+ ```
361
+
119
362
  ## AI Skills
120
363
 
121
364
  This library includes `.ai/skills/` — markdown files that teach AI coding assistants (Cursor, Copilot, Windsurf, etc.) to follow the project's coding standards. See [`.ai/skills/README.md`](.ai/skills/README.md).
@@ -127,6 +370,7 @@ This library includes `.ai/skills/` — markdown files that teach AI coding assi
127
370
  ## Testing & CI/CD
128
371
 
129
372
  Tested on every push across 4 runtimes:
373
+
130
374
  - **Node.js 25.x** (npm)
131
375
  - **Bun 1.3.x**
132
376
  - **pnpm 10.x**
@@ -0,0 +1,87 @@
1
+ # Quality reports and configuration
2
+ .quality-report.md
3
+ .code-quality/
4
+
5
+ # Build outputs
6
+ dist/
7
+ build/
8
+ .next/
9
+ out/
10
+
11
+ # Dependencies
12
+ node_modules/
13
+
14
+ # Logs
15
+ *.log
16
+ npm-debug.log*
17
+ yarn-debug.log*
18
+ yarn-error.log*
19
+
20
+ # Runtime data
21
+ pids
22
+ *.pid
23
+ *.seed
24
+ *.pid.lock
25
+
26
+ # Coverage directory used by tools like istanbul
27
+ coverage/
28
+ *.lcov
29
+
30
+ # nyc test coverage
31
+ .nyc_output
32
+
33
+ # Dependency directories
34
+ jspm_packages/
35
+
36
+ # Optional npm cache directory
37
+ .npm
38
+
39
+ # Optional eslint cache
40
+ .eslintcache
41
+
42
+ # Optional REPL history
43
+ .node_repl_history
44
+
45
+ # Output of 'npm pack'
46
+ *.tgz
47
+
48
+ # Yarn Integrity file
49
+ .yarn-integrity
50
+
51
+ # dotenv environment variables file
52
+ .env
53
+ .env.test
54
+ .env.local
55
+ .env.development.local
56
+ .env.test.local
57
+ .env.production.local
58
+
59
+ # parcel-bundler cache (https://parceljs.org/)
60
+ .cache
61
+ .parcel-cache
62
+
63
+ # next.js build output
64
+ .next
65
+
66
+ # nuxt.js build output
67
+ .nuxt
68
+
69
+ # vuepress build output
70
+ .vuepress/dist
71
+
72
+ # Serverless directories
73
+ .serverless
74
+
75
+ # FuseBox cache
76
+ .fusebox/
77
+
78
+ # DynamoDB Local files
79
+ .dynamodb/
80
+
81
+ # TernJS port file
82
+ .tern-port
83
+
84
+ # Stores VSCode versions used for testing VSCode extensions
85
+ .vscode-test
86
+
87
+ .venv
@@ -0,0 +1,17 @@
1
+ {
2
+ "semi": false,
3
+ "trailingComma": "es5",
4
+ "singleQuote": true,
5
+ "printWidth": 100,
6
+ "tabWidth": 2,
7
+ "useTabs": false,
8
+ "endOfLine": "lf",
9
+ "arrowParens": "always",
10
+ "bracketSpacing": true,
11
+ "bracketSameLine": false,
12
+ "quoteProps": "as-needed",
13
+ "jsxSingleQuote": true,
14
+ "proseWrap": "preserve",
15
+ "htmlWhitespaceSensitivity": "css",
16
+ "embeddedLanguageFormatting": "auto"
17
+ }
@@ -0,0 +1,32 @@
1
+ # Code Quality Configuration
2
+
3
+ This directory contains reference configuration files for code quality tools.
4
+
5
+ ## Files
6
+
7
+ - **eslint.config.mjs** - ESLint flat config with React, TypeScript, and accessibility rules
8
+ - **tsconfig.json** - TypeScript configuration with strict settings
9
+ - **.prettierrc** - Prettier formatting rules
10
+ - **.prettierrcignore** - Files to ignore when formatting
11
+ - **knip.json** - Dead code detection configuration
12
+
13
+ ## Usage
14
+
15
+ These files are automatically copied to your project's `.code-quality/` directory when you run:
16
+
17
+ ```bash
18
+ code-quality --init
19
+ # or
20
+ code-quality --wizard
21
+ ```
22
+
23
+ ## Customization
24
+
25
+ You can modify these files after copying them to suit your project's needs.
26
+
27
+ ## Notes
28
+
29
+ - ESLint config uses conditional loading for optional plugins (Next.js, jsx-a11y, prettier)
30
+ - TypeScript config is optimized for React/Next.js projects
31
+ - Prettier config matches ESLint semicolon settings
32
+ - Knip config is set to ignore test files and dependencies
@@ -0,0 +1,30 @@
1
+ {
2
+ "packageManager": "bun",
3
+ "environments": {
4
+ "development": {
5
+ "tools": [
6
+ "ESLint",
7
+ "TypeScript",
8
+ "Prettier"
9
+ ]
10
+ },
11
+ "ci": {
12
+ "tools": [
13
+ "ESLint",
14
+ "TypeScript",
15
+ "Prettier",
16
+ "Knip",
17
+ "Snyk"
18
+ ]
19
+ },
20
+ "production": {
21
+ "tools": [
22
+ "ESLint",
23
+ "TypeScript",
24
+ "Prettier",
25
+ "Knip",
26
+ "Snyk"
27
+ ]
28
+ }
29
+ }
30
+ }