Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add option to ignore comments invue/multiline-html-element-content-newline#2581

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
dsl101 wants to merge5 commits intovuejs:master
base:master
Choose a base branch
Loading
fromdsl101:ignore-comments

Conversation

dsl101
Copy link
Contributor

@dsl101dsl101 commentedOct 23, 2024
edited by FloEdelmann
Loading

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.

@dsl101dsl101 changed the titleAdd option to ignore comments when enforcing rulesAdd option to ignore comments invue/multiline-html-element-content-newlineOct 23, 2024
@dsl101
Copy link
ContributorAuthor

If the approach is OK, I'll add to the docs

@FloEdelmann
Copy link
Member

Looks good to me 🙂
Please go ahead and adjust the docs now 😉

@FloEdelmann
Copy link
Member

And could you also add the same option tovue/singleline-html-element-content-newline as well please?

@dsl101
Copy link
ContributorAuthor

dsl101 commentedOct 23, 2024
edited
Loading

And could you also add the same option tovue/singleline-html-element-content-newline as well please?

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, withignoreComments: true this test failes:

  valid:[{code:`      <template>        <div attr> <!-- comment --> </div>      </template>`,options:[{ignoreComments:true}]}]

with these errors:

  1) singleLineRule       valid      <template>        <div attr> <!-- comment --> </div>      </template>:      AssertionError [ERR_ASSERTION]: Should have no errors but had 2: [  {    ruleId: 'singleLineRule',    severity: 1,    message: 'Expected 1 line break after opening tag (`<div>`), but no line breaks found.',    line: 3,    column: 19,    nodeType: 'HTMLTagClose',    messageId: 'unexpectedAfterClosingBracket',    endLine: 3,    endColumn: 37,    fix: { range: [Array], text: '\n' }  },  {    ruleId: 'singleLineRule',    severity: 1,    message: 'Expected 1 line break before closing tag (`</div>`), but no line breaks found.',    line: 3,    column: 19,    nodeType: 'HTMLEndTagOpen',    messageId: 'unexpectedBeforeOpeningBracket',    endLine: 3,    endColumn: 37,    fix: { range: [Array], text: '\n' }  }]

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 testelem.children.length === 0andgetFirstTokensBetween().length === 0—indeed, commenting that line out:

if(ignoreWhenEmpty&&// elem.children.length === 0 &&template.getFirstTokensBetween(elem.startTag,elem.endTag,getTokenOption).length===0){return}

then makes this valid:

<template><divattr><!-- comment --></div></template>`

but still reports errors for this:

<template><divattr> content<!-- comment --></div></template>`

@FloEdelmann
Copy link
Member

FloEdelmann commentedOct 24, 2024
edited
Loading

I'm not sure why it's required to testelem.children.length === 0andgetFirstTokensBetween().length === 0

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 theelem.children.length check should be fine.

@dsl101
Copy link
ContributorAuthor

Ah, this is a bit more complicated than I thought. Without my proposed changes, the default settings forsingleline-html-element-content-newline give these test results:

  1. <div></div> → OK
  2. <div> </div> → OK
  3. <div attr></div> → OK
  4. <div attr> </div> → Fail

I'm not sure if the behaviour here is really consistent—shouldn't 2 and 4 give the same result? Because the setting isignoreWhenNoAttributes and defaults totrue, I can't see a way to configure that case 4 passes the test. Is the only option here to just disable thesingleline-html-element-content-newline rule altogether?

It complicates my use case, as it's very common to put white space around comments, but then that white space counts as 'content':

<div attr><!-- comment --></div> → OK
<div attr> <!-- comment --> </div> → Fail

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.

@FloEdelmann
Copy link
Member

It seems that the simple fix is also not working correctly formultiline-html-element-content-newline, seehttps://deploy-preview-2581--eslint-plugin-vue.netlify.app/rules/multiline-html-element-content-newline.html#ignorecomments-true:

<template><!-- should be good, but actually is reported because the div is now 2 line breaks below the template-->  <divclass="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 thesingleline-html-element-content-newline rule.

Copy link
Member

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 tovue/singleline-html-element-content-newline from this rule docs page?

And also vice-versa a link fromvue/singleline-html-element-content-newline tovue/multiline-html-element-content-newline.

Copy link
ContributorAuthor

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 wouldalmost always wantallowEmptyLines: true since it's not clear how many empty lines you'll have. I couldn't see an easy way around that.

Copy link
ContributorAuthor

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...

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@FloEdelmannFloEdelmannFloEdelmann left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Ignore HTML comments invue/multiline-html-element-content-newline
2 participants
@dsl101@FloEdelmann

[8]ページ先頭

©2009-2025 Movatter.jp