Skip to content

Commit f458b0d

Browse files
committed
fix(plugin-axe): resolve ESLint errors and warnings
1 parent a1d5a2f commit f458b0d

File tree

7 files changed

+33
-20
lines changed

7 files changed

+33
-20
lines changed

packages/plugin-axe/src/lib/config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ import {
55
} from '@code-pushup/models';
66
import { AXE_DEFAULT_PRESET, AXE_PRESETS } from './constants.js';
77

8+
const DEFAULT_TIMEOUT_MS = 30_000;
9+
810
export const axePluginOptionsSchema = z
911
.object({
1012
preset: z.enum(AXE_PRESETS).default(AXE_DEFAULT_PRESET).meta({
1113
description:
1214
'Accessibility ruleset preset (default: wcag21aa for WCAG 2.1 Level AA compliance)',
1315
}),
1416
scoreTargets: pluginScoreTargetsSchema.optional(),
15-
timeout: positiveIntSchema.default(30_000).meta({
17+
timeout: positiveIntSchema.default(DEFAULT_TIMEOUT_MS).meta({
1618
description:
1719
'Page navigation timeout in milliseconds (default: 30000ms / 30s)',
1820
}),

packages/plugin-axe/src/lib/config.unit.test.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { describe, expect, it } from 'vitest';
2+
import { ZodError } from 'zod';
23
import { axePluginOptionsSchema } from './config.js';
34

45
describe('axePluginOptionsSchema', () => {
@@ -31,17 +32,21 @@ describe('axePluginOptionsSchema', () => {
3132
});
3233

3334
it('should reject invalid preset values', () => {
34-
expect(() => axePluginOptionsSchema.parse({ preset: 'wcag3aa' })).toThrow();
35+
expect(() => axePluginOptionsSchema.parse({ preset: 'wcag3aa' })).toThrow(
36+
ZodError,
37+
);
3538
});
3639

3740
it('should reject scoreTargets values greater than 1', () => {
38-
expect(() => axePluginOptionsSchema.parse({ scoreTargets: 1.5 })).toThrow();
41+
expect(() => axePluginOptionsSchema.parse({ scoreTargets: 1.5 })).toThrow(
42+
ZodError,
43+
);
3944
});
4045

4146
it('should reject negative scoreTargets', () => {
42-
expect(() =>
43-
axePluginOptionsSchema.parse({ scoreTargets: -0.1 }),
44-
).toThrow();
47+
expect(() => axePluginOptionsSchema.parse({ scoreTargets: -0.1 })).toThrow(
48+
ZodError,
49+
);
4550
});
4651

4752
it('should accept custom timeout value', () => {
@@ -51,11 +56,17 @@ describe('axePluginOptionsSchema', () => {
5156
});
5257

5358
it('should reject non-positive timeout values', () => {
54-
expect(() => axePluginOptionsSchema.parse({ timeout: 0 })).toThrow();
55-
expect(() => axePluginOptionsSchema.parse({ timeout: -1000 })).toThrow();
59+
expect(() => axePluginOptionsSchema.parse({ timeout: 0 })).toThrow(
60+
ZodError,
61+
);
62+
expect(() => axePluginOptionsSchema.parse({ timeout: -1000 })).toThrow(
63+
ZodError,
64+
);
5665
});
5766

5867
it('should reject non-integer timeout values', () => {
59-
expect(() => axePluginOptionsSchema.parse({ timeout: 1000.5 })).toThrow();
68+
expect(() => axePluginOptionsSchema.parse({ timeout: 1000.5 })).toThrow(
69+
ZodError,
70+
);
6071
});
6172
});

packages/plugin-axe/src/lib/meta/groups.unit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('transformRulesToGroups', () => {
7777
'best-practice',
7878
);
7979

80-
expect(groups).toSatisfyAll<Group>(({ slug }) => !slug.match(/^cat\./));
80+
expect(groups).toSatisfyAll<Group>(({ slug }) => !/^cat\./.test(slug));
8181
});
8282

8383
it('should include both WCAG 2.2 and category groups for "all" preset', () => {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export function transformRulesToGroups(
4747
return createWcagGroups(rules, '2.1');
4848
case 'wcag22aa':
4949
return createWcagGroups(rules, '2.2');
50+
// eslint-disable-next-line sonarjs/no-duplicate-string
5051
case 'best-practice':
5152
return createCategoryGroups(rules);
5253
case 'all':
@@ -128,7 +129,7 @@ function createCategoryGroups(rules: axe.RuleMetadata[]): Group[] {
128129
rules.flatMap(({ tags }) => tags.filter(tag => tag.startsWith('cat.'))),
129130
);
130131

131-
return Array.from(categoryTags).map(tag => {
132+
return [...categoryTags].map(tag => {
132133
const slug = tag.replace('cat.', '');
133134
const title = formatCategoryTitle(tag, slug);
134135
const categoryRules = rules.filter(({ tags }) => tags.includes(tag));

packages/plugin-axe/src/lib/processing.unit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it } from 'vitest';
2-
import { processAuditsAndGroups } from './processing';
2+
import { processAuditsAndGroups } from './processing.js';
33

44
describe('processAuditsAndGroups', () => {
55
it('should return audits and groups without expansion when analyzing single URL', () => {

packages/plugin-axe/src/lib/runner/transform.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import type { AxeResults, ImpactValue, NodeResult, Result } from 'axe-core';
2-
import type axe from 'axe-core';
1+
import axe from 'axe-core';
32
import type {
43
AuditOutput,
54
AuditOutputs,
@@ -18,7 +17,7 @@ import {
1817
* Priority: violations > incomplete > passes > inapplicable
1918
*/
2019
export function toAuditOutputs(
21-
{ passes, violations, incomplete, inapplicable }: AxeResults,
20+
{ passes, violations, incomplete, inapplicable }: axe.AxeResults,
2221
url: string,
2322
): AuditOutputs {
2423
const auditMap = new Map<string, AuditOutput>([
@@ -28,15 +27,15 @@ export function toAuditOutputs(
2827
...violations.map(res => [res.id, toAuditOutput(res, url, 0)] as const),
2928
]);
3029

31-
return Array.from(auditMap.values());
30+
return [...auditMap.values()];
3231
}
3332

3433
/**
3534
* For failing audits (score 0), includes detailed issues with locations and severities.
3635
* For passing audits (score 1), only includes element count.
3736
*/
3837
function toAuditOutput(
39-
result: Result,
38+
result: axe.Result,
4039
url: string,
4140
score: number,
4241
): AuditOutput {
@@ -69,7 +68,7 @@ function formatSelector(selector: axe.CrossTreeSelector): string {
6968
return selector.join(' >> ');
7069
}
7170

72-
function toIssue(node: NodeResult, result: Result, url: string): Issue {
71+
function toIssue(node: axe.NodeResult, result: axe.Result, url: string): Issue {
7372
const selector = formatSelector(node.target?.[0] || node.html);
7473
const rawMessage = node.failureSummary || result.help;
7574
const cleanedMessage = rawMessage.replace(/\s+/g, ' ').trim();
@@ -82,7 +81,7 @@ function toIssue(node: NodeResult, result: Result, url: string): Issue {
8281
};
8382
}
8483

85-
function impactToSeverity(impact: ImpactValue | undefined): IssueSeverity {
84+
function impactToSeverity(impact: axe.ImpactValue | undefined): IssueSeverity {
8685
switch (impact) {
8786
case 'critical':
8887
case 'serious':

packages/plugin-axe/src/lib/runner/transform.unit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ describe('toAuditOutputs', () => {
287287
issues: [
288288
{
289289
message:
290-
'[`<div role=\"invalid-role\">Content</div>`] Fix this: Ensure all values assigned to role=\"\" correspond to valid ARIA roles ([example.com](https://example.com))',
290+
'[`<div role="invalid-role">Content</div>`] Fix this: Ensure all values assigned to role="" correspond to valid ARIA roles ([example.com](https://example.com))',
291291
severity: 'error',
292292
},
293293
],

0 commit comments

Comments
 (0)