code-quality-lib 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 NoonCore
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,385 @@
1
+ # Code Quality Library
2
+
3
+ [![npm version](https://img.shields.io/npm/v/code-quality-lib)](https://www.npmjs.com/package/code-quality-lib)
4
+ [![CI/CD](https://github.com/NoonCore/code-quality-lib/actions/workflows/ci.yml/badge.svg)](https://github.com/NoonCore/code-quality-lib/actions/workflows/ci.yml)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+ [![Node.js](https://img.shields.io/badge/node-%3E%3D18.0.0-brightgreen)](https://nodejs.org/)
7
+ [![TypeScript](https://img.shields.io/badge/TypeScript-included-blue)](https://www.typescriptlang.org/)
8
+
9
+ > A configurable code quality checker for Node.js — auto-detects your package manager and runs **TypeScript**, **ESLint**, **Prettier**, **Knip**, and **Snyk** with all dependencies bundled.
10
+
11
+ ## Features
12
+
13
+ - **All tools bundled** — no need to install TypeScript, ESLint, Prettier, Knip, or Snyk separately
14
+ - **Auto-detects package manager** — npm, bun, pnpm, yarn
15
+ - **CLI + Library** — use from terminal or programmatically
16
+ - **Detailed reports** — generates `.quality-report.md` with AI-friendly error info
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
21
+ - **TypeScript definitions** — full type safety included
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ npm install -D code-quality-lib # npm
27
+ bun add -D code-quality-lib # bun
28
+ pnpm add -D code-quality-lib # pnpm
29
+ yarn add -D code-quality-lib # yarn
30
+ ```
31
+
32
+ ## Quick Start
33
+
34
+ ```bash
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
43
+ ```
44
+
45
+ ## CLI Usage
46
+
47
+ ```bash
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
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)
56
+ code-quality --help # show help
57
+ code-quality --version # show version
58
+ ```
59
+
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:
225
+
226
+ ```javascript
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
239
+
240
+ ```javascript
241
+ const { CodeQualityChecker, runQualityCheck } = require('code-quality-lib')
242
+
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')
246
+
247
+ // Advanced — custom configuration
248
+ const customChecker = new CodeQualityChecker({
249
+ environments: {
250
+ development: { tools: ['ESLint', 'TypeScript'] },
251
+ ci: { tools: ['ESLint', 'TypeScript', 'Prettier', 'Knip', 'Snyk'] },
252
+ },
253
+ packageManager: 'npm',
254
+ commands: {
255
+ TypeScript: 'tsc --noEmit',
256
+ ESLint: 'eslint src/ --ext .ts,.tsx',
257
+ },
258
+ })
259
+
260
+ const result = await customChecker.run({ showLogs: true })
261
+ console.log(result.results) // per-tool results array
262
+ ```
263
+
264
+ ## Configuration Options
265
+
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
284
+
285
+ The library intelligently resolves tools in this order:
286
+
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
290
+
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 |
308
+
309
+ ## Package Manager Detection
310
+
311
+ Automatically detected by lock file presence:
312
+
313
+ 1. `bun.lock` / `bun.lockb` → bun
314
+ 2. `pnpm-lock.yaml` → pnpm
315
+ 3. `yarn.lock` → yarn
316
+ 4. `package-lock.json` → npm
317
+ 5. Fallback: checks installed binaries, defaults to npm
318
+
319
+ ## Error Reporting
320
+
321
+ Every run generates `.quality-report.md` with:
322
+
323
+ - Status of each check (pass/fail)
324
+ - Full error output for failed checks
325
+ - AI-friendly structured information for automated fixes
326
+
327
+ Add `.quality-report.md` to your `.gitignore`.
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
+
362
+ ## AI Skills
363
+
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).
365
+
366
+ ## Requirements
367
+
368
+ - **Node.js** >= 18.0.0
369
+
370
+ ## Testing & CI/CD
371
+
372
+ Tested on every push across 4 runtimes:
373
+
374
+ - **Node.js 25.x** (npm)
375
+ - **Bun 1.3.x**
376
+ - **pnpm 10.x**
377
+ - **Yarn 4.13.0**
378
+
379
+ ## Contributing
380
+
381
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup and guidelines.
382
+
383
+ ## License
384
+
385
+ MIT — see [LICENSE](LICENSE).
@@ -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
+ }