question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

html-indent: Wants to indent comments too deep after multiline tags

See original GitHub issue

Tell us about your environment

  • ESLint Version: 4.19.1
  • eslint-plugin-vue Version: 4.5.0
  • Node Version: 10.3.0

Please show your full configuration:

module.exports = {
    root: true,
    plugins: ["vue"],
    extends: [
	"eslint:recommended",
	"plugin:vue/recommended",
    ],
    rules: {
	"vue/max-attributes-per-line": ["warn", {
	    "multiline": {"allowFirstLine": true}
	}],
    }
}

What did you do? Please include the actual source code causing the issue.

<template>
  <div>
    <input type="text"
           value="foo">
    <!-- comment -->
  </div>
</template>

What did you expect to happen?

There to be no problem with the file; no warnings/or errors.

What actually happened? Please include the actual, raw output from ESLint.

$ ./node_modules/.bin/eslint test.vue                                                                                    

/home/lukeshu/testcase/test.vue
  5:1  error  Expected indentation of 11 spaces but found 4 spaces  vue/html-indent

✖ 1 problem (1 error, 0 warnings)
  1 error, 0 warnings potentially fixable with the `--fix` option.

$ ./node_modules/.bin/eslint --fix test.vue                                                                                                    
$ cat test.vue                                                                                                                                 
<template>
  <div>
    <input type="text"
           value="foo">
           <!-- comment -->
  </div>
</template>

It wants to indent the comment too deep–as if it were inside of the <input> tag. This is because it is aligning to the previous line, not the previous… I’m not sure what word to use… “statement”?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mysticateacommented, Nov 23, 2018

In that TypeScript case, the previous token is an unknown token (TypeScript’s original AST), so it’s ignored. As a result, the comment is adjusted to only the next token }.

I think we can add TypeScript support to our indent rules.

0reactions
armano2commented, Nov 23, 2018

This issue is also present in js/ts code

class Foo {
  prop = 2
  // foo
}

it wants to align it to 0 indent

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTML Indentation, Spacing, and Comments
The first debate is on whether we should use spaces or tabs to indent our code. The second is on whether our indents...
Read more >
How to indent a few lines in Markdown markup?
Wrapped lines in long text are not indented which you may not want in your layout. Resize your rendered view to test. Also,...
Read more >
How To Put a Multi-Line Indent on a Styled Blockquote
This brief and easy tutorial provides a method to indent multiple lines of text around a background image on a styled <blockquote> element....
Read more >
Comments and indentation | PracticalSeries: Web Development
Understand the importance of commenting HTML, CSS and Java script. Learn how to minimise HTML and CSS and understand the concept of indentation....
Read more >
Reindent command breaks on (multiline) comments #1271
Selecting an entire document that contains comments that span multiple lines, and using the Edit -> Line -> Reindent command, stops indenting at...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found