-
-
Notifications
You must be signed in to change notification settings - Fork 652
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
Rule proposition: No async in computed property functions #53
Comments
Sounds nice! I think this one will definitely fit in Could you please add few examples of code that in your opinion should cause warnings @chrisvfritz ? |
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 () {})
}
} |
I have a concern about callbacks. Can it distinguish sync or async? For example, |
@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 |
I think we should cover first 3 examples, and the last one would be to detect presence of any of |
@michalsnik Good thinking. 🙂 |
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.']
}
] |
Almost there @armano2, I have few things to mention:
computed: {
foo: {
get() {},
set() {}
}
}
|
i partially implemented those rules yesterday, but i will have a look into your helpers 🍡 thank you for feedback |
Done in |
A common issue that beginners run into is relying on async code in a computed property function, even though we warn about it in the docs. This might not be possible to identify 100% of the time, but it would be nice for the linter to warn about:
async
/await
Am I missing any cases where either of the above would actually be valid inside a computed property function?
The text was updated successfully, but these errors were encountered: