Skip to content

Commit

Permalink
fix(linter): Normalize paths when in getSourceFilePath (#18601)
Browse files Browse the repository at this point in the history
Co-authored-by: jgelin <jgelin@seligent.com>
  • Loading branch information
jogelin and jgelin committed Aug 17, 2023
1 parent 2034cdd commit 1f9b3c4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
17 changes: 17 additions & 0 deletions packages/eslint-plugin/src/utils/runtime-lint-utils.spec.ts
Expand Up @@ -9,6 +9,7 @@ import {
DepConstraint,
findConstraintsFor,
findTransitiveExternalDependencies,
getSourceFilePath,
hasBannedDependencies,
hasBannedImport,
hasNoneOfTheseTags,
Expand Down Expand Up @@ -558,3 +559,19 @@ describe('hasNoneOfTheseTags', () => {
}
);
});

describe('getSourceFilePath', () => {
it.each([
['/root/libs/dev-kit/package.json', '/root'],
['/root/libs/dev-kit/package.json', 'C:\\root'],
['C:\\root\\libs\\dev-kit\\package.json', '/root'],
['C:\\root\\libs\\dev-kit\\package.json', 'C:\\root'],
])(
'should return "libs/dev-kit/package.json" when sourceFileName is "%s" and projectPath is "%s"',
(sourceFileName, projectPath) => {
expect(getSourceFilePath(sourceFileName, projectPath)).toBe(
'libs/dev-kit/package.json'
);
}
);
});
5 changes: 3 additions & 2 deletions packages/eslint-plugin/src/utils/runtime-lint-utils.ts
Expand Up @@ -222,8 +222,9 @@ export function onlyLoadChildren(
}

export function getSourceFilePath(sourceFileName: string, projectPath: string) {
const relativePath = sourceFileName.slice(projectPath.length + 1);
return normalizePath(relativePath);
const normalizedProjectPath = normalizePath(projectPath);
const normalizedSourceFileName = normalizePath(sourceFileName);
return normalizedSourceFileName.slice(normalizedProjectPath.length + 1);
}

/**
Expand Down

1 comment on commit 1f9b3c4

@vercel
Copy link

@vercel vercel bot commented on 1f9b3c4 Aug 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-nrwl.vercel.app
nx.dev
nx-dev-git-master-nrwl.vercel.app
nx-five.vercel.app

Please sign in to comment.