BenoitZugmeyer / eslint-plugin-html

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

Can eslint-plugin-html be used to enforce initial indentation inside <script> tags? #12

Closed klebba closed 8 years ago

klebba commented 8 years ago

I want to enforce an indentation style of script tags:

<script>
    // code indented four spaces
</script>

vs.

<script>
// code has no initial indentation
</script>

Is this possible with eslint-plugin-html?

Thanks

BenoitZugmeyer commented 8 years ago

That's a good idea, I'll work on this soon.

BenoitZugmeyer commented 8 years ago

@klebba I rewrote pretty much everything and now it has two options, "html/indent" and "html/report-bad-indent". Could you test it and tell me if it works in your use case? See the Settings section of the README.

klebba commented 8 years ago

@BenoitZugmeyer I gave it a try; it's not quite working for me yet. I have configured to use "+2" spaces but the linter does not complain for this snippet:

<script>
(function () {
  var myvar;
})();
</script>

It does complain for this one:

<script>
(function () {
var myvar;
})();
</script>

I haven't tried many more cases yet

BenoitZugmeyer commented 8 years ago

Thank you for trying this. I tried to reproduce without success. Could you make sure you have the latest master version by running npm install git+https://github.com/BenoitZugmeyer/eslint-plugin-html (maybe with -g if you installed eslint globally), then:

git clone https://gist.github.com/BenoitZugmeyer/405d6299837300fe9efb report-bad-indent-test
cd report-bad-indent-test
eslint test.html

In my case I've got the following output:

/home/.../tmp/report-bad-indent-test/test.html
  2:1  error  Bad line indentation  (html plugin)
  4:1  error  Bad line indentation  (html plugin)

✖ 2 problems (2 errors, 0 warnings)
klebba commented 8 years ago

Ok, that does work -- the reason it was failing is that the Atom editor does not run the rule until you interact with the contents of the script tag. Not an issue with eslint-plugin-html -- thanks!

BenoitZugmeyer commented 8 years ago

Lot of Atom users today :grin: I'll make a release soon, probably tomorrow.