Skip to content

Commit dff8141

Browse files
committed
test: add debug logging to getConfigGroups
1 parent 4afcda5 commit dff8141

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

lib/getConfigGroups.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22

33
import path from 'path'
44

5+
import debug from 'debug'
6+
import objectInspect from 'object-inspect'
7+
58
import { loadConfig } from './loadConfig.js'
69
import { ConfigNotFoundError } from './symbols.js'
710
import { validateConfig } from './validateConfig.js'
811

12+
const debugLog = debug('lint-staged:getConfigGroups')
13+
914
/**
1015
* Return matched files grouped by their configuration.
1116
*
@@ -20,14 +25,20 @@ export const getConfigGroups = async (
2025
{ configObject, configPath, cwd, files },
2126
logger = console
2227
) => {
28+
debugLog('Grouping configuration files...')
29+
2330
// Return explicit config object from js API
2431
if (configObject) {
32+
debugLog('Using single direct configuration object...')
33+
2534
const config = validateConfig(configObject, 'config object', logger)
2635
return { '': { config, files } }
2736
}
2837

2938
// Use only explicit config path instead of discovering multiple
3039
if (configPath) {
40+
debugLog('Using single configuration path...')
41+
3142
const { config, filepath } = await loadConfig({ configPath }, logger)
3243

3344
if (!config) {
@@ -39,6 +50,8 @@ export const getConfigGroups = async (
3950
return { [configPath]: { config: validatedConfig, files } }
4051
}
4152

53+
debugLog('Grouping staged files by their directories...')
54+
4255
// Group files by their base directory
4356
const filesByDir = files.reduce((acc, file) => {
4457
const dir = path.normalize(path.dirname(file))
@@ -52,18 +65,29 @@ export const getConfigGroups = async (
5265
return acc
5366
}, {})
5467

68+
debugLog('Grouped staged files into %d directories:', Object.keys(filesByDir).length)
69+
debugLog(objectInspect(filesByDir, { indent: 2 }))
70+
5571
// Group files by their discovered config
5672
// { '.lintstagedrc.json': { config: {...}, files: [...] } }
5773
const configGroups = {}
5874

75+
debugLog('Searching config files...')
76+
5977
const searchConfig = async (cwd, files = []) => {
6078
const { config, filepath } = await loadConfig({ cwd }, logger)
61-
if (!config) return
79+
if (!config) {
80+
debugLog('Found no config from "%s"!', cwd)
81+
return
82+
}
6283

6384
if (filepath in configGroups) {
85+
debugLog('Found existing config "%s" from "%s"!', filepath, cwd)
6486
// Re-use cached config and skip validation
6587
configGroups[filepath].files.push(...files)
6688
} else {
89+
debugLog('Found new config "%s" from "%s"!', filepath, cwd)
90+
6791
const validatedConfig = validateConfig(config, filepath, logger)
6892
configGroups[filepath] = { config: validatedConfig, files }
6993
}
@@ -77,9 +101,12 @@ export const getConfigGroups = async (
77101

78102
// Throw if no configurations were found
79103
if (Object.keys(configGroups).length === 0) {
104+
debugLog('Found no config groups!')
80105
logger.error(`${ConfigNotFoundError.message}.`)
81106
throw ConfigNotFoundError
82107
}
83108

109+
debugLog('Grouped staged files into %d groups!', Object.keys(configGroups).length)
110+
84111
return configGroups
85112
}

0 commit comments

Comments
 (0)