Skip to content

Commit

Permalink
Add vue/no-undef-properties rule
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Jul 30, 2021
1 parent ea1be9f commit 251dfdf
Show file tree
Hide file tree
Showing 5 changed files with 1,973 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/rules/README.md
Expand Up @@ -317,6 +317,7 @@ For example:
| [vue/no-static-inline-styles](./no-static-inline-styles.md) | disallow static inline `style` attributes | |
| [vue/no-template-target-blank](./no-template-target-blank.md) | disallow target="_blank" attribute without rel="noopener noreferrer" | |
| [vue/no-this-in-before-route-enter](./no-this-in-before-route-enter.md) | disallow `this` usage in a `beforeRouteEnter` method | |
| [vue/no-undef-properties](./no-undef-properties.md) | disallow undefined properties | |
| [vue/no-unregistered-components](./no-unregistered-components.md) | disallow using components that are not registered inside templates | |
| [vue/no-unsupported-features](./no-unsupported-features.md) | disallow unsupported Vue.js syntax on the specified version | :wrench: |
| [vue/no-unused-properties](./no-unused-properties.md) | disallow unused properties | |
Expand Down
90 changes: 90 additions & 0 deletions docs/rules/no-undef-properties.md
@@ -0,0 +1,90 @@
---
pageClass: rule-details
sidebarDepth: 0
title: vue/no-undef-properties
description: disallow undefined properties
---
# vue/no-undef-properties

> disallow undefined properties
- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>

## :book: Rule Details

This rule warns of using undefined properties.
This rule can help you locate potential errors resulting from misspellings property names, and implicitly added properties.

::: warning Note
This rule cannot detect properties defined in other files or components.
:::

<eslint-code-block :rules="{'vue/no-undef-properties': ['error']}">

```vue
<template>
<!-- ✓ GOOD -->
<div>{{ name }}: {{ count }}</div>
<!-- ✗ BAD -->
<div>{{ label }}: {{ cnt }}</div>
</template>
<script>
export default {
props: ['name'],
data () {
return {
count: 0
}
},
methods: {
click() {
/* ✓ GOOD */
this.count++
/* ✗ BAD */
this.cnt++
}
}
}
</script>
```

</eslint-code-block>

## :wrench: Options

```json
{
"vue/no-undef-properties": ["error", {
"ignores": ["/^\\$/"]
}]
}
```

- `ignores` (`string[]`) ... An array of property names or patterns that have already been defined property, or property to ignore from the check. Default is `["/^\\$/"]`.

### `"ignores": ["/^\\$/"]` (default)

<eslint-code-block :rules="{'vue/no-undef-properties': ['error', {ignores: ['/^\\$/']}]}">

```vue
<template>
<!-- ✓ GOOD -->
<div>{{ $t('foo') }}</div>
</template>
<script>
export default {
mounted() {
/* ✓ GOOD */
const hash = this.$route.hash
}
}
</script>
```

</eslint-code-block>

## :mag: Implementation

- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/no-undef-properties.js)
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/no-undef-properties.js)
1 change: 1 addition & 0 deletions lib/index.js
Expand Up @@ -117,6 +117,7 @@ module.exports = {
'no-template-target-blank': require('./rules/no-template-target-blank'),
'no-textarea-mustache': require('./rules/no-textarea-mustache'),
'no-this-in-before-route-enter': require('./rules/no-this-in-before-route-enter'),
'no-undef-properties': require('./rules/no-undef-properties'),
'no-unregistered-components': require('./rules/no-unregistered-components'),
'no-unsupported-features': require('./rules/no-unsupported-features'),
'no-unused-components': require('./rules/no-unused-components'),
Expand Down

0 comments on commit 251dfdf

Please sign in to comment.