Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(linter): fix plugin race condition #27810

Merged
merged 1 commit into from
Sep 6, 2024
Merged
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
28 changes: 10 additions & 18 deletions packages/eslint/src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,11 @@ const internalCreateNodes = async (
};
};

let collectingLintableFilesPromise: Promise<void>;
const internalCreateNodesV2 = async (
configFilePath: string,
options: EslintPluginOptions,
context: CreateNodesContextV2,
eslintConfigFiles: string[],
allProjectRoots: string[],
projectRootsByEslintRoots: Map<string, string[]>,
lintableFilesPerProjectRoot: Map<string, string[]>,
projectsCache: Record<string, CreateNodesResult['projects']>
Expand Down Expand Up @@ -208,17 +206,6 @@ const internalCreateNodesV2 = async (
return;
}

if (!lintableFilesPerProjectRoot.size) {
collectingLintableFilesPromise ??= collectLintableFilesByProjectRoot(
lintableFilesPerProjectRoot,
allProjectRoots,
options,
context
);
await collectingLintableFilesPromise;
collectingLintableFilesPromise = null;
}

const eslint = new ESLint({
cwd: join(context.workspaceRoot, projectRoot),
});
Expand Down Expand Up @@ -273,8 +260,11 @@ export const createNodesV2: CreateNodesV2<EslintPluginOptions> = [

const { eslintConfigFiles, projectRoots, projectRootsByEslintRoots } =
splitConfigFiles(configFiles);
const lintableFilesPerProjectRoot = new Map<string, string[]>();

const lintableFilesPerProjectRoot = await collectLintableFilesByProjectRoot(
projectRoots,
options,
context
);
try {
return await createNodesFromFiles(
(configFile, options, context) =>
Expand All @@ -283,7 +273,6 @@ export const createNodesV2: CreateNodesV2<EslintPluginOptions> = [
options,
context,
eslintConfigFiles,
projectRoots,
projectRootsByEslintRoots,
lintableFilesPerProjectRoot,
targetsCache
Expand Down Expand Up @@ -360,11 +349,12 @@ function groupProjectRootsByEslintRoots(
}

async function collectLintableFilesByProjectRoot(
lintableFilesPerProjectRoot: Map<string, string[]>,
projectRoots: string[],
options: EslintPluginOptions,
context: CreateNodesContext | CreateNodesContextV2
): Promise<void> {
): Promise<Map<string, string[]>> {
const lintableFilesPerProjectRoot = new Map<string, string[]>();

const lintableFiles = await globWithWorkspaceContext(context.workspaceRoot, [
`**/*.{${options.extensions.join(',')}}`,
]);
Expand All @@ -382,6 +372,8 @@ async function collectLintableFilesByProjectRoot(
lintableFilesPerProjectRoot.get(projectRoot).push(file);
}
}

return lintableFilesPerProjectRoot;
}

function getRootForDirectory(
Expand Down