code-quality-lib 2.0.0 → 2.0.2
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 +80 -263
- package/index.d.ts +25 -7
- package/index.js +347 -166
- package/package.json +11 -19
- package/.code-quality.json.example +0 -8
- package/.eslintrc.js +0 -121
- package/.prettierrc +0 -17
- package/knip.json +0 -76
- package/tsconfig.json +0 -41
package/README.md
CHANGED
|
@@ -1,324 +1,141 @@
|
|
|
1
1
|
# Code Quality Library
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/code-quality-lib)
|
|
4
|
-
[](https://opensource.org/licenses/MIT)
|
|
5
|
-
[](https://nodejs.org/)
|
|
6
|
-
[](https://bun.sh/)
|
|
7
|
-
[](https://pnpm.io/)
|
|
8
|
-
[](https://yarnpkg.com/)
|
|
9
4
|
[](https://github.com/NoonCore/code-quality-lib/actions/workflows/ci.yml)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](https://nodejs.org/)
|
|
10
7
|
[](https://www.typescriptlang.org/)
|
|
11
8
|
|
|
12
|
-
>
|
|
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.
|
|
13
10
|
|
|
14
11
|
## Features
|
|
15
12
|
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
- 🔍 --logs flag for verbose terminal output
|
|
23
|
-
- 🤖 AI-friendly structured error information
|
|
24
|
-
- 📦 **All dependencies bundled** - No need to install TypeScript, ESLint, Prettier, Knip, or Snyk separately!
|
|
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
|
+
- **TypeScript definitions** — full type safety included
|
|
25
19
|
|
|
26
20
|
## Installation
|
|
27
21
|
|
|
28
|
-
### npm
|
|
29
|
-
```bash
|
|
30
|
-
# Install as development dependency (recommended)
|
|
31
|
-
npm install -D code-quality-lib
|
|
32
|
-
|
|
33
|
-
# Install globally for CLI usage
|
|
34
|
-
npm install -g code-quality-lib
|
|
35
|
-
|
|
36
|
-
# Install from GitHub (development)
|
|
37
|
-
npm install -D https://github.com/NoonCore/code-quality-lib.git
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
### bun (recommended - faster)
|
|
41
22
|
```bash
|
|
42
|
-
|
|
43
|
-
bun add -D code-quality-lib
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
bun add -g code-quality-lib
|
|
47
|
-
|
|
48
|
-
# Install from GitHub (development)
|
|
49
|
-
bun add -D https://github.com/NoonCore/code-quality-lib.git
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
### pnpm
|
|
53
|
-
```bash
|
|
54
|
-
# Install as development dependency (recommended)
|
|
55
|
-
pnpm add -D code-quality-lib
|
|
56
|
-
|
|
57
|
-
# Install globally for CLI usage
|
|
58
|
-
pnpm add -g code-quality-lib
|
|
59
|
-
|
|
60
|
-
# Install from GitHub (development)
|
|
61
|
-
pnpm add -D https://github.com/NoonCore/code-quality-lib.git
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
### yarn
|
|
65
|
-
```bash
|
|
66
|
-
# Install as development dependency (recommended)
|
|
67
|
-
yarn add -D code-quality-lib
|
|
68
|
-
|
|
69
|
-
# Install globally for CLI usage
|
|
70
|
-
yarn global add code-quality-lib
|
|
71
|
-
|
|
72
|
-
# Install from GitHub (development)
|
|
73
|
-
yarn add -D https://github.com/NoonCore/code-quality-lib.git
|
|
23
|
+
npm install -D code-quality-lib # npm
|
|
24
|
+
bun add -D code-quality-lib # bun
|
|
25
|
+
pnpm add -D code-quality-lib # pnpm
|
|
26
|
+
yarn add -D code-quality-lib # yarn
|
|
74
27
|
```
|
|
75
28
|
|
|
76
|
-
|
|
77
29
|
## Quick Start
|
|
78
30
|
|
|
79
31
|
```bash
|
|
80
|
-
#
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
bun add -D code-quality-lib && bunx code-quality
|
|
85
|
-
|
|
86
|
-
# Or with yarn
|
|
87
|
-
yarn add -D code-quality-lib && yarn code-quality
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
## Usage
|
|
91
|
-
|
|
92
|
-
### As a CLI Tool
|
|
93
|
-
|
|
94
|
-
```bash
|
|
95
|
-
# Run all quality checks
|
|
96
|
-
code-quality
|
|
97
|
-
|
|
98
|
-
# Run with detailed error logs in terminal
|
|
99
|
-
code-quality --logs
|
|
100
|
-
|
|
101
|
-
# Or use with npx (without installing)
|
|
102
|
-
npx code-quality-lib
|
|
103
|
-
|
|
104
|
-
# Or with bunx (without installing)
|
|
105
|
-
bunx code-quality-lib
|
|
106
|
-
|
|
107
|
-
# Or with yarn
|
|
108
|
-
yarn code-quality
|
|
32
|
+
npx code-quality # npm
|
|
33
|
+
bunx code-quality # bun
|
|
34
|
+
pnpm dlx code-quality # pnpm
|
|
35
|
+
yarn dlx code-quality # yarn
|
|
109
36
|
```
|
|
110
37
|
|
|
111
|
-
|
|
38
|
+
## CLI Usage
|
|
112
39
|
|
|
113
|
-
The library automatically generates a detailed error report at `.quality-report.md` with:
|
|
114
|
-
- ✅ Status of each quality check
|
|
115
|
-
- 📋 Full error output for failed checks
|
|
116
|
-
- 💡 Suggestions for fixing common issues
|
|
117
|
-
- 🤖 AI-friendly structured information
|
|
118
|
-
|
|
119
|
-
**Viewing Errors:**
|
|
120
40
|
```bash
|
|
121
|
-
#
|
|
122
|
-
code-quality
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
code-quality --logs
|
|
126
|
-
|
|
127
|
-
# View the report
|
|
128
|
-
cat .quality-report.md
|
|
41
|
+
code-quality # run all quality checks
|
|
42
|
+
code-quality --logs # show detailed error output
|
|
43
|
+
code-quality --help # show help
|
|
44
|
+
code-quality --version # show version
|
|
129
45
|
```
|
|
130
46
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
### As a Library
|
|
47
|
+
## Library Usage
|
|
134
48
|
|
|
135
49
|
```javascript
|
|
136
|
-
const { CodeQualityChecker } = require('code-quality-lib');
|
|
50
|
+
const { CodeQualityChecker, runQualityCheck } = require('code-quality-lib');
|
|
137
51
|
|
|
138
|
-
//
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
console.log(result.success ? '✅ All checks passed!' : '❌ Some checks failed');
|
|
142
|
-
});
|
|
143
|
-
```
|
|
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');
|
|
144
55
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
- **TypeScript** (v5.8.3) - Type checking and compilation
|
|
151
|
-
- **ESLint** (v9.18.0) - Code linting and style checking with plugins:
|
|
152
|
-
- @typescript-eslint/eslint-plugin & parser
|
|
153
|
-
- eslint-plugin-react & react-hooks
|
|
154
|
-
- eslint-plugin-prettier
|
|
155
|
-
- eslint-plugin-sonarjs
|
|
156
|
-
- eslint-plugin-unicorn
|
|
157
|
-
- eslint-plugin-import
|
|
158
|
-
- **Prettier** (v3.4.2) - Code formatting validation
|
|
159
|
-
- **Knip** (v5.43.2) - Dead code detection and unused exports
|
|
160
|
-
- **Snyk** (v1.1293.1) - Security vulnerability scanning
|
|
161
|
-
|
|
162
|
-
**No need to install these tools separately!** Everything is bundled with the library.
|
|
163
|
-
|
|
164
|
-
### Custom Configuration
|
|
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();
|
|
165
61
|
|
|
166
|
-
|
|
62
|
+
// Custom — select tools, override commands
|
|
167
63
|
const customChecker = new CodeQualityChecker({
|
|
168
|
-
// Force specific package manager
|
|
169
|
-
packageManager: 'pnpm', // 'bun' | 'pnpm' | 'yarn' | 'npm'
|
|
170
|
-
|
|
171
|
-
// Only run specific tools
|
|
172
64
|
tools: ['TypeScript', 'ESLint'],
|
|
173
|
-
|
|
174
|
-
// Custom commands for each tool
|
|
65
|
+
packageManager: 'pnpm',
|
|
175
66
|
commands: {
|
|
176
67
|
TypeScript: 'tsc --noEmit',
|
|
177
68
|
ESLint: 'eslint src/ --ext .ts,.tsx',
|
|
178
|
-
Prettier: 'prettier --check "src/**/*.{ts,tsx}"'
|
|
179
69
|
},
|
|
180
|
-
|
|
181
|
-
// Custom descriptions
|
|
182
|
-
descriptions: {
|
|
183
|
-
TypeScript: 'TypeScript type checking',
|
|
184
|
-
ESLint: 'ESLint code analysis'
|
|
185
|
-
},
|
|
186
|
-
|
|
187
|
-
// Disable .env loading
|
|
188
|
-
loadEnv: false
|
|
70
|
+
loadEnv: false,
|
|
189
71
|
});
|
|
190
|
-
```
|
|
191
72
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
The library automatically detects your package manager in this order:
|
|
195
|
-
1. **Lock files**: `bun.lock`, `pnpm-lock.yaml`, `yarn.lock`, `package-lock.json`
|
|
196
|
-
2. **Available commands**: Checks if `bun`, `pnpm`, `yarn` are installed
|
|
197
|
-
3. **Fallback**: Uses `npm` if nothing else is found
|
|
198
|
-
|
|
199
|
-
You can also override the detection:
|
|
200
|
-
```javascript
|
|
201
|
-
const checker = new CodeQualityChecker({
|
|
202
|
-
packageManager: 'yarn' // Force yarn usage
|
|
203
|
-
});
|
|
73
|
+
const result = await customChecker.run({ showLogs: true });
|
|
74
|
+
console.log(result.results); // per-tool results array
|
|
204
75
|
```
|
|
205
76
|
|
|
77
|
+
## Configuration Options
|
|
206
78
|
|
|
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 |
|
|
207
87
|
|
|
208
|
-
##
|
|
209
|
-
|
|
210
|
-
### CodeQualityChecker
|
|
211
|
-
|
|
212
|
-
#### Constructor
|
|
213
|
-
```javascript
|
|
214
|
-
new CodeQualityChecker(options)
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
#### Options
|
|
218
|
-
- `loadEnv` (boolean): Load environment variables from `.env` file
|
|
219
|
-
- `tools` (string[]): Array of tool names to run
|
|
220
|
-
- `commands` (Record<string, string>): Custom commands for each tool
|
|
221
|
-
- `descriptions` (Record<string, string>): Descriptions shown during execution
|
|
222
|
-
- `packageManager` ('bun' | 'pnpm' | 'yarn' | 'npm'): Force specific package manager (auto-detected if not specified)
|
|
223
|
-
|
|
224
|
-
#### Methods
|
|
225
|
-
- `run()`: Promise<QualityCheckResult> - Run all configured checks
|
|
226
|
-
- `runCommand(command, description)`: CommandResult - Execute a single command
|
|
227
|
-
- `formatOutput(tool, result)`: string - Format output for a tool
|
|
228
|
-
- `checkSnykToken()`: boolean - Check Snyk authentication status
|
|
229
|
-
|
|
230
|
-
### Types
|
|
231
|
-
|
|
232
|
-
```typescript
|
|
233
|
-
interface CodeQualityOptions {
|
|
234
|
-
loadEnv?: boolean;
|
|
235
|
-
tools?: string[];
|
|
236
|
-
commands?: Record<string, string>;
|
|
237
|
-
descriptions?: Record<string, string>;
|
|
238
|
-
packageManager?: 'bun' | 'pnpm' | 'yarn' | 'npm';
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
interface CommandResult {
|
|
242
|
-
success: boolean;
|
|
243
|
-
output: string;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
interface QualityCheckResult {
|
|
247
|
-
success: boolean;
|
|
248
|
-
message: string;
|
|
249
|
-
}
|
|
250
|
-
```
|
|
88
|
+
## Bundled Tools
|
|
251
89
|
|
|
252
|
-
|
|
90
|
+
All tools are included as dependencies — zero extra setup:
|
|
253
91
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
- **Snyk** - `npm install -D snyk` or `bun add -D snyk`
|
|
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 |
|
|
262
99
|
|
|
263
|
-
|
|
100
|
+
## Package Manager Detection
|
|
264
101
|
|
|
265
|
-
|
|
266
|
-
```bash
|
|
267
|
-
# Install all quality tools
|
|
268
|
-
npm install -D typescript eslint prettier knip snyk
|
|
102
|
+
Automatically detected by lock file presence:
|
|
269
103
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
104
|
+
1. `bun.lock` / `bun.lockb` → bun
|
|
105
|
+
2. `pnpm-lock.yaml` → pnpm
|
|
106
|
+
3. `yarn.lock` → yarn
|
|
107
|
+
4. `package-lock.json` → npm
|
|
108
|
+
5. Fallback: checks installed binaries, defaults to npm
|
|
273
109
|
|
|
274
|
-
|
|
275
|
-
```bash
|
|
276
|
-
# Install all quality tools
|
|
277
|
-
bun add -D typescript eslint prettier knip snyk
|
|
110
|
+
## Error Reporting
|
|
278
111
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
112
|
+
Every run generates `.quality-report.md` with:
|
|
113
|
+
- Status of each check (pass/fail)
|
|
114
|
+
- Full error output for failed checks
|
|
115
|
+
- AI-friendly structured information for automated fixes
|
|
282
116
|
|
|
283
|
-
|
|
284
|
-
```bash
|
|
285
|
-
# Install all quality tools
|
|
286
|
-
pnpm add -D typescript eslint prettier knip snyk
|
|
117
|
+
Add `.quality-report.md` to your `.gitignore`.
|
|
287
118
|
|
|
288
|
-
|
|
289
|
-
pnpm add -D typescript eslint prettier
|
|
290
|
-
```
|
|
119
|
+
## AI Skills
|
|
291
120
|
|
|
292
|
-
|
|
293
|
-
```bash
|
|
294
|
-
# Install all quality tools
|
|
295
|
-
yarn add -D typescript eslint prettier knip snyk
|
|
121
|
+
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).
|
|
296
122
|
|
|
297
|
-
|
|
298
|
-
yarn add -D typescript eslint prettier
|
|
299
|
-
```
|
|
123
|
+
## Requirements
|
|
300
124
|
|
|
301
|
-
**
|
|
125
|
+
- **Node.js** >= 18.0.0
|
|
302
126
|
|
|
303
|
-
##
|
|
127
|
+
## Testing & CI/CD
|
|
304
128
|
|
|
305
|
-
|
|
129
|
+
Tested on every push across 4 runtimes:
|
|
130
|
+
- **Node.js 25.x** (npm)
|
|
131
|
+
- **Bun 1.3.x**
|
|
132
|
+
- **pnpm 10.x**
|
|
133
|
+
- **Yarn 4.13.0**
|
|
306
134
|
|
|
307
135
|
## Contributing
|
|
308
136
|
|
|
309
|
-
|
|
137
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup and guidelines.
|
|
310
138
|
|
|
311
139
|
## License
|
|
312
140
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
## Testing & CI/CD
|
|
316
|
-
|
|
317
|
-
This library is automatically tested across multiple runtimes:
|
|
318
|
-
- **Node.js** 25.x (npm)
|
|
319
|
-
- **Bun** 1.3.x
|
|
320
|
-
- **pnpm** 10.x
|
|
321
|
-
- **Yarn** 4.13.0
|
|
322
|
-
|
|
323
|
-
All tests run in parallel on every push and pull request. The library only publishes to npm when all tests pass.
|
|
324
|
-
|
|
141
|
+
MIT — see [LICENSE](LICENSE).
|
package/index.d.ts
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
export interface CodeQualityOptions {
|
|
2
|
+
/** Load environment variables from .env file (default: true) */
|
|
2
3
|
loadEnv?: boolean;
|
|
4
|
+
/** Use project's own config files instead of bundled configs (default: true) */
|
|
5
|
+
useProjectConfig?: boolean;
|
|
6
|
+
/** Array of tool names to run (default: all tools) */
|
|
3
7
|
tools?: string[];
|
|
8
|
+
/** Custom commands for each tool, keyed by tool name */
|
|
4
9
|
commands?: Record<string, string>;
|
|
10
|
+
/** Custom descriptions for each tool, keyed by tool name */
|
|
5
11
|
descriptions?: Record<string, string>;
|
|
12
|
+
/** Force a specific package manager (auto-detected if not specified) */
|
|
6
13
|
packageManager?: 'bun' | 'pnpm' | 'yarn' | 'npm';
|
|
14
|
+
/** Show detailed error logs in terminal */
|
|
15
|
+
showLogs?: boolean;
|
|
7
16
|
}
|
|
8
17
|
|
|
9
18
|
export interface CommandResult {
|
|
@@ -11,21 +20,30 @@ export interface CommandResult {
|
|
|
11
20
|
output: string;
|
|
12
21
|
}
|
|
13
22
|
|
|
23
|
+
export interface CheckResult {
|
|
24
|
+
name: string;
|
|
25
|
+
description: string;
|
|
26
|
+
success: boolean;
|
|
27
|
+
output: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
14
30
|
export interface QualityCheckResult {
|
|
15
31
|
success: boolean;
|
|
16
32
|
message: string;
|
|
33
|
+
results: CheckResult[];
|
|
17
34
|
}
|
|
18
35
|
|
|
19
36
|
export class CodeQualityChecker {
|
|
37
|
+
options: Required<Omit<CodeQualityOptions, 'showLogs'>>;
|
|
38
|
+
|
|
20
39
|
constructor(options?: CodeQualityOptions);
|
|
21
|
-
|
|
40
|
+
|
|
41
|
+
/** Execute a single shell command and return the result */
|
|
22
42
|
runCommand(command: string, description: string): CommandResult;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
checkSnykToken(): boolean;
|
|
27
|
-
|
|
28
|
-
run(): Promise<QualityCheckResult>;
|
|
43
|
+
|
|
44
|
+
/** Run all configured quality checks */
|
|
45
|
+
run(options?: { showLogs?: boolean }): Promise<QualityCheckResult>;
|
|
29
46
|
}
|
|
30
47
|
|
|
48
|
+
/** Convenience function to run quality checks without instantiating the class */
|
|
31
49
|
export function runQualityCheck(options?: CodeQualityOptions): Promise<QualityCheckResult>;
|