-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugin-eslint): register audit metadata based on eslintrc and fi…
…le patterns
- Loading branch information
1 parent
a9dc323
commit 3aac581
Showing
7 changed files
with
118 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import { eslintPlugin } from './lib/eslint-plugin'; | ||
|
||
export default eslintPlugin; | ||
|
||
export type { ESLintPluginConfig } from './lib/eslint-plugin'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
import { eslintPlugin } from './eslint-plugin'; | ||
|
||
describe('eslintPlugin', () => { | ||
it('should initialize ESLint plugin', () => { | ||
expect(eslintPlugin({ config: '.eslintrc.json' }).slug).toBe('eslint'); | ||
it('should initialize ESLint plugin', async () => { | ||
const plugin = await eslintPlugin({ | ||
eslintrc: '.eslintrc.json', | ||
patterns: ['**/*.ts', '**/*.js', '**/*.json'], | ||
}); | ||
console.log(plugin); | ||
expect(plugin.slug).toBe('eslint'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import type { Audit } from '@quality-metrics/models'; | ||
import { distinct, toArray } from '@quality-metrics/utils'; | ||
import type { ESLint, Linter, Rule } from 'eslint'; | ||
|
||
export async function listAudits( | ||
eslint: ESLint, | ||
patterns: string | string[], | ||
): Promise<Audit[]> { | ||
const configs = await toArray(patterns).reduce( | ||
async (acc, pattern) => [ | ||
...(await acc), | ||
await eslint.calculateConfigForFile(pattern), | ||
], | ||
Promise.resolve<Linter.Config[]>([]), | ||
); | ||
|
||
const rulesIds = distinct( | ||
configs.flatMap(config => Object.keys(config.rules ?? {})), | ||
); | ||
const rulesMeta = eslint.getRulesMetaForResults([ | ||
{ | ||
messages: rulesIds.map(ruleId => ({ ruleId })), | ||
suppressedMessages: [] as Linter.SuppressedLintMessage[], | ||
} as ESLint.LintResult, | ||
]); | ||
|
||
return Object.entries(rulesMeta).map(args => ruleToAudit(...args)); | ||
} | ||
|
||
function ruleToAudit(ruleId: string, meta: Rule.RuleMetaData): Audit { | ||
return { | ||
slug: ruleId, // TODO: slugify | ||
title: meta.docs?.description ?? ruleId, | ||
docsUrl: meta.docs?.url, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
export { | ||
executeProcess, | ||
ProcessConfig, | ||
ProcessResult, | ||
ProcessObserver, | ||
ProcessError, | ||
ProcessObserver, | ||
ProcessResult, | ||
executeProcess, | ||
objectToCliArgs, | ||
} from './lib/execute-process'; | ||
export { calcDuration, formatBytes } from './lib/utils'; | ||
export { reportToStdout } from './lib/report-to-stdout'; | ||
export { reportToMd } from './lib/report-to-md'; | ||
export { importModule } from './lib/load-file'; | ||
export { reportToMd } from './lib/report-to-md'; | ||
export { reportToStdout } from './lib/report-to-stdout'; | ||
export { calcDuration, formatBytes, toArray, distinct } from './lib/utils'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters