-
-
Notifications
You must be signed in to change notification settings - Fork 681
Allow to use @vue/component to set enable parsing vue objects #123
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
Allow to use @vue/component to set enable parsing vue objects #123
Conversation
tests/lib/rules/no-dupe-keys.js
Outdated
@@ -77,8 +77,8 @@ ruleTester.run('no-dupe-keys', rule, { | |||
|
|||
invalid: [ | |||
{ | |||
filename: 'test.vue', | |||
code: ` | |||
// filename: 'test.vue', |
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.
Please create another tests for that, don't comment actual ones. Also try case with block comment too :)
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
5ff441f
to
56a0306
Compare
@michalsnik new tests added |
c3484a4
to
eacc0d0
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.
LGTM 👍 Nice one. Only one more thing - we need to add information about this somewhere in readme, so that people actually know it's there and that it's ready to be used.
@michalsnik do you have any suggestions? I'm terrible at describing/naming stuff xd |
I was thinking about adding information in Btw. Now I realised that there might be other cases, when you for example want to create few small components inside one
such a situation might also have place in The above file could look like this:
|
@michalsnik hmm i like it, and i was thinking about it before. component definition should work only if next block is what do you think? |
There are also async components, I wonder if simple check for an object right below comment wouldn't be enough. Then it would be also possible to do:
|
@michalsnik i'm going to create separate test file for all cases to have them all in one place and i'm going to include async component to |
@michalsnik can you check if i didn't forgo about something? |
tests/lib/utils/vue-component.js
Outdated
}, | ||
{ | ||
filename: 'test.js', | ||
code: `Vue.component('async-example', function (resolve, reject) { })`, |
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.
resolve({})
missing
tests/lib/utils/vue-component.js
Outdated
parserOptions | ||
}, | ||
{ | ||
filename: 'test.js', |
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.
Add some cases with .jsx
and .vue
files too that are not to be treated as components by default.
tests/lib/utils/vue-component.js
Outdated
errors: [makeError(1)] | ||
}, | ||
{ | ||
filename: 'test.vue', |
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.
Add the same test for test.jsx
file
tests/lib/utils/vue-component.js
Outdated
{ | ||
filename: 'test.js', | ||
code: `Vue.component('async-example', function (resolve, reject) { | ||
resolve({}) |
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.
This should actually be not treated as component, we're not supporting this case by default, only with optional comment.
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
dad5cd6
to
753d86d
Compare
@michalsnik i applied all requested changes, and all tests are more generic now. |
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.
Added few suggestions and questions. Plus we still don't have an information in readme about those comments.
tests/lib/utils/vue-component.js
Outdated
code: `export default { }`, | ||
parserOptions | ||
} | ||
].concat(notFoundTests('js')).concat(notFoundTests('jsx')).concat(notFoundTests('vue')), |
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 it validTests
and invalidTests
for consistency.
tests/lib/utils/vue-component.js
Outdated
return [ | ||
{ | ||
filename: `test.${ext}`, | ||
code: `// ${ext} |
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 guess you added those comments for easier debugging?
If yes please keep them in once place, as for now I can see them on top and bottom of the code example.
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.
Yes that was the point, and i moved them to down (i forgot to this will all of them)
tests/lib/utils/vue-component.js
Outdated
return utils.executeOnVueComponent(context, obj => { | ||
context.report({ | ||
node: obj, | ||
message: 'Internal test: component.' |
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 Component detected
message would be a little bit more descriptive.
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 changed
lib/utils/index.js
Outdated
'ExportDefaultDeclaration:exit' (node) { | ||
// export default {} in .vue || .jsx | ||
if (!_this.isVueComponentFile(node, filePath)) return | ||
if (!_this.isVueComponentFile(node, filePath, context) || hasNode(node)) 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.
Why did you passed context
to isVueComponentFile
? And why did you added hasNode
here? I thought current check is ok and we only needed to add comment detection before objects?
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.
context removed and to prevent duplicates from callback, i renamed this function to isDuplicateNode
lib/utils/index.js
Outdated
cb(node.declaration) | ||
}, | ||
'CallExpression:exit' (node) { | ||
// Vue.component('xxx', {}) || component('xxx', {}) | ||
if (!_this.isVueComponent(node)) return | ||
if (!_this.isVueComponent(node) || foundNodes.some(el => el.loc.start.line === node.loc.start.line)) 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.
Why did you added here additional check too?
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.
to prevent duplicates when someone do callExpression and declare // @vue/component
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.
Ah I see, good thinking :)
tests/lib/utils/vue-component.js
Outdated
}, | ||
{ | ||
filename: `test.${ext}`, | ||
code: `// ${ext} |
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.
Please consider formatting those code example as follows:
code: `
/* @vue/component */
export default {}
`
I think they would be much easier to read :)
@michalsnik thank you for suggestions, changes applied |
Cool @armano2 Now please add info in readme and we're good to go :) Good work! |
@michalsnik now the hardest part 👎 i wrote something, but i don't like it :( |
@armano2 And what do you think about: AttentionAll component-related rules are being applied to code that passes any of the following checks:
If you however want to take advantage of our rules in any of your custom objects that are Vue components, you might need to use special comment
|
@michalsnik i like it way more i'm just terrible at writing documentations |
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 👍 But can you please also take a look @mysticatea ?
db720cf
to
93ca30f
Compare
93ca30f
to
b7b4991
Compare
@michalsnik There is one issue with this solution, it will not work with eslint 4 |
LineComment and BlockComment was removed in 4.0.0
1646194
to
ba38e5a
Compare
fixes #109