code-quality-lib 2.0.1 → 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 CHANGED
@@ -49,12 +49,18 @@ code-quality --version # show version
49
49
  ```javascript
50
50
  const { CodeQualityChecker, runQualityCheck } = require('code-quality-lib');
51
51
 
52
- // Quick — run all checks with defaults
52
+ // Quick — run all checks with defaults (uses project's config files)
53
53
  const result = await runQualityCheck();
54
54
  console.log(result.success ? 'All passed' : 'Some failed');
55
55
 
56
- // Custom select tools, override commands
56
+ // Use bundled configs instead of project's configs
57
57
  const checker = new CodeQualityChecker({
58
+ useProjectConfig: false, // use library's bundled .eslintrc, .prettierrc, etc.
59
+ });
60
+ await checker.run();
61
+
62
+ // Custom — select tools, override commands
63
+ const customChecker = new CodeQualityChecker({
58
64
  tools: ['TypeScript', 'ESLint'],
59
65
  packageManager: 'pnpm',
60
66
  commands: {
@@ -64,7 +70,7 @@ const checker = new CodeQualityChecker({
64
70
  loadEnv: false,
65
71
  });
66
72
 
67
- const result = await checker.run({ showLogs: true });
73
+ const result = await customChecker.run({ showLogs: true });
68
74
  console.log(result.results); // per-tool results array
69
75
  ```
70
76
 
@@ -72,6 +78,7 @@ console.log(result.results); // per-tool results array
72
78
 
73
79
  | Option | Type | Default | Description |
74
80
  |--------|------|---------|-------------|
81
+ | `useProjectConfig` | `boolean` | `true` | Use project's config files (`.eslintrc.js`, `.prettierrc`, etc.) instead of bundled configs |
75
82
  | `tools` | `string[]` | All 5 tools | Which tools to run |
76
83
  | `packageManager` | `'npm' \| 'bun' \| 'pnpm' \| 'yarn'` | auto-detected | Force a specific package manager |
77
84
  | `commands` | `Record<string, string>` | bundled paths | Custom commands per tool |
package/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  export interface CodeQualityOptions {
2
2
  /** Load environment variables from .env file (default: true) */
3
3
  loadEnv?: boolean;
4
+ /** Use project's own config files instead of bundled configs (default: true) */
5
+ useProjectConfig?: boolean;
4
6
  /** Array of tool names to run (default: all tools) */
5
7
  tools?: string[];
6
8
  /** Custom commands for each tool, keyed by tool name */
package/index.js CHANGED
@@ -79,6 +79,73 @@ function resolveToolBinDir() {
79
79
  }
80
80
  }
81
81
 
82
+ // ─── Config File Detection ──────────────────────────────────────────────────
83
+
84
+ function detectProjectConfigs() {
85
+ const cwd = process.cwd();
86
+ const configs = {
87
+ eslint: null,
88
+ prettier: null,
89
+ typescript: null,
90
+ knip: null,
91
+ };
92
+
93
+ // ESLint config
94
+ const eslintFiles = [
95
+ '.eslintrc.js',
96
+ '.eslintrc.cjs',
97
+ '.eslintrc.json',
98
+ '.eslintrc.yml',
99
+ '.eslintrc.yaml',
100
+ 'eslint.config.js',
101
+ 'eslint.config.mjs',
102
+ ];
103
+ for (const file of eslintFiles) {
104
+ const fullPath = path.join(cwd, file);
105
+ if (fs.existsSync(fullPath)) {
106
+ configs.eslint = fullPath;
107
+ break;
108
+ }
109
+ }
110
+
111
+ // Prettier config
112
+ const prettierFiles = [
113
+ '.prettierrc',
114
+ '.prettierrc.json',
115
+ '.prettierrc.yml',
116
+ '.prettierrc.yaml',
117
+ '.prettierrc.js',
118
+ '.prettierrc.cjs',
119
+ 'prettier.config.js',
120
+ 'prettier.config.cjs',
121
+ ];
122
+ for (const file of prettierFiles) {
123
+ const fullPath = path.join(cwd, file);
124
+ if (fs.existsSync(fullPath)) {
125
+ configs.prettier = fullPath;
126
+ break;
127
+ }
128
+ }
129
+
130
+ // TypeScript config
131
+ const tsconfigPath = path.join(cwd, 'tsconfig.json');
132
+ if (fs.existsSync(tsconfigPath)) {
133
+ configs.typescript = tsconfigPath;
134
+ }
135
+
136
+ // Knip config
137
+ const knipFiles = ['knip.json', 'knip.jsonc', '.knip.json', '.knip.jsonc'];
138
+ for (const file of knipFiles) {
139
+ const fullPath = path.join(cwd, file);
140
+ if (fs.existsSync(fullPath)) {
141
+ configs.knip = fullPath;
142
+ break;
143
+ }
144
+ }
145
+
146
+ return configs;
147
+ }
148
+
82
149
  // ─── Default Checks ─────────────────────────────────────────────────────────
