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 <[email protected]>
(cherry picked from commit 1f9b3c4)
  • Loading branch information
jogelin authored and FrozenPandaz committed Aug 18, 2023
1 parent 3b1a1b3 commit da3ca76
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit da3ca76

Please sign in to comment.