Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions packages/core/src/project-info/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,22 +266,14 @@ export const extractDependencyInfo = (packageJson: PackageJson): DependencyInfo
...packageJson.dependencies,
...packageJson.devDependencies,
};
const reactVersion = pickConcreteVersion(packageJson, "react", [
"dependencies",
"peerDependencies",
"devDependencies",
]);
const reactVersion = pickConcreteVersion(packageJson, "react", REACT_SECTIONS);
const tailwindVersion = pickConcreteVersion(
packageJson,
"tailwindcss",
["dependencies", "devDependencies", "peerDependencies"],
TAILWIND_ZOD_SECTIONS,
isTailwindPostcss7CompatAlias,
);
const zodVersion = pickConcreteVersion(packageJson, "zod", [
"dependencies",
"devDependencies",
"peerDependencies",
]);
const zodVersion = pickConcreteVersion(packageJson, "zod", TAILWIND_ZOD_SECTIONS);
return {
reactVersion,
tailwindVersion,
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/project-info/discover-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
SHOPIFY_FLASH_LIST_PACKAGE_NAME,
} from "./collect-project-facts.js";
import { resolveInstalledReactVersion } from "./resolve-installed-react-version.js";
import { readPackageJson } from "./package-json.js";
import { clearPackageJsonCache, readPackageJson } from "./package-json.js";
import { getTanStackQueryVersion } from "./get-tanstack-query-version.js";
import {
getDependencyMajorWithinSupportedRange,
Expand All @@ -51,6 +51,7 @@ export interface DiscoverProjectOptions {
// tsconfig.json / monorepo manifests change between diagnose() calls.
export const clearProjectCache = (): void => {
cachedProjectInfos.clear();
clearPackageJsonCache();
clearTargetBlankOpenerProtectionCache();
};

Expand Down
8 changes: 3 additions & 5 deletions packages/core/src/project-info/discover-react-subprojects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import { isDirectory, isFile, readDirectoryEntries } from "./fs-utils.js";
import { hasReactDependency } from "./dependencies.js";
import { readPackageJson } from "./package-json.js";
import {
getNxWorkspaceDirectories,
getWorkspacePatterns,
listWorkspacePackages,
parsePnpmWorkspacePatterns,
resolveWorkspaceDirectories,
} from "./workspaces.js";

Expand All @@ -32,9 +31,8 @@ const listManifestWorkspacePackages = (rootDirectory: string): WorkspacePackage[
const packageJsonPath = path.join(rootDirectory, "package.json");
if (isFile(packageJsonPath)) return listWorkspacePackages(rootDirectory);

const patterns = parsePnpmWorkspacePatterns(rootDirectory);
const nxPatterns = patterns.length > 0 ? [] : getNxWorkspaceDirectories(rootDirectory);
const directories = (patterns.length > 0 ? patterns : nxPatterns).flatMap((pattern) =>
const patterns = getWorkspacePatterns(rootDirectory, {});
const directories = patterns.flatMap((pattern) =>
resolveWorkspaceDirectories(rootDirectory, pattern),
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import type { PackageJson } from "../types/index.js";
import { getDependencyDeclaration } from "./dependencies.js";

const PREFERRED_DEPENDENCY_SECTIONS: ReadonlyArray<
"dependencies" | "peerDependencies" | "devDependencies"
> = ["dependencies", "peerDependencies", "devDependencies"];
import { getDependencyDeclaration, REACT_SECTIONS } from "./dependencies.js";

interface GetPreferredDependencyVersionOptions {
packageJson: PackageJson;
Expand All @@ -18,7 +14,7 @@ export const getPreferredDependencyVersion = ({
const declaration = getDependencyDeclaration({
packageJson,
packageName,
sections: PREFERRED_DEPENDENCY_SECTIONS,
sections: REACT_SECTIONS,
});
if (declaration.version !== null) return declaration.version;
}
Expand Down
8 changes: 3 additions & 5 deletions packages/core/src/project-info/monorepo-root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// cycle — dependencies.ts imports findMonorepoRoot while workspaces.ts imports
// dependencies.ts.
import * as path from "node:path";
import { ancestorDirectories } from "../utils/ancestor-directories.js";
import { isFile } from "./fs-utils.js";
import { readPackageJson } from "./package-json.js";

Expand All @@ -15,11 +16,8 @@ export const isMonorepoRoot = (directory: string): boolean => {
};

export const findMonorepoRoot = (startDirectory: string): string | null => {
let currentDirectory = path.dirname(startDirectory);

while (currentDirectory !== path.dirname(currentDirectory)) {
if (isMonorepoRoot(currentDirectory)) return currentDirectory;
currentDirectory = path.dirname(currentDirectory);
for (const ancestorDirectory of ancestorDirectories(startDirectory, { includeStart: false })) {
if (isMonorepoRoot(ancestorDirectory)) return ancestorDirectory;
}

return null;
Expand Down
31 changes: 11 additions & 20 deletions packages/core/src/services/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ export class Files extends Context.Service<
static readonly layerInMemory = (tree: ReadonlyMap<string, string>): Layer.Layer<Files> => {
const resolveAbsolute = (filePath: string, rootDirectory: string): string =>
path.isAbsolute(filePath) ? filePath : `${rootDirectory}/${filePath}`;
const listRelativePaths = (rootDirectory: string): string[] => {
const prefix = rootDirectory.endsWith("/") ? rootDirectory : `${rootDirectory}/`;
const files: string[] = [];
for (const absolute of tree.keys()) {
if (!absolute.startsWith(prefix)) continue;
files.push(absolute.slice(prefix.length));
}
return files;
};

return Layer.succeed(
Files,
Expand All @@ -63,27 +72,9 @@ export class Files extends Context.Service<
const content = tree.get(absolute);
return content === undefined ? null : content.split("\n");
}),
listSourceFiles: (rootDirectory) =>
Effect.sync(() => {
const prefix = rootDirectory.endsWith("/") ? rootDirectory : `${rootDirectory}/`;
const files: string[] = [];
for (const absolute of tree.keys()) {
if (!absolute.startsWith(prefix)) continue;
files.push(absolute.slice(prefix.length));
}
return files;
}),
listSourceFiles: (rootDirectory) => Effect.sync(() => listRelativePaths(rootDirectory)),
listSourceFilesCooperative: (input) =>
Effect.sync(() => {
const rootDirectory = input.rootDirectory;
const prefix = rootDirectory.endsWith("/") ? rootDirectory : `${rootDirectory}/`;
const files: string[] = [];
for (const absolute of tree.keys()) {
if (!absolute.startsWith(prefix)) continue;
files.push(absolute.slice(prefix.length));
}
return files;
}),
Effect.sync(() => listRelativePaths(input.rootDirectory)),
isFile: (filePath) => Effect.sync(() => tree.has(filePath)),
isDirectory: (filePath) =>
Effect.sync(() => {
Expand Down
3 changes: 2 additions & 1 deletion packages/core/tests/services/files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ describe("Files.layerInMemory", () => {
}),
);
expect(lines).not.toBeNull();
expect((lines as string[]).length).toBeGreaterThan(0);
if (lines === null) throw new Error("Expected relative path read to return lines");
expect(lines.length).toBeGreaterThan(0);
});

it("readLines returns null when the path is absent", async () => {
Expand Down
6 changes: 1 addition & 5 deletions packages/eslint-plugin-react-doctor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ const wrapAsEslintRule = (ruleName: string, ruleImpl: EslintAdapterRule): Eslint
meta: {
type: ruleImpl.severity === "warn" ? "suggestion" : "problem",
docs: {
description:
ruleImpl.title ??
ruleName
.replaceAll("-", " ")
.replace(/\b\w/g, (innerCharacter) => innerCharacter.toUpperCase()),
description: ruleImpl.title ?? ruleName,
url: `${RULE_DOCS_BASE_URL}/${PLUGIN_NAMESPACE}/${ruleName}`,
recommended: recommendedRuleKeys.has(`${PLUGIN_NAMESPACE}/${ruleName}`),
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, expect, it } from "vite-plus/test";
import oxlintPlugin, {
ALL_REACT_DOCTOR_RULES,
NEXTJS_RULES,
PREACT_RULES,
REACT_NATIVE_RULES,
Expand All @@ -12,7 +13,7 @@ import eslintPlugin from "../src/index.js";
describe("eslint-plugin-react-doctor", () => {
it("exports the expected plugin shape", () => {
expect(eslintPlugin.meta.name).toBe("react-doctor");
expect(Object.keys(eslintPlugin.rules).length).toBeGreaterThan(0);
expect(Object.keys(eslintPlugin.rules).sort()).toEqual(Object.keys(oxlintPlugin.rules).sort());
expect(Object.keys(eslintPlugin.configs).sort()).toEqual([
"all",
"next",
Expand All @@ -37,6 +38,7 @@ describe("eslint-plugin-react-doctor", () => {
expect(eslintPlugin.configs["tanstack-start"].rules).toEqual(TANSTACK_START_RULES);
expect(eslintPlugin.configs["tanstack-query"].rules).toEqual(TANSTACK_QUERY_RULES);
expect(eslintPlugin.configs.preact.rules).toEqual(PREACT_RULES);
expect(eslintPlugin.configs.all.rules).toEqual(ALL_REACT_DOCTOR_RULES);
});

it("only references wrapped rule ids from presets", () => {
Expand All @@ -54,9 +56,7 @@ describe("eslint-plugin-react-doctor", () => {
const eslintRule = eslintPlugin.rules[ruleName];
expect(oxlintRule).toBeDefined();
expect(eslintRule).toBeDefined();
if (!oxlintRule || !eslintRule) return;

expect(eslintRule.meta.docs.description).toBe("Array index used as a key");
expect(eslintRule.meta.docs.description).toBe(oxlintRule.title);
expect(eslintRule.meta.docs.url).toBe(
"https://react.doctor/docs/rules/react-doctor/no-array-index-as-key",
Expand Down
6 changes: 3 additions & 3 deletions packages/react-doctor/src/cli/ink/components/report.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const Report = ({
() => new Set(),
);
const [isCiSetupQueued, setIsCiSetupQueued] = useState(false);
const [shouldShowIssueStream, setShouldShowIssueStream] = useState(true);
const didDismissIssueStream = useRef(false);
const didRecordCompactReport = useRef(false);
const didRecordIssueStream = useRef(false);
const didRecordStackedReportCap = useRef(false);
Expand Down Expand Up @@ -161,7 +161,7 @@ export const Report = ({
markViewerRuleRead(index);
};
const openReportScreen = (nextScreen: ReportScreen): void => {
setShouldShowIssueStream(false);
didDismissIssueStream.current = true;
setCiSetupFeedback(undefined);
setActiveReportScreen(nextScreen);
};
Expand Down Expand Up @@ -317,7 +317,7 @@ export const Report = ({

return (
<>
{activeReportScreen === "landing" && shouldShowIssueStream ? issueStream : null}
{activeReportScreen === "landing" && !didDismissIssueStream.current ? issueStream : null}
{activeScreenContent}
</>
);
Expand Down
3 changes: 3 additions & 0 deletions scripts/fn-mining/run-fn-mining.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ for (const [ruleId, ruleResults] of resultsByRule) {
const isCarveOut = !result.miningCase.shouldFire;
const marker = result.didFire ? " [fired] " : isCarveOut ? " [carved] " : " [SILENT] ";
console.log(`${marker}${result.miningCase.description}`);
if (isCarveOut && result.miningCase.carveOutReason) {
console.log(` carve-out: ${result.miningCase.carveOutReason}`);
}
for (const parseError of result.parseErrors) {
console.log(` parse error: ${parseError}`);
}
Expand Down
Loading