Skip to content

Commit

Permalink
refactor: Use micromatch ignore option instead of patterns with neg…
Browse files Browse the repository at this point in the history
…ations
  • Loading branch information
Andrey Okonetchnikov committed Feb 7, 2019
1 parent 6e32188 commit f9e5d7b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/generateTasks.js
Expand Up @@ -12,16 +12,14 @@ module.exports = function generateTasks(config, stagedRelFiles) {
debug('Generating linter tasks')

const normalizedConfig = getConfig(config) // Ensure we have a normalized config
const { linters, globOptions } = normalizedConfig
const ignorePatterns = normalizedConfig.ignore.map(pattern => `!${pattern}`)
const { linters, globOptions, ignore } = normalizedConfig

const gitDir = resolveGitDir()
const cwd = process.cwd()
const stagedFiles = stagedRelFiles.map(file => path.resolve(gitDir, file))

return Object.keys(linters).map(pattern => {
const isParentDirPattern = pattern.startsWith('../')
const patterns = [pattern].concat(ignorePatterns)
const commands = linters[pattern]

const fileList = micromatch(
Expand All @@ -31,8 +29,11 @@ module.exports = function generateTasks(config, stagedRelFiles) {
.filter(file => isParentDirPattern || pathIsInside(file, cwd))
// Make the paths relative to CWD for filtering
.map(file => path.relative(cwd, file)),
patterns,
globOptions
pattern,
{
...globOptions,
ignore
}
).map(file => {
// if you set relative option, then the file path will be relative to your package.json
if (config.relative) {
Expand Down

0 comments on commit f9e5d7b

Please sign in to comment.