react-doctor 0.5.1-dev.038aaf7 → 0.5.1-dev.0a9d583

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/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
  };
@@ -38460,8 +38481,18 @@ const shouldSuppressLocalUseHookDiagnostic = (diagnostic, rootDirectory) => {
38460
38481
  return bindingResolution !== null && !bindingResolution.isReactUseBinding;
38461
38482
  };
38462
38483
  const FILEPATH_WITH_LOCATION_PATTERN = /\S+\.\w+:\d+:\d+[\s\S]*$/;
38484
+ const LEADING_SEVERITY_LABEL_PATTERN = /^(?:Error|Warning):\s*/;
38485
+ const TRAILING_PERIOD_PATTERN = /\.$/;
38463
38486
  const REACT_COMPILER_TITLE = "React Compiler can't optimize this";
38464
- 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.";
38487
+ const REACT_COMPILER_TODO_TITLE = "React Compiler doesn't support this syntax";
38488
+ const REACT_COMPILER_IMPACT = "This component misses React Compiler's automatic memoization & re-renders more than it should";
38489
+ const REACT_COMPILER_ACTION = "Rewrite the flagged code so the compiler can optimize it.";
38490
+ const REACT_COMPILER_GENERIC_MESSAGE = `${REACT_COMPILER_IMPACT}. ${REACT_COMPILER_ACTION}`;
38491
+ const buildReactCompilerMessage = (reasonSummary) => {
38492
+ const normalizedSummary = reasonSummary.replace(TRAILING_PERIOD_PATTERN, "");
38493
+ if (!normalizedSummary) return REACT_COMPILER_GENERIC_MESSAGE;
38494
+ return `${REACT_COMPILER_IMPACT}: ${normalizedSummary}. ${REACT_COMPILER_ACTION}`;
38495
+ };
38465
38496
  const PLUGIN_CATEGORY_MAP = {
38466
38497
  react: "Bugs",
38467
38498
  "react-hooks": "Bugs",
@@ -38488,7 +38519,10 @@ const getRuleRecommendation = (ruleName, project) => {
38488
38519
  };
38489
38520
  const getRuleCategory = (ruleName) => reactDoctorPlugin.rules[ruleName]?.category;
38490
38521
  const getRuleTitle = (ruleName) => reactDoctorPlugin.rules[ruleName]?.title;
38491
- const resolveDiagnosticTitle = (plugin, rule) => plugin === "react-hooks-js" ? REACT_COMPILER_TITLE : getRuleTitle(rule);
38522
+ const resolveDiagnosticTitle = (plugin, rule) => {
38523
+ if (plugin !== "react-hooks-js") return getRuleTitle(rule);
38524
+ return rule === "todo" ? REACT_COMPILER_TODO_TITLE : REACT_COMPILER_TITLE;
38525
+ };
38492
38526
  const cleanDiagnosticMessage = (message, help, plugin, rule, project) => {
38493
38527
  const cleaned = resolveCleanedDiagnostic(typeof message === "string" ? message : "", typeof help === "string" ? help : "", plugin, rule, project);
38494
38528
  return {
@@ -38497,10 +38531,19 @@ const cleanDiagnosticMessage = (message, help, plugin, rule, project) => {
38497
38531
  };
38498
38532
  };
38499
38533
  const resolveCleanedDiagnostic = (message, help, plugin, rule, project) => {
38500
- if (plugin === "react-hooks-js") return {
38501
- message: REACT_COMPILER_MESSAGE,
38502
- help: appendReanimatedSharedValueHint(message.replace(FILEPATH_WITH_LOCATION_PATTERN, "").trim() || help, rule, project)
38503
- };
38534
+ if (plugin === "react-hooks-js") {
38535
+ const bailoutReason = message.replace(FILEPATH_WITH_LOCATION_PATTERN, "").trim().replace(LEADING_SEVERITY_LABEL_PATTERN, "").trim();
38536
+ if (rule === "todo") return {
38537
+ message: REACT_COMPILER_GENERIC_MESSAGE,
38538
+ help: appendReanimatedSharedValueHint(bailoutReason || help, rule, project)
38539
+ };
38540
+ const [reasonSummary = "", ...reasonDetailLines] = bailoutReason.split("\n");
38541
+ const reasonDetail = reasonDetailLines.join("\n").trim();
38542
+ return {
38543
+ message: buildReactCompilerMessage(reasonSummary.trim()),
38544
+ help: appendReanimatedSharedValueHint(reasonDetail || help, rule, project)
38545
+ };
38546
+ }
38504
38547
  return {
38505
38548
  message: message.replace(FILEPATH_WITH_LOCATION_PATTERN, "").trim() || message,
38506
38549
  help: help || getRuleRecommendation(rule, project) || ""
@@ -39167,7 +39210,7 @@ const ScoreApiResponseSchema = Struct({
39167
39210
  })))
39168
39211
  });
39169
39212
  const parseScoreResult = (value) => getOrNull(decodeUnknownOption(ScoreApiResponseSchema)(value));
39170
- const stripFilePaths = (diagnostics) => diagnostics.map(({ filePath: _filePath, ...rest }) => rest);
39213
+ const stripLocalFileFields = (diagnostics) => diagnostics.map(({ filePath: _filePath, fileContext: _fileContext, ...rest }) => rest);
39171
39214
  const isAbortError = (error) => error instanceof Error && (error.name === "AbortError" || error.name === "TimeoutError");
39172
39215
  const describeFailure = (error) => {
39173
39216
  if (isAbortError(error)) return `timed out after ${FETCH_TIMEOUT_MS / 1e3}s`;
@@ -39180,7 +39223,7 @@ const calculateScore = async (diagnostics, options = {}) => {
39180
39223
  const requestUrl = options.isCi ? `${SCORE_API_URL}?ci=1` : SCORE_API_URL;
39181
39224
  try {
39182
39225
  const compressedBody = gzipSync(JSON.stringify({
39183
- diagnostics: stripFilePaths(diagnostics),
39226
+ diagnostics: stripLocalFileFields(diagnostics),
39184
39227
  ...options.metadata?.repo ? { repo: options.metadata.repo } : {},
39185
39228
  ...options.metadata?.sha ? { sha: options.metadata.sha } : {},
39186
39229
  ...options.metadata?.framework ? { framework: options.metadata.framework } : {},
@@ -41709,6 +41752,8 @@ const METRIC = {
41709
41752
  cliInvoked: "cli.invoked",
41710
41753
  cliError: "cli.error",
41711
41754
  projectDetected: "project.detected",
41755
+ projectPathSelected: "project.path_selected",
41756
+ projectConfigSelected: "project.config_selected",
41712
41757
  scanCompleted: "scan.completed",
41713
41758
  scanDuration: "scan.duration",
41714
41759
  scanPhaseDuration: "scan.phase_duration",
@@ -42052,5 +42097,5 @@ const startLanguageServer = () => {
42052
42097
  };
42053
42098
  //#endregion
42054
42099
  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
42100
+ !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]="d189cded-30cd-5adf-aa54-2429b20c538b")}catch(e){}}();
42101
+ //# debugId=d189cded-30cd-5adf-aa54-2429b20c538b
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.0a9d583",
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.24",
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.0a9d583"
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"