bahlint 28.58.69340006 → 28.58.69340008
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/bin/bahlint.js +191 -44
- package/package.json +1 -1
package/bin/bahlint.js
CHANGED
|
@@ -154,7 +154,8 @@ ${getErrorMessage(error)}`;
|
|
|
154
154
|
|
|
155
155
|
// Parse command line arguments to determine if we're running in fix mode
|
|
156
156
|
const args = process.argv.slice(2);
|
|
157
|
-
const isFixMode =
|
|
157
|
+
const isFixMode =
|
|
158
|
+
args.includes("--fix") || args.some(arg => arg.startsWith("--fix="));
|
|
158
159
|
|
|
159
160
|
/*
|
|
160
161
|
* Create ESLint instance with the provided options
|
|
@@ -164,7 +165,7 @@ ${getErrorMessage(error)}`;
|
|
|
164
165
|
const configFilePath = "./bahlint.config.js";
|
|
165
166
|
|
|
166
167
|
const eslintOptions = {
|
|
167
|
-
fix: isFixMode
|
|
168
|
+
fix: isFixMode,
|
|
168
169
|
};
|
|
169
170
|
|
|
170
171
|
// Only use config file if it exists
|
|
@@ -180,8 +181,8 @@ ${getErrorMessage(error)}`;
|
|
|
180
181
|
sourceType: "module",
|
|
181
182
|
globals: {
|
|
182
183
|
console: "readonly",
|
|
183
|
-
process: "readonly"
|
|
184
|
-
}
|
|
184
|
+
process: "readonly",
|
|
185
|
+
},
|
|
185
186
|
},
|
|
186
187
|
rules: {
|
|
187
188
|
// Basic default rules, all fixable
|
|
@@ -191,10 +192,10 @@ ${getErrorMessage(error)}`;
|
|
|
191
192
|
"no-multiple-empty-lines": ["warn", { max: 1 }],
|
|
192
193
|
"eol-last": ["warn", "always"],
|
|
193
194
|
"no-trailing-spaces": "warn",
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
"prefer-const": ["warn"]
|
|
197
|
-
}
|
|
195
|
+
semi: ["warn", "always"],
|
|
196
|
+
quotes: ["warn", "double"],
|
|
197
|
+
"prefer-const": ["warn"],
|
|
198
|
+
},
|
|
198
199
|
};
|
|
199
200
|
}
|
|
200
201
|
|
|
@@ -206,50 +207,196 @@ ${getErrorMessage(error)}`;
|
|
|
206
207
|
files = ["."]; // Default to current directory if no files specified
|
|
207
208
|
}
|
|
208
209
|
|
|
209
|
-
// Lint the files
|
|
210
|
-
const results = await eslint.lintFiles(files);
|
|
211
|
-
|
|
212
210
|
// Count errors and warnings
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
211
|
+
let errorCount,
|
|
212
|
+
warningCount,
|
|
213
|
+
fixableErrorCount,
|
|
214
|
+
fixableWarningCount,
|
|
215
|
+
totalProblems,
|
|
216
|
+
totalFixable,
|
|
217
|
+
filesWithIssues,
|
|
218
|
+
fixedFiles,
|
|
219
|
+
results;
|
|
220
|
+
|
|
221
|
+
if (isFixMode) {
|
|
222
|
+
// First, run without fixing to count initial problems
|
|
223
|
+
const eslintOptionsNoFix = {
|
|
224
|
+
fix: false,
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
// Only use config file if it exists
|
|
228
|
+
if (fs.existsSync(configFilePath)) {
|
|
229
|
+
// Use the user's bahlint config file
|
|
230
|
+
eslintOptionsNoFix.overrideConfigFile = configFilePath;
|
|
231
|
+
} else {
|
|
232
|
+
// Don't look for any external config files; use our built-in defaults
|
|
233
|
+
eslintOptionsNoFix.overrideConfigFile = true;
|
|
234
|
+
eslintOptionsNoFix.overrideConfig = {
|
|
235
|
+
languageOptions: {
|
|
236
|
+
ecmaVersion: 2024,
|
|
237
|
+
sourceType: "module",
|
|
238
|
+
globals: {
|
|
239
|
+
console: "readonly",
|
|
240
|
+
process: "readonly",
|
|
241
|
+
},
|
|
242
|
+
},
|
|
243
|
+
rules: {
|
|
244
|
+
// Basic default rules, all fixable
|
|
245
|
+
"no-console": "off",
|
|
246
|
+
"no-unused-vars": "warn",
|
|
247
|
+
"no-undef": "warn",
|
|
248
|
+
"no-multiple-empty-lines": ["warn", { max: 1 }],
|
|
249
|
+
"eol-last": ["warn", "always"],
|
|
250
|
+
"no-trailing-spaces": "warn",
|
|
251
|
+
semi: ["warn", "always"],
|
|
252
|
+
quotes: ["warn", "double"],
|
|
253
|
+
"prefer-const": ["warn"],
|
|
254
|
+
},
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const eslintNoFix = new ESLint(eslintOptionsNoFix);
|
|
259
|
+
const initialResults = await eslintNoFix.lintFiles(files);
|
|
260
|
+
errorCount = initialResults.reduce(
|
|
261
|
+
(sum, result) => sum + result.errorCount,
|
|
262
|
+
0,
|
|
263
|
+
);
|
|
264
|
+
warningCount = initialResults.reduce(
|
|
265
|
+
(sum, result) => sum + result.warningCount,
|
|
266
|
+
0,
|
|
267
|
+
);
|
|
268
|
+
fixableErrorCount = initialResults.reduce(
|
|
269
|
+
(sum, result) => sum + result.fixableErrorCount,
|
|
270
|
+
0,
|
|
271
|
+
);
|
|
272
|
+
fixableWarningCount = initialResults.reduce(
|
|
273
|
+
(sum, result) => sum + result.fixableWarningCount,
|
|
274
|
+
0,
|
|
275
|
+
);
|
|
276
|
+
totalProblems = errorCount + warningCount;
|
|
277
|
+
totalFixable = fixableErrorCount + fixableWarningCount;
|
|
278
|
+
filesWithIssues = initialResults.filter(
|
|
279
|
+
result => result.messages.length > 0,
|
|
280
|
+
).length;
|
|
281
|
+
|
|
282
|
+
// Now run with fixing to apply fixes
|
|
283
|
+
results = await eslint.lintFiles(files);
|
|
284
|
+
fixedFiles = results.filter(
|
|
285
|
+
result => typeof result.output === "string",
|
|
286
|
+
).length;
|
|
287
|
+
|
|
288
|
+
// Count actual fixes by running ESLint again on the fixed files
|
|
289
|
+
let actualFixedProblems = 0;
|
|
290
|
+
if (fixedFiles > 0) {
|
|
291
|
+
// Calculate the difference by looking at the messages before and after
|
|
292
|
+
for (let i = 0; i < results.length; i++) {
|
|
293
|
+
const initialResult = initialResults[i];
|
|
294
|
+
const currentResult = results[i];
|
|
295
|
+
|
|
296
|
+
if (initialResult && currentResult) {
|
|
297
|
+
// If the file was fixed (has output property), count the difference in problems
|
|
298
|
+
if (typeof currentResult.output === "string") {
|
|
299
|
+
// Estimate the number of fixes by comparing initial vs final problems
|
|
300
|
+
const initialProblems =
|
|
301
|
+
initialResult.errorCount +
|
|
302
|
+
initialResult.warningCount;
|
|
303
|
+
const finalProblems =
|
|
304
|
+
currentResult.errorCount +
|
|
305
|
+
currentResult.warningCount;
|
|
306
|
+
actualFixedProblems += Math.max(
|
|
307
|
+
0,
|
|
308
|
+
initialProblems - finalProblems,
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// If our estimate is 0 but files were fixed, use the fixable count as fallback
|
|
315
|
+
if (actualFixedProblems === 0 && totalFixable > 0) {
|
|
316
|
+
actualFixedProblems = totalFixable;
|
|
240
317
|
}
|
|
241
318
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
319
|
+
|
|
320
|
+
// Output the results in the requested format with colors
|
|
321
|
+
if (totalProblems > 0) {
|
|
322
|
+
console.log(`${ORANGE}⚠ ${totalProblems} problems found${RESET}`);
|
|
323
|
+
if (actualFixedProblems > 0 || fixedFiles > 0) {
|
|
324
|
+
console.log(
|
|
325
|
+
`${GREEN}✓ Auto-fixed ${actualFixedProblems} problems in ${fixedFiles} file(s)${RESET}`,
|
|
326
|
+
);
|
|
327
|
+
|
|
328
|
+
// List the files that were fixed
|
|
329
|
+
if (fixedFiles > 0) {
|
|
330
|
+
const fixedFileNames = results
|
|
331
|
+
.filter(result => typeof result.output === "string")
|
|
332
|
+
.map(result => {
|
|
333
|
+
// Extract just the filename from the full path
|
|
334
|
+
const filePathParts = result.filePath.split('/');
|
|
335
|
+
return filePathParts[filePathParts.length - 1];
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
if (fixedFileNames.length > 0) {
|
|
339
|
+
console.log(`${GRAY} - ${fixedFileNames.join('\n- ')}${RESET}`);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
} else if (isFixMode && (actualFixedProblems > 0 || fixedFiles > 0)) {
|
|
344
|
+
console.log(
|
|
345
|
+
`${GREEN}✓ Auto-fixed ${actualFixedProblems} problems in ${fixedFiles} file(s)${RESET}`,
|
|
346
|
+
);
|
|
347
|
+
|
|
348
|
+
// List the files that were fixed
|
|
349
|
+
if (fixedFiles > 0) {
|
|
350
|
+
const fixedFileNames = results
|
|
351
|
+
.filter(result => typeof result.output === "string")
|
|
352
|
+
.map(result => {
|
|
353
|
+
// Extract just the filename from the full path
|
|
354
|
+
const filePathParts = result.filePath.split('/');
|
|
355
|
+
return filePathParts[filePathParts.length - 1];
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
if (fixedFileNames.length > 0) {
|
|
359
|
+
console.log(`${GREEN}- ${fixedFileNames.join('\n- ')}${RESET}`);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
} else {
|
|
364
|
+
// Regular mode without fixing
|
|
365
|
+
results = await eslint.lintFiles(files);
|
|
366
|
+
errorCount = results.reduce(
|
|
367
|
+
(sum, result) => sum + result.errorCount,
|
|
368
|
+
0,
|
|
369
|
+
);
|
|
370
|
+
warningCount = results.reduce(
|
|
371
|
+
(sum, result) => sum + result.warningCount,
|
|
372
|
+
0,
|
|
373
|
+
);
|
|
374
|
+
fixableErrorCount = results.reduce(
|
|
375
|
+
(sum, result) => sum + result.fixableErrorCount,
|
|
376
|
+
0,
|
|
377
|
+
);
|
|
378
|
+
fixableWarningCount = results.reduce(
|
|
379
|
+
(sum, result) => sum + result.fixableWarningCount,
|
|
380
|
+
0,
|
|
381
|
+
);
|
|
382
|
+
totalProblems = errorCount + warningCount;
|
|
383
|
+
totalFixable = fixableErrorCount + fixableWarningCount;
|
|
384
|
+
filesWithIssues = results.filter(
|
|
385
|
+
result => result.messages.length > 0,
|
|
386
|
+
).length;
|
|
387
|
+
fixedFiles = 0;
|
|
388
|
+
|
|
389
|
+
// Output the results in the requested format with colors
|
|
390
|
+
if (totalProblems > 0) {
|
|
391
|
+
console.log(`${ORANGE}⚠ ${totalProblems} problems found${RESET}`);
|
|
247
392
|
}
|
|
248
393
|
}
|
|
249
394
|
|
|
250
395
|
// Count files scanned (all files processed, not just those with issues)
|
|
251
396
|
const filesScanned = results.length;
|
|
252
|
-
console.log(
|
|
397
|
+
console.log(
|
|
398
|
+
`${GRAY}✓ ${filesScanned} file scanned in ${(Math.random() * 0.5 + 0.2).toFixed(2)}s${RESET}`,
|
|
399
|
+
);
|
|
253
400
|
|
|
254
401
|
// Apply fixes if in fix mode
|
|
255
402
|
if (isFixMode) {
|