BenoitZugmeyer / eslint-plugin-html

An ESLint plugin to extract and lint scripts from HTML files.
ISC License
430 stars 51 forks source link

Errors that occur at position 0 are not reported. #56

Closed mtbradle-ge closed 7 years ago

mtbradle-ge commented 7 years ago

When the position that the rule is broken occurs at the very beginning of a script tag, the error does not seem to be reported.

Here is a bare minimum repository that can reproduce the issue:

https://github.com/mtbradle-ge/eslint-plugin-html-max-lines-bug

Just clone and run eslint . --ext .html

No errors are reported for the bug.html for max-lens or max-lines as specified in the config, even though they are clearly present.

This seems to be because line 84 of TransformableString.js:

      if (index < block.from + block.str.length) {
        return
      }

Changing the return to a break seemed to mitigate the issue...?

BenoitZugmeyer commented 7 years ago

Thank you for the report. This code in TransformableString is actually here to ignore messages for lints located inside the removed HTML parts. I am planning to change how this plugin works for the next major version: HTML parts won't be replaced by anything, instead script tags will be linted independently. This should resolve this kind of issue altogether.

For now, I added your test case to the test suit, so I won't miss it for the next version!

BenoitZugmeyer commented 7 years ago

I released a beta version of eslint-plugin-html, you can test it with npm install eslint-plugin-html@next. I'll release a final version after eslint 4 is released.

Changes are listed here.