( configPath: string | undefined, base: string, formatter: Formatter )
| 404 | |
| 405 | // search and load config |
| 406 | function getConfig( |
| 407 | configPath: string | undefined, |
| 408 | base: string, |
| 409 | formatter: Formatter |
| 410 | ): Ruleset | undefined { |
| 411 | if (configPath === undefined && existsSync(base)) { |
| 412 | // find default config file in parent directory |
| 413 | if (statSync(base).isDirectory() === false) { |
| 414 | base = dirname(base) |
| 415 | } |
| 416 | |
| 417 | while (base) { |
| 418 | const tmpConfigFile = resolve(base, '.htmlhintrc') |
| 419 | |
| 420 | if (existsSync(tmpConfigFile)) { |
| 421 | configPath = tmpConfigFile |
| 422 | break |
| 423 | } |
| 424 | |
| 425 | base = base.substring(0, base.lastIndexOf(sep)) |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | if (configPath !== undefined && existsSync(configPath)) { |
| 430 | const config = readFileSync(configPath, 'utf-8') |
| 431 | let ruleset: Ruleset = {} |
| 432 | |
| 433 | try { |
| 434 | ruleset = JSON.parse(stripJsonComments(config)) |
| 435 | formatter.emit('config', { |
| 436 | ruleset: ruleset, |
| 437 | configPath: configPath, |
| 438 | }) |
| 439 | return ruleset |
| 440 | } catch (e) { |
| 441 | console.log(' Config could not be parsed: %s', chalk.yellow(configPath)) |
| 442 | console.log('') |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | // Return undefined if no valid config is found |
| 447 | return undefined |
| 448 | } |
| 449 | |
| 450 | // walk path |
| 451 | function walkPath( |
no test coverage detected