Questions about new indent rule behavior in regards to comments
See original GitHub issueTell us about your environment
- ESLint Version: Master
- Node Version: 6.x
- npm Version: 4.x
What parser (default, Babel-ESLint, etc.) are you using? Espree
Please show your full configuration:
{
"rules": {
"indent": ["error", 2]
}
}
What did you do? Please include the actual source code causing the issue. Noticed an inconsistency with how comments are handled by the new indent rule
What did you expect to happen? For this to pass:
function foo() {
if (true) {
// some comment
}
}
And for these to not:
function foo() {
if (true) {
// some comment
}
}
function foo() {
if (true) {
// some comment
}
}
What actually happened? Please include the actual, raw output from ESLint. Both the following code snippets do not throw an error with the above configuration:
function foo() {
if (true) {
// some comment
}
}
function foo() {
if (true) {
// some comment
}
}
However, the following example does:
function foo() {
if (true) {
// some comment
}
}
/Users/cataldo/Code/test/eslint-test/index.js
3:1 error Expected indentation of 4 spaces but found 0 indent
I think there are two issues at play here:
- I believe the error message is correct, and that it should enforce for 4 spaces with the above code snippet
- It’s confusing that the error message expects 4 spaces but is satisfied with 2 spaces
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (8 by maintainers)
Top Results From Across the Web
Allow comments that match any previous level of indentation
Comments that match a previous level of indentation should be allowed, at the end of that level of indentation.
Read more >indentation - How to align "end of line comments" in sh-mode?
Choose the indentation to use for a right-hand-side comment. The criteria are (in this order): - try to keep the comment's text within...
Read more >What setting in vim counteracts smartindent's refusal to indent ...
When editing a shell script, I try to create a comment at the current indent level, but smartindent will have nothing to do...
Read more >Formatting Questions - Qualtrics
While formatting questions, navigate to the Question behavior section to add advanced behavior to your questions, such as the ability to hide questions...
Read more >THE BLUEBOOK MADE EASY - Penn State Law
Abbreviate “on the relation of,” “for the use of,” “on behalf of,” and similar expressions to “ex rel.” This type of proceeding occurs...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The problem I’m trying to solve is that I’ve enabled the new rule in our codebases at work and am able to fix everything but comments. Manually going through and fixing a PR that has
+3,978 −3,991
changes is difficult.I wonder if we could make the rule smarter by saying that it’s safe to assume the comment should be indented if it’s at the top of a block?
I have a lot of instances where the following:
get autofixed to:
It seems like a safe assumption that the comment should also be indented, but maybe I’m missing something here!
Edit: Also wanted to mention that the new indent rule is great! Having it not do crazy things when autofixing is amazing 🎉
Edit 2: Fixed a typo in the example
@yairEO This is working as intended. If you’d like a version of the
indent
rule that is less strict and ignores comments, you can use theindent-legacy
rule.