Skip to content

Commit

Permalink
Use minimatch windows capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
mrginglymus committed Dec 19, 2024
1 parent 76c2ed0 commit 7e691d7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/rules/no-extraneous-dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ function testConfig(config: string[] | boolean | undefined, filename: string) {
return config.some(
c =>
minimatch(filename, c) ||
minimatch(filename, path.resolve(c).replaceAll(path.sep, '/')),
minimatch(filename, path.resolve(c), { windowsPathsNoEscape: true }),
)
}

Expand Down
6 changes: 3 additions & 3 deletions src/rules/no-restricted-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const containsPath = (filepath: string, target: string) => {

function isMatchingTargetPath(filename: string, targetPath: string) {
if (isGlob(targetPath)) {
const mm = new Minimatch(targetPath.replaceAll(path.sep, '/'))
const mm = new Minimatch(targetPath, { windowsPathsNoEscape: true })
return mm.match(filename)
}

Expand Down Expand Up @@ -171,14 +171,14 @@ export = createRule<[Options?], MessageId>({
) {
let isPathException: ((absoluteImportPath: string) => boolean) | undefined

const mm = new Minimatch(absoluteFrom.replaceAll(path.sep, '/'))
const mm = new Minimatch(absoluteFrom, { windowsPathsNoEscape: true })
const isPathRestricted = (absoluteImportPath: string) =>
mm.match(absoluteImportPath)
const hasValidExceptions = zoneExcept.every(it => isGlob(it))

if (hasValidExceptions) {
const exceptionsMm = zoneExcept.map(
except => new Minimatch(except.replaceAll(path.sep, '/')),
except => new Minimatch(except, { windowsPathsNoEscape: true }),
)
isPathException = (absoluteImportPath: string) =>
exceptionsMm.some(mm => mm.match(absoluteImportPath))
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-unassigned-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function testIsAllow(
return globs.some(
glob =>
minimatch(filePath, glob) ||
minimatch(filePath, path.resolve(glob).replaceAll(path.sep, '/')),
minimatch(filePath, path.resolve(glob), { windowsPathsNoEscape: true }),
)
}

Expand Down

0 comments on commit 7e691d7

Please sign in to comment.