react-doctor 0.5.1-dev.038aaf7 → 0.5.1-dev.04e72a4

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/index.d.ts CHANGED
@@ -9237,6 +9237,22 @@ interface ReactDoctorConfig {
9237
9237
  * requested directory).
9238
9238
  */
9239
9239
  rootDir?: string;
9240
+ /**
9241
+ * Projects to scan and score separately — the config-file equivalent of
9242
+ * the CLI `--project` flag, for repos that always want per-module scoring
9243
+ * (e.g. a monorepo dashboard tracking each module's score daily) without
9244
+ * passing the flag on every run.
9245
+ *
9246
+ * Entries resolve exactly like `--project` values: workspace package
9247
+ * names (or directory basenames) first, then directory paths relative to
9248
+ * the scanned root. `"*"` selects every discovered workspace project.
9249
+ * Invalid entries fail the run with the same error as the flag.
9250
+ *
9251
+ * Precedence: an explicit `--project` flag overrides this list. Only the
9252
+ * config at the invocation root is consulted — `projects` inside a
9253
+ * module's own config is ignored (modules can't redirect the scan).
9254
+ */
9255
+ projects?: string[];
9240
9256
  textComponents?: string[];
9241
9257
  /**
9242
9258
  * Names of components that safely route string-only children through a
@@ -9436,6 +9452,7 @@ interface DiagnosticRelatedLocation {
9436
9452
  endColumn?: number;
9437
9453
  message: string;
9438
9454
  }
9455
+ type DiagnosticFileContext = "test" | "story" | "production";
9439
9456
  interface Diagnostic {
9440
9457
  filePath: string;
9441
9458
  plugin: string;
@@ -9462,6 +9479,12 @@ interface Diagnostic {
9462
9479
  /** 1-indexed end column of the primary span, when derivable. */
9463
9480
  endColumn?: number;
9464
9481
  category: string;
9482
+ /**
9483
+ * Set when the file never ships to users (`"test"` / `"story"`), so
9484
+ * renderers can label the site instead of implying production impact.
9485
+ * Omitted for production files (the default).
9486
+ */
9487
+ fileContext?: Exclude<DiagnosticFileContext, "production">;
9465
9488
  suppressionHint?: string;
9466
9489
  /** Secondary source locations (oxlint's non-primary labels). */
9467
9490
  relatedLocations?: DiagnosticRelatedLocation[];
@@ -9601,12 +9624,55 @@ interface DiagnoseResult {
9601
9624
  elapsedMilliseconds: number;
9602
9625
  }
9603
9626
  /**
9604
- * A single project to scan as part of a `diagnoseProjects()` batch.
9627
+ * A single project to scan as part of a `diagnose({ projects })` batch.
9605
9628
  * Scan options (`deadCode`, `lint`, etc.) are flat on the entry and
9606
9629
  * layer on top of the global defaults — omitted fields fall through.
9607
- * `config` is a full `ReactDoctorConfig` override that replaces the
9608
- * on-disk `doctor.config.*` for this project's scan.
9609
9630
  */
9631
+ interface ProjectDefinition extends DiagnoseOptions {
9632
+ directory: string;
9633
+ /**
9634
+ * Per-project config overrides, layered additively (see
9635
+ * `mergeReactDoctorConfigs`) on top of the project's on-disk
9636
+ * `doctor.config.*` and the batch-level `DiagnoseProjectsInput.config`
9637
+ * — so disabling one rule here keeps every base rule intact.
9638
+ */
9639
+ config?: ReactDoctorConfig;
9640
+ }
9641
+ interface ProjectResultOk extends DiagnoseResult {
9642
+ ok: true;
9643
+ directory: string;
9644
+ }
9645
+ interface ProjectResultError {
9646
+ ok: false;
9647
+ directory: string;
9648
+ error: Error;
9649
+ }
9650
+ type ProjectResult = ProjectResultOk | ProjectResultError;
9651
+ interface DiagnoseProjectsInput extends DiagnoseOptions {
9652
+ projects: ProjectDefinition[];
9653
+ /**
9654
+ * Config overrides applied to every project in the batch, layered
9655
+ * additively (see `mergeReactDoctorConfigs`) between each project's
9656
+ * on-disk `doctor.config.*` and its `ProjectDefinition.config` — one
9657
+ * base rule set for the batch, overridden per project only where needed.
9658
+ */
9659
+ config?: ReactDoctorConfig;
9660
+ /**
9661
+ * Maximum number of projects to scan concurrently. Defaults to
9662
+ * `DEFAULT_PROJECT_SCAN_CONCURRENCY` (4) — each project scan fans out
9663
+ * its own lint workers, so the batch is bounded rather than fully
9664
+ * parallel. Set to `1` for sequential execution. Values below 1 are
9665
+ * clamped to 1.
9666
+ */
9667
+ concurrency?: number;
9668
+ }
9669
+ interface DiagnoseProjectsResult {
9670
+ projects: ProjectResult[];
9671
+ diagnostics: Diagnostic[];
9672
+ score: ScoreResult | null;
9673
+ elapsedMilliseconds: number;
9674
+ } //#endregion
9675
+ //#region src/types/handle-error.d.ts
9610
9676
  //#endregion
9611
9677
  //#region src/types/inspect.d.ts
