Skip to content

Commit a6aac56

Browse files
committed
fix(plugin-eslint): truncate rule texts to pass models validations
1 parent bdce572 commit a6aac56

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

packages/plugin-eslint/src/lib/meta/transform.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Audit } from '@code-pushup/models';
2+
import { truncateDescription, truncateTitle } from '@code-pushup/utils';
23
import { ruleIdToSlug } from './hash';
34
import { RuleData } from './rules';
45

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

1819
return {
1920
slug: ruleIdToSlug(ruleId, options),
20-
title: meta.docs?.description ?? name,
21-
description: lines.join('\n\n'),
21+
title: truncateTitle(meta.docs?.description ?? name),
22+
description: truncateDescription(lines.join('\n\n')),
2223
...(meta.docs?.url && {
2324
docsUrl: meta.docs.url,
2425
}),

packages/plugin-eslint/src/lib/meta/transform.unit.test.ts

+24
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,28 @@ Custom options:
144144
'https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/extensions.md',
145145
});
146146
});
147+
148+
it('rule with overlong description -> title is truncated', () => {
149+
expect(
150+
ruleToAudit({
151+
ruleId: '@angular-eslint/template/mouse-events-have-key-events',
152+
meta: {
153+
docs: {
154+
description:
155+
'[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',
156+
url: 'https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin-template/docs/rules/mouse-events-have-key-events.md',
157+
},
158+
},
159+
options: [],
160+
}),
161+
).toEqual<Audit>({
162+
slug: 'angular-eslint-template-mouse-events-have-key-events',
163+
title:
164+
'[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...',
165+
description:
166+
'ESLint rule **mouse-events-have-key-events**, from _@angular-eslint/template_ plugin.',
167+
docsUrl:
168+
'https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin-template/docs/rules/mouse-events-have-key-events.md',
169+
});
170+
});
147171
});

0 commit comments

Comments
 (0)