Skip to content

Commit

Permalink
refactor: replace "for...of" with "await Promise.all()"
Browse files Browse the repository at this point in the history
  • Loading branch information
iiroj committed Jan 18, 2022
1 parent 3731f10 commit 2604ac7
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions lib/getConfigGroups.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,26 @@ export const getConfigGroups = async ({ configObject, configPath, files }, logge
// { '.lintstagedrc.json': { config: {...}, files: [...] } }
const configGroups = {}

for (const [dir, files] of Object.entries(filesByDir)) {
// Discover config from the base directory of the file
const { config, filepath } = await loadConfig({ cwd: dir }, logger)
await Promise.all(
Object.entries(filesByDir).map(([dir, files]) => {
// Discover config from the base directory of the file
return loadConfig({ cwd: dir }, logger).then(({ config, filepath }) => {
if (!config) {
logger.error(`${ConfigNotFoundError.message}.`)
throw ConfigNotFoundError
}

if (!config) {
logger.error(`${ConfigNotFoundError.message}.`)
throw ConfigNotFoundError
}
if (filepath in configGroups) {
// Re-use cached config and skip validation
configGroups[filepath].files.push(...files)
return
}

if (filepath in configGroups) {
// Re-use cached config and skip validation
configGroups[filepath].files.push(...files)
continue
}

const validatedConfig = validateConfig(config, filepath, logger)
configGroups[filepath] = { config: validatedConfig, files }
}
const validatedConfig = validateConfig(config, filepath, logger)
configGroups[filepath] = { config: validatedConfig, files }
})
})
)

return configGroups
}

0 comments on commit 2604ac7

Please sign in to comment.