Skip to content

Commit d0b890f

Browse files
authored
Add attributes option to no-raw-text rule (#259)
1 parent b8d2f27 commit d0b890f

File tree

4 files changed

+679
-103
lines changed

4 files changed

+679
-103
lines changed

docs/rules/no-raw-text.md

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,17 @@ export default {
134134
"@intlify/vue-i18n/no-raw-text": [
135135
"error",
136136
{
137+
"attributes": {
138+
"/.+/": [
139+
"title",
140+
"aria-label",
141+
"aria-placeholder",
142+
"aria-roledescription",
143+
"aria-valuetext"
144+
],
145+
"input": ["placeholder"],
146+
"img": ["alt"]
147+
},
137148
"ignoreNodes": ["md-icon", "v-icon"],
138149
"ignorePattern": "^[-#:()&]+$",
139150
"ignoreText": ["EUR", "HKD", "USD"]
@@ -142,9 +153,47 @@ export default {
142153
}
143154
```
144155

145-
- `ignoreNodes`: specify nodes to ignore such as icon components
146-
- `ignorePattern`: specify a regexp pattern that matches strings to ignore
147-
- `ignoreText`: specify an array of strings to ignore
156+
- `attributes`: An object whose keys are tag name or patterns and value is an array of attributes to check for that tag name. Default empty.
157+
- `ignoreNodes`: specify nodes to ignore such as icon components. Default empty.
158+
- `ignorePattern`: specify a regexp pattern that matches strings to ignore. Default none.
159+
- `ignoreText`: specify an array of strings to ignore. Default empty.
160+
161+
### `attributes`
162+
163+
<eslint-code-block>
164+
165+
<!-- eslint-skip -->
166+
167+
```vue
168+
<script>
169+
/* eslint @intlify/vue-i18n/no-raw-text: ['error', {attributes: { '/.+/': ['label'] }}] */
170+
</script>
171+
<template>
172+
<!-- ✗ BAD -->
173+
<my-input label="hello" />
174+
<any-component label="hello" />
175+
</template>
176+
```
177+
178+
</eslint-code-block>
179+
180+
<eslint-code-block>
181+
182+
<!-- eslint-skip -->
183+
184+
```vue
185+
<script>
186+
/* eslint @intlify/vue-i18n/no-raw-text: ['error', {attributes: { 'MyInput': ['label'] }}] */
187+
</script>
188+
<template>
189+
<!-- ✗ BAD -->
190+
<my-input label="hello" />
191+
<!-- ✓ GOOD -->
192+
<other-component label="hello" />
193+
</template>
194+
```
195+
196+
</eslint-code-block>
148197

149198
## :rocket: Version
150199

0 commit comments

Comments
 (0)