lint-staged
Advanced tools
Comparing version 12.2.1 to 12.2.2
@@ -5,2 +5,5 @@ /** @typedef {import('./index').Logger} Logger */ | ||
import debug from 'debug' | ||
import objectInspect from 'object-inspect' | ||
import { loadConfig } from './loadConfig.js' | ||
@@ -10,2 +13,4 @@ import { ConfigNotFoundError } from './symbols.js' | ||
const debugLog = debug('lint-staged:getConfigGroups') | ||
/** | ||
@@ -18,7 +23,15 @@ * Return matched files grouped by their configuration. | ||
* @param {string} [options.cwd] - Current working directory | ||
* @param {string} [options.files] - List of staged files | ||
* @param {Logger} logger | ||
*/ | ||
export const getConfigGroups = async ({ configObject, configPath, files }, logger = console) => { | ||
export const getConfigGroups = async ( | ||
{ configObject, configPath, cwd, files }, | ||
logger = console | ||
) => { | ||
debugLog('Grouping configuration files...') | ||
// Return explicit config object from js API | ||
if (configObject) { | ||
debugLog('Using single direct configuration object...') | ||
const config = validateConfig(configObject, 'config object', logger) | ||
@@ -30,2 +43,4 @@ return { '': { config, files } } | ||
if (configPath) { | ||
debugLog('Using single configuration path...') | ||
const { config, filepath } = await loadConfig({ configPath }, logger) | ||
@@ -42,2 +57,4 @@ | ||
debugLog('Grouping staged files by their directories...') | ||
// Group files by their base directory | ||
@@ -56,2 +73,5 @@ const filesByDir = files.reduce((acc, file) => { | ||
debugLog('Grouped staged files into %d directories:', Object.keys(filesByDir).length) | ||
debugLog(objectInspect(filesByDir, { indent: 2 })) | ||
// Group files by their discovered config | ||
@@ -61,22 +81,32 @@ // { '.lintstagedrc.json': { config: {...}, files: [...] } } | ||
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) return | ||
debugLog('Searching config files...') | ||
if (filepath in configGroups) { | ||
// Re-use cached config and skip validation | ||
configGroups[filepath].files.push(...files) | ||
return | ||
} | ||
const searchConfig = async (cwd, files = []) => { | ||
const { config, filepath } = await loadConfig({ cwd }, logger) | ||
if (!config) { | ||
debugLog('Found no config from "%s"!', cwd) | ||
return | ||
} | ||
const validatedConfig = validateConfig(config, filepath, logger) | ||
configGroups[filepath] = { config: validatedConfig, files } | ||
}) | ||
}) | ||
) | ||
if (filepath in configGroups) { | ||
debugLog('Found existing config "%s" from "%s"!', filepath, cwd) | ||
// Re-use cached config and skip validation | ||
configGroups[filepath].files.push(...files) | ||
} else { | ||
debugLog('Found new config "%s" from "%s"!', filepath, cwd) | ||
const validatedConfig = validateConfig(config, filepath, logger) | ||
configGroups[filepath] = { config: validatedConfig, files } | ||
} | ||
} | ||
// Start by searching from cwd | ||
await searchConfig(cwd) | ||
// Discover configs from the base directory of each file | ||
await Promise.all(Object.entries(filesByDir).map(([dir, files]) => searchConfig(dir, files))) | ||
// Throw if no configurations were found | ||
if (Object.keys(configGroups).length === 0) { | ||
debugLog('Found no config groups!') | ||
logger.error(`${ConfigNotFoundError.message}.`) | ||
@@ -86,3 +116,5 @@ throw ConfigNotFoundError | ||
debugLog('Grouped staged files into %d groups!', Object.keys(configGroups).length) | ||
return configGroups | ||
} |
@@ -117,3 +117,3 @@ /** @typedef {import('./index').Logger} Logger */ | ||
const configGroups = await getConfigGroups({ configObject, configPath, files }, logger) | ||
const configGroups = await getConfigGroups({ configObject, configPath, cwd, files }, logger) | ||
@@ -120,0 +120,0 @@ // lint-staged 10 will automatically add modifications to index |
{ | ||
"name": "lint-staged", | ||
"version": "12.2.1", | ||
"version": "12.2.2", | ||
"description": "Lint files staged by git", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
94838
1638