Skip to content

Commit

Permalink
fix(plugin-eslint): truncate rule texts to pass models validations
Browse files Browse the repository at this point in the history
  • Loading branch information
matejchalk committed Dec 4, 2023
1 parent bdce572 commit a6aac56
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/plugin-eslint/src/lib/meta/transform.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Audit } from '@code-pushup/models';
import { truncateDescription, truncateTitle } from '@code-pushup/utils';
import { ruleIdToSlug } from './hash';
import { RuleData } from './rules';

Expand All @@ -17,8 +18,8 @@ export function ruleToAudit({ ruleId, meta, options }: RuleData): Audit {

return {
slug: ruleIdToSlug(ruleId, options),
title: meta.docs?.description ?? name,
description: lines.join('\n\n'),
title: truncateTitle(meta.docs?.description ?? name),
description: truncateDescription(lines.join('\n\n')),
...(meta.docs?.url && {
docsUrl: meta.docs.url,
}),
Expand Down
24 changes: 24 additions & 0 deletions packages/plugin-eslint/src/lib/meta/transform.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,28 @@ Custom options:
'https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/extensions.md',
});
});

it('rule with overlong description -> title is truncated', () => {
expect(
ruleToAudit({
ruleId: '@angular-eslint/template/mouse-events-have-key-events',
meta: {
docs: {
description:
'[Accessibility] Ensures that the mouse events `mouseout` and `mouseover` are accompanied by `focus` and `blur` events respectively. Coding for the keyboard is important for users with physical disabilities who cannot use a mouse, AT compatibility, and screenreader users. See more at https://www.w3.org/WAI/WCAG21/Understanding/keyboard',
url: 'https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin-template/docs/rules/mouse-events-have-key-events.md',
},
},
options: [],
}),
).toEqual<Audit>({
slug: 'angular-eslint-template-mouse-events-have-key-events',
title:
'[Accessibility] Ensures that the mouse events `mouseout` and `mouseover` are accompanied by `focus` and `blur` events respectively. Coding for the keyboard is important for users with physical disabilities who cannot use a mouse, AT compatibility, and s...',
description:
'ESLint rule **mouse-events-have-key-events**, from _@angular-eslint/template_ plugin.',
docsUrl:
'https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin-template/docs/rules/mouse-events-have-key-events.md',
});
});
});

0 comments on commit a6aac56

Please sign in to comment.