htmlhint / HTMLHint

⚙️ The static code analysis tool you need for your HTML
https://htmlhint.com
MIT License
3.08k stars 383 forks source link

Custom rules not working #1381

Closed LucEnden closed 10 months ago

LucEnden commented 11 months ago

Describe the bug None of my custom rules seem to work.

Bellow is a testing rule I have setup (linting/htmlhint/no-div.js):

module.exports = HTMLHint => {
    HTMLHint.addRule({
        id: 'no-div',
        description: 'Description of my rule',
        init(parser, reporter) {
            const self = this;
            parser.addListener('tagstart', event => {
                const tagName = event.tagName.toLowerCase();
                if (tagName === 'div') {
                    reporter.warn('Do not use divs!', event.line, event.col, self, event.raw);
                }
            });
        },
    });
};

.htmlhintrc:

{
    "rulesdir": ["linting/htmlhint"],
    "no-div": true,
    "tagname-lowercase": false,
    "attr-lowercase": false,
    "attr-value-double-quotes": true,
    "doctype-first": false,
    "tag-pair": true,
    "spec-char-escape": true,
    "id-unique": true,
    "src-not-empty": true,
    "attr-no-duplication": true,
    "title-require": true
}

test file (test.html):

<div>test</div>

I run npx htmlhint, which finds the right config file, but my rule does not trigger.

To Reproduce Steps to reproduce the behavior:

  1. Use npm install --save-dev htmlhint@1.1.4
  2. Recreate the file structure as described in the description
  3. run npx htmlhint, which finds the right config file, but my rule does not trigger.
  4. No linting errors reported

Expected behavior An error should be reported that I am using a div

Screenshots image

Edit: I already tried the following;

terenc3 commented 10 months ago

You need to provide the rulesdir via cli not configuration file e.g. npx htmlhint --rulesdir linting/htmlhint/

LucEnden commented 10 months ago

You need to provide the rulesdir via cli not configuration file e.g. npx htmlhint --rulesdir linting/htmlhint/

I will be trying this tonight

LucEnden commented 10 months ago

I will be trying this tonight The error persists when specifying the rules dir via the CLI image

mehakkumar08 commented 10 months ago

@LucEnden did you find out a solution? i'm trying to add custom rules & i got the same result as you

LucEnden commented 10 months ago

@LucEnden did you find out a solution? i'm trying to add custom rules & i got the same result as you

I opted to use custom logic (Python script) to implement my linting. I have removed HTMLHint from my application

So no, I did not find a solution for this particular problem.