Skip to content

Custom rules not working #1381

@LucEnden

Description

@LucEnden

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;

  • Using differnet paths for the rulesdir option
  • Different implementations for my rule file

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions