( artifacts: PluginArtifactOptions, )
| 12 | import type { LinterOutput } from './types.js'; |
| 13 | |
| 14 | export async function loadArtifacts( |
| 15 | artifacts: PluginArtifactOptions, |
| 16 | ): Promise<LinterOutput[]> { |
| 17 | if (artifacts.generateArtifactsCommand) { |
| 18 | const { command, args = [] } = |
| 19 | typeof artifacts.generateArtifactsCommand === 'string' |
| 20 | ? { command: artifacts.generateArtifactsCommand } |
| 21 | : artifacts.generateArtifactsCommand; |
| 22 | |
| 23 | await executeProcess({ |
| 24 | command, |
| 25 | args, |
| 26 | ignoreExitCode: true, |
| 27 | }); |
| 28 | } |
| 29 | |
| 30 | const artifactPatterns = toArray(artifacts.artifactsPaths); |
| 31 | |
| 32 | const artifactPaths = await glob(artifactPatterns); |
| 33 | |
| 34 | const outputs = await Promise.all( |
| 35 | artifactPaths.map(async artifactPath => { |
| 36 | // ESLint CLI outputs raw ESLint.LintResult[], but we need LinterOutput format |
| 37 | const results = await readJsonFile<ESLint.LintResult[]>(artifactPath); |
| 38 | return { |
| 39 | results, |
| 40 | ruleOptionsPerFile: {}, // TODO |
| 41 | }; |
| 42 | }), |
| 43 | ); |
| 44 | |
| 45 | logger.info( |
| 46 | `Loaded lint outputs from ${pluralizeToken('artifact', artifactPaths.length)} matching ${pluralize('pattern', artifactPatterns.length)}: ${artifactPatterns.join(' ')}`, |
| 47 | ); |
| 48 | |
| 49 | return outputs; |
| 50 | } |
no test coverage detected