9612
9678
  interface InspectResult {
@@ -10027,41 +10093,20 @@ declare const defineConfig: (config: ReactDoctorConfig) => ReactDoctorConfig; //
10027
10093
  //#endregion
10028
10094
  //#region ../api/dist/index.d.ts
10029
10095
  //#region src/diagnose.d.ts
10030
- declare const diagnose: (directory: string, options?: DiagnoseOptions) => Promise<DiagnoseResult>;
10031
- /**
10032
- * Scan multiple projects in parallel and return per-project scores,
10033
- * diagnostics, and an aggregate score (worst-of across all projects).
10034
- *
10035
- * Each project runs its own independent `runInspect` pipeline — the
10036
- * same pipeline `diagnose()` uses — so per-project config overrides,
10037
- * dead-code analysis, and scoring all work identically to a single
10038
- * `diagnose()` call.
10039
- *
10040
- * Projects that fail (e.g. missing `package.json`, no React dependency)
10041
- * are included in the result with `ok: false` rather than aborting the
10042
- * entire batch, so callers always receive partial results.
10043
- *
10044
- * ```ts
10045
- * const result = await diagnoseProjects({
10046
- * projects: [
10047
- * { directory: "packages/app" },
10048
- * { directory: "packages/shared", deadCode: false },
10049
- * { directory: "packages/admin", config: {
10050
- * rules: { "react-doctor/no-array-index-as-key": "off" },
10051
- * }},
10052
- * ],
10053
- * concurrency: 4,
10054
- * });
10055
- *
10056
- * for (const project of result.projects) {
10057
- * if (project.ok) {
10058
- * console.log(project.directory, project.score);
10059
- * } else {
10060
- * console.error(project.directory, project.error);
10061
- * }
10062
- * }
10063
- * ```
10064
- */
10096
+ interface Diagnose {
10097
+ /** Scan a single project directory and return diagnostics + score. */
10098
+ (directory: string, options?: DiagnoseOptions): Promise<DiagnoseResult>;
10099
+ /**
10100
+ * Scan multiple projects in parallel — each through the same pipeline as
10101
+ * the single-directory form — and return per-project results plus an
10102
+ * aggregate worst-of score. A failing project (e.g. no `package.json`)
10103
+ * comes back with `ok: false` instead of aborting the batch. Per-project
10104
+ * `config` layers on the batch `config`, which layers on each project's
10105
+ * on-disk config (see `mergeReactDoctorConfigs`).
10106
+ */
10107
+ (input: DiagnoseProjectsInput): Promise<DiagnoseProjectsResult>;
10108
+ }
10109
+ declare const diagnose: Diagnose; //#endregion
10065
10110
  //#endregion
10066
10111
  //#region src/index.d.ts
10067
10112
  declare const clearCaches: () => void;
@@ -10072,5 +10117,5 @@ interface ToJsonReportOptions {
10072
10117
  }
10073
10118
  declare const toJsonReport: (result: DiagnoseResult, options: ToJsonReportOptions) => JsonReport;
10074
10119
  //#endregion
10075
- export { AmbiguousProjectError, type DiagnoseOptions, type DiagnoseResult, type Diagnostic, type DiffInfo, type JsonReport, type JsonReportDiffInfo, type JsonReportError, type JsonReportMode, type JsonReportProjectEntry, type JsonReportSummary, NoReactDependencyError, NotADirectoryError, PackageJsonNotFoundError, type ProjectInfo, ProjectNotFoundError, type ReactDoctorConfig, ReactDoctorError, type ScoreResult, buildJsonReport, buildJsonReportError, clearCaches, defineConfig, diagnose, filterSourceFiles, getDiffInfo, isProjectDiscoveryError, isReactDoctorError, summarizeDiagnostics, toJsonReport };
10120
+ export { AmbiguousProjectError, type DiagnoseOptions, type DiagnoseProjectsInput, type DiagnoseProjectsResult, type DiagnoseResult, type Diagnostic, type DiffInfo, type JsonReport, type JsonReportDiffInfo, type JsonReportError, type JsonReportMode, type JsonReportProjectEntry, type JsonReportSummary, NoReactDependencyError, NotADirectoryError, PackageJsonNotFoundError, type ProjectDefinition, type ProjectInfo, ProjectNotFoundError, type ProjectResult, type ProjectResultError, type ProjectResultOk, type ReactDoctorConfig, ReactDoctorError, type ScoreResult, buildJsonReport, buildJsonReportError, clearCaches, defineConfig, diagnose, filterSourceFiles, getDiffInfo, isProjectDiscoveryError, isReactDoctorError, summarizeDiagnostics, toJsonReport };
10076
10121
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="0090e471-3c19-51d5-8774-cc4c6a98e591")}catch(e){}}();
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="c6b4816b-fc2f-591f-9bf8-42201170eb9d")}catch(e){}}();
3
3
  import { r as __toESM$1, t as __commonJSMin$1 } from "./chunk-N93fKeF6.js";
4
4
  import { createRequire } from "node:module";
5
5
  import * as NFS from "node:fs";
@@ -19253,6 +19253,7 @@ var Diagnostic = class extends Class("Diagnostic")({
19253
19253
  endLine: optional(Number$1),
19254
19254
  endColumn: optional(Number$1),
19255
19255
  category: String$1,
19256
+ fileContext: optional(Literals(["test", "story"])),
19256
19257
  suppressionHint: optional(String$1),
19257
19258
  relatedLocations: optional(ArraySchema(DiagnosticRelatedLocation))
19258
19259
  }) {};
