fix(linter): Normalize paths when in getSourceFilePath (#18601)

Co-authored-by: jgelin <jgelin@seligent.com>
This commit is contained in:
jogelin 2023-08-17 11:28:52 +02:00 committed by GitHub
parent 2034cddf04
commit 1f9b3c4a5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View File

@ -9,6 +9,7 @@ import {
DepConstraint,
findConstraintsFor,
findTransitiveExternalDependencies,
getSourceFilePath,
hasBannedDependencies,
hasBannedImport,
hasNoneOfTheseTags,
@ -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'
);
}
);
});

View File

@ -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);
}
/**