-
Notifications
You must be signed in to change notification settings - Fork 205
/
lint-staged.js
37 lines (32 loc) · 1.05 KB
/
lint-staged.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
35
36
37
const path = require('path')
const resolve = require('resolve')
const {hasPkgProp, hasFile} = require('../../utils')
const useBuiltinConfig =
!hasFile('.lintstagedrc') &&
!hasFile('lint-staged.config.js') &&
!hasPkgProp('lint-staged')
const lintStagedPath = require.resolve('lint-staged')
const cosmiconfigPath = resolve.sync('cosmiconfig', {
basedir: path.dirname(lintStagedPath),
})
const realCosmicConfig = require(cosmiconfigPath)
// lint-staged uses cosmiconfig to find its configuration
// and it has no other way to provide config
// (via a node API or command-line flag)
// So, we're doing this require cache magic to provide our own
// config so folks don't have to have that in their package.json
function fakeCosmiconfig(...args) {
if (args[0] === 'lint-staged') {
return {
load() {
return Promise.resolve({config: require('../../config/lintstagedrc')})
},
}
} else {
return realCosmicConfig(...args)
}
}
if (useBuiltinConfig) {
require.cache[cosmiconfigPath] = {exports: fakeCosmiconfig}
}
require(lintStagedPath)