Skip to content

Commit 501bb77

Browse files
committed
feat(vue): support accessibility
(cherry picked from commit 330ef08)
1 parent a650818 commit 501bb77

File tree

5 files changed

+51
-2
lines changed

5 files changed

+51
-2
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
"eslint-plugin-unicorn": "^55.0.0",
123123
"eslint-plugin-unused-imports": "^4.1.3",
124124
"eslint-plugin-vue": "^9.27.0",
125+
"eslint-plugin-vuejs-accessibility": "^2.4.1",
125126
"eslint-plugin-yml": "^1.14.0",
126127
"eslint-processor-vue-blocks": "^0.1.2",
127128
"globals": "^15.9.0",

pnpm-lock.yaml

+18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/configs/vue.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { mergeProcessors } from 'eslint-merge-processors'
2-
import { interopDefault } from '../utils'
2+
import { changeLevel, interopDefault } from '../utils'
33
import type { OptionsFiles, OptionsHasTypeScript, OptionsOverrides, OptionsStylistic, OptionsVue, TypedFlatConfigItem } from '../types'
44
import { GLOB_VUE } from '../globs'
55

66
export async function vue(
77
options: OptionsVue & OptionsHasTypeScript & OptionsOverrides & OptionsStylistic & OptionsFiles = {},
88
): Promise<TypedFlatConfigItem[]> {
99
const {
10+
accessibility = true,
1011
files = [GLOB_VUE],
1112
overrides = {},
1213
stylistic = true,
@@ -25,11 +26,13 @@ export async function vue(
2526
pluginVue,
2627
parserVue,
2728
processorVueBlocks,
29+
pluginVueAccessibility,
2830
] = await Promise.all([
2931
// @ts-expect-error missing types
3032
interopDefault(import('eslint-plugin-vue')),
3133
interopDefault(import('vue-eslint-parser')),
3234
interopDefault(import('eslint-processor-vue-blocks')),
35+
interopDefault(import('eslint-plugin-vuejs-accessibility')),
3336
] as const)
3437

3538
return [
@@ -56,7 +59,8 @@ export async function vue(
5659
},
5760
name: 'antfu/vue/setup',
5861
plugins: {
59-
vue: pluginVue,
62+
'vue': pluginVue,
63+
'vuejs-accessibility': pluginVueAccessibility,
6064
},
6165
},
6266
{
@@ -102,6 +106,12 @@ export async function vue(
102106
...pluginVue.configs['vue3-recommended'].rules as any,
103107
},
104108

109+
...accessibility
110+
? {
111+
...changeLevel(pluginVueAccessibility.configs.recommended.rules, 'error', 'warn'),
112+
}
113+
: {},
114+
105115
'node/prefer-global/process': 'off',
106116
'vue/block-order': ['error', {
107117
order: ['script', 'template', 'style'],

src/types.ts

+8
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ export interface OptionsVue extends OptionsOverrides {
4444
* @default 3
4545
*/
4646
vueVersion?: 2 | 3
47+
48+
/**
49+
* Enable accessibility support.
50+
*
51+
* @see https://vue-a11y.github.io/eslint-plugin-vuejs-accessibility/
52+
* @default true
53+
*/
54+
accessibility?: boolean
4755
}
4856

4957
export type OptionsTypescript =

src/utils.ts

+12
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,15 @@ export function isInGitHooksOrLintStaged(): boolean {
152152
|| process.env.npm_lifecycle_script?.startsWith('lint-staged')
153153
)
154154
}
155+
156+
export function changeLevel<T extends Record<string, unknown>>(rules: T, from: string, to: string): T {
157+
return Object.fromEntries(Object.entries(rules).map(
158+
([key, value]) => {
159+
if (value === from)
160+
value = to
161+
else if (Array.isArray(value) && value.at(0) === from)
162+
value = [to, ...value.slice(1)]
163+
return [key, value]
164+
},
165+
)) as T
166+
}

0 commit comments

Comments
 (0)