Skip to content

Commit 36b9546

Browse files
committed
fix: only throw if no configurations were found
Previously lint-staged would throw if any staged file was missing a config, but it should be enough that at least one file has a matching config.
1 parent 2604ac7 commit 36b9546

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

lib/getConfigGroups.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,7 @@ export const getConfigGroups = async ({ configObject, configPath, files }, logge
5656
Object.entries(filesByDir).map(([dir, files]) => {
5757
// Discover config from the base directory of the file
5858
return loadConfig({ cwd: dir }, logger).then(({ config, filepath }) => {
59-
if (!config) {
60-
logger.error(`${ConfigNotFoundError.message}.`)
61-
throw ConfigNotFoundError
62-
}
59+
if (!config) return
6360

6461
if (filepath in configGroups) {
6562
// Re-use cached config and skip validation
@@ -73,5 +70,11 @@ export const getConfigGroups = async ({ configObject, configPath, files }, logge
7370
})
7471
)
7572

73+
// Throw if no configurations were found
74+
if (Object.keys(configGroups).length === 0) {
75+
logger.error(`${ConfigNotFoundError.message}.`)
76+
throw ConfigNotFoundError
77+
}
78+
7679
return configGroups
7780
}

test/getConfigGroups.spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,19 @@ describe('getConfigGroups', () => {
5353
'/deeper/.lintstagedrc.json': { config, files: ['/deeper/foo.js', '/even/deeper/foo.js'] },
5454
})
5555
})
56+
57+
it('should find config for one file, and not care about other', async () => {
58+
// '/foo.js'
59+
loadConfig.mockResolvedValueOnce({})
60+
// '/deeper/foo.js'
61+
loadConfig.mockResolvedValueOnce({ config, filepath: '/deeper/.lintstagedrc.json' })
62+
63+
const configGroups = await getConfigGroups({
64+
files: ['/foo.js', '/deeper/foo.js'],
65+
})
66+
67+
expect(configGroups).toEqual({
68+
'/deeper/.lintstagedrc.json': { config, files: ['/deeper/foo.js'] },
69+
})
70+
})
5671
})

0 commit comments

Comments
 (0)