Skip to content

Commit 575bae5

Browse files
committed
feat(vue-a11y): include the plugin into vue option instead
1 parent 44cf0f6 commit 575bae5

File tree

7 files changed

+62
-92
lines changed

7 files changed

+62
-92
lines changed

README.md

+20-1
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,26 @@ export default antfu({
538538
})
539539
```
540540

541-
As it's in maintenance mode, we only accept bug fixes for Vue 2. It might also be removed in the future when `eslint-plugin-vue` drops support for Vue 2. We recommend upgrading to Vue 3 if possible.
541+
#### Vue Accessibility
542+
543+
To enable Vue accessibility support, you need to explicitly turn it on:
544+
545+
```js
546+
// eslint.config.js
547+
import antfu from '@antfu/eslint-config'
548+
549+
export default antfu({
550+
vue: {
551+
a11y: true
552+
},
553+
})
554+
```
555+
556+
Running `npx eslint` should prompt you to install the required dependencies, otherwise, you can install them manually:
557+
558+
```bash
559+
npm i -D eslint-plugin-vuejs-accessibility
560+
```
542561

543562
### Optional Configs
544563

eslint.config.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import { antfu } from './src'
44

55
export default antfu(
66
{
7-
vue: true,
8-
vueA11y: true,
7+
vue: {
8+
a11y: true,
9+
},
910
react: true,
1011
solid: true,
1112
svelte: true,

src/configs/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,4 @@ export * from './typescript'
2525
export * from './unicorn'
2626
export * from './unocss'
2727
export * from './vue'
28-
export * from './vueA11y'
2928
export * from './yaml'

src/configs/vue.ts

+31
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export async function vue(
1515
options: OptionsVue & OptionsHasTypeScript & OptionsOverrides & OptionsStylistic & OptionsFiles = {},
1616
): Promise<TypedFlatConfigItem[]> {
1717
const {
18+
a11y = false,
1819
files = [GLOB_VUE],
1920
overrides = {},
2021
stylistic = true,
@@ -33,10 +34,12 @@ export async function vue(
3334
pluginVue,
3435
parserVue,
3536
processorVueBlocks,
37+
pluginVueA11y,
3638
] = await Promise.all([
3739
interopDefault(import('eslint-plugin-vue')),
3840
interopDefault(import('vue-eslint-parser')),
3941
interopDefault(import('eslint-processor-vue-blocks')),
42+
...a11y ? [interopDefault(import('eslint-plugin-vuejs-accessibility'))] : [],
4043
] as const)
4144

4245
return [
@@ -64,6 +67,7 @@ export async function vue(
6467
name: 'antfu/vue/setup',
6568
plugins: {
6669
vue: pluginVue,
70+
...a11y ? { 'vue-a11y': pluginVueA11y } : {},
6771
},
6872
},
6973
{
@@ -192,6 +196,33 @@ export async function vue(
192196
}
193197
: {},
194198

199+
...a11y
200+
? {
201+
'vue-a11y/alt-text': 'error',
202+
'vue-a11y/anchor-has-content': 'error',
203+
'vue-a11y/aria-props': 'error',
204+
'vue-a11y/aria-role': 'error',
205+
'vue-a11y/aria-unsupported-elements': 'error',
206+
'vue-a11y/click-events-have-key-events': 'error',
207+
'vue-a11y/form-control-has-label': 'error',
208+
'vue-a11y/heading-has-content': 'error',
209+
'vue-a11y/iframe-has-title': 'error',
210+
'vue-a11y/interactive-supports-focus': 'error',
211+
'vue-a11y/label-has-for': 'error',
212+
'vue-a11y/media-has-caption': 'warn',
213+
'vue-a11y/mouse-events-have-key-events': 'error',
214+
'vue-a11y/no-access-key': 'error',
215+
'vue-a11y/no-aria-hidden-on-focusable': 'error',
216+
'vue-a11y/no-autofocus': 'warn',
217+
'vue-a11y/no-distracting-elements': 'error',
218+
'vue-a11y/no-redundant-roles': 'error',
219+
'vue-a11y/no-role-presentation-on-focusable': 'error',
220+
'vue-a11y/no-static-element-interactions': 'error',
221+
'vue-a11y/role-has-required-aria-props': 'error',
222+
'vue-a11y/tabindex-no-positive': 'warn',
223+
}
224+
: {},
225+
195226
...overrides,
196227
},
197228
},

src/configs/vueA11y.ts

-72
This file was deleted.

src/factory.ts

-8
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import {
3131
unicorn,
3232
unocss,
3333
vue,
34-
vueA11y,
3534
yaml,
3635
} from './configs'
3736
import { formatters } from './configs/formatters'
@@ -98,7 +97,6 @@ export function antfu(
9897
unicorn: enableUnicorn = true,
9998
unocss: enableUnoCSS = false,
10099
vue: enableVue = VuePackages.some(i => isPackageExists(i)),
101-
vueA11y: enableVueA11y = false,
102100
} = options
103101

104102
let isInEditor = options.isInEditor
@@ -208,12 +206,6 @@ export function antfu(
208206
}))
209207
}
210208

211-
if (enableVueA11y) {
212-
configs.push(vueA11y({
213-
overrides: getOverrides(options, 'vueA11y'),
214-
}))
215-
}
216-
217209
if (enableReact) {
218210
configs.push(react({
219211
...typescriptOptions,

src/types.ts

+8-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+
* Vue accessibility plugin. Help check a11y issue in `.vue` files upon enabled
50+
*
51+
* @see https://vue-a11y.github.io/eslint-plugin-vuejs-accessibility/
52+
* @default false
53+
*/
54+
a11y?: boolean
4755
}
4856

4957
export type OptionsTypescript =
@@ -290,14 +298,6 @@ export interface OptionsConfig extends OptionsComponentExts, OptionsProjectType
290298
*/
291299
vue?: boolean | OptionsVue
292300

293-
/**
294-
* Enable Vue A11y support.
295-
*
296-
* @see https://vue-a11y.github.io/eslint-plugin-vuejs-accessibility/
297-
* @default auto-detect based on the dependencies
298-
*/
299-
vueA11y?: boolean | OptionsOverrides
300-
301301
/**
302302
* Enable JSONC support.
303303
*

0 commit comments

Comments
 (0)