Skip to content

Commit

Permalink
fix: trim ignore rules before matching (#28)
Browse files Browse the repository at this point in the history
Looks like the latest minimatch doesn't do this anymore.
  • Loading branch information
wraithgar authored Apr 6, 2022
1 parent 78ee822 commit e6a9acc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ class Walker extends EE {
}
const rules = data.split(/\r?\n/)
.filter(line => !/^#|^$/.test(line.trim()))
.map(r => new Minimatch(r, mmopt))
.map(rule => {
return new Minimatch(rule.trim(), mmopt)
})

this.ignoreRules[file] = rules

Expand Down
34 changes: 34 additions & 0 deletions test/ignore-spaces.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict'
const walk = require('..')
const { resolve } = require('path')
const path = resolve(__dirname, 'fixtures')

// set the ignores just for this test
const c = require('./common.js')
c.ignores({
'd/.ignore-spaces': [' h'],
})

// the files that we expect to not see
const notAllowed = [
/^d\/h\/.*/,
]

const t = require('tap')

t.test('async', t => walk({
path,
ignoreFiles: ['.ignore-spaces'],
}, (er, result) => {
result.forEach(r => notAllowed.forEach(na =>
t.notMatch(r, na, r + ' !~ ' + na)))
}))

t.test('sync', t => {
walk.sync({
path,
ignoreFiles: ['.ignore-spaces'],
}).forEach(r => notAllowed.forEach(na =>
t.notMatch(r, na, r + ' !~ ' + na)))
t.end()
})

0 comments on commit e6a9acc

Please sign in to comment.