| 52 | } |
| 53 | |
| 54 | function 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 | } |