-
-
Notifications
You must be signed in to change notification settings - Fork 681
Add rule require-render-return
.
#114
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
Conversation
9d6d85f
to
e4e31af
Compare
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.
Thank you for contributing! I'm sorry for the delay.
Mostly looks good to me. But I'm not sure Array#filter
and Array#forEach
is proper in this case. I left a few comments.
lib/rules/require-render-return.js
Outdated
|
||
return utils.executeOnVue(context, obj => { | ||
obj.properties | ||
.filter(item => item.type === 'Property' && |
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 that Array#find
fits more in this case.
render: () => null | ||
}`, | ||
parserOptions | ||
} |
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 tests that this rule does not report functions which are not the render
?
@mysticatea merged and few additional tests added |
code: `Vue.component('test', { | ||
render: function () { | ||
if (a) { | ||
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.
and what about:
render() {
if (a) {
return `<div>a</div>`
} else {
return `<span>a</span>`
}
}
?
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.
@michalsnik i forgot about this case, thank you 🍡
@michalsnik issue with |
56d5f2d
to
3a83a68
Compare
lib/utils/index.js
Outdated
}, | ||
|
||
/** | ||
* Find all function witch do not allways return values |
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.
Should be: Find all functions which do not always return values
lib/utils/index.js
Outdated
* @param {Array} nodes an array nodes | ||
* @param {boolean} treatUndefinedAsUnspecified | ||
*/ | ||
findMissingReturns (nodes, treatUndefinedAsUnspecified) { |
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.
You should avoid mutating arguments. I suggest to modify this function to be more explicit (we can even change the name a bit, to be consistent with executeOnVue
and so on):
executeOnFunctionsWithoutReturn (treatUndefinedAsUnspecified, cb) {
// ...
return {
// ...
'ArrowFunctionExpression:exit' (node) {
if (isValidReturn()) return
cb(funcInfo.node)
},
'FunctionExpression:exit' (node) {
if (isValidReturn()) return
cb(funcInfo.node)
}
}
}
Then you could use it like this:
return Object.assign({},
utils.executeOnFunctionsWithoutReturn(treatUndefinedAsUnspecified, node => {
forbiddenNodes.push(node)
}),
utils.executeOnVue(context, properties => {
// ...
})
)
I think it will be much easier to understand, and what do you think @armano2 ?
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.
seems logical, and more consistent with executeOnVue
👍
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.
LGTM 👍 Good work @armano2 :)
* master: Add rule `vue/require-valid-default-prop`. (vuejs#119) 3.10.0 Update readme to 3.10.0 Chore: remove package-lock.json (vuejs#128) Fix: parserService must exist always (fixes vuejs#125) (vuejs#127) Add rule `require-render-return`. (vuejs#114) 3.9.0 Update package-lock Update: options for `no-duplicate-attributes` (fixes vuejs#112)(vuejs#113) New: add rule `attribute-hyphenation`. (fixes vuejs#92)(vuejs#95) Add namespace check of svg & mathML instead of tag names (vuejs#120)⚠️ Add support for deprecated state in update-rules⚠️ (vuejs#121) Add rules: `no-dupe-keys` and `no-reserved-keys`. (vuejs#88) Chore: Improve tests for name-property-casing & improve documentation (vuejs#115) New: add `require-prop-types` rule (fixes vuejs#19)(vuejs#85) Update: upgrade vue-eslint-parser (fixes vuejs#36, fixes vuejs#56, fixes vuejs#96) (vuejs#116)
This PR implements rules proposed in #107
DONE:
fixes #107