@@ -34570,8 +34571,10 @@ const isFileIgnoredByPatterns = (filePath, rootDirectory, patterns) => {
34570
34571
  const relativePath = toRelativePath(filePath, rootDirectory);
34571
34572
  return patterns.some((pattern) => pattern.test(relativePath));
34572
34573
  };
34574
+ const SCRIPT_EXTENSION_FRAGMENT = "[cm]?[jt]sx?";
34575
+ const STORY_FILE_SUFFIX_PATTERN = new RegExp(`\\.(?:stories|story)\\.(?:${SCRIPT_EXTENSION_FRAGMENT})$`);
34576
+ const TEST_FILE_SUFFIX_PATTERN = new RegExp(`\\.(?:test|spec|fixture|fixtures)\\.(?:${SCRIPT_EXTENSION_FRAGMENT})$`);
34573
34577
  const TEST_FILE_DIRECTORY_PATTERN = /(?:^|\/)(?:__tests__|__test__|tests|test|__mocks__|cypress|e2e|playwright)\//;
34574
- const TEST_FILE_SUFFIX_PATTERN = /\.(?:test|spec|stories|story|fixture|fixtures)\.(?:[cm]?[jt]sx?)$/;
34575
34578
  const FIXTURE_PROJECT_PATTERN = /\/(?:fixtures|__fixtures__)\//;
34576
34579
  const SOURCE_ROOT_PATTERN = /\/(?:src|app|lib|components|pages|features|modules|packages|apps|frontend|client)\//g;
34577
34580
  const stripAboveSourceRoot = (relativePath) => {
@@ -34582,12 +34585,23 @@ const stripAboveSourceRoot = (relativePath) => {
34582
34585
  if (lastIdx >= 0) return relativePath.slice(lastIdx);
34583
34586
  return relativePath.slice(fixtureMatch.index + fixtureMatch[0].length - 1);
34584
34587
  };
34585
- const isTestFilePath = (relativePath) => {
34586
- if (relativePath.length === 0) return false;
34588
+ /**
34589
+ * Classifies where a file sits relative to shipped code. A finding in a
34590
+ * `.stories.tsx` or `.spec.ts` file never runs in front of users, so
34591
+ * renderers label those sites instead of framing them as production
34592
+ * impact (`rn-no-raw-text` in a spec doesn't say users crash).
34593
+ *
34594
+ * `"story"` is the `.stories.*` / `.story.*` suffix; `"test"` is the
34595
+ * test/spec/fixture suffixes and test directories; `"production"` is
34596
+ * the default.
34597
+ */
34598
+ const classifyFileContext = (relativePath) => {
34599
+ if (relativePath.length === 0) return "production";
34587
34600
  const forwardSlashed = relativePath.replaceAll("\\", "/");
34588
- if (TEST_FILE_SUFFIX_PATTERN.test(forwardSlashed)) return true;
34601
+ if (STORY_FILE_SUFFIX_PATTERN.test(forwardSlashed)) return "story";
34602
+ if (TEST_FILE_SUFFIX_PATTERN.test(forwardSlashed)) return "test";
34589
34603
  const scoped = stripAboveSourceRoot(forwardSlashed);
34590
- return TEST_FILE_DIRECTORY_PATTERN.test(scoped);
34604
+ return TEST_FILE_DIRECTORY_PATTERN.test(scoped) ? "test" : "production";
34591
34605
  };
34592
34606
  /**
34593
34607
  * Resolves the user-configured severity override for a rule.
@@ -34811,6 +34825,8 @@ const collectStringSet = (values) => {
34811
34825
  * 5. `rn-no-raw-text` suppression via configured `textComponents` and
34812
34826
  * `rawTextWrapperComponents` (config-driven JSX enclosure checks)
34813
34827
  * 6. inline suppressions (`// react-doctor-disable-next-line ...`)
34828
+ * 7. file-context stamping (`fileContext: "test" | "story"` on
34829
+ * survivors in non-production files, so renderers can label them)
34814
34830
  *
34815
34831
  * Returns `null` when the diagnostic is dropped, the (possibly
34816
34832
  * severity-restamped) diagnostic otherwise.
@@ -34830,7 +34846,7 @@ const buildDiagnosticPipeline = (input) => {
34830
34846
  const hasTextComponents = textComponentNames.size > 0;
34831
34847
  const hasRawTextWrappers = rawTextWrapperComponentNames.size > 0;
34832
34848
  const fileLinesCache = /* @__PURE__ */ new Map();
34833
- const testFileCache = /* @__PURE__ */ new Map();
34849
+ const fileContextCache = /* @__PURE__ */ new Map();
34834
34850
  const libraryFileCache = /* @__PURE__ */ new Map();
34835
34851
  const isLibraryFile = (filePath) => {
34836
34852
  let cached = libraryFileCache.get(filePath);
@@ -34847,11 +34863,11 @@ const buildDiagnosticPipeline = (input) => {
34847
34863
  fileLinesCache.set(filePath, lines);
34848
34864
  return lines;
34849
34865
  };
34850
- const isTest = (filePath) => {
34851
- let cached = testFileCache.get(filePath);
34866
+ const getFileContext = (filePath) => {
34867
+ let cached = fileContextCache.get(filePath);
34852
34868
  if (cached === void 0) {
34853
- cached = isTestFilePath(filePath);
34854
- testFileCache.set(filePath, cached);
34869
+ cached = classifyFileContext(filePath);
34870
+ fileContextCache.set(filePath, cached);
34855
34871
  }
34856
34872
  return cached;
34857
34873
  };
@@ -34860,7 +34876,7 @@ const buildDiagnosticPipeline = (input) => {
34860
34876
  const rule = reactDoctorPlugin.rules[diagnostic.rule];
34861
34877
  if (!rule?.tags?.includes("test-noise")) return false;
34862
34878
  if (rule.tags.includes("migration-hint")) return false;
34863
- return isTest(diagnostic.filePath);
34879
+ return getFileContext(diagnostic.filePath) !== "production";
34864
34880
  };
34865
34881
  const isRuleIgnored = (ruleIdentifier) => {
34866
34882
  for (const ignored of ignoredRules) if (isSameRuleKey(ignored, ruleIdentifier)) return true;
@@ -34917,6 +34933,11 @@ const buildDiagnosticPipeline = (input) => {
34917
34933
  };
34918
34934
  }
34919
34935
  }
34936
+ const fileContext = getFileContext(current.filePath);
34937
+ if (fileContext !== "production") current = {
34938
+ ...current,
34939
+ fileContext
34940
+ };
34920
34941
  return current;
34921
34942
  } };
34922
34943
  };
