Skip to content

Commit

Permalink
feat: check current config ignores as well
Browse files Browse the repository at this point in the history
  • Loading branch information
yidingww committed Dec 28, 2024
1 parent 470d160 commit d5e0321
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/pages/configs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ onMounted(async () => {
<div>Ignored by globs:</div>
<div flex="~ gap-2 items-center wrap">
<GlobItem
v-for="glob, idx of fileMatchResult.globs"
v-for="glob, idx of fileMatchResult.globs.filter(glob => !glob.startsWith('!'))"
:key="idx"
:glob="glob"
popup="configs"
Expand Down
21 changes: 18 additions & 3 deletions shared/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,32 @@ export function matchFile(
}

configs.forEach((config, index) => {
const isFileGlobalIgnored = configArray.isFileIgnored(filepath)
let isFileIgnoredInCurrConfig = false
if (config.ignores) {
const ignoreConfigArray = buildConfigArray([{
index: config.index,
// only include ignores because of how ConfigArray works internally:
// isFileIgnored only works when only `ignore` exists
// (https://github.com/eslint/rewrite/blob/config-array-v0.19.1/packages/config-array/src/config-array.js#L726)
ignores: config.ignores ?? [],
}], configArray.basePath)
isFileIgnoredInCurrConfig = ignoreConfigArray.isFileIgnored(filepath)
}

const positive = getMatchedGlobs(filepath, config.files || [])
const negative = getMatchedGlobs(filepath, config.ignores || [])
if (configArray && !configArray.isFileIgnored(filepath) && positive.length > 0) {
if (!isFileGlobalIgnored && !isFileIgnoredInCurrConfig && positive.length > 0) {
result.configs.push(index)
// push positive globs only when there are configs matched
result.globs.push(...positive)
}
// push negative globs except for unignore globs
result.globs.push(...negative.filter(glob => !glob.startsWith('!')))

result.globs.push(...negative)
})

result.globs = [...new Set(result.globs)]

return result
}

Expand Down

0 comments on commit d5e0321

Please sign in to comment.