Skip to content

Commit 035b406

Browse files
authored
fix(linter): fix plugin race condition (#27810)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> There is a race condition in the `@nx/eslint/plugin` causing projects to be missing lint. ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> The `@nx/eslint/plugin` creates a map of lintable files up front before analyzing any particular project and there is no race condition. ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
1 parent ac9da41 commit 035b406

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

packages/eslint/src/plugins/plugin.ts

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,11 @@ const internalCreateNodes = async (
169169
};
170170
};
171171

172-
let collectingLintableFilesPromise: Promise<void>;
173172
const internalCreateNodesV2 = async (
174173
configFilePath: string,
175174
options: EslintPluginOptions,
176175
context: CreateNodesContextV2,
177176
eslintConfigFiles: string[],
178-
allProjectRoots: string[],
179177
projectRootsByEslintRoots: Map<string, string[]>,
180178
lintableFilesPerProjectRoot: Map<string, string[]>,
181179
projectsCache: Record<string, CreateNodesResult['projects']>
@@ -208,17 +206,6 @@ const internalCreateNodesV2 = async (
208206
return;
209207
}
210208

211-
if (!lintableFilesPerProjectRoot.size) {
212-
collectingLintableFilesPromise ??= collectLintableFilesByProjectRoot(
213-
lintableFilesPerProjectRoot,
214-
allProjectRoots,
215-
options,
216-
context
217-
);
218-
await collectingLintableFilesPromise;
219-
collectingLintableFilesPromise = null;
220-
}
221-
222209
const eslint = new ESLint({
223210
cwd: join(context.workspaceRoot, projectRoot),
224211
});
@@ -273,8 +260,11 @@ export const createNodesV2: CreateNodesV2<EslintPluginOptions> = [
273260

274261
const { eslintConfigFiles, projectRoots, projectRootsByEslintRoots } =
275262
splitConfigFiles(configFiles);
276-
const lintableFilesPerProjectRoot = new Map<string, string[]>();
277-
263+
const lintableFilesPerProjectRoot = await collectLintableFilesByProjectRoot(
264+
projectRoots,
265+
options,
266+
context
267+
);
278268
try {
279269
return await createNodesFromFiles(
280270
(configFile, options, context) =>
@@ -283,7 +273,6 @@ export const createNodesV2: CreateNodesV2<EslintPluginOptions> = [
283273
options,
284274
context,
285275
eslintConfigFiles,
286-
projectRoots,
287276
projectRootsByEslintRoots,
288277
lintableFilesPerProjectRoot,
289278
targetsCache
@@ -360,11 +349,12 @@ function groupProjectRootsByEslintRoots(
360349
}
361350

362351
async function collectLintableFilesByProjectRoot(
363-
lintableFilesPerProjectRoot: Map<string, string[]>,
364352
projectRoots: string[],
365353
options: EslintPluginOptions,
366354
context: CreateNodesContext | CreateNodesContextV2
367-
): Promise<void> {
355+
): Promise<Map<string, string[]>> {
356+
const lintableFilesPerProjectRoot = new Map<string, string[]>();
357+
368358
const lintableFiles = await globWithWorkspaceContext(context.workspaceRoot, [
369359
`**/*.{${options.extensions.join(',')}}`,
370360
]);
@@ -382,6 +372,8 @@ async function collectLintableFilesByProjectRoot(
382372
lintableFilesPerProjectRoot.get(projectRoot).push(file);
383373
}
384374
}
375+
376+
return lintableFilesPerProjectRoot;
385377
}
386378

387379
function getRootForDirectory(

0 commit comments

Comments
 (0)