BenoitZugmeyer / eslint-plugin-html

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

How does the indent rule work? I always get errors no matter what formatting. #105

Closed trusktr closed 5 years ago

trusktr commented 5 years ago

I'm trying to learn how the indent rule work. I have some code that I think is formatted well, but I get an error. This my config:

    settings: {
        'html/html-extensions': ['.html'],
        'html/indent': 'tab',
        'html/report-bad-indent': 'error',
    },

And I get this error:

screen shot 2018-10-27 at 5 42 48 pm screen shot 2018-10-27 at 5 42 56 pm screen shot 2018-10-27 at 5 43 50 pm

(same error on that last one).

If I change the config to 'html/indent': '+2',, then I get the same error on all lines:

screen shot 2018-10-27 at 5 45 50 pm

What does this option do exactly?

BenoitZugmeyer commented 5 years ago

Sorry for the late answer. Is the documentation not clear enough?

So: in your first configuration, you are using "tab". The first JS line should be indented with a single tab, no space. Ex:

»   »   <script>
»   const $ = require('jquery')
»   ...

Using "+tab", you'll need to indent your code relatively to the <script> tag, ex:

»   »   <script>
»   »   »   const $ = require('jquery')
»   »   »   ...

By using "+2", you'll need to indent your code with 2 spaces relatively to the <script> tag, ex:

········<script>
··········const $ = require('jquery')
··········...

Let me know if it is not clear.

trusktr commented 5 years ago

@BenoitZugmeyer Hi, thanks for the reply. Ah, I get it, so I needed the +.