Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New: add no-use-computed-property-like-method rules #1234

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b14d0f3
chore: init rule
tyankatsu0105 Jul 7, 2020
6b0b860
feat: getable methodProperties
tyankatsu0105 Oct 10, 2020
4d8ae20
feat: move getMethodProperties into util
tyankatsu0105 Oct 10, 2020
7aaf02d
feat: pass rule
tyankatsu0105 Oct 10, 2020
f5c426c
feat: remove getMethodProperties
tyankatsu0105 Oct 10, 2020
e97c749
docs: add docs
tyankatsu0105 Oct 10, 2020
c61acae
chore: run update
tyankatsu0105 Oct 10, 2020
587d808
feat: check return type of data props methods computed
tyankatsu0105 Nov 13, 2020
f460c6f
feat: add types to eslint utils getStaticValue
tyankatsu0105 Nov 13, 2020
969120a
feat: refactor rule
tyankatsu0105 Nov 14, 2020
7ce7a03
docs: fix docs
tyankatsu0105 Nov 14, 2020
cc7cde4
docs: fix docs
tyankatsu0105 Nov 14, 2020
62b82be
feat: change report node
tyankatsu0105 Nov 14, 2020
c614b6d
chore: remove unused file
tyankatsu0105 Nov 14, 2020
13eff80
refactor: improve JSDoc
tyankatsu0105 Nov 14, 2020
01c4f84
docs: remove template
tyankatsu0105 Nov 14, 2020
9c54158
docs: fix docs
tyankatsu0105 Nov 14, 2020
00dc589
docs: fix docs
tyankatsu0105 Nov 14, 2020
78c203d
feat: change target node
tyankatsu0105 Nov 14, 2020
96fecb1
feat: rename getComponentPropsType
tyankatsu0105 Dec 4, 2020
3edce05
Merge branch 'master' into feat/add-no-use-computed-property-like-method
tyankatsu0105 May 1, 2021
330d188
rename eslint
tyankatsu0105 May 2, 2021
11b7ef1
refactor: rename PropertyMap
tyankatsu0105 May 2, 2021
8b825e5
refactor: improve if statement
tyankatsu0105 May 2, 2021
2e316f8
Revert "refactor: improve if statement"
tyankatsu0105 May 2, 2021
d8a8af9
feat: consider basic props type
tyankatsu0105 May 2, 2021
986648b
chore: run update
tyankatsu0105 May 2, 2021
b06421b
refactor improve selector
tyankatsu0105 May 2, 2021
7459eea
feat: addPropertyMap
tyankatsu0105 May 2, 2021
d885a36
refactor: use findProperty
tyankatsu0105 May 3, 2021
ccbee98
refactor: add comment
tyankatsu0105 May 3, 2021
c2bc020
feat: cover ThisExpression
tyankatsu0105 May 3, 2021
c082183
Merge branch 'master' into feat/add-no-use-computed-property-like-method
tyankatsu0105 Jul 17, 2021
3b77c4e
feat: support return statement return nothing
tyankatsu0105 Jul 17, 2021
ce93fa6
fix: support undefined of propertyMap[thisMember]
tyankatsu0105 Jul 17, 2021
60e7c48
style: run lint
tyankatsu0105 Jul 17, 2021
7cb18fe
test: add test case
tyankatsu0105 Jul 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/rules/README.md
Expand Up @@ -320,6 +320,7 @@ For example:
| [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 | |
| [vue/no-unused-refs](./no-unused-refs.md) | disallow unused refs | |
| [vue/no-use-computed-property-like-method](./no-use-computed-property-like-method.md) | disallow use computed property like method | |
| [vue/no-useless-mustaches](./no-useless-mustaches.md) | disallow unnecessary mustache interpolations | :wrench: |
| [vue/no-useless-v-bind](./no-useless-v-bind.md) | disallow unnecessary `v-bind` directives | :wrench: |
| [vue/padding-line-between-blocks](./padding-line-between-blocks.md) | require or disallow padding lines between blocks | :wrench: |
Expand Down Expand Up @@ -365,7 +366,7 @@ The following rules extend the rules provided by ESLint itself and apply them to
| [vue/no-restricted-syntax](./no-restricted-syntax.md) | disallow specified syntax | |
| [vue/no-sparse-arrays](./no-sparse-arrays.md) | disallow sparse arrays | |
| [vue/no-useless-concat](./no-useless-concat.md) | disallow unnecessary concatenation of literals or template literals | |
| [vue/object-curly-newline](./object-curly-newline.md) | enforce consistent line breaks after opening and before closing braces | :wrench: |
| [vue/object-curly-newline](./object-curly-newline.md) | enforce consistent line breaks inside braces | :wrench: |
| [vue/object-curly-spacing](./object-curly-spacing.md) | enforce consistent spacing inside braces | :wrench: |
| [vue/object-property-newline](./object-property-newline.md) | enforce placing object properties on separate lines | :wrench: |
| [vue/operator-linebreak](./operator-linebreak.md) | enforce consistent linebreak style for operators | :wrench: |
Expand Down
340 changes: 340 additions & 0 deletions docs/rules/no-use-computed-property-like-method.md
@@ -0,0 +1,340 @@
---
pageClass: rule-details
sidebarDepth: 0
title: vue/no-use-computed-property-like-method
description: disallow use computed property like method
---
# vue/no-use-computed-property-like-method

> disallow use computed property like method

- :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 disallows to use computed property like method.

<eslint-code-block :rules="{'vue/no-use-computed-property-like-method': ['error']}">

```vue
<script>
export default {
data() {
return {
dataString: 'dataString',
dataNumber: 10,
dataObject: {
inside: 'inside'
},
dataArray: [1, 2, 3, 4, 5],
dataBoolean: true,
dataFunction() {
alert('dataFunction')
}
}
},
props: {
propsString: String,
propsNumber: Number,
propsObject: Object,
propsArray: Array,
propsBoolean: Boolean,
propsFunction: Function,

objectPropsString: {
type: String
},
objectPropsNumber: {
type: Number
},
objectPropsObject: {
type: Object
},
objectPropsArray: {
type: Array
},
objectPropsBoolean: {
type: Boolean
},
objectPropsFunction: {
type: Function
}
},
computed: {
computedReturnDataString() {
return this.dataString
},
computedReturnDataNumber() {
return this.dataNumber
},
computedReturnDataObject() {
return this.dataObject
},
computedReturnDataArray() {
return this.dataArray
},
computedReturnDataBoolean() {
return this.dataBoolean
},
computedReturnDataFunction() {
return this.dataFunction
},

computedReturnPropsString() {
return this.propsString
},
computedReturnPropsNumber() {
return this.propsNumber
},
computedReturnPropsObject() {
return this.propsObject
},
computedReturnPropsArray() {
return this.propsArray
},
computedReturnPropsBoolean() {
return this.propsBoolean
},
computedReturnPropsFunction() {
return this.propsFunction
},

computedReturnObjectPropsString() {
return this.objectPropsString
},
computedReturnObjectPropsNumber() {
return this.objectPropsNumber
},
computedReturnObjectPropsObject() {
return this.objectPropsObject
},
computedReturnObjectPropsArray() {
return this.objectPropsArray
},
computedReturnObjectPropsBoolean() {
return this.objectPropsBoolean
},
computedReturnObjectPropsFunction() {
return this.objectPropsFunction
},

computedReturnString() {
return 'computedReturnString'
},
computedReturnNumber() {
return 10
},
computedReturnObject() {
return {
inside: 'inside'
}
},
computedReturnArray() {
return [1, 2, 3, 4, 5]
},
computedReturnBoolean() {
return true
},
computedReturnFunction() {
const fn = () => alert('computedReturnFunction')
return fn
},

computedReturnMethodsReturnString() {
return this.methodsReturnString
},
computedReturnMethodsReturnNumber() {
return this.methodsReturnNumber
},
computedReturnMethodsReturnObject() {
return this.methodsReturnObject
},
computedReturnMethodsReturnArray() {
return this.methodsReturnArray
},
computedReturnMethodsReturnBoolean() {
return this.methodsReturnBoolean
},
computedReturnMethodsReturnFunction() {
return this.methodsReturnFunction
}
},
methods: {
methodsReturnString() {
return 'methodsReturnString'
},
methodsReturnNumber() {
return 'methodsReturnNumber'
},
methodsReturnObject() {
return {
inside: 'inside'
}
},
methodsReturnArray() {
return [1, 2, 3, 4, 5]
},
methodsReturnBoolean() {
return true
},
methodsReturnFunction() {
const fn = () => alert('methodsReturnFunction')
return fn
},

fn() {
/* Reference data */
/* ✓ GOOD */
this.computedReturnDataString
this.computedReturnDataNumber
this.computedReturnDataObject
this.computedReturnDataArray
this.computedReturnDataBoolean
this.computedReturnDataFunction
this.computedReturnDataFunction()
/* ✗ BAD */
this.computedReturnDataString()
this.computedReturnDataNumber()
this.computedReturnDataObject()
this.computedReturnDataArray()
this.computedReturnDataBoolean()

/* Reference props */
/* ✓ GOOD */
this.computedReturnPropsString
this.computedReturnPropsNumber
this.computedReturnPropsObject
this.computedReturnPropsArray
this.computedReturnPropsBoolean
this.computedReturnPropsFunction
this.computedReturnPropsFunction()
/* ✗ BAD */
this.computedReturnPropsString()
this.computedReturnPropsNumber()
this.computedReturnPropsObject()
this.computedReturnPropsArray()
this.computedReturnPropsBoolean()

/* ✓ GOOD */
this.computedReturnObjectPropsString
this.computedReturnObjectPropsNumber
this.computedReturnObjectPropsObject
this.computedReturnObjectPropsArray
this.computedReturnObjectPropsBoolean
this.computedReturnObjectPropsFunction
this.computedReturnObjectPropsFunction()
/* ✗ BAD */
this.computedReturnObjectPropsString()
this.computedReturnObjectPropsNumber()
this.computedReturnObjectPropsObject()
this.computedReturnObjectPropsArray()
this.computedReturnObjectPropsBoolean()

/* Reference computed */
/* ✓ GOOD */
this.computedReturnString
this.computedReturnNumber
this.computedReturnObject
this.computedReturnArray
this.computedReturnBoolean
this.computedReturnFunction
this.computedReturnFunction()
/* ✗ BAD */
this.computedReturnString()
this.computedReturnNumber()
this.computedReturnObject()
this.computedReturnArray()
this.computedReturnBoolean()

/* Reference methods */
/* ✓ GOOD */
this.computedReturnMethodsReturnString
this.computedReturnMethodsReturnNumber
this.computedReturnMethodsReturnObject
this.computedReturnMethodsReturnArray
this.computedReturnMethodsReturnBoolean
this.computedReturnMethodsReturnFunction
this.computedReturnMethodsReturnFunction()
/* ✗ BAD */
this.computedReturnMethodsReturnString()
this.computedReturnMethodsReturnNumber()
this.computedReturnMethodsReturnObject()
this.computedReturnMethodsReturnArray()
this.computedReturnMethodsReturnBoolean()
}
}
}
</script>
```

</eslint-code-block>

This rule can't check if props is used as array:

<eslint-code-block :rules="{'vue/no-use-computed-property-like-method': ['error']}">

```vue
<script>
export default {
props: [
'propsString',
'propsNumber',
'propsObject',
'propsArray',
'propsBoolean',
'propsFunction'
],
computed: {
computedReturnPropsString() {
return this.propsString
},
computedReturnPropsNumber() {
return this.propsNumber
},
computedReturnPropsObject() {
return this.propsObject
},
computedReturnPropsArray() {
return this.propsArray
},
computedReturnPropsBoolean() {
return this.propsBoolean
},
computedReturnPropsFunction() {
return this.propsFunction
}
},
methods: {
fn() {
/* Reference props */
/* ✓ GOOD */
this.computedReturnPropsString
this.computedReturnPropsString()
this.computedReturnPropsNumber
this.computedReturnPropsNumber()
this.computedReturnPropsObject
this.computedReturnPropsObject()
this.computedReturnPropsArray
this.computedReturnPropsArray()
this.computedReturnPropsBoolean
this.computedReturnPropsBoolean()
this.computedReturnPropsFunction
this.computedReturnPropsFunction()
/* ✗ BAD */
/* Nope. everything is GOOD!! */
}
}
}
</script>
```

</eslint-code-block>

## :wrench: Options

Nothing.

## :mag: Implementation

- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/no-use-computed-property-like-method.js)
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/no-use-computed-property-like-method.js)
4 changes: 2 additions & 2 deletions docs/rules/object-curly-newline.md
Expand Up @@ -2,12 +2,12 @@
pageClass: rule-details
sidebarDepth: 0
title: vue/object-curly-newline
description: enforce consistent line breaks after opening and before closing braces
description: enforce consistent line breaks inside braces
since: v7.0.0
---
# vue/object-curly-newline

> enforce consistent line breaks after opening and before closing braces
> enforce consistent line breaks inside braces

- :wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule.

Expand Down
1 change: 1 addition & 0 deletions lib/index.js
Expand Up @@ -122,6 +122,7 @@ module.exports = {
'no-unused-properties': require('./rules/no-unused-properties'),
'no-unused-refs': require('./rules/no-unused-refs'),
'no-unused-vars': require('./rules/no-unused-vars'),
'no-use-computed-property-like-method': require('./rules/no-use-computed-property-like-method'),
'no-use-v-if-with-v-for': require('./rules/no-use-v-if-with-v-for'),
'no-useless-concat': require('./rules/no-useless-concat'),
'no-useless-mustaches': require('./rules/no-useless-mustaches'),
Expand Down