Skip to content

Commit

Permalink
feat: Display a message if there are no files that match a pattern. (#…
Browse files Browse the repository at this point in the history
…139)

* Adding logging for when no files match a pattern.
* Using Listr `skip` to skip tasks with empty file lists.

Closes #135
  • Loading branch information
Noirbot authored and okonet committed Mar 13, 2017
1 parent 3acd6c7 commit b0204ee
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
13 changes: 5 additions & 8 deletions src/generateTasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@ module.exports = function generateTasks(config, files) {
dot: true
})
const fileList = Object.keys(files).filter(filter).map(resolve)
if (fileList.length) {
return {
pattern,
commands,
fileList
}
return {
pattern,
commands,
fileList
}
return undefined
}).filter(Boolean) // Filter undefined values
})
}
8 changes: 7 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ cosmiconfig('lint-staged', {
exitOnError: true
}
)
)
),
skip: () => {
if (task.fileList.length === 0) {
return `No staged files match ${ task.pattern }`
}
return false
}
}))


Expand Down
18 changes: 8 additions & 10 deletions test/generateTasks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,15 @@ describe('generateTasks', () => {
])
})

it('should return only linters it could find files for', () => {
it('should return an empty file list for linters with no matches.', () => {
const result = generateTasks(linters, files)
const commands = result.map(match => match.commands)
expect(commands).toEqual([
'root-js',
'any-js',
'deeper-js',
'hidden-js',
// 'unknown-js' does not match any files
'root-css-or-js'
])
for (const task of result) {
if (task.commands === 'unknown-js') {
expect(task.fileList.length).toEqual(0)
} else {
expect(task.fileList.length).toNotEqual(0)
}
}
})

it('should match pattern "*.js"', () => {
Expand Down

0 comments on commit b0204ee

Please sign in to comment.