react-doctor 0.0.2 → 0.0.3
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/dist/cli.cjs +49 -27
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -69,6 +69,7 @@ var handleError = (error) => {
|
|
|
69
69
|
|
|
70
70
|
// src/constants.ts
|
|
71
71
|
var SOURCE_FILE_PATTERN = /\.(tsx?|jsx?)$/;
|
|
72
|
+
var JSX_FILE_PATTERN = /\.(tsx|jsx)$/;
|
|
72
73
|
var SEPARATOR_LENGTH = 62;
|
|
73
74
|
var SPAWN_MAX_BUFFER_BYTES = 100 * 1024 * 1024;
|
|
74
75
|
var FRAMEWORK_PACKAGES = {
|
|
@@ -219,7 +220,16 @@ var discoverProject = (directory) => {
|
|
|
219
220
|
|
|
220
221
|
// src/oxlint-config.ts
|
|
221
222
|
var OXLINT_CONFIG = {
|
|
222
|
-
|
|
223
|
+
categories: {
|
|
224
|
+
correctness: "off",
|
|
225
|
+
suspicious: "off",
|
|
226
|
+
pedantic: "off",
|
|
227
|
+
perf: "off",
|
|
228
|
+
restriction: "off",
|
|
229
|
+
style: "off",
|
|
230
|
+
nursery: "off"
|
|
231
|
+
},
|
|
232
|
+
plugins: ["react", "jsx-a11y", "react-perf"],
|
|
223
233
|
rules: {
|
|
224
234
|
"react/rules-of-hooks": "error",
|
|
225
235
|
"react/no-direct-mutation-state": "error",
|
|
@@ -252,16 +262,7 @@ var OXLINT_CONFIG = {
|
|
|
252
262
|
"react-perf/jsx-no-new-object-as-prop": "warn",
|
|
253
263
|
"react-perf/jsx-no-new-array-as-prop": "warn",
|
|
254
264
|
"react-perf/jsx-no-new-function-as-prop": "warn",
|
|
255
|
-
"react-perf/jsx-no-jsx-as-prop": "warn"
|
|
256
|
-
"import/no-cycle": "error",
|
|
257
|
-
"import/no-self-import": "error",
|
|
258
|
-
"import/no-duplicates": "warn",
|
|
259
|
-
"import/no-named-default": "warn",
|
|
260
|
-
"typescript/consistent-type-imports": "warn",
|
|
261
|
-
"typescript/no-explicit-any": "warn",
|
|
262
|
-
"typescript/no-non-null-assertion": "warn",
|
|
263
|
-
"typescript/prefer-ts-expect-error": "warn",
|
|
264
|
-
"typescript/no-unnecessary-type-assertion": "warn"
|
|
265
|
+
"react-perf/jsx-no-jsx-as-prop": "warn"
|
|
265
266
|
}
|
|
266
267
|
};
|
|
267
268
|
|
|
@@ -270,12 +271,7 @@ var PLUGIN_CATEGORY_MAP = {
|
|
|
270
271
|
react: "Correctness",
|
|
271
272
|
"react-hooks": "Correctness",
|
|
272
273
|
"jsx-a11y": "Accessibility",
|
|
273
|
-
"react-perf": "Performance"
|
|
274
|
-
import: "Bundle Size",
|
|
275
|
-
typescript: "TypeScript",
|
|
276
|
-
eslint: "Code Quality",
|
|
277
|
-
oxc: "Code Quality",
|
|
278
|
-
unicorn: "Code Quality"
|
|
274
|
+
"react-perf": "Performance"
|
|
279
275
|
};
|
|
280
276
|
var normalizePluginName = (rawPlugin) => rawPlugin.replace(/^eslint-plugin-/, "").replace(/^typescript-eslint$/, "typescript");
|
|
281
277
|
var parseRuleCode = (code) => {
|
|
@@ -311,7 +307,9 @@ var runOxlint = (rootDirectory, hasTypeScript) => {
|
|
|
311
307
|
return [];
|
|
312
308
|
}
|
|
313
309
|
const output = JSON.parse(stdout);
|
|
314
|
-
return output.diagnostics.
|
|
310
|
+
return output.diagnostics.filter(
|
|
311
|
+
(diagnostic) => JSX_FILE_PATTERN.test(diagnostic.filename)
|
|
312
|
+
).map((diagnostic) => {
|
|
315
313
|
const { plugin, rule } = parseRuleCode(diagnostic.code);
|
|
316
314
|
const primaryLabel = diagnostic.labels[0];
|
|
317
315
|
return {
|
|
@@ -343,18 +341,42 @@ var groupDiagnosticsByCategory = (diagnostics) => {
|
|
|
343
341
|
}
|
|
344
342
|
return groups;
|
|
345
343
|
};
|
|
344
|
+
var groupDiagnosticsByRule = (diagnostics) => {
|
|
345
|
+
const groups = /* @__PURE__ */ new Map();
|
|
346
|
+
for (const diagnostic of diagnostics) {
|
|
347
|
+
const ruleKey = `${diagnostic.plugin}/${diagnostic.rule}`;
|
|
348
|
+
const existing = groups.get(ruleKey) ?? [];
|
|
349
|
+
existing.push(diagnostic);
|
|
350
|
+
groups.set(ruleKey, existing);
|
|
351
|
+
}
|
|
352
|
+
return groups;
|
|
353
|
+
};
|
|
346
354
|
var printCategorySection = (category, diagnostics) => {
|
|
347
|
-
const separatorFill = "\u2500".repeat(
|
|
355
|
+
const separatorFill = "\u2500".repeat(
|
|
356
|
+
SEPARATOR_LENGTH - category.length - 6
|
|
357
|
+
);
|
|
348
358
|
logger.log(`\u2500\u2500\u2500\u2500 ${category} ${separatorFill}`);
|
|
349
359
|
logger.break();
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
360
|
+
const ruleGroups = groupDiagnosticsByRule(diagnostics);
|
|
361
|
+
for (const [ruleKey, ruleDiagnostics] of ruleGroups) {
|
|
362
|
+
const firstDiagnostic = ruleDiagnostics[0];
|
|
363
|
+
const icon = firstDiagnostic.severity === "error" ? highlighter.error("\u2717") : highlighter.warn("\u26A0");
|
|
364
|
+
const count = ruleDiagnostics.length;
|
|
365
|
+
const countLabel = count > 1 ? ` (${count})` : "";
|
|
366
|
+
logger.log(` ${icon} ${firstDiagnostic.message}${countLabel}`);
|
|
367
|
+
if (firstDiagnostic.help) {
|
|
368
|
+
logger.dim(` ${firstDiagnostic.help}`);
|
|
369
|
+
}
|
|
370
|
+
logger.dim(` Rule: ${ruleKey}`);
|
|
371
|
+
const fileOccurrences = /* @__PURE__ */ new Map();
|
|
372
|
+
for (const diagnostic of ruleDiagnostics) {
|
|
373
|
+
const currentCount = fileOccurrences.get(diagnostic.filePath) ?? 0;
|
|
374
|
+
fileOccurrences.set(diagnostic.filePath, currentCount + 1);
|
|
375
|
+
}
|
|
376
|
+
for (const [filePath, occurrenceCount] of fileOccurrences) {
|
|
377
|
+
const fileCountLabel = occurrenceCount > 1 ? ` (${occurrenceCount}x)` : "";
|
|
378
|
+
logger.dim(` ${filePath}${fileCountLabel}`);
|
|
355
379
|
}
|
|
356
|
-
logger.dim(` ${diagnostic.filePath}:${diagnostic.line}:${diagnostic.column}`);
|
|
357
|
-
logger.dim(` Rule: ${diagnostic.plugin}/${diagnostic.rule}`);
|
|
358
380
|
logger.break();
|
|
359
381
|
}
|
|
360
382
|
};
|
|
@@ -396,7 +418,7 @@ var scan = (directory) => {
|
|
|
396
418
|
};
|
|
397
419
|
|
|
398
420
|
// src/cli.ts
|
|
399
|
-
var VERSION = "0.0.
|
|
421
|
+
var VERSION = "0.0.3";
|
|
400
422
|
process.on("SIGINT", () => process.exit(0));
|
|
401
423
|
process.on("SIGTERM", () => process.exit(0));
|
|
402
424
|
var program = new commander.Command().name("react-doctor").description("Diagnose React codebase health").version(VERSION, "-v, --version", "display the version number").argument("[directory]", "project directory to scan", ".").action((directory) => {
|