Skip to content

Commit

Permalink
feat: Add advanced option globOptions to customise minimatch (#179)
Browse files Browse the repository at this point in the history
Closes #173
  • Loading branch information
georeith authored and okonet committed Jun 1, 2017
1 parent 4c60017 commit c5b9804
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -91,6 +91,7 @@ To set options and keep lint-staged extensible, advanced format can be used. Thi
* `chunkSize` — Max allowed chunk size based on number of files for glob pattern. This is important on windows based systems to avoid command length limitations. See #147
* `subTaskConcurrency``2` — Controls concurrency for processing chunks generated for each linter.
* `verbose`*false* — runs lint-staged in verbose mode. When `true` it will use https://github.com/SamVerschueren/listr-verbose-renderer.
* `globOptions``{ matchBase: true, dot: true }`[minimatch options](https://github.com/isaacs/minimatch#options) to customize how glob patterns match files.

## Filtering files

Expand Down
7 changes: 5 additions & 2 deletions src/generateTasks.js
Expand Up @@ -2,16 +2,19 @@

const minimatch = require('minimatch')

const readConfigOption = require('./readConfigOption')

module.exports = function generateTasks(config, files) {
const linters = config.linters !== undefined ? config.linters : config
const resolve = file => files[file]
return Object.keys(linters)
.map((pattern) => {
const commands = linters[pattern]
const filter = minimatch.filter(pattern, {
const globOptions = readConfigOption(config, 'globOptions', {})
const filter = minimatch.filter(pattern, Object.assign({
matchBase: true,
dot: true
})
}, globOptions))
const fileList = Object.keys(files).filter(filter).map(resolve)
return {
pattern,
Expand Down
21 changes: 21 additions & 0 deletions test/generateTasks.spec.js
Expand Up @@ -146,4 +146,25 @@ describe('generateTasks', () => {
]
})
})

it('should support globOptions specified in advanced configuration', () => {
const result = generateTasks(
{
globOptions: {
matchBase: false,
nocase: true
},
linters: {
'TeSt.*': 'lint'
}
},
files
)
const linter = result.find(item => item.pattern === 'TeSt.*')
expect(linter).toEqual({
pattern: 'TeSt.*',
commands: 'lint',
fileList: ['/root/test.js', '/root/test.css', '/root/test.txt']
})
})
})

0 comments on commit c5b9804

Please sign in to comment.