MCPcopy Create free account
hub / github.com/code-pushup/cli / loadRuleOptionsPerFile

Function loadRuleOptionsPerFile

packages/plugin-eslint/src/lib/runner/lint.ts:54–82  ·  view source on GitHub ↗
(
  eslint: ESLint,
  results: ESLint.LintResult[],
)

Source from the content-addressed store, hash-verified

52}
53
54function loadRuleOptionsPerFile(
55 eslint: ESLint,
56 results: ESLint.LintResult[],
57): Promise<RuleOptionsPerFile> {
58 return results.reduce(async (acc, { filePath, messages }) => {
59 const filesMap = await acc;
60 const config = (await eslint.calculateConfigForFile(
61 filePath,
62 )) as Linter.Config;
63 const ruleIds = distinct(
64 messages
65 .map(({ ruleId }) => ruleId)
66 .filter((ruleId): ruleId is string => ruleId != null),
67 );
68 const rulesMap = Object.fromEntries(
69 ruleIds.map(ruleId => [
70 ruleId,
71 toArray(config.rules?.[ruleId] ?? []).slice(1),
72 ]),
73 );
74 return {
75 ...filesMap,
76 [filePath]: {
77 ...filesMap[filePath],
78 ...rulesMap,
79 },
80 };
81 }, Promise.resolve<RuleOptionsPerFile>({}));
82}

Callers 1

lintFunction · 0.85

Calls 2

distinctFunction · 0.90
toArrayFunction · 0.90

Tested by

no test coverage detected