@@ -38475,6 +38496,7 @@ const shouldSuppressLocalUseHookDiagnostic = (diagnostic, rootDirectory) => {
38475
38496
  };
38476
38497
  const FILEPATH_WITH_LOCATION_PATTERN = /\S+\.\w+:\d+:\d+[\s\S]*$/;
38477
38498
  const REACT_COMPILER_TITLE = "React Compiler can't optimize this";
38499
+ const REACT_COMPILER_TODO_TITLE = "React Compiler doesn't support this syntax";
38478
38500
  const REACT_COMPILER_MESSAGE = "This component misses React Compiler's automatic memoization & re-renders more than it should. Rewrite the flagged code so the compiler can optimize it.";
38479
38501
  const PLUGIN_CATEGORY_MAP = {
38480
38502
  react: "Bugs",
@@ -38502,7 +38524,10 @@ const getRuleRecommendation = (ruleName, project) => {
38502
38524
  };
38503
38525
  const getRuleCategory = (ruleName) => reactDoctorPlugin.rules[ruleName]?.category;
38504
38526
  const getRuleTitle = (ruleName) => reactDoctorPlugin.rules[ruleName]?.title;
38505
- const resolveDiagnosticTitle = (plugin, rule) => plugin === "react-hooks-js" ? REACT_COMPILER_TITLE : getRuleTitle(rule);
38527
+ const resolveDiagnosticTitle = (plugin, rule) => {
38528
+ if (plugin !== "react-hooks-js") return getRuleTitle(rule);
38529
+ return rule === "todo" ? REACT_COMPILER_TODO_TITLE : REACT_COMPILER_TITLE;
38530
+ };
38506
38531
  const cleanDiagnosticMessage = (message, help, plugin, rule, project) => {
38507
38532
  const cleaned = resolveCleanedDiagnostic(typeof message === "string" ? message : "", typeof help === "string" ? help : "", plugin, rule, project);
38508
38533
  return {
@@ -39181,7 +39206,7 @@ const ScoreApiResponseSchema = Struct({
39181
39206
  })))
39182
39207
  });
39183
39208
  const parseScoreResult = (value) => getOrNull(decodeUnknownOption(ScoreApiResponseSchema)(value));
39184
- const stripFilePaths = (diagnostics) => diagnostics.map(({ filePath: _filePath, ...rest }) => rest);
39209
+ const stripLocalFileFields = (diagnostics) => diagnostics.map(({ filePath: _filePath, fileContext: _fileContext, ...rest }) => rest);
39185
39210
  const isAbortError = (error) => error instanceof Error && (error.name === "AbortError" || error.name === "TimeoutError");
