Skip to content

Commit 65111b4

Browse files
committed
Add vue/no-undef-properties rule
1 parent 62f577d commit 65111b4

File tree

6 files changed

+1711
-1
lines changed

6 files changed

+1711
-1
lines changed

docs/rules/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ For example:
312312
| [vue/no-restricted-v-bind](./no-restricted-v-bind.md) | disallow specific argument in `v-bind` | |
313313
| [vue/no-static-inline-styles](./no-static-inline-styles.md) | disallow static inline `style` attributes | |
314314
| [vue/no-template-target-blank](./no-template-target-blank.md) | disallow target="_blank" attribute without rel="noopener noreferrer" | |
315+
| [vue/no-undef-properties](./no-undef-properties.md) | disallow undefined properties | |
315316
| [vue/no-unregistered-components](./no-unregistered-components.md) | disallow using components that are not registered inside templates | |
316317
| [vue/no-unsupported-features](./no-unsupported-features.md) | disallow unsupported Vue.js syntax on the specified version | :wrench: |
317318
| [vue/no-unused-properties](./no-unused-properties.md) | disallow unused properties | |

docs/rules/no-undef-properties.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
pageClass: rule-details
3+
sidebarDepth: 0
4+
title: vue/no-undef-properties
5+
description: disallow undefined properties
6+
---
7+
# vue/no-undef-properties
8+
9+
> disallow undefined properties
10+
11+
- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
12+
13+
## :book: Rule Details
14+
15+
This rule warns of using undefined properties.
16+
This rule can help you locate potential errors resulting from misspellings property names, and implicitly added properties.
17+
18+
::: warning Note
19+
This rule cannot detect properties defined in other files or components.
20+
:::
21+
22+
<eslint-code-block :rules="{'vue/no-undef-properties': ['error']}">
23+
24+
```vue
25+
<template>
26+
<!-- ✓ GOOD -->
27+
<div>{{ name }}: {{ count }}</div>
28+
<!-- ✗ BAD -->
29+
<div>{{ label }}: {{ cnt }}</div>
30+
</template>
31+
<script>
32+
export default {
33+
props: ['name'],
34+
data () {
35+
return {
36+
count: 0
37+
}
38+
},
39+
methods: {
40+
click() {
41+
/* ✓ GOOD */
42+
this.count++
43+
44+
/* ✗ BAD */
45+
this.cnt++
46+
}
47+
}
48+
}
49+
</script>
50+
```
51+
52+
</eslint-code-block>
53+
54+
## :wrench: Options
55+
56+
```json
57+
{
58+
"vue/no-undef-properties": ["error", {
59+
"ignores": ["/^\\$/"]
60+
}]
61+
}
62+
```
63+
64+
- `ignores` (`string[]`) ... An array of property names or patterns that have already been defined property, or property to ignore from the check. Default is `["/^\\$/"]`.
65+
66+
### `"ignores": ["/^\\$/"]` (default)
67+
68+
<eslint-code-block :rules="{'vue/no-undef-properties': ['error', {ignores: ['/^\\$/']}]}">
69+
70+
```vue
71+
<template>
72+
<!-- ✓ GOOD -->
73+
<div>{{ $t('foo') }}</div>
74+
</template>
75+
<script>
76+
export default {
77+
mounted() {
78+
/* ✓ GOOD */
79+
const hash = this.$route.hash
80+
}
81+
}
82+
</script>
83+
```
84+
85+
</eslint-code-block>
86+
87+
## :mag: Implementation
88+
89+
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/no-undef-properties.js)
90+
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/no-undef-properties.js)

lib/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ module.exports = {
112112
'no-template-shadow': require('./rules/no-template-shadow'),
113113
'no-template-target-blank': require('./rules/no-template-target-blank'),
114114
'no-textarea-mustache': require('./rules/no-textarea-mustache'),
115+
'no-undef-properties': require('./rules/no-undef-properties'),
115116
'no-unregistered-components': require('./rules/no-unregistered-components'),
116117
'no-unsupported-features': require('./rules/no-unsupported-features'),
117118
'no-unused-components': require('./rules/no-unused-components'),

0 commit comments

Comments
 (0)