Skip to content

Commit 0bcece9

Browse files
committed
Add vue/no-undef-properties rule
1 parent 1ece73e commit 0bcece9

File tree

5 files changed

+1974
-0
lines changed

5 files changed

+1974
-0
lines changed

docs/rules/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ For example:
319319
| [vue/no-static-inline-styles](./no-static-inline-styles.md) | disallow static inline `style` attributes | |
320320
| [vue/no-template-target-blank](./no-template-target-blank.md) | disallow target="_blank" attribute without rel="noopener noreferrer" | |
321321
| [vue/no-this-in-before-route-enter](./no-this-in-before-route-enter.md) | disallow `this` usage in a `beforeRouteEnter` method | |
322+
| [vue/no-undef-properties](./no-undef-properties.md) | disallow undefined properties | |
322323
| [vue/no-unregistered-components](./no-unregistered-components.md) | disallow using components that are not registered inside templates | |
323324
| [vue/no-unsupported-features](./no-unsupported-features.md) | disallow unsupported Vue.js syntax on the specified version | :wrench: |
324325
| [vue/no-unused-properties](./no-unused-properties.md) | disallow unused properties | |

docs/rules/no-undef-properties.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
Note that there are many false positives if you are using mixins.
21+
:::
22+
23+
<eslint-code-block :rules="{'vue/no-undef-properties': ['error']}">
24+
25+
```vue
26+
<template>
27+
<!-- ✓ GOOD -->
28+
<div>{{ name }}: {{ count }}</div>
29+
<!-- ✗ BAD -->
30+
<div>{{ label }}: {{ cnt }}</div>
31+
</template>
32+
<script>
33+
export default {
34+
props: ['name'],
35+
data () {
36+
return {
37+
count: 0
38+
}
39+
},
40+
methods: {
41+
click() {
42+
/* ✓ GOOD */
43+
this.count++
44+
45+
/* ✗ BAD */
46+
this.cnt++
47+
}
48+
}
49+
}
50+
</script>
51+
```
52+
53+
</eslint-code-block>
54+
55+
## :wrench: Options
56+
57+
```json
58+
{
59+
"vue/no-undef-properties": ["error", {
60+
"ignores": ["/^\\$/"]
61+
}]
62+
}
63+
```
64+
65+
- `ignores` (`string[]`) ... An array of property names or patterns that have already been defined property, or property to ignore from the check. Default is `["/^\\$/"]`.
66+
67+
### `"ignores": ["/^\\$/"]` (default)
68+
69+
<eslint-code-block :rules="{'vue/no-undef-properties': ['error', {ignores: ['/^\\$/']}]}">
70+
71+
```vue
72+
<template>
73+
<!-- ✓ GOOD -->
74+
<div>{{ $t('foo') }}</div>
75+
</template>
76+
<script>
77+
export default {
78+
mounted() {
79+
/* ✓ GOOD */
80+
const hash = this.$route.hash
81+
}
82+
}
83+
</script>
84+
```
85+
86+
</eslint-code-block>
87+
88+
## :mag: Implementation
89+
90+
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/no-undef-properties.js)
91+
- [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
@@ -119,6 +119,7 @@ module.exports = {
119119
'no-template-target-blank': require('./rules/no-template-target-blank'),
120120
'no-textarea-mustache': require('./rules/no-textarea-mustache'),
121121
'no-this-in-before-route-enter': require('./rules/no-this-in-before-route-enter'),
122+
'no-undef-properties': require('./rules/no-undef-properties'),
122123
'no-unregistered-components': require('./rules/no-unregistered-components'),
123124
'no-unsupported-features': require('./rules/no-unsupported-features'),
124125
'no-unused-components': require('./rules/no-unused-components'),

0 commit comments

Comments
 (0)