83
150
 
84
151
  const DEFAULT_TOOLS = [
@@ -95,6 +162,7 @@ class CodeQualityChecker {
95
162
  constructor(options = {}) {
96
163
  this.options = {
97
164
  loadEnv: options.loadEnv !== false,
165
+ useProjectConfig: options.useProjectConfig !== false,
98
166
  tools: options.tools || DEFAULT_TOOLS.map((t) => t.name),
99
167
  commands: options.commands || {},
100
168
  descriptions: options.descriptions || {},
@@ -102,6 +170,9 @@ class CodeQualityChecker {
102
170
  };
103
171
 
104
172
  if (this.options.loadEnv) loadEnvFile();
173
+
174
+ // Detect project configs if useProjectConfig is enabled
175
+ this.projectConfigs = this.options.useProjectConfig ? detectProjectConfigs() : {};
105
176
  }
106
177
 
107
178
  _getChecks() {
@@ -112,9 +183,28 @@ class CodeQualityChecker {
112
183
  const defaultTool = DEFAULT_TOOLS.find((t) => t.name === toolName);
113
184
  if (!defaultTool && !this.options.commands[toolName]) continue;
114
185
 
115
- const cmd =
116
- this.options.commands[toolName] ||
117
- `${path.join(binDir, defaultTool.bin)}${defaultTool.args ? ' ' + defaultTool.args : ''}`;
186
+ let cmd = this.options.commands[toolName];
187
+
188
+ // If no custom command, build default with config detection
189
+ if (!cmd) {
190
+ const binPath = path.join(binDir, defaultTool.bin);
191
+ let args = defaultTool.args;
192
+
193
+ // Add config flags if project configs exist and useProjectConfig is true
194
+ if (this.options.useProjectConfig) {
195
+ if (toolName === 'ESLint' && this.projectConfigs.eslint) {
196
+ args = `${args} --config ${this.projectConfigs.eslint}`;
197
+ } else if (toolName === 'Prettier' && this.projectConfigs.prettier) {
198
+ args = `${args} --config ${this.projectConfigs.prettier}`;
199
+ } else if (toolName === 'TypeScript' && this.projectConfigs.typescript) {
200
+ args = `--project ${this.projectConfigs.typescript} --noEmit`;
201
+ } else if (toolName === 'Knip' && this.projectConfigs.knip) {
202
+ args = `--config ${this.projectConfigs.knip}`;
203
+ }
204
+ }
205
+
206
+ cmd = `${binPath}${args ? ' ' + args : ''}`;
207
+ }
118
208
 
119
209
  const description =
120
210
  this.options.descriptions[toolName] ||
@@ -144,9 +234,10 @@ class CodeQualityChecker {
144
234
  const results = [];
145
235
  let allPassed = true;
146
236
 
147
- console.log('\n Professional Code Quality Check\n');
237
+ console.log('\n🔍 Professional Code Quality Check\n');
148
238
  console.log('─'.repeat(50));
149
- console.log(`📦 Using ${pm} package manager\n`);
239
+ console.log(`📦 Using ${pm} package manager`);
240
+ console.log(`⚙️ Config: ${this.options.useProjectConfig ? 'Project configs' : 'Bundled configs'}\n`);
150
241
 
151
242
  if (showLogs) {
152
243
  console.log('📋 Detailed error logging enabled (--logs flag)\n');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "code-quality-lib",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "A configurable code quality checker library for Node.js projects",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",