Skip to content

Commit

Permalink
Fix multiple given files w/o ignore
Browse files Browse the repository at this point in the history
Closes GH-57.
  • Loading branch information
wooorm committed Dec 20, 2021
1 parent e0bae0b commit 2387aa9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
8 changes: 5 additions & 3 deletions lib/finder.js
Expand Up @@ -289,19 +289,21 @@ function statAndIgnore(file, options, callback) {
expected++
fs.stat(fp, (error, value) => {
stats = value
onStartOrCheck(error)
onStatOrCheck(error)
})
}

options.ignore.check(fp, (error, value) => {
ignored = value
onStartOrCheck(error)

// `ignore.check` is sometimes sync, we need to force async behavior.
setImmediate(onStatOrCheck, error)
})

/**
* @param {Error|null} error
*/
function onStartOrCheck(error) {
function onStatOrCheck(error) {
actual++

if (error) {
Expand Down
44 changes: 43 additions & 1 deletion test/input.js
Expand Up @@ -13,7 +13,7 @@ const cross = process.platform === 'win32' ? '×' : '✖'
const fixtures = path.join('test', 'fixtures')

test('input', (t) => {
t.plan(20)
t.plan(21)

t.test('should fail without input', (t) => {
const stream = new PassThrough()
Expand Down Expand Up @@ -430,6 +430,48 @@ test('input', (t) => {
)
})

t.test('should not attempt to read files with `value` (3)', (t) => {
const stderr = spy()
const cwd = path.join(fixtures, 'empty')
const file1 = toVFile({
path: path.join(cwd, 'not-existing-1.txt'),
value: 'foo'
})
const file2 = toVFile({
path: path.join(cwd, 'not-existing-2.txt'),
value: 'bar'
})

t.plan(1)

engine(
{
processor: noop().use(
/** @type {import('unified').Plugin<[], import('unist').Node>} */
function () {
return (_, file) => {
file.message('!')
}
}
),
cwd,
streamError: stderr.stream,
files: [file1, file2]
},
(error, code) => {
t.deepEqual(
[error, code, stderr()],
[
null,
0,
'not-existing-1.txt\n 1:1 warning !\n\nnot-existing-2.txt\n 1:1 warning !\n\n⚠ 2 warnings\n'
],
'should report'
)
}
)
})

t.test('should not attempt to read files with `value` (3)', (t) => {
const stderr = spy()
const cwd = path.join(fixtures, 'empty')
Expand Down

0 comments on commit 2387aa9

Please sign in to comment.