-
Notifications
You must be signed in to change notification settings - Fork 15
feat(plugin-eslint): log initializer and runner steps #1176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c909320
5772810
89c0468
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| export const ESLINT_PLUGIN_SLUG = 'eslint'; | ||
| export const ESLINT_PLUGIN_TITLE = 'ESLint'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| import { pluginMetaLogFormatter } from '@code-pushup/utils'; | ||
| import { ESLINT_PLUGIN_TITLE } from '../constants.js'; | ||
|
|
||
| export const formatMetaLog = pluginMetaLogFormatter(ESLINT_PLUGIN_TITLE); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import type { ESLint } from 'eslint'; | ||
|
|
||
| export type LintResultsStats = { | ||
| problemsCount: number; | ||
| failedFilesCount: number; | ||
| failedRulesCount: number; | ||
| }; | ||
|
|
||
| export function aggregateLintResultsStats( | ||
| results: ESLint.LintResult[], | ||
| ): LintResultsStats { | ||
| const problemsCount = results.reduce( | ||
| (acc, result) => acc + result.messages.length, | ||
| 0, | ||
| ); | ||
| const failedFilesCount = results.length; | ||
| const failedRulesCount = new Set( | ||
| results.flatMap(({ messages }) => | ||
| messages.map(({ ruleId }) => ruleId).filter(Boolean), | ||
| ), | ||
| ).size; | ||
| return { problemsCount, failedFilesCount, failedRulesCount }; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import type { ESLint } from 'eslint'; | ||
BioPhoton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| import { type LintResultsStats, aggregateLintResultsStats } from './stats.js'; | ||
|
|
||
| describe('aggregateLintResultsStats', () => { | ||
|
Check failure on line 4 in packages/plugin-eslint/src/lib/runner/stats.unit.test.ts
|
||
| it('should sum all errors and warning across all files', () => { | ||
|
Check failure on line 5 in packages/plugin-eslint/src/lib/runner/stats.unit.test.ts
|
||
| expect( | ||
| aggregateLintResultsStats([ | ||
| { | ||
| filePath: 'src/main.js', | ||
| messages: [{ severity: 2 }], | ||
| }, | ||
| { | ||
| filePath: 'src/lib/index.js', | ||
| messages: [{ severity: 2 }, { severity: 1 }], | ||
| }, | ||
| { | ||
| filePath: 'src/lib/utils.js', | ||
| messages: [ | ||
| { severity: 1 }, | ||
| { severity: 1 }, | ||
| { severity: 2 }, | ||
| { severity: 1 }, | ||
| ], | ||
| }, | ||
| ] as ESLint.LintResult[]), | ||
| ).toEqual( | ||
| expect.objectContaining<Partial<LintResultsStats>>({ | ||
| problemsCount: 7, | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| it('should count files with problems', () => { | ||
|
Check failure on line 33 in packages/plugin-eslint/src/lib/runner/stats.unit.test.ts
|
||
| expect( | ||
| aggregateLintResultsStats([ | ||
| { filePath: 'src/main.js', messages: [{}] }, | ||
| { filePath: 'src/lib/index.js', messages: [{}, {}] }, | ||
| { filePath: 'src/lib/utils.js', messages: [{}, {}, {}] }, | ||
| ] as ESLint.LintResult[]), | ||
| ).toEqual( | ||
| expect.objectContaining<Partial<LintResultsStats>>({ | ||
| failedFilesCount: 3, | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| it('should count unique rules with reported problems', () => { | ||
|
Check failure on line 47 in packages/plugin-eslint/src/lib/runner/stats.unit.test.ts
|
||
| expect( | ||
| aggregateLintResultsStats([ | ||
| { filePath: 'src/lib/main.js', messages: [{}] }, // empty ruleId ignored | ||
| { | ||
| filePath: 'src/lib/index.js', | ||
| messages: [{ ruleId: 'max-lines' }, { ruleId: 'no-unused-vars' }], | ||
| }, | ||
| { | ||
| filePath: 'src/lib/utils.js', | ||
| messages: [ | ||
| { ruleId: 'no-unused-vars' }, | ||
| { ruleId: 'eqeqeq' }, | ||
| { ruleId: 'no-unused-vars' }, | ||
| { ruleId: 'yoda' }, | ||
| { ruleId: 'eqeqeq' }, | ||
| ], | ||
| }, | ||
| ] as ESLint.LintResult[]), | ||
| ).toEqual( | ||
| expect.objectContaining<Partial<LintResultsStats>>({ | ||
| failedRulesCount: 4, // no-unused-vars (3), eqeqeq (2), max-lines (1), yoda (1) | ||
| }), | ||
| ); | ||
| }); | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.