39186
39211
  const describeFailure = (error) => {
39187
39212
  if (isAbortError(error)) return `timed out after ${FETCH_TIMEOUT_MS / 1e3}s`;
@@ -39194,7 +39219,7 @@ const calculateScore = async (diagnostics, options = {}) => {
39194
39219
  const requestUrl = options.isCi ? `${SCORE_API_URL}?ci=1` : SCORE_API_URL;
39195
39220
  try {
39196
39221
  const compressedBody = gzipSync(JSON.stringify({
39197
- diagnostics: stripFilePaths(diagnostics),
39222
+ diagnostics: stripLocalFileFields(diagnostics),
39198
39223
  ...options.metadata?.repo ? { repo: options.metadata.repo } : {},
39199
39224
  ...options.metadata?.sha ? { sha: options.metadata.sha } : {},
39200
39225
  ...options.metadata?.framework ? { framework: options.metadata.framework } : {},
@@ -40099,13 +40124,55 @@ const clearAutoSuppressionCaches = () => {};
40099
40124
  * untouched so the loader sees the same plain object either way.
40100
40125
  */
40101
40126
  const defineConfig = (config) => config;
40127
+ const unionValues = (baseValues, overrideValues) => [...new Set([...baseValues, ...overrideValues])];
40128
+ const mergeIgnores = (baseIgnore, overrideIgnore) => {
40129
+ const mergedIgnore = {
40130
+ ...baseIgnore,
40131
+ ...overrideIgnore
40132
+ };
40133
+ if (baseIgnore.rules && overrideIgnore.rules) mergedIgnore.rules = unionValues(baseIgnore.rules, overrideIgnore.rules);
40134
+ if (baseIgnore.files && overrideIgnore.files) mergedIgnore.files = unionValues(baseIgnore.files, overrideIgnore.files);
40135
+ if (baseIgnore.tags && overrideIgnore.tags) mergedIgnore.tags = unionValues(baseIgnore.tags, overrideIgnore.tags);
40136
+ if (baseIgnore.overrides && overrideIgnore.overrides) mergedIgnore.overrides = [...baseIgnore.overrides, ...overrideIgnore.overrides];
40137
+ return mergedIgnore;
40138
+ };
40139
+ /**
40140
+ * Layer one `ReactDoctorConfig` on top of another, additively: `rules` /
40141
+ * `categories` / `supplyChain` merge per key, `ignore` lists union
40142
+ * (`ignore.overrides` concatenate), and every other field is a scalar the
40143
+ * override simply wins on when set. Returns the base unchanged when there
40144
+ * is no override, and vice versa — so callers can thread `null` /
40145
+ * `undefined` through without special-casing.
40146
+ */
40147
+ const mergeReactDoctorConfigs = (baseConfig, overrideConfig) => {
40148
+ if (overrideConfig === void 0) return baseConfig;
40149
+ if (baseConfig === null) return overrideConfig;
40150
+ const mergedConfig = {
40151
+ ...baseConfig,
40152
+ ...overrideConfig
40153
+ };
40154
+ if (baseConfig.rules && overrideConfig.rules) mergedConfig.rules = {
40155
+ ...baseConfig.rules,
40156
+ ...overrideConfig.rules
40157
+ };
40158
+ if (baseConfig.categories && overrideConfig.categories) mergedConfig.categories = {
40159
+ ...baseConfig.categories,
40160
+ ...overrideConfig.categories
40161
+ };
40162
+ if (baseConfig.supplyChain && overrideConfig.supplyChain) mergedConfig.supplyChain = {
40163
+ ...baseConfig.supplyChain,
40164
+ ...overrideConfig.supplyChain
40165
+ };
40166
+ if (baseConfig.ignore && overrideConfig.ignore) mergedConfig.ignore = mergeIgnores(baseConfig.ignore, overrideConfig.ignore);
40167
+ return mergedConfig;
40168
+ };
40102
40169
  //#endregion
40103
40170
  //#region ../api/dist/index.js
40104
- const buildDiagnoseLayer = (config, configOverride) => {
40105
- const configLayer = configOverride === void 0 ? Config.layerNode : Config.layerOf({
40171
+ const buildDiagnoseLayer = (config, configOverrideTarget) => {
40172
+ const configLayer = configOverrideTarget === void 0 ? Config.layerNode : Config.layerOf({
40106
40173
  config,
40107
- resolvedDirectory: configOverride.resolvedDirectory,
40108
- configSourceDirectory: null
40174
+ resolvedDirectory: configOverrideTarget.resolvedDirectory,
40175
+ configSourceDirectory: configOverrideTarget.configSourceDirectory
40109
40176
  });
40110
40177
  return mergeAll$1(Project.layerNode, configLayer, DeadCode.layerNode, Files.layerNode, Git.layerNode, Linter.layerOxlint, LintPartialFailures.layerLive, Progress.layerNoop, Reporter.layerNoop, Score.layerHttp, config?.supplyChain?.enabled !== false ? SupplyChain.layerNode : SupplyChain.layerOf([]));
40111
40178
  };
@@ -40137,11 +40204,64 @@ const outputToDiagnoseResult = (output, elapsedMilliseconds) => {
40137
40204
  elapsedMilliseconds
40138
40205
  };
40139
40206
  };
40140
- const diagnose = async (directory, options = {}) => {
40207
+ const diagnoseDirectory = async (directory, options) => {
40141
40208
  const startTime = globalThis.performance.now();
40142
40209
  const scanTarget = await resolveScanTarget(directory);
40143
40210
  return outputToDiagnoseResult(await runPromise(restoreLegacyThrow(buildInspectProgram(scanTarget, options).pipe(provide(buildDiagnoseLayer(scanTarget.userConfig)), provide(layerOtlp)))), globalThis.performance.now() - startTime);
40144
40211
  };
40212
+ const findWorstScore = (projectResults) => {
40213
+ let worstResult = null;
40214
+ let worstScore = Number.POSITIVE_INFINITY;
40215
+ for (const projectResult of projectResults) {
40216
+ if (!projectResult.ok || projectResult.score === null) continue;
40217
+ if (projectResult.score.score < worstScore) {
40218
+ worstScore = projectResult.score.score;
40219
+ worstResult = projectResult.score;
40220
+ }
40221
+ }
40222
+ return worstResult;
40223
+ };
40224
+ const diagnoseProject = async (projectDefinition, baseOptions, batchConfig) => {
40225
+ const startTime = globalThis.performance.now();
40226
+ try {
40227
+ const scanTarget = await resolveScanTarget(projectDefinition.directory);
40228
+ const { directory: _, config: projectConfig, ...perProjectOptions } = projectDefinition;
40229
+ const didOverrideConfig = batchConfig !== void 0 || projectConfig !== void 0;
40230
+ const effectiveConfig = mergeReactDoctorConfigs(mergeReactDoctorConfigs(scanTarget.userConfig, batchConfig), projectConfig);
40231
+ const program = buildInspectProgram(scanTarget, {
40232
+ ...baseOptions,
40233
+ ...perProjectOptions
40234
+ }, effectiveConfig ?? void 0);
40235
+ const didOverridePlugins = batchConfig?.plugins !== void 0 || projectConfig?.plugins !== void 0;
40236
+ const layer = buildDiagnoseLayer(effectiveConfig, didOverrideConfig ? {
40237
+ resolvedDirectory: scanTarget.resolvedDirectory,
40238
+ configSourceDirectory: didOverridePlugins ? null : scanTarget.configSourceDirectory
40239
+ } : void 0);
40240
+ return {
40241
+ ok: true,
40242
+ ...outputToDiagnoseResult(await runPromise(restoreLegacyThrow(program.pipe(provide(layer), provide(layerOtlp)))), globalThis.performance.now() - startTime),
40243
+ directory: scanTarget.resolvedDirectory
40244
+ };
40245
+ } catch (error) {
40246
+ return {
40247
+ ok: false,
40248
+ directory: projectDefinition.directory,
40249
+ error: error instanceof Error ? error : new Error(String(error))
40250
+ };
40251
+ }
40252
+ };
40253
+ const diagnoseProjectBatch = async (input) => {
40254
+ const startTime = globalThis.performance.now();
40255
+ const { projects, concurrency, config: batchConfig, ...baseOptions } = input;
40256
+ const projectResults = await mapWithConcurrency(projects, concurrency ?? 4, (projectDefinition) => diagnoseProject(projectDefinition, baseOptions, batchConfig));
40257
+ return {
40258
+ projects: projectResults,
40259
+ diagnostics: projectResults.flatMap((projectResult) => projectResult.ok ? projectResult.diagnostics : []),
40260
+ score: findWorstScore(projectResults),
40261
+ elapsedMilliseconds: globalThis.performance.now() - startTime
40262
+ };
40263
+ };
40264
+ const diagnose = (async (directoryOrInput, options = {}) => typeof directoryOrInput === "string" ? diagnoseDirectory(directoryOrInput, options) : diagnoseProjectBatch(directoryOrInput));
40145
40265
  //#endregion
40146
40266
  //#region src/index.ts
40147
40267
  const clearCaches = () => {
@@ -40174,4 +40294,4 @@ const toJsonReport = (result, options) => buildJsonReport({
40174
40294
  export { AmbiguousProjectError, NoReactDependencyError, NotADirectoryError, PackageJsonNotFoundError, ProjectNotFoundError, ReactDoctorError, buildJsonReport, buildJsonReportError, clearCaches, defineConfig, diagnose, filterSourceFiles, getDiffInfo, isProjectDiscoveryError, isReactDoctorError, summarizeDiagnostics, toJsonReport };
40175
40295
 
40176
40296
  //# sourceMappingURL=index.js.map
40177
- //# debugId=0090e471-3c19-51d5-8774-cc4c6a98e591
40297
+ //# debugId=c6b4816b-fc2f-591f-9bf8-42201170eb9d
package/dist/lsp.js CHANGED
@@ -19283,6 +19283,7 @@ var Diagnostic = class extends Class("Diagnostic")({
19283
19283
  endLine: optional(Number$1),
19284
19284
  endColumn: optional(Number$1),
19285
19285
  category: String$1,
19286
+ fileContext: optional(Literals(["test", "story"])),
19286
19287
  suppressionHint: optional(String$1),
19287
19288
  relatedLocations: optional(ArraySchema(DiagnosticRelatedLocation))
19288
19289
  }) {};
@@ -34630,8 +34631,10 @@ const isFileIgnoredByPatterns = (filePath, rootDirectory, patterns) => {
34630
34631
  const relativePath = toRelativePath(filePath, rootDirectory);
34631
34632
  return patterns.some((pattern) => pattern.test(relativePath));
34632
34633
  };
34634
+ const SCRIPT_EXTENSION_FRAGMENT = "[cm]?[jt]sx?";
34635
+ const STORY_FILE_SUFFIX_PATTERN = new RegExp(`\\.(?:stories|story)\\.(?:${SCRIPT_EXTENSION_FRAGMENT})$`);
34636
+ const TEST_FILE_SUFFIX_PATTERN = new RegExp(`\\.(?:test|spec|fixture|fixtures)\\.(?:${SCRIPT_EXTENSION_FRAGMENT})$`);
34633
34637
  const TEST_FILE_DIRECTORY_PATTERN = /(?:^|\/)(?:__tests__|__test__|tests|test|__mocks__|cypress|e2e|playwright)\//;
34634
- const TEST_FILE_SUFFIX_PATTERN = /\.(?:test|spec|stories|story|fixture|fixtures)\.(?:[cm]?[jt]sx?)$/;
34635
34638
  const FIXTURE_PROJECT_PATTERN = /\/(?:fixtures|__fixtures__)\//;
34636
34639
  const SOURCE_ROOT_PATTERN = /\/(?:src|app|lib|components|pages|features|modules|packages|apps|frontend|client)\//g;
34637
34640
  const stripAboveSourceRoot = (relativePath) => {
@@ -34642,12 +34645,23 @@ const stripAboveSourceRoot = (relativePath) => {
34642
34645
  if (lastIdx >= 0) return relativePath.slice(lastIdx);
34643
34646
  return relativePath.slice(fixtureMatch.index + fixtureMatch[0].length - 1);
34644
34647
  };
34645
- const isTestFilePath = (relativePath) => {
34646
- if (relativePath.length === 0) return false;
34648
+ /**
34649
+ * Classifies where a file sits relative to shipped code. A finding in a
34650
+ * `.stories.tsx` or `.spec.ts` file never runs in front of users, so
34651
+ * renderers label those sites instead of framing them as production
34652
+ * impact (`rn-no-raw-text` in a spec doesn't say users crash).
34653
+ *
34654
+ * `"story"` is the `.stories.*` / `.story.*` suffix; `"test"` is the
34655
+ * test/spec/fixture suffixes and test directories; `"production"` is
34656
+ * the default.
34657
+ */
34658
+ const classifyFileContext = (relativePath) => {
34659
+ if (relativePath.length === 0) return "production";
34647
34660
  const forwardSlashed = relativePath.replaceAll("\\", "/");
34648
- if (TEST_FILE_SUFFIX_PATTERN.test(forwardSlashed)) return true;
34661
+ if (STORY_FILE_SUFFIX_PATTERN.test(forwardSlashed)) return "story";
34662
+ if (TEST_FILE_SUFFIX_PATTERN.test(forwardSlashed)) return "test";
34649
34663
  const scoped = stripAboveSourceRoot(forwardSlashed);
34650
- return TEST_FILE_DIRECTORY_PATTERN.test(scoped);
34664
+ return TEST_FILE_DIRECTORY_PATTERN.test(scoped) ? "test" : "production";
34651
34665
  };
34652
34666
  /**
34653
34667
  * Resolves the user-configured severity override for a rule.
@@ -34867,6 +34881,8 @@ const collectStringSet = (values) => {
34867
34881
  * 5. `rn-no-raw-text` suppression via configured `textComponents` and
34868
34882
  * `rawTextWrapperComponents` (config-driven JSX enclosure checks)
34869
34883
  * 6. inline suppressions (`// react-doctor-disable-next-line ...`)
34884
+ * 7. file-context stamping (`fileContext: "test" | "story"` on
34885
+ * survivors in non-production files, so renderers can label them)
34870
34886
  *
34871
34887
  * Returns `null` when the diagnostic is dropped, the (possibly
34872
34888
  * severity-restamped) diagnostic otherwise.
@@ -34886,7 +34902,7 @@ const buildDiagnosticPipeline = (input) => {
34886
34902
  const hasTextComponents = textComponentNames.size > 0;
34887
34903
  const hasRawTextWrappers = rawTextWrapperComponentNames.size > 0;
34888
34904
  const fileLinesCache = /* @__PURE__ */ new Map();
34889
- const testFileCache = /* @__PURE__ */ new Map();
34905
+ const fileContextCache = /* @__PURE__ */ new Map();
34890
34906
  const libraryFileCache = /* @__PURE__ */ new Map();
34891
34907
  const isLibraryFile = (filePath) => {
34892
34908
  let cached = libraryFileCache.get(filePath);
@@ -34903,11 +34919,11 @@ const buildDiagnosticPipeline = (input) => {
34903
34919
  fileLinesCache.set(filePath, lines);
34904
34920
  return lines;
34905
34921
  };
34906
- const isTest = (filePath) => {
34907
- let cached = testFileCache.get(filePath);
34922
+ const getFileContext = (filePath) => {
34923
+ let cached = fileContextCache.get(filePath);
34908
34924
  if (cached === void 0) {
34909
- cached = isTestFilePath(filePath);
34910
- testFileCache.set(filePath, cached);
34925
+ cached = classifyFileContext(filePath);
34926
+ fileContextCache.set(filePath, cached);
34911
34927
  }
34912
34928
  return cached;
34913
34929
  };
@@ -34916,7 +34932,7 @@ const buildDiagnosticPipeline = (input) => {
34916
34932
  const rule = reactDoctorPlugin.rules[diagnostic.rule];
34917
34933
  if (!rule?.tags?.includes("test-noise")) return false;
34918
34934
  if (rule.tags.includes("migration-hint")) return false;
34919
- return isTest(diagnostic.filePath);
34935
+ return getFileContext(diagnostic.filePath) !== "production";
34920
34936
  };
34921
34937
  const isRuleIgnored = (ruleIdentifier) => {
34922
34938
  for (const ignored of ignoredRules) if (isSameRuleKey(ignored, ruleIdentifier)) return true;
@@ -34973,6 +34989,11 @@ const buildDiagnosticPipeline = (input) => {
34973
34989
  };
34974
34990
  }
34975
34991
  }
34992
+ const fileContext = getFileContext(current.filePath);
34993
+ if (fileContext !== "production") current = {
34994
+ ...current,
34995
+ fileContext
34996
+ };
34976
34997
  return current;
34977
34998
  } };
34978
34999
  };
@@ -38461,6 +38482,7 @@ const shouldSuppressLocalUseHookDiagnostic = (diagnostic, rootDirectory) => {
38461
38482
  };
38462
38483
  const FILEPATH_WITH_LOCATION_PATTERN = /\S+\.\w+:\d+:\d+[\s\S]*$/;
38463
38484
  const REACT_COMPILER_TITLE = "React Compiler can't optimize this";
38485
+ const REACT_COMPILER_TODO_TITLE = "React Compiler doesn't support this syntax";
38464
38486
  const REACT_COMPILER_MESSAGE = "This component misses React Compiler's automatic memoization & re-renders more than it should. Rewrite the flagged code so the compiler can optimize it.";
38465
38487
  const PLUGIN_CATEGORY_MAP = {
38466
38488
  react: "Bugs",
@@ -38488,7 +38510,10 @@ const getRuleRecommendation = (ruleName, project) => {
38488
38510
  };
38489
38511
  const getRuleCategory = (ruleName) => reactDoctorPlugin.rules[ruleName]?.category;
38490
38512
  const getRuleTitle = (ruleName) => reactDoctorPlugin.rules[ruleName]?.title;
38491
- const resolveDiagnosticTitle = (plugin, rule) => plugin === "react-hooks-js" ? REACT_COMPILER_TITLE : getRuleTitle(rule);
38513
+ const resolveDiagnosticTitle = (plugin, rule) => {
38514
+ if (plugin !== "react-hooks-js") return getRuleTitle(rule);
38515
+ return rule === "todo" ? REACT_COMPILER_TODO_TITLE : REACT_COMPILER_TITLE;
38516
+ };
38492
38517
  const cleanDiagnosticMessage = (message, help, plugin, rule, project) => {
38493
38518
  const cleaned = resolveCleanedDiagnostic(typeof message === "string" ? message : "", typeof help === "string" ? help : "", plugin, rule, project);
38494
38519
  return {
@@ -39167,7 +39192,7 @@ const ScoreApiResponseSchema = Struct({
39167
39192
  })))
39168
39193
  });
39169
39194
  const parseScoreResult = (value) => getOrNull(decodeUnknownOption(ScoreApiResponseSchema)(value));
39170
- const stripFilePaths = (diagnostics) => diagnostics.map(({ filePath: _filePath, ...rest }) => rest);
39195
+ const stripLocalFileFields = (diagnostics) => diagnostics.map(({ filePath: _filePath, fileContext: _fileContext, ...rest }) => rest);
39171
39196
  const isAbortError = (error) => error instanceof Error && (error.name === "AbortError" || error.name === "TimeoutError");
39172
39197
  const describeFailure = (error) => {
39173
39198
  if (isAbortError(error)) return `timed out after ${FETCH_TIMEOUT_MS / 1e3}s`;
@@ -39180,7 +39205,7 @@ const calculateScore = async (diagnostics, options = {}) => {
39180
39205
  const requestUrl = options.isCi ? `${SCORE_API_URL}?ci=1` : SCORE_API_URL;
39181
39206
  try {
39182
39207
  const compressedBody = gzipSync(JSON.stringify({
39183
- diagnostics: stripFilePaths(diagnostics),
39208
+ diagnostics: stripLocalFileFields(diagnostics),
39184
39209
  ...options.metadata?.repo ? { repo: options.metadata.repo } : {},
39185
39210
  ...options.metadata?.sha ? { sha: options.metadata.sha } : {},
39186
39211
  ...options.metadata?.framework ? { framework: options.metadata.framework } : {},
@@ -41709,6 +41734,8 @@ const METRIC = {
41709
41734
  cliInvoked: "cli.invoked",
41710
41735
  cliError: "cli.error",
41711
41736
  projectDetected: "project.detected",
41737
+ projectPathSelected: "project.path_selected",
41738
+ projectConfigSelected: "project.config_selected",
41712
41739
  scanCompleted: "scan.completed",
41713
41740
  scanDuration: "scan.duration",
41714
41741
  scanPhaseDuration: "scan.phase_duration",
@@ -42052,5 +42079,5 @@ const startLanguageServer = () => {
42052
42079
  };
42053
42080
  //#endregion
42054
42081
  export { startLanguageServer };
42055
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="3f2681f1-5caf-5b77-a639-8334ae51b66f")}catch(e){}}();
42056
- //# debugId=3f2681f1-5caf-5b77-a639-8334ae51b66f
42082
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="b2c89de5-a634-5b30-b964-aa07fc01b030")}catch(e){}}();
42083
+ //# debugId=b2c89de5-a634-5b30-b964-aa07fc01b030
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-doctor",
3
- "version": "0.5.1-dev.038aaf7",
3
+ "version": "0.5.1-dev.04e72a4",
4
4
  "description": "Your agent writes bad React. This catches it",
5
5
  "keywords": [
6
6
  "accessibility",
@@ -54,17 +54,17 @@
54
54
  "agent-install": "0.0.5",
55
55
  "conf": "^15.1.0",
56
56
  "confbox": "^0.2.4",
57
- "deslop-js": "^0.0.21",
57
+ "deslop-js": "^0.0.23",
58
58
  "eslint-plugin-react-hooks": "^7.1.1",
59
59
  "jiti": "^2.7.0",
60
60
  "magicast": "^0.5.3",
61
- "oxlint": "^1.66.0",
61
+ "oxlint": ">=1.66.0 <1.67.0",
62
62
  "prompts": "^2.4.2",
63
63
  "typescript": ">=5.0.4 <7",
64
64
  "vscode-languageserver": "^9.0.1",
65
65
  "vscode-languageserver-textdocument": "^1.0.12",
66
66
  "vscode-uri": "^3.1.0",
67
- "oxlint-plugin-react-doctor": "0.5.1-dev.038aaf7"
67
+ "oxlint-plugin-react-doctor": "0.5.1-dev.04e72a4"
68
68
  },
69
69
  "devDependencies": {
70
70
  "@types/babel__code-frame": "^7.27.0",
@@ -73,8 +73,8 @@
73
73
  "commander": "^14.0.3",
74
74
  "ora": "^9.4.0",
75
75
  "@react-doctor/core": "0.5.1",
76
- "@react-doctor/language-server": "0.5.1",
77
- "@react-doctor/api": "0.5.1"
76
+ "@react-doctor/api": "0.5.1",
77
+ "@react-doctor/language-server": "0.5.1"
78
78
  },
79
79
  "engines": {
80
80
  "node": "^20.19.0 || >=22.13.0"