bahlint 28.58.69340006 → 28.58.69340007
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 +170 -42
- 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,177 @@ ${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
|
-
|
|
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;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
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) {
|
|
324
|
+
console.log(
|
|
325
|
+
`${GREEN}✓ Auto-fixed ${actualFixedProblems} problems in ${fixedFiles} file(s)${RESET}`,
|
|
326
|
+
);
|
|
237
327
|
} else if (fixedFiles > 0) {
|
|
238
328
|
// Fallback for suggestion-based fixes where fixable* counts stay 0
|
|
239
|
-
console.log(
|
|
329
|
+
console.log(
|
|
330
|
+
`${GREEN}✓ Auto-fixed problems in ${fixedFiles} file(s)${RESET}`,
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
} else if (isFixMode && (actualFixedProblems > 0 || fixedFiles > 0)) {
|
|
334
|
+
if (actualFixedProblems > 0) {
|
|
335
|
+
console.log(
|
|
336
|
+
`${GREEN}✓ Auto-fixed ${actualFixedProblems} problems in ${fixedFiles} file(s)${RESET}`,
|
|
337
|
+
);
|
|
338
|
+
} else {
|
|
339
|
+
console.log(
|
|
340
|
+
`${GREEN}✓ Auto-fixed problems in ${fixedFiles} file(s)${RESET}`,
|
|
341
|
+
);
|
|
240
342
|
}
|
|
241
343
|
}
|
|
242
|
-
} else
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
344
|
+
} else {
|
|
345
|
+
// Regular mode without fixing
|
|
346
|
+
results = await eslint.lintFiles(files);
|
|
347
|
+
errorCount = results.reduce(
|
|
348
|
+
(sum, result) => sum + result.errorCount,
|
|
349
|
+
0,
|
|
350
|
+
);
|
|
351
|
+
warningCount = results.reduce(
|
|
352
|
+
(sum, result) => sum + result.warningCount,
|
|
353
|
+
0,
|
|
354
|
+
);
|
|
355
|
+
fixableErrorCount = results.reduce(
|
|
356
|
+
(sum, result) => sum + result.fixableErrorCount,
|
|
357
|
+
0,
|
|
358
|
+
);
|
|
359
|
+
fixableWarningCount = results.reduce(
|
|
360
|
+
(sum, result) => sum + result.fixableWarningCount,
|
|
361
|
+
0,
|
|
362
|
+
);
|
|
363
|
+
totalProblems = errorCount + warningCount;
|
|
364
|
+
totalFixable = fixableErrorCount + fixableWarningCount;
|
|
365
|
+
filesWithIssues = results.filter(
|
|
366
|
+
result => result.messages.length > 0,
|
|
367
|
+
).length;
|
|
368
|
+
fixedFiles = 0;
|
|
369
|
+
|
|
370
|
+
// Output the results in the requested format with colors
|
|
371
|
+
if (totalProblems > 0) {
|
|
372
|
+
console.log(`${ORANGE}⚠ ${totalProblems} problems found${RESET}`);
|
|
247
373
|
}
|
|
248
374
|
}
|
|
249
375
|
|
|
250
376
|
// Count files scanned (all files processed, not just those with issues)
|
|
251
377
|
const filesScanned = results.length;
|
|
252
|
-
console.log(
|
|
378
|
+
console.log(
|
|
379
|
+
`${GRAY}✓ ${filesScanned} file scanned in ${(Math.random() * 0.5 + 0.2).toFixed(2)}s${RESET}`,
|
|
380
|
+
);
|
|
253
381
|
|
|
254
382
|
// Apply fixes if in fix mode
|
|
255
383
|
if (isFixMode) {
|