react-doctor 0.5.1-dev.fee3fc4 → 0.5.2-dev.022790b
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.js +287 -102
- package/dist/index.d.ts +7 -0
- package/dist/index.js +249 -80
- package/dist/lsp.js +250 -81
- package/package.json +6 -6
package/dist/cli.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]="
|
|
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]="7cac4c8f-fabe-50fb-942b-a3388562ae09")}catch(e){}}();
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import * as NodeChildProcess from "node:child_process";
|
|
5
5
|
import { execFile, execFileSync, spawn, spawnSync } from "node:child_process";
|
|
@@ -13,11 +13,11 @@ import reactDoctorPlugin, { ALL_REACT_DOCTOR_RULE_KEYS, FRAMEWORK_SPECIFIC_RULE_
|
|
|
13
13
|
import * as OS from "node:os";
|
|
14
14
|
import os, { tmpdir } from "node:os";
|
|
15
15
|
import { parseJSON5 } from "confbox";
|
|
16
|
+
import * as NodeUrl from "node:url";
|
|
17
|
+
import { fileURLToPath } from "node:url";
|
|
16
18
|
import { createJiti } from "jiti";
|
|
17
19
|
import * as Crypto from "node:crypto";
|
|
18
20
|
import crypto, { createHash, randomUUID } from "node:crypto";
|
|
19
|
-
import * as NodeUrl from "node:url";
|
|
20
|
-
import { fileURLToPath } from "node:url";
|
|
21
21
|
import { gzipSync } from "node:zlib";
|
|
22
22
|
import * as Sentry from "@sentry/node";
|
|
23
23
|
import { performance as performance$1 } from "node:perf_hooks";
|
|
@@ -22356,6 +22356,7 @@ var Diagnostic = class extends Class("Diagnostic")({
|
|
|
22356
22356
|
endLine: optional(Number$1),
|
|
22357
22357
|
endColumn: optional(Number$1),
|
|
22358
22358
|
category: String$1,
|
|
22359
|
+
fileContext: optional(Literals(["test", "story"])),
|
|
22359
22360
|
suppressionHint: optional(String$1),
|
|
22360
22361
|
relatedLocations: optional(ArraySchema(DiagnosticRelatedLocation))
|
|
22361
22362
|
}) {};
|
|
@@ -37767,8 +37768,10 @@ const isFileIgnoredByPatterns = (filePath, rootDirectory, patterns) => {
|
|
|
37767
37768
|
const relativePath = toRelativePath(filePath, rootDirectory);
|
|
37768
37769
|
return patterns.some((pattern) => pattern.test(relativePath));
|
|
37769
37770
|
};
|
|
37771
|
+
const SCRIPT_EXTENSION_FRAGMENT = "[cm]?[jt]sx?";
|
|
37772
|
+
const STORY_FILE_SUFFIX_PATTERN = new RegExp(`\\.(?:stories|story)\\.(?:${SCRIPT_EXTENSION_FRAGMENT})$`);
|
|
37773
|
+
const TEST_FILE_SUFFIX_PATTERN = new RegExp(`\\.(?:test|spec|fixture|fixtures)\\.(?:${SCRIPT_EXTENSION_FRAGMENT})$`);
|
|
37770
37774
|
const TEST_FILE_DIRECTORY_PATTERN = /(?:^|\/)(?:__tests__|__test__|tests|test|__mocks__|cypress|e2e|playwright)\//;
|
|
37771
|
-
const TEST_FILE_SUFFIX_PATTERN = /\.(?:test|spec|stories|story|fixture|fixtures)\.(?:[cm]?[jt]sx?)$/;
|
|
37772
37775
|
const FIXTURE_PROJECT_PATTERN = /\/(?:fixtures|__fixtures__)\//;
|
|
37773
37776
|
const SOURCE_ROOT_PATTERN = /\/(?:src|app|lib|components|pages|features|modules|packages|apps|frontend|client)\//g;
|
|
37774
37777
|
const stripAboveSourceRoot = (relativePath) => {
|
|
@@ -37779,12 +37782,23 @@ const stripAboveSourceRoot = (relativePath) => {
|
|
|
37779
37782
|
if (lastIdx >= 0) return relativePath.slice(lastIdx);
|
|
37780
37783
|
return relativePath.slice(fixtureMatch.index + fixtureMatch[0].length - 1);
|
|
37781
37784
|
};
|
|
37782
|
-
|
|
37783
|
-
|
|
37785
|
+
/**
|
|
37786
|
+
* Classifies where a file sits relative to shipped code. A finding in a
|
|
37787
|
+
* `.stories.tsx` or `.spec.ts` file never runs in front of users, so
|
|
37788
|
+
* renderers label those sites instead of framing them as production
|
|
37789
|
+
* impact (`rn-no-raw-text` in a spec doesn't say users crash).
|
|
37790
|
+
*
|
|
37791
|
+
* `"story"` is the `.stories.*` / `.story.*` suffix; `"test"` is the
|
|
37792
|
+
* test/spec/fixture suffixes and test directories; `"production"` is
|
|
37793
|
+
* the default.
|
|
37794
|
+
*/
|
|
37795
|
+
const classifyFileContext = (relativePath) => {
|
|
37796
|
+
if (relativePath.length === 0) return "production";
|
|
37784
37797
|
const forwardSlashed = relativePath.replaceAll("\\", "/");
|
|
37785
|
-
if (
|
|
37798
|
+
if (STORY_FILE_SUFFIX_PATTERN.test(forwardSlashed)) return "story";
|
|
37799
|
+
if (TEST_FILE_SUFFIX_PATTERN.test(forwardSlashed)) return "test";
|
|
37786
37800
|
const scoped = stripAboveSourceRoot(forwardSlashed);
|
|
37787
|
-
return TEST_FILE_DIRECTORY_PATTERN.test(scoped);
|
|
37801
|
+
return TEST_FILE_DIRECTORY_PATTERN.test(scoped) ? "test" : "production";
|
|
37788
37802
|
};
|
|
37789
37803
|
/**
|
|
37790
37804
|
* Resolves the user-configured severity override for a rule.
|
|
@@ -38004,6 +38018,8 @@ const collectStringSet = (values) => {
|
|
|
38004
38018
|
* 5. `rn-no-raw-text` suppression via configured `textComponents` and
|
|
38005
38019
|
* `rawTextWrapperComponents` (config-driven JSX enclosure checks)
|
|
38006
38020
|
* 6. inline suppressions (`// react-doctor-disable-next-line ...`)
|
|
38021
|
+
* 7. file-context stamping (`fileContext: "test" | "story"` on
|
|
38022
|
+
* survivors in non-production files, so renderers can label them)
|
|
38007
38023
|
*
|
|
38008
38024
|
* Returns `null` when the diagnostic is dropped, the (possibly
|
|
38009
38025
|
* severity-restamped) diagnostic otherwise.
|
|
@@ -38023,7 +38039,7 @@ const buildDiagnosticPipeline = (input) => {
|
|
|
38023
38039
|
const hasTextComponents = textComponentNames.size > 0;
|
|
38024
38040
|
const hasRawTextWrappers = rawTextWrapperComponentNames.size > 0;
|
|
38025
38041
|
const fileLinesCache = /* @__PURE__ */ new Map();
|
|
38026
|
-
const
|
|
38042
|
+
const fileContextCache = /* @__PURE__ */ new Map();
|
|
38027
38043
|
const libraryFileCache = /* @__PURE__ */ new Map();
|
|
38028
38044
|
const isLibraryFile = (filePath) => {
|
|
38029
38045
|
let cached = libraryFileCache.get(filePath);
|
|
@@ -38040,11 +38056,11 @@ const buildDiagnosticPipeline = (input) => {
|
|
|
38040
38056
|
fileLinesCache.set(filePath, lines);
|
|
38041
38057
|
return lines;
|
|
38042
38058
|
};
|
|
38043
|
-
const
|
|
38044
|
-
let cached =
|
|
38059
|
+
const getFileContext = (filePath) => {
|
|
38060
|
+
let cached = fileContextCache.get(filePath);
|
|
38045
38061
|
if (cached === void 0) {
|
|
38046
|
-
cached =
|
|
38047
|
-
|
|
38062
|
+
cached = classifyFileContext(filePath);
|
|
38063
|
+
fileContextCache.set(filePath, cached);
|
|
38048
38064
|
}
|
|
38049
38065
|
return cached;
|
|
38050
38066
|
};
|
|
@@ -38053,7 +38069,7 @@ const buildDiagnosticPipeline = (input) => {
|
|
|
38053
38069
|
const rule = reactDoctorPlugin.rules[diagnostic.rule];
|
|
38054
38070
|
if (!rule?.tags?.includes("test-noise")) return false;
|
|
38055
38071
|
if (rule.tags.includes("migration-hint")) return false;
|
|
38056
|
-
return
|
|
38072
|
+
return getFileContext(diagnostic.filePath) !== "production";
|
|
38057
38073
|
};
|
|
38058
38074
|
const isRuleIgnored = (ruleIdentifier) => {
|
|
38059
38075
|
for (const ignored of ignoredRules) if (isSameRuleKey(ignored, ruleIdentifier)) return true;
|
|
@@ -38110,6 +38126,11 @@ const buildDiagnosticPipeline = (input) => {
|
|
|
38110
38126
|
};
|
|
38111
38127
|
}
|
|
38112
38128
|
}
|
|
38129
|
+
const fileContext = getFileContext(current.filePath);
|
|
38130
|
+
if (fileContext !== "production") current = {
|
|
38131
|
+
...current,
|
|
38132
|
+
fileContext
|
|
38133
|
+
};
|
|
38113
38134
|
return current;
|
|
38114
38135
|
} };
|
|
38115
38136
|
};
|
|
@@ -38506,10 +38527,41 @@ const PACKAGE_JSON_CONFIG_KEY$1 = "reactDoctor";
|
|
|
38506
38527
|
const LEGACY_CONFIG_FILENAME = "react-doctor.config.json";
|
|
38507
38528
|
const jiti = createJiti(import.meta.url);
|
|
38508
38529
|
const formatError = (error) => error instanceof Error ? error.message : String(error);
|
|
38509
|
-
const
|
|
38510
|
-
const imported = await
|
|
38530
|
+
const importDefaultExport = async (jitiInstance, filePath) => {
|
|
38531
|
+
const imported = await jitiInstance.import(filePath);
|
|
38511
38532
|
return imported?.default ?? imported;
|
|
38512
38533
|
};
|
|
38534
|
+
const SELF_PACKAGE_IMPORT_SPECIFIER = "react-doctor/api";
|
|
38535
|
+
const SELF_PACKAGE_RESOLVE_TARGETS = ["react-doctor/api", "@react-doctor/core"];
|
|
38536
|
+
const MODULE_NOT_FOUND_ERROR_CODES = new Set(["MODULE_NOT_FOUND", "ERR_MODULE_NOT_FOUND"]);
|
|
38537
|
+
let selfAliasJiti;
|
|
38538
|
+
const getSelfAliasJiti = () => {
|
|
38539
|
+
if (selfAliasJiti !== void 0) return selfAliasJiti;
|
|
38540
|
+
for (const resolveTarget of SELF_PACKAGE_RESOLVE_TARGETS) try {
|
|
38541
|
+
const aliasTargetPath = fileURLToPath(jiti.esmResolve(resolveTarget));
|
|
38542
|
+
selfAliasJiti = createJiti(import.meta.url, { alias: { [SELF_PACKAGE_IMPORT_SPECIFIER]: aliasTargetPath } });
|
|
38543
|
+
return selfAliasJiti;
|
|
38544
|
+
} catch {
|
|
38545
|
+
continue;
|
|
38546
|
+
}
|
|
38547
|
+
selfAliasJiti = null;
|
|
38548
|
+
return selfAliasJiti;
|
|
38549
|
+
};
|
|
38550
|
+
const isSelfPackageResolutionError = (error) => error instanceof Error && "code" in error && typeof error.code === "string" && MODULE_NOT_FOUND_ERROR_CODES.has(error.code) && error.message.includes(SELF_PACKAGE_IMPORT_SPECIFIER);
|
|
38551
|
+
const loadModuleConfig = async (filePath) => {
|
|
38552
|
+
try {
|
|
38553
|
+
return await importDefaultExport(jiti, filePath);
|
|
38554
|
+
} catch (error) {
|
|
38555
|
+
if (!isSelfPackageResolutionError(error)) throw error;
|
|
38556
|
+
const aliasJiti = getSelfAliasJiti();
|
|
38557
|
+
if (!aliasJiti) throw error;
|
|
38558
|
+
try {
|
|
38559
|
+
return await importDefaultExport(aliasJiti, filePath);
|
|
38560
|
+
} catch (retryError) {
|
|
38561
|
+
throw new Error(`${formatError(error)} (retry with ${SELF_PACKAGE_IMPORT_SPECIFIER} aliased to the running react-doctor package also failed: ${formatError(retryError)})`, { cause: retryError });
|
|
38562
|
+
}
|
|
38563
|
+
}
|
|
38564
|
+
};
|
|
38513
38565
|
const readDataConfig = (filePath) => parseJSON5(NFS.readFileSync(filePath, "utf-8"));
|
|
38514
38566
|
const readEmbeddedPackageJsonConfig = (directory) => {
|
|
38515
38567
|
const packageJsonPath = Path.join(directory, PACKAGE_JSON_FILENAME);
|
|
@@ -39245,6 +39297,17 @@ const checkPnpmHardening = (rootDirectory) => {
|
|
|
39245
39297
|
}));
|
|
39246
39298
|
return diagnostics;
|
|
39247
39299
|
};
|
|
39300
|
+
const buildReactNativeDiagnostic = (input) => ({
|
|
39301
|
+
filePath: input.filePath,
|
|
39302
|
+
plugin: "react-doctor",
|
|
39303
|
+
rule: input.rule,
|
|
39304
|
+
severity: input.severity ?? "warning",
|
|
39305
|
+
message: input.message,
|
|
39306
|
+
help: input.help,
|
|
39307
|
+
line: input.line ?? 0,
|
|
39308
|
+
column: input.column ?? 0,
|
|
39309
|
+
category: input.category ?? "Correctness"
|
|
39310
|
+
});
|
|
39248
39311
|
const BUILDER_BOB_PACKAGE = "react-native-builder-bob";
|
|
39249
39312
|
const isBuilderBobLibrary = (packageJson) => {
|
|
39250
39313
|
const bobConfig = packageJson[BUILDER_BOB_PACKAGE];
|
|
@@ -39256,17 +39319,12 @@ const checkReactNativeLibraryDependencies = (rootDirectory) => {
|
|
|
39256
39319
|
const misplaced = ["react", "react-native"].filter((name) => packageJson.dependencies?.[name] !== void 0);
|
|
39257
39320
|
if (misplaced.length === 0) return [];
|
|
39258
39321
|
const quoted = misplaced.map((name) => `"${name}"`).join(" and ");
|
|
39259
|
-
return [{
|
|
39322
|
+
return [buildReactNativeDiagnostic({
|
|
39260
39323
|
filePath: "package.json",
|
|
39261
|
-
plugin: "react-doctor",
|
|
39262
39324
|
rule: "rn-library-react-in-dependencies",
|
|
39263
|
-
severity: "warning",
|
|
39264
39325
|
message: `This react-native-builder-bob library lists ${quoted} in \`dependencies\` — that ships a second copy into consumer apps, causing "Invalid hook call" (duplicate React) and duplicate-native-module crashes.`,
|
|
39265
|
-
help: `Move ${quoted} to \`peerDependencies\` (keep ${misplaced.length === 1 ? "it" : "them"} in \`devDependencies\` for local development)
|
|
39266
|
-
|
|
39267
|
-
column: 0,
|
|
39268
|
-
category: "Correctness"
|
|
39269
|
-
}];
|
|
39326
|
+
help: `Move ${quoted} to \`peerDependencies\` (keep ${misplaced.length === 1 ? "it" : "them"} in \`devDependencies\` for local development).`
|
|
39327
|
+
})];
|
|
39270
39328
|
};
|
|
39271
39329
|
const BABEL_CONFIG_FILE_NAMES = [
|
|
39272
39330
|
"babel.config.js",
|
|
@@ -39278,6 +39336,8 @@ const BABEL_CONFIG_FILE_NAMES = [
|
|
|
39278
39336
|
".babelrc.json"
|
|
39279
39337
|
];
|
|
39280
39338
|
const LEGACY_PRESET_SPEC = "module:metro-react-native-babel-preset";
|
|
39339
|
+
const MODERN_PRESET_REFERENCE = new RegExp(`['"]module:@react-native/babel-preset['"]`);
|
|
39340
|
+
const ENABLE_BABEL_RUNTIME_VERSION = /enableBabelRuntime["']?\s*:\s*['"]/;
|
|
39281
39341
|
const checkReactNativeMetroBabelPreset = (rootDirectory) => {
|
|
39282
39342
|
for (const fileName of BABEL_CONFIG_FILE_NAMES) {
|
|
39283
39343
|
const filePath = Path.join(rootDirectory, fileName);
|
|
@@ -39288,18 +39348,20 @@ const checkReactNativeMetroBabelPreset = (rootDirectory) => {
|
|
|
39288
39348
|
} catch {
|
|
39289
39349
|
continue;
|
|
39290
39350
|
}
|
|
39291
|
-
if (
|
|
39292
|
-
return [{
|
|
39351
|
+
if (contents.includes(LEGACY_PRESET_SPEC)) return [buildReactNativeDiagnostic({
|
|
39293
39352
|
filePath: fileName,
|
|
39294
|
-
plugin: "react-doctor",
|
|
39295
39353
|
rule: "rn-no-metro-babel-preset",
|
|
39296
39354
|
severity: "error",
|
|
39297
39355
|
message: "`module:metro-react-native-babel-preset` was renamed to `@react-native/babel-preset` and is no longer installed by React Native 0.73+ — this preset reference fails to resolve and breaks the Metro/Babel transform.",
|
|
39298
|
-
help: "Replace the preset with `module:@react-native/babel-preset` (or `babel-preset-expo` on Expo) and remove the old `metro-react-native-babel-preset` dependency."
|
|
39299
|
-
|
|
39300
|
-
|
|
39301
|
-
|
|
39302
|
-
|
|
39356
|
+
help: "Replace the preset with `module:@react-native/babel-preset` (or `babel-preset-expo` on Expo) and remove the old `metro-react-native-babel-preset` dependency."
|
|
39357
|
+
})];
|
|
39358
|
+
if (MODERN_PRESET_REFERENCE.test(contents) && !ENABLE_BABEL_RUNTIME_VERSION.test(contents)) return [buildReactNativeDiagnostic({
|
|
39359
|
+
filePath: fileName,
|
|
39360
|
+
rule: "rn-no-metro-babel-runtime-version",
|
|
39361
|
+
severity: "warning",
|
|
39362
|
+
message: "`module:@react-native/babel-preset` has no `enableBabelRuntime` version, so Babel runtime helpers can be duplicated across files instead of imported once from @babel/runtime, increasing the JS bundle size.",
|
|
39363
|
+
help: "Set `enableBabelRuntime` to the @babel/runtime version from package.json, e.g. `['module:@react-native/babel-preset', { enableBabelRuntime: '^7.26.0' }]`."
|
|
39364
|
+
})];
|
|
39303
39365
|
}
|
|
39304
39366
|
return [];
|
|
39305
39367
|
};
|
|
@@ -41711,9 +41773,18 @@ const shouldSuppressLocalUseHookDiagnostic = (diagnostic, rootDirectory) => {
|
|
|
41711
41773
|
return bindingResolution !== null && !bindingResolution.isReactUseBinding;
|
|
41712
41774
|
};
|
|
41713
41775
|
const FILEPATH_WITH_LOCATION_PATTERN = /\S+\.\w+:\d+:\d+[\s\S]*$/;
|
|
41776
|
+
const LEADING_SEVERITY_LABEL_PATTERN = /^(?:Error|Warning):\s*/;
|
|
41777
|
+
const TRAILING_PERIOD_PATTERN = /\.$/;
|
|
41714
41778
|
const REACT_COMPILER_TITLE = "React Compiler can't optimize this";
|
|
41715
41779
|
const REACT_COMPILER_TODO_TITLE = "React Compiler doesn't support this syntax";
|
|
41716
|
-
const
|
|
41780
|
+
const REACT_COMPILER_IMPACT = "This component misses React Compiler's automatic memoization & re-renders more than it should";
|
|
41781
|
+
const REACT_COMPILER_ACTION = "Rewrite the flagged code so the compiler can optimize it.";
|
|
41782
|
+
const REACT_COMPILER_GENERIC_MESSAGE = `${REACT_COMPILER_IMPACT}. ${REACT_COMPILER_ACTION}`;
|
|
41783
|
+
const buildReactCompilerMessage = (reasonSummary) => {
|
|
41784
|
+
const normalizedSummary = reasonSummary.replace(TRAILING_PERIOD_PATTERN, "");
|
|
41785
|
+
if (!normalizedSummary) return REACT_COMPILER_GENERIC_MESSAGE;
|
|
41786
|
+
return `${REACT_COMPILER_IMPACT}: ${normalizedSummary}. ${REACT_COMPILER_ACTION}`;
|
|
41787
|
+
};
|
|
41717
41788
|
const PLUGIN_CATEGORY_MAP = {
|
|
41718
41789
|
react: "Bugs",
|
|
41719
41790
|
"react-hooks": "Bugs",
|
|
@@ -41752,10 +41823,19 @@ const cleanDiagnosticMessage = (message, help, plugin, rule, project) => {
|
|
|
41752
41823
|
};
|
|
41753
41824
|
};
|
|
41754
41825
|
const resolveCleanedDiagnostic = (message, help, plugin, rule, project) => {
|
|
41755
|
-
if (plugin === "react-hooks-js")
|
|
41756
|
-
message
|
|
41757
|
-
|
|
41758
|
-
|
|
41826
|
+
if (plugin === "react-hooks-js") {
|
|
41827
|
+
const bailoutReason = message.replace(FILEPATH_WITH_LOCATION_PATTERN, "").trim().replace(LEADING_SEVERITY_LABEL_PATTERN, "").trim();
|
|
41828
|
+
if (rule === "todo") return {
|
|
41829
|
+
message: REACT_COMPILER_GENERIC_MESSAGE,
|
|
41830
|
+
help: appendReanimatedSharedValueHint(bailoutReason || help, rule, project)
|
|
41831
|
+
};
|
|
41832
|
+
const [reasonSummary = "", ...reasonDetailLines] = bailoutReason.split("\n");
|
|
41833
|
+
const reasonDetail = reasonDetailLines.join("\n").trim();
|
|
41834
|
+
return {
|
|
41835
|
+
message: buildReactCompilerMessage(reasonSummary.trim()),
|
|
41836
|
+
help: appendReanimatedSharedValueHint(reasonDetail || help, rule, project)
|
|
41837
|
+
};
|
|
41838
|
+
}
|
|
41759
41839
|
return {
|
|
41760
41840
|
message: message.replace(FILEPATH_WITH_LOCATION_PATTERN, "").trim() || message,
|
|
41761
41841
|
help: help || getRuleRecommendation(rule, project) || ""
|
|
@@ -42422,7 +42502,7 @@ const ScoreApiResponseSchema = Struct({
|
|
|
42422
42502
|
})))
|
|
42423
42503
|
});
|
|
42424
42504
|
const parseScoreResult = (value) => getOrNull(decodeUnknownOption(ScoreApiResponseSchema)(value));
|
|
42425
|
-
const
|
|
42505
|
+
const stripLocalFileFields = (diagnostics) => diagnostics.map(({ filePath: _filePath, fileContext: _fileContext, ...rest }) => rest);
|
|
42426
42506
|
const isAbortError = (error) => error instanceof Error && (error.name === "AbortError" || error.name === "TimeoutError");
|
|
42427
42507
|
const describeFailure = (error) => {
|
|
42428
42508
|
if (isAbortError(error)) return `timed out after ${FETCH_TIMEOUT_MS / 1e3}s`;
|
|
@@ -42435,7 +42515,7 @@ const calculateScore = async (diagnostics, options = {}) => {
|
|
|
42435
42515
|
const requestUrl = options.isCi ? `${SCORE_API_URL}?ci=1` : SCORE_API_URL;
|
|
42436
42516
|
try {
|
|
42437
42517
|
const compressedBody = gzipSync(JSON.stringify({
|
|
42438
|
-
diagnostics:
|
|
42518
|
+
diagnostics: stripLocalFileFields(diagnostics),
|
|
42439
42519
|
...options.metadata?.repo ? { repo: options.metadata.repo } : {},
|
|
42440
42520
|
...options.metadata?.sha ? { sha: options.metadata.sha } : {},
|
|
42441
42521
|
...options.metadata?.framework ? { framework: options.metadata.framework } : {},
|
|
@@ -42491,42 +42571,74 @@ var Score = class Score extends Service()("react-doctor/Score") {
|
|
|
42491
42571
|
}) }));
|
|
42492
42572
|
static layerOf = (result) => succeed$3(Score, Score.of({ compute: () => succeed$2(result) }));
|
|
42493
42573
|
};
|
|
42494
|
-
const
|
|
42574
|
+
const isControlCharacter = (codePoint) => codePoint <= 31 || codePoint >= 127 && codePoint <= 159;
|
|
42575
|
+
const sanitizeTerminalText = (value) => {
|
|
42576
|
+
let sanitized = "";
|
|
42577
|
+
for (const character of value) {
|
|
42578
|
+
if (isControlCharacter(character.codePointAt(0) ?? 0)) continue;
|
|
42579
|
+
sanitized += character === "`" ? "'" : character;
|
|
42580
|
+
}
|
|
42581
|
+
return sanitized;
|
|
42582
|
+
};
|
|
42583
|
+
const SocketScoreSchema = Struct({
|
|
42495
42584
|
overall: Number$1,
|
|
42496
42585
|
license: Number$1,
|
|
42497
42586
|
maintenance: Number$1,
|
|
42498
42587
|
quality: Number$1,
|
|
42499
42588
|
supplyChain: Number$1,
|
|
42500
42589
|
vulnerability: Number$1
|
|
42501
|
-
})
|
|
42502
|
-
const
|
|
42503
|
-
|
|
42504
|
-
|
|
42505
|
-
|
|
42506
|
-
|
|
42507
|
-
|
|
42508
|
-
|
|
42509
|
-
|
|
42510
|
-
|
|
42511
|
-
|
|
42512
|
-
|
|
42590
|
+
});
|
|
42591
|
+
const SocketAlertSchema = Struct({
|
|
42592
|
+
type: String$1,
|
|
42593
|
+
severity: String$1,
|
|
42594
|
+
file: optional(NullOr(String$1)),
|
|
42595
|
+
props: optional(NullOr(Struct({ note: optional(NullOr(String$1)) })))
|
|
42596
|
+
});
|
|
42597
|
+
const SocketArtifactSchema = Struct({ score: optional(SocketScoreSchema) });
|
|
42598
|
+
const RawAlertsSchema = Struct({ alerts: optional(NullOr(ArraySchema(Unknown))) });
|
|
42599
|
+
const decodeArtifact = decodeUnknownOption(SocketArtifactSchema);
|
|
42600
|
+
const decodeRawAlerts = decodeUnknownOption(RawAlertsSchema);
|
|
42601
|
+
const decodeAlert = decodeUnknownOption(SocketAlertSchema);
|
|
42602
|
+
const extractAlerts = (parsed) => {
|
|
42603
|
+
const rawAlerts = getOrNull(decodeRawAlerts(parsed))?.alerts;
|
|
42604
|
+
if (!rawAlerts) return [];
|
|
42605
|
+
const alerts = [];
|
|
42606
|
+
for (const candidate of rawAlerts) {
|
|
42607
|
+
const alert = getOrNull(decodeAlert(candidate));
|
|
42608
|
+
if (alert !== null) alerts.push(alert);
|
|
42609
|
+
}
|
|
42610
|
+
return alerts;
|
|
42611
|
+
};
|
|
42612
|
+
const GATED_AXES = [{
|
|
42613
|
+
key: "supplyChain",
|
|
42614
|
+
label: "supply chain",
|
|
42615
|
+
guidance: {
|
|
42616
|
+
meaning: "risky install-time behavior — install scripts, obfuscated or native code, network/filesystem/shell access, or typosquatting",
|
|
42617
|
+
remediation: "Confirm this is the package you meant to install, and prefer a more established, audited alternative"
|
|
42618
|
+
}
|
|
42619
|
+
}, {
|
|
42620
|
+
key: "vulnerability",
|
|
42621
|
+
label: "vulnerability",
|
|
42622
|
+
guidance: {
|
|
42623
|
+
meaning: "known security vulnerabilities (CVEs) affecting this version",
|
|
42624
|
+
remediation: "Upgrade to a version with no known advisories (run `npm audit` to find one), or replace it"
|
|
42625
|
+
}
|
|
42626
|
+
}];
|
|
42627
|
+
const CONTEXT_AXES = [
|
|
42513
42628
|
{
|
|
42514
42629
|
key: "maintenance",
|
|
42515
|
-
label: "maintenance"
|
|
42516
|
-
gates: false
|
|
42630
|
+
label: "maintenance"
|
|
42517
42631
|
},
|
|
42518
42632
|
{
|
|
42519
42633
|
key: "quality",
|
|
42520
|
-
label: "quality"
|
|
42521
|
-
gates: false
|
|
42634
|
+
label: "quality"
|
|
42522
42635
|
},
|
|
42523
42636
|
{
|
|
42524
42637
|
key: "license",
|
|
42525
|
-
label: "license"
|
|
42526
|
-
gates: false
|
|
42638
|
+
label: "license"
|
|
42527
42639
|
}
|
|
42528
42640
|
];
|
|
42529
|
-
const
|
|
42641
|
+
const SCORE_AXES = [...GATED_AXES, ...CONTEXT_AXES];
|
|
42530
42642
|
const worstGatedAxis = (score) => {
|
|
42531
42643
|
let worst = GATED_AXES[0];
|
|
42532
42644
|
for (const axis of GATED_AXES) if (score[axis.key] < score[worst.key]) worst = axis;
|
|
@@ -42549,8 +42661,7 @@ const resolveConcreteVersion = (spec) => {
|
|
|
42549
42661
|
const trimmed = spec.trim();
|
|
42550
42662
|
if (trimmed.length === 0) return null;
|
|
42551
42663
|
if (trimmed.includes(":")) return null;
|
|
42552
|
-
|
|
42553
|
-
return match ? match[0] : null;
|
|
42664
|
+
return import_semver.minVersion(trimmed)?.version ?? null;
|
|
42554
42665
|
};
|
|
42555
42666
|
const locateDependencyKey = (packageJsonText, section, name) => {
|
|
42556
42667
|
const needle = `"${name}"`;
|
|
@@ -42634,7 +42745,7 @@ const collectMonorepoDependencies = (startDirectory, includeDevDependencies) =>
|
|
|
42634
42745
|
return [...dependenciesByKey.values()];
|
|
42635
42746
|
};
|
|
42636
42747
|
const toPurl = (dependency) => `pkg:npm/${dependency.name}@${dependency.version}`;
|
|
42637
|
-
const
|
|
42748
|
+
const parseArtifactFromBody = (body) => {
|
|
42638
42749
|
for (const line of body.split("\n")) {
|
|
42639
42750
|
if (line.trim().length === 0) continue;
|
|
42640
42751
|
let parsed;
|
|
@@ -42644,26 +42755,30 @@ const parseScoreFromBody = (body) => {
|
|
|
42644
42755
|
continue;
|
|
42645
42756
|
}
|
|
42646
42757
|
const artifact = getOrNull(decodeArtifact(parsed));
|
|
42647
|
-
if (artifact?.score) return
|
|
42758
|
+
if (artifact?.score) return {
|
|
42759
|
+
score: artifact.score,
|
|
42760
|
+
alerts: extractAlerts(parsed)
|
|
42761
|
+
};
|
|
42648
42762
|
}
|
|
42649
42763
|
return null;
|
|
42650
42764
|
};
|
|
42651
|
-
const
|
|
42765
|
+
const fetchSocketArtifact = (dependency) => tryPromise(async (signal) => {
|
|
42652
42766
|
const requestUrl = `${SOCKET_FREE_PURL_API_BASE}/${encodeURIComponent(toPurl(dependency))}`;
|
|
42653
42767
|
const response = await fetch(requestUrl, {
|
|
42654
42768
|
headers: { "User-Agent": SOCKET_FREE_USER_AGENT },
|
|
42655
42769
|
signal
|
|
42656
42770
|
});
|
|
42657
42771
|
if (!response.ok) return null;
|
|
42658
|
-
return
|
|
42659
|
-
}).pipe(timeout(FETCH_TIMEOUT_MS), orElseSucceed(() => null), tap$1((
|
|
42772
|
+
return parseArtifactFromBody(await response.text());
|
|
42773
|
+
}).pipe(timeout(FETCH_TIMEOUT_MS), orElseSucceed(() => null), tap$1((artifact) => {
|
|
42660
42774
|
const scoreAttributes = {};
|
|
42661
|
-
if (
|
|
42662
|
-
scoreAttributes["socket.score.overall"] = toHundred(score.overall);
|
|
42663
|
-
for (const axis of SCORE_AXES) scoreAttributes[`socket.score.${axis.key}`] = toHundred(score[axis.key]);
|
|
42775
|
+
if (artifact !== null) {
|
|
42776
|
+
scoreAttributes["socket.score.overall"] = toHundred(artifact.score.overall);
|
|
42777
|
+
for (const axis of SCORE_AXES) scoreAttributes[`socket.score.${axis.key}`] = toHundred(artifact.score[axis.key]);
|
|
42778
|
+
scoreAttributes["socket.alert.count"] = artifact.alerts.length;
|
|
42664
42779
|
}
|
|
42665
42780
|
return annotateCurrentSpan({
|
|
42666
|
-
"socket.scored":
|
|
42781
|
+
"socket.scored": artifact !== null,
|
|
42667
42782
|
...scoreAttributes
|
|
42668
42783
|
});
|
|
42669
42784
|
}), withSpan("SupplyChain.fetchScore", { attributes: {
|
|
@@ -42671,16 +42786,69 @@ const fetchSocketScore = (dependency) => tryPromise(async (signal) => {
|
|
|
42671
42786
|
"socket.version": dependency.version,
|
|
42672
42787
|
"socket.purl": toPurl(dependency)
|
|
42673
42788
|
} }));
|
|
42674
|
-
const
|
|
42675
|
-
const
|
|
42789
|
+
const formatOtherAxisScores = (score, failingKey) => SCORE_AXES.filter((axis) => axis.key !== failingKey).map((axis) => `${axis.label} ${toHundred(score[axis.key])}`).join(", ");
|
|
42790
|
+
const ALERT_SEVERITY_RANK = {
|
|
42791
|
+
critical: 4,
|
|
42792
|
+
high: 3,
|
|
42793
|
+
middle: 2,
|
|
42794
|
+
medium: 2,
|
|
42795
|
+
low: 1
|
|
42796
|
+
};
|
|
42797
|
+
const severityRank = (severity) => ALERT_SEVERITY_RANK[severity.toLowerCase()] ?? 0;
|
|
42798
|
+
const displaySeverity = (severity) => {
|
|
42799
|
+
const normalized = sanitizeTerminalText(severity.toLowerCase());
|
|
42800
|
+
return normalized === "middle" ? "medium" : normalized;
|
|
42801
|
+
};
|
|
42802
|
+
const ALERT_TYPE_LABELS = {
|
|
42803
|
+
malware: "known malware",
|
|
42804
|
+
gptMalware: "AI-detected malware",
|
|
42805
|
+
gptSecurity: "AI-detected security risk",
|
|
42806
|
+
gptAnomaly: "AI-detected code anomaly",
|
|
42807
|
+
envVars: "environment-variable access",
|
|
42808
|
+
usesEval: "use of eval",
|
|
42809
|
+
troll: "protestware",
|
|
42810
|
+
didYouMean: "possible typosquat",
|
|
42811
|
+
typosquat: "possible typosquat"
|
|
42812
|
+
};
|
|
42813
|
+
const humanizeAlertType = (type) => type.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]+/g, " ").toLowerCase().trim();
|
|
42814
|
+
const friendlyAlertType = (type) => ALERT_TYPE_LABELS[type] ?? sanitizeTerminalText(humanizeAlertType(type));
|
|
42815
|
+
const summarizeAlertNote = (note) => {
|
|
42816
|
+
const collapsed = sanitizeTerminalText(note.replace(/\s+/g, " ").trim());
|
|
42817
|
+
const firstSentence = collapsed.split(/(?<=\.)\s/)[0] || collapsed;
|
|
42818
|
+
if (firstSentence.length <= 160) return firstSentence.replace(/\.$/, "");
|
|
42819
|
+
return `${firstSentence.slice(0, 160).trimEnd()}…`;
|
|
42820
|
+
};
|
|
42821
|
+
const selectTopAlerts = (alerts) => [...alerts].sort((left, right) => severityRank(right.severity) - severityRank(left.severity)).slice(0, 3);
|
|
42822
|
+
const formatAlertReason = (topAlerts, totalCount) => {
|
|
42823
|
+
if (topAlerts.length === 1) {
|
|
42824
|
+
const [alert] = topAlerts;
|
|
42825
|
+
const location = alert.file ? ` in \`${sanitizeTerminalText(alert.file)}\`` : "";
|
|
42826
|
+
const note = alert.props?.note ? summarizeAlertNote(alert.props.note) : null;
|
|
42827
|
+
const detail = note ? `: "${note}"` : "";
|
|
42828
|
+
return `Socket flagged a ${displaySeverity(alert.severity)} ${friendlyAlertType(alert.type)} alert${location}${detail}.`;
|
|
42829
|
+
}
|
|
42830
|
+
return `Socket flagged ${totalCount} alerts (${topAlerts.map((alert) => friendlyAlertType(alert.type)).join(", ")}${totalCount > topAlerts.length ? ` (+${totalCount - topAlerts.length} more)` : ""}); most severe: ${displaySeverity(topAlerts[0].severity)}.`;
|
|
42831
|
+
};
|
|
42832
|
+
const formatDependencyIdentity = (dependency) => import_semver.valid(dependency.spec) !== null ? `${dependency.name}@${dependency.version}` : `${dependency.name}@${dependency.version} (lowest version "${dependency.spec}" allows)`;
|
|
42833
|
+
const buildSupplyChainHelp = (dependency, failingAxis, topAlerts, packagePageUrl, options) => {
|
|
42834
|
+
const hasCriticalAlert = topAlerts.some((alert) => alert.severity.toLowerCase() === "critical");
|
|
42835
|
+
const entry = `\`"${dependency.name}": "${dependency.spec}"\``;
|
|
42836
|
+
return `${hasCriticalAlert ? `Treat ${dependency.name} as compromised — do not ship it. Remove ${entry} from package.json and your lockfile, then audit anything it ran.` : `${failingAxis.guidance.remediation}; update ${entry} in package.json.`} Full report: ${packagePageUrl}. ${hasCriticalAlert ? `Only if you've confirmed this is a false positive, set \`supplyChain.enabled: false\`.` : `If you've reviewed and accepted this package, raise \`supplyChain.minScore\` (currently ${options.minScore}) or set \`supplyChain.severity: "warning"\`.`}`;
|
|
42837
|
+
};
|
|
42838
|
+
const buildLowScoreDiagnostic = (dependency, artifact, failingAxis, options) => {
|
|
42676
42839
|
const packagePageUrl = `${SOCKET_PACKAGE_PAGE_BASE}/${dependency.name}/overview/${dependency.version}`;
|
|
42840
|
+
const failingScore = toHundred(artifact.score[failingAxis.key]);
|
|
42841
|
+
const topAlerts = selectTopAlerts(artifact.alerts);
|
|
42842
|
+
const reason = topAlerts.length > 0 ? formatAlertReason(topAlerts, artifact.alerts.length) : `This points to ${failingAxis.guidance.meaning}.`;
|
|
42843
|
+
const headline = `\`${formatDependencyIdentity(dependency)}\` scored ${failingScore}/100 on Socket's ${failingAxis.label} axis (minimum ${options.minScore}).`;
|
|
42844
|
+
const otherAxes = `Other axes — ${formatOtherAxisScores(artifact.score, failingAxis.key)}.`;
|
|
42677
42845
|
return {
|
|
42678
42846
|
filePath: "package.json",
|
|
42679
42847
|
plugin: SUPPLY_CHAIN_PLUGIN,
|
|
42680
42848
|
rule: SUPPLY_CHAIN_RULE,
|
|
42681
42849
|
severity: options.severity,
|
|
42682
|
-
message:
|
|
42683
|
-
help:
|
|
42850
|
+
message: `${headline} ${reason} ${otherAxes}`,
|
|
42851
|
+
help: buildSupplyChainHelp(dependency, failingAxis, topAlerts, packagePageUrl, options),
|
|
42684
42852
|
url: packagePageUrl,
|
|
42685
42853
|
line: dependency.line,
|
|
42686
42854
|
column: dependency.column,
|
|
@@ -42700,13 +42868,13 @@ const collectSupplyChainScores = (input) => gen(function* () {
|
|
|
42700
42868
|
const options = resolveOptions(input.userConfig);
|
|
42701
42869
|
const dependencies = collectMonorepoDependencies(input.rootDirectory, options.includeDevDependencies);
|
|
42702
42870
|
if (dependencies.length === 0) return [];
|
|
42703
|
-
const
|
|
42871
|
+
const artifacts = yield* forEach$1(dependencies, fetchSocketArtifact, { concurrency: 8 });
|
|
42704
42872
|
return dependencies.map((dependency, index) => {
|
|
42705
|
-
const
|
|
42873
|
+
const artifact = artifacts[index];
|
|
42706
42874
|
return {
|
|
42707
42875
|
name: dependency.name,
|
|
42708
42876
|
version: dependency.version,
|
|
42709
|
-
overall:
|
|
42877
|
+
overall: artifact ? toHundred(artifact.score.overall) : null
|
|
42710
42878
|
};
|
|
42711
42879
|
});
|
|
42712
42880
|
});
|
|
@@ -42729,14 +42897,14 @@ const checkSupplyChain = (input) => gen(function* () {
|
|
|
42729
42897
|
const packageJsonPath = Path.join(input.rootDirectory, "package.json");
|
|
42730
42898
|
const dependencies = collectDependenciesToScore(readPackageJson$1(packageJsonPath), readPackageJsonText(packageJsonPath), options.includeDevDependencies);
|
|
42731
42899
|
if (dependencies.length === 0) return [];
|
|
42732
|
-
const
|
|
42900
|
+
const artifacts = yield* forEach$1(dependencies, fetchSocketArtifact, { concurrency: 8 });
|
|
42733
42901
|
const diagnostics = [];
|
|
42734
42902
|
for (let index = 0; index < dependencies.length; index += 1) {
|
|
42735
|
-
const
|
|
42736
|
-
if (!
|
|
42737
|
-
const worstAxis = worstGatedAxis(score);
|
|
42738
|
-
if (toHundred(score[worstAxis.key]) >= options.minScore) continue;
|
|
42739
|
-
diagnostics.push(buildLowScoreDiagnostic(dependencies[index],
|
|
42903
|
+
const artifact = artifacts[index];
|
|
42904
|
+
if (!artifact) continue;
|
|
42905
|
+
const worstAxis = worstGatedAxis(artifact.score);
|
|
42906
|
+
if (toHundred(artifact.score[worstAxis.key]) >= options.minScore) continue;
|
|
42907
|
+
diagnostics.push(buildLowScoreDiagnostic(dependencies[index], artifact, worstAxis, options));
|
|
42740
42908
|
}
|
|
42741
42909
|
return diagnostics;
|
|
42742
42910
|
});
|
|
@@ -43721,7 +43889,7 @@ const makeNoopConsole = () => ({
|
|
|
43721
43889
|
});
|
|
43722
43890
|
//#endregion
|
|
43723
43891
|
//#region src/cli/utils/version.ts
|
|
43724
|
-
const VERSION = "0.5.
|
|
43892
|
+
const VERSION = "0.5.2-dev.022790b";
|
|
43725
43893
|
//#endregion
|
|
43726
43894
|
//#region src/cli/utils/json-mode.ts
|
|
43727
43895
|
let context = null;
|
|
@@ -44079,13 +44247,13 @@ const isDevVersion = (version) => version === "0.0.0" || version.includes("-");
|
|
|
44079
44247
|
* uploads source-map artifacts under, so stack frames symbolicate. Honors the
|
|
44080
44248
|
* standard `SENTRY_RELEASE` override.
|
|
44081
44249
|
*/
|
|
44082
|
-
const resolveSentryRelease = () => process.env.SENTRY_RELEASE || `react-doctor@0.5.
|
|
44250
|
+
const resolveSentryRelease = () => process.env.SENTRY_RELEASE || `react-doctor@0.5.2-dev.022790b`;
|
|
44083
44251
|
/**
|
|
44084
44252
|
* Deployment environment shown in Sentry's environment filter. Defaults to
|
|
44085
44253
|
* `production` for tagged releases and `development` for dev/unbuilt versions,
|
|
44086
44254
|
* overridable via the standard `SENTRY_ENVIRONMENT` env var.
|
|
44087
44255
|
*/
|
|
44088
|
-
const resolveSentryEnvironment = () => process.env.SENTRY_ENVIRONMENT || (isDevVersion("0.5.
|
|
44256
|
+
const resolveSentryEnvironment = () => process.env.SENTRY_ENVIRONMENT || (isDevVersion("0.5.2-dev.022790b") ? "development" : "production");
|
|
44089
44257
|
/**
|
|
44090
44258
|
* Performance-tracing sample rate in `[0, 1]`. Reads `SENTRY_TRACES_SAMPLE_RATE`
|
|
44091
44259
|
* (set to `0` to disable tracing) and falls back to
|
|
@@ -47690,6 +47858,12 @@ const buildOutcomeAttributes = (input) => {
|
|
|
47690
47858
|
topRule = rule;
|
|
47691
47859
|
topRuleCount = count;
|
|
47692
47860
|
}
|
|
47861
|
+
let diagnosticsInTestFiles = 0;
|
|
47862
|
+
let diagnosticsInStoryFiles = 0;
|
|
47863
|
+
for (const diagnostic of result.diagnostics) {
|
|
47864
|
+
if (diagnostic.fileContext === "test") diagnosticsInTestFiles += 1;
|
|
47865
|
+
if (diagnostic.fileContext === "story") diagnosticsInStoryFiles += 1;
|
|
47866
|
+
}
|
|
47693
47867
|
const attributes = {
|
|
47694
47868
|
outcome,
|
|
47695
47869
|
exitCode: wouldBlock ? 1 : 0,
|
|
@@ -47700,6 +47874,8 @@ const buildOutcomeAttributes = (input) => {
|
|
|
47700
47874
|
errorCount: summary.errorCount,
|
|
47701
47875
|
warningCount: summary.warningCount,
|
|
47702
47876
|
affectedFiles: summary.affectedFileCount,
|
|
47877
|
+
diagnosticsInTestFiles,
|
|
47878
|
+
diagnosticsInStoryFiles,
|
|
47703
47879
|
distinctRulesFired: countByRule.size,
|
|
47704
47880
|
topRule,
|
|
47705
47881
|
scannedFileCount: result.scannedFileCount ?? null,
|
|
@@ -48032,17 +48208,24 @@ const writeStdout = (text) => sync(() => {
|
|
|
48032
48208
|
const POINTER = isUnicodeSupported() ? "›" : ">";
|
|
48033
48209
|
const colorizeBySeverity = (text, severity) => severity === "error" ? highlighter.error(text) : highlighter.warn(text);
|
|
48034
48210
|
const collectAffectedFiles = (diagnostics) => new Set(diagnostics.map((diagnostic) => diagnostic.filePath));
|
|
48035
|
-
const
|
|
48036
|
-
|
|
48211
|
+
const formatFileContextTag = (diagnostic) => diagnostic.fileContext ? ` (${diagnostic.fileContext} file)` : "";
|
|
48212
|
+
const buildVerboseFileEntries = (diagnostics) => {
|
|
48213
|
+
const fileEntries = /* @__PURE__ */ new Map();
|
|
48037
48214
|
for (const diagnostic of diagnostics) {
|
|
48038
|
-
|
|
48039
|
-
if (
|
|
48215
|
+
let entry = fileEntries.get(diagnostic.filePath);
|
|
48216
|
+
if (entry === void 0) {
|
|
48217
|
+
entry = {
|
|
48218
|
+
contextTag: formatFileContextTag(diagnostic),
|
|
48219
|
+
sites: []
|
|
48220
|
+
};
|
|
48221
|
+
fileEntries.set(diagnostic.filePath, entry);
|
|
48222
|
+
}
|
|
48223
|
+
if (diagnostic.line > 0) entry.sites.push({
|
|
48040
48224
|
line: diagnostic.line,
|
|
48041
48225
|
suppressionHint: diagnostic.suppressionHint
|
|
48042
48226
|
});
|
|
48043
|
-
fileSites.set(diagnostic.filePath, sites);
|
|
48044
48227
|
}
|
|
48045
|
-
return
|
|
48228
|
+
return fileEntries;
|
|
48046
48229
|
};
|
|
48047
48230
|
const formatSiteCountBadge = (count) => count > 1 ? `×${count}` : "";
|
|
48048
48231
|
const formatTrailingSiteBadge = (count) => {
|
|
@@ -48131,10 +48314,11 @@ const clusterNearbyDiagnostics = (diagnostics) => {
|
|
|
48131
48314
|
return clusters;
|
|
48132
48315
|
};
|
|
48133
48316
|
const formatClusterLocation = (cluster) => {
|
|
48134
|
-
const
|
|
48135
|
-
|
|
48136
|
-
if (cluster.
|
|
48137
|
-
return `${filePath}:${cluster.startLine}`;
|
|
48317
|
+
const lead = cluster.diagnostics[0];
|
|
48318
|
+
const contextTag = formatFileContextTag(lead);
|
|
48319
|
+
if (cluster.startLine <= 0) return `${lead.filePath}${contextTag}`;
|
|
48320
|
+
if (cluster.endLine > cluster.startLine) return `${lead.filePath}:${cluster.startLine}-${cluster.endLine}${contextTag}`;
|
|
48321
|
+
return `${lead.filePath}:${cluster.startLine}${contextTag}`;
|
|
48138
48322
|
};
|
|
48139
48323
|
const buildDiagnosticClusterLines = (cluster, resolveSourceRoot, renderCodeFrame) => {
|
|
48140
48324
|
const lead = cluster.diagnostics[0];
|
|
@@ -48277,25 +48461,26 @@ const formatElapsedTime = (elapsedMilliseconds) => {
|
|
|
48277
48461
|
};
|
|
48278
48462
|
const formatRuleSummary = (ruleKey, ruleDiagnostics) => {
|
|
48279
48463
|
const firstDiagnostic = ruleDiagnostics[0];
|
|
48464
|
+
const distinctMessages = [...new Set(ruleDiagnostics.map((diagnostic) => diagnostic.message))];
|
|
48280
48465
|
const sections = [
|
|
48281
48466
|
`Rule: ${ruleKey}`,
|
|
48282
48467
|
`Severity: ${firstDiagnostic.severity}`,
|
|
48283
48468
|
`Category: ${firstDiagnostic.category}`,
|
|
48284
48469
|
`Count: ${ruleDiagnostics.length}`,
|
|
48285
48470
|
"",
|
|
48286
|
-
|
|
48471
|
+
distinctMessages.join("\n\n")
|
|
48287
48472
|
];
|
|
48288
48473
|
if (firstDiagnostic.help) sections.push("", `Suggestion: ${firstDiagnostic.help}`);
|
|
48289
48474
|
if (firstDiagnostic.url) sections.push("", `Docs: ${firstDiagnostic.url}`);
|
|
48290
48475
|
const fixRecipeLine = formatFixRecipeLine(firstDiagnostic);
|
|
48291
48476
|
if (fixRecipeLine) sections.push("", fixRecipeLine);
|
|
48292
48477
|
sections.push("", "Files:");
|
|
48293
|
-
const
|
|
48294
|
-
for (const [filePath, sites] of
|
|
48295
|
-
sections.push(` ${filePath}:${site.line}`);
|
|
48478
|
+
const fileEntries = buildVerboseFileEntries(ruleDiagnostics);
|
|
48479
|
+
for (const [filePath, { contextTag, sites }] of fileEntries) if (sites.length > 0) for (const site of sites) {
|
|
48480
|
+
sections.push(` ${filePath}:${site.line}${contextTag}`);
|
|
48296
48481
|
if (site.suppressionHint) sections.push(` ${site.suppressionHint}`);
|
|
48297
48482
|
}
|
|
48298
|
-
else sections.push(` ${filePath}`);
|
|
48483
|
+
else sections.push(` ${filePath}${contextTag}`);
|
|
48299
48484
|
return sections.join("\n") + "\n";
|
|
48300
48485
|
};
|
|
48301
48486
|
//#endregion
|
|
@@ -53744,4 +53929,4 @@ Promise.resolve().then(() => assertNoRemovedFlags(process.argv)).then(() => prog
|
|
|
53744
53929
|
export {};
|
|
53745
53930
|
|
|
53746
53931
|
//# sourceMappingURL=cli.js.map
|
|
53747
|
-
//# debugId=
|
|
53932
|
+
//# debugId=7cac4c8f-fabe-50fb-942b-a3388562ae09
|