Comments (10)
I think we should cover first 3 examples, and the last one would be to detect presence of any of then
, catch
or finally
in all CallExpression
s inside computed property's body. Bur I'm against checking arguments response
and res
as they might be used even if the body has nothing to do with async computing. For example application has a module that gathers users' responses for a given topic, than we could have a computed property activeResponse
in which we'd like to call a utility function with response
argument, or short res. I had similar case with route
in other plugin. I thought it's enough to check for that name and then someone had an app with generating routes on google maps :D
from eslint-plugin-vue.
Sounds nice! I think this one will definitely fit in Best practices
category.
Could you please add few examples of code that in your opinion should cause warnings @chrisvfritz ?
This way it will be easier to get anyone's head around this and later to define proper test scenarios.
from eslint-plugin-vue.
Test scenarios:
computed: {
foo: async function () {
return await someFunc()
}
}
computed: {
foo () {
return new Promise((resolve, reject) => {})
}
}
computed: {
foo () {
return fetch(url).then(response => {})
}
}
computed: {
foo () {
return funcWithCallback(function () {})
}
}
from eslint-plugin-vue.
I have a concern about callbacks. Can it distinguish sync or async? For example, return this.users.map(u => u.name)
. It may be Array#map
or Promise#map
(Bluebird).
from eslint-plugin-vue.
@mysticatea I think it'd be better to err on the side of undermatching than overmatching, but I'm thinking about a variety of strategies that could be combined for pretty good detection. For example, if there's a then
method or any argument called response
or res
.
from eslint-plugin-vue.
@michalsnik Good thinking. 🙂
from eslint-plugin-vue.
It's all or did i miss something?
invalid: [
{
filename: 'test.vue',
code: `export default {
computed: {
foo: async function () {
return await someFunc()
}
}
}`,
errors: ['Computed properies cannot have side effect.']
},
{
filename: 'test.vue',
code: `export default {
computed: {
foo: async function () {
return new Promise((resolve, reject) => {}) }
}
}
}`,
errors: ['Computed properies cannot have side effect.']
},
{
filename: 'test.vue',
code: `export default {
computed: {
foo: function () {
return bar.then(response => {})
}
}
}`,
errors: ['Computed properies cannot have side effect.']
}
{
filename: 'test.vue',
code: `export default {
computed: {
foo: function () {
return bar.catch(e => {})
}
}
}`,
errors: ['Computed properies cannot have side effect.']
},
{
filename: 'test.vue',
code: `export default {
computed: {
foo: function () {
return Promise.all([])
}
}
}`,
errors: ['Computed properies cannot have side effect.']
},
{
filename: 'test.vue',
code: `export default {
computed: {
foo: function () {
return Promise.race([])
}
}
}`,
errors: ['Computed properies cannot have side effect.']
},
{
filename: 'test.vue',
code: `export default {
computed: {
foo: function () {
return Promise.reject([])
}
}
}`,
errors: ['Computed properies cannot have side effect.']
},
{
filename: 'test.vue',
code: `export default {
computed: {
foo: function () {
return Promise.resolve([])
}
}
}`,
errors: ['Computed properies cannot have side effect.']
}
]
from eslint-plugin-vue.
Almost there @armano2, I have few things to mention:
- You missed the case with
.finally
- Message should be:
Unexpected asynchronous action in computed property "xxx"
or something similar. - We should also test cases with explicit getters and setters:
computed: {
foo: {
get() {},
set() {}
}
}
- We should wait with implementation of this rule, as I'm introducing logic that will help implementing this scenario in
no-side-effects-in-computed-property
rule.
from eslint-plugin-vue.
i partially implemented those rules yesterday, but i will have a look into your helpers 🍡
thank you for feedback
from eslint-plugin-vue.
Done in v3.8.0
🚀 Thanks @armano2 for the hard work!
from eslint-plugin-vue.
Related Issues (20)
- `vue/multi-word-component-names` also applies to pages directory HOT 2
- disallow importing macros: defineProps etc
- `vue/custom-event-name-casing`: should check and report `update:kebab-case`/`update:camelCase` event names too HOT 1
- HTML indent to extend from ESLint Stylistic HOT 1
- unmet peer eslint@"^6.2.0 || ^7.0.0 || ^8.0.0": found 9.0.0 HOT 3
- how to configure for .vue with <script setup lang="ts" HOT 4
- `getCommentsBefore` empty in Vue SFC with two `script` tags HOT 1
- Support for ESLint 9 HOT 4
- Full example for flat config with object
- Under default configuration, HelloWorld.vue in the vite ts template will be detected as an error HOT 3
- Rule proposal: no-computed-after-await HOT 1
- Flat config : Parsing error: Unexpected token ) HOT 3
- bind `:=` syntax error on `Windows` HOT 1
- `vue/no-ref-as-operand` not catching `computed` refs
- vue/use-v-on-exact - false positive on multiple @keydown.* attributes HOT 2
- Namespace handling makes it impossible to lint recursive SVG / MathML components
- Eslint is not marking not defined properties of a component as invalid HOT 6
- Suggestion: allow `["inline", "inline-function"]` option for `v-on-handler-style`
- vue/no-undef-components-exclude-auto-import HOT 3
- `v-bind` shorthand syntax without argument (`:=`) generates `vue/no-unused-vars` false positive HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eslint-plugin-vue.