@@ -13,9 +13,13 @@ import { validateConfig } from './validateConfig.js'
13
13
* @param {Object } [options.configObject] - Explicit config object from the js API
14
14
* @param {string } [options.configPath] - Explicit path to a config file
15
15
* @param {string } [options.cwd] - Current working directory
16
+ * @param {string } [options.files] - List of staged files
16
17
* @param {Logger } logger
17
18
*/
18
- export const getConfigGroups = async ( { configObject, configPath, files } , logger = console ) => {
19
+ export const getConfigGroups = async (
20
+ { configObject, configPath, cwd, files } ,
21
+ logger = console
22
+ ) => {
19
23
// Return explicit config object from js API
20
24
if ( configObject ) {
21
25
const config = validateConfig ( configObject , 'config object' , logger )
@@ -52,23 +56,24 @@ export const getConfigGroups = async ({ configObject, configPath, files }, logge
52
56
// { '.lintstagedrc.json': { config: {...}, files: [...] } }
53
57
const configGroups = { }
54
58
55
- await Promise . all (
56
- Object . entries ( filesByDir ) . map ( ( [ dir , files ] ) => {
57
- // Discover config from the base directory of the file
58
- return loadConfig ( { cwd : dir } , logger ) . then ( ( { config, filepath } ) => {
59
- if ( ! config ) return
60
-
61
- if ( filepath in configGroups ) {
62
- // Re-use cached config and skip validation
63
- configGroups [ filepath ] . files . push ( ...files )
64
- return
65
- }
66
-
67
- const validatedConfig = validateConfig ( config , filepath , logger )
68
- configGroups [ filepath ] = { config : validatedConfig , files }
69
- } )
70
- } )
71
- )
59
+ const searchConfig = async ( cwd , files = [ ] ) => {
60
+ const { config, filepath } = await loadConfig ( { cwd } , logger )
61
+ if ( ! config ) return
62
+
63
+ if ( filepath in configGroups ) {
64
+ // Re-use cached config and skip validation
65
+ configGroups [ filepath ] . files . push ( ...files )
66
+ } else {
67
+ const validatedConfig = validateConfig ( config , filepath , logger )
68
+ configGroups [ filepath ] = { config : validatedConfig , files }
69
+ }
70
+ }
71
+
72
+ // Start by searching from cwd
73
+ await searchConfig ( cwd )
74
+
75
+ // Discover configs from the base directory of each file
76
+ await Promise . all ( Object . entries ( filesByDir ) . map ( ( [ dir , files ] ) => searchConfig ( dir , files ) ) )
72
77
73
78
// Throw if no configurations were found
74
79
if ( Object . keys ( configGroups ) . length === 0 ) {
0 commit comments