Skip to content
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

To ignore rules in some lines #138

Closed
nasu opened this issue May 13, 2016 · 11 comments
Closed

To ignore rules in some lines #138

nasu opened this issue May 13, 2016 · 11 comments

Comments

@nasu
Copy link

nasu commented May 13, 2016

I would like to ignore rules in some lines. Are there any plans to adopt such a functions?

It assume that I set the rule of "tag-pair" and I have a file of following HTML's snippet.

<div class="item">
    <div class="item-name"><%= name %></div           // Oops! I forgot to write &gt; sign...
    <div class="item-price"><%= price %><%= unit %></div>
<!-- close-tag against "div class=item" is defined other snippets -->

In this case, I will find two errors of "tag-pair" in Line 2 and 5. But I want to skip the error of Line 5 because of expecting.

So I suppose how to write following.

<div class="item" data-htmlhint-ignore="tag-pair">
    <div class="item-name"><%= name %></div           // Oops! I forgot to write &gt; sign...
    <div class="item-price"><%= price %><%= unit %></div>
<!-- close-tag against "div class=item" is defined other snippets -->

And I can modify src/rules/tag-pair.js

HTMLHint(master)> git di src/
diff --git a/src/rules/tag-pair.js b/src/rules/tag-pair.js
index 060e941..454ca3f 100644
--- a/src/rules/tag-pair.js
+++ b/src/rules/tag-pair.js
@@ -49,6 +49,14 @@ HTMLHint.addRule({
             }
             if(arrTags.length > 0){
                 var lastEvent = stack[stack.length-1];
+                var matches = /data-htmlhint-ignore="(.+)?"/.exec(lastEvent.raw);
+                if (matches.length) {
+                    var rules = matches[1].split(/[,\s]+/);
+                    if (rules.some(function (rule) { return self.id === rule; })) {
+                        // skip
+                        return;
+                    }
+                }
                 reporter.error('Tag must be paired, missing: [ '+ arrTags.join('') + ' ], open tag match failed [ ' + lastEvent.raw + ' ] on line ' + lastEvent.line + '.', event.line, event.col, self, '');
             }
         });

Would you consider it?
Thank you for your time.

@yaniswang
Copy link
Contributor

HTMLHint only support html code, your code is template.

@nasu
Copy link
Author

nasu commented May 16, 2016

Thank you for your response. As you say, my code is a template. Don't you have a plan to support template - HTML snipet?

@yaniswang
Copy link
Contributor

I have no idea to support template.
You can hint the html code after rendered.

@nasu
Copy link
Author

nasu commented May 16, 2016

Yes! I understood. Thanks! 😄

@xianshenglu
Copy link

However, the true question is how can i ignore some lines?

@xianshenglu
Copy link

xianshenglu commented Jun 10, 2019

Is there any choices like <!--htmlhint disable-->, <!--htmlhint enable-->, <!--htmlhint disable-next-line --> etc ?

@Shinigami92
Copy link
Contributor

Is there any choices like <!--htmlhint disable-->, <!--htmlhint enable-->, <!--htmlhint disable-next-line --> etc ?

I think no, but I like the idea/syntax

@xianshenglu
Copy link

because eslint, stylelint all support such function and their syntax was all like this. Hope if can support it.

@Shinigami92
Copy link
Contributor

@xianshenglu I think the best idea is to open a new issue with title proposal, because this issue is old and closed for a long time
Also @thedaviddias is the admin of this project, hopefully he likes this idea too
I'm working on other projects and are not using html anymore, but I am active in comment sections like this
Maybe you can then provide a pull request and I can review it

@xianshenglu
Copy link

#161 This proposal has already existed.

@Shinigami92
Copy link
Contributor

in this case you should suggest your proposal there 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants