-
-
Notifications
You must be signed in to change notification settings - Fork 666
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 option to ignore comments in vue/multiline-html-element-content-newline
#2581
base: master
Are you sure you want to change the base?
Conversation
vue/multiline-html-element-content-newline
If the approach is OK, I'll add to the docs |
Looks good to me 🙂 |
And could you also add the same option to |
I'm unsure how to do this, as a straight copy / paste of the changes into that rule doesn't quite work the same. For example, with valid: [{
code: `
<template>
<div attr> <!-- comment --> </div>
</template>`,
options: [
{
ignoreComments: true
}
]
}] with these errors:
But if I remove the whitespace around the comment: valid: [{
code: `
<template>
<div attr><!-- comment --></div>
</template>`,
options: [
{
ignoreComments: true
}
]
}] the test passes fine. I didn't see this issue in the multiline rule. In this section of the rule code here: if (
ignoreWhenEmpty &&
elem.children.length === 0 &&
template.getFirstTokensBetween(
elem.startTag,
elem.endTag,
getTokenOption
).length === 0
) {
return
} I'm not sure why it's required to test if (
ignoreWhenEmpty &&
// elem.children.length === 0 &&
template.getFirstTokensBetween(
elem.startTag,
elem.endTag,
getTokenOption
).length === 0
) {
return
} then makes this valid: <template>
<div attr> <!-- comment --> </div>
</template>` but still reports errors for this: <template>
<div attr> content <!-- comment --> </div>
</template>` |
Probably it is indeed not needed, seems like both were added at the same time in #684. I guess if the other tests are passing, then removing the |
Ah, this is a bit more complicated than I thought. Without my proposed changes, the default settings for
I'm not sure if the behaviour here is really consistent—shouldn't 2 and 4 give the same result? Because the setting is It complicates my use case, as it's very common to put white space around comments, but then that white space counts as 'content':
But I think that's OK, and is consistent with the existing rules / tests. I'll push an update with documentation for you to see. |
It seems that the simple fix is also not working correctly for <template>
<!-- should be good, but actually is reported because the div is now 2 line breaks below the template -->
<div class="red"> <!-- no error is reported here -->
content
</div>
</template> So apparently a more elaborate logic is needed after all, probably that logic can then also be used for the |
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.
By the way, while you're at it: Could you please add a "Related rules" section here and link to vue/singleline-html-element-content-newline
from this rule docs page?
And also vice-versa a link from vue/singleline-html-element-content-newline
to vue/multiline-html-element-content-newline
.
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, since comments are ignored, you would almost always want allowEmptyLines: true
since it's not clear how many empty lines you'll have. I couldn't see an easy way around that.
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 love to spend more time digging in, but I'm afraid I have to get back to the project I'm using this on! I guess I'll just have to disable those rules for now...
Fixes #2179
I finally got around to looking at a PR. It seems deceptively simple, so not sure if it broke something elsewhere, but no other tests seemed affected.