-
-
Notifications
You must be signed in to change notification settings - Fork 681
Add return-in-computed-property
rule.
#78
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
Add return-in-computed-property
rule.
#78
Conversation
computed-property-return
rule.
computed-property-return
rule.computed-property-return
rule.
86d85c6
to
dbb36d8
Compare
@michalsnik can you review this pull request? |
Sure, later today I'll try to push my PR and both of yours forward. Busy time :) |
It's my first time working with rules from eslint (developing them) but they seems not to complex to make. sorry for pushing you to test my code 🗡 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll continue checking the rest once my PR that serves as the base for all of yours is merged so the diff is more obvious :)
@@ -0,0 +1,44 @@ | |||
# Enforces that a return statement is present in computed property (computed-property-return) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd call this rule return-in-computed-property
to make it more descriptive. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm bad at naming stuff, your name is way better
- `"treatUndefinedAsUnspecified"`: `true` (default) allows implicitly returning undefined with a `return;` statement. | ||
|
||
``` | ||
vue/order-in-components: [2, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops
## :wrench: Options | ||
|
||
This rule has an object option: | ||
- `"treatUndefinedAsUnspecified"`: `true` (default) allows implicitly returning undefined with a `return;` statement. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should force to return something explicitly, thus in my opinion return;
should also trigger an error and this option should not be necessary.
We could consider two types of messages:
- There is no
return
statement insidefoo
computed property - There is an incomplete
return
statement insidefoo
computed property
What do you think @armano2 @chrisvfritz ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
damn description is invalid, i forgot to change it, by default its treating undefined as unspecified than return;
will thrown an error, but i prefer to leave a choice to disable it because undefined can be useful in some cases.
} | ||
} | ||
}, | ||
utils.executeOnVueInstance(context, properties => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be executeOnVueComponent
? And this one in computed-data
rule instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no right now there is 2 functions, executeOnVueInstance
and executeOnVueComponent
we have to distinct both of those types,
see: 281f230
Vue Component ~ Vue Instance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but I thought this matters for data
as function case, as it's ok to have data as object in vue instance, but not in component. And this rule is about return
statement in computed property which seems irrelevant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
executeOnVueInstance
supports components
& new vue
i just renamed function to simplified merges and improve readability.
computed-property-return
rule.return-in-computed-property
rule.
12eb0f1
to
253a86e
Compare
@michalsnik cleaned up and merged |
Will this also flag computed properties that technically have a return somewhere in their content, but not directly? For example: computed: {
foo: function () {
function bar () {
return this.baz * 2
}
bar()
}
} |
@chrisvfritz yes (test for this case added) i think i should make distinction in messages based on |
message: 'Expected to return a value in "foo" computed property.', | ||
line: 4 | ||
}] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add invalid tests for treatUndefinedAsUnspecified
option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mysticatea added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @armano2 !
This PR implements rules proposed in #75
DONE:
return
return
valuetreatUndefinedAsUnspecified
- disallows implicitly returning undefined with areturn;
statement.