forked from anvilco/spectaql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lint-staged.config.js
34 lines (28 loc) · 1.13 KB
/
lint-staged.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// https://github.com/okonet/lint-staged#readme
// This file exports a function that is passed all the staged files, and returns
// the command(s) to be executed by lint-staged.
// This is a dependency of `lint-staged`
const micromatch = require('micromatch')
const { scripts } = require('./package.json')
module.exports = (allStagedFiles) => {
// The globs are centrally stored in the package.json, so we grab them from there
// and do some processing
const globs = scripts.lint
.split('eslint ')[1]
.split(' ')
.map((glob) => {
glob = glob.replace(/"/g, '').replace(/'/g, '')
if (glob.startsWith('**')) {
return glob
}
// lint-staged will pass absolute paths, but our globs may not be prepared to
// work with that. If this becomes an issue, there is a way to work with relative
// paths: https://github.com/okonet/lint-staged#example-use-relative-paths-for-commands
return `**/${glob}`
})
const codeFiles = micromatch(allStagedFiles, globs).join(' ')
if (!codeFiles.length) {
return []
}
return [`prettier --write ${codeFiles}`, `eslint --quiet --fix ${codeFiles}`]
}