Open joeyparis opened 3 years ago
Pinging @DracoAter as he originally created the IndentationStyle
cop and probably knows the most about how it works.
P.S. As a fellow stubborn-tab-user I really appreciate you creating this cop because it's what finally made me happy using rubocop in my projects
Upon further debugging, I was able to get the desired behavior. Although this may be a "bug" I think it could sufficiently be corrected with improved documentation.
If
Layout/IndentationStyle
->EnforcedStyle
is set to tabs, thenLayout/IndentationStyle
->IndentationWidth
MUST be set to 1. To avoid double indentation it is also recommended to setLayout/IndentationWidth
->Width
to 1.
Alternatively, a fix for this bug would be to change line 85 to "\t" * match.size
and making not that IndentationWidth
is ignored when EnforcedStyle
is tabs.
I still think adding a note about setting LayoutIndentation/Width
to 1 would be helpful. I'll make a pull request now for these changes.
It looks to me like the Layout/IndentationWidth
cop is redundant to the IndentationWidth
parameter of Layout/IndentationStyle
cop. Would it make sense to deprecate one and standardize on the other?
There are some places that check both:
It would be really weird of the two values differed from each other. We should just standardize on one.
Having this same issue with relaxed.ruby.style + Layout/IndentationStyle: EnforcedStyle: tabs
Using just:
instead of:
leads to an infinite loop detected error.
Second, but related bug Setting the IndentationWidth to 1 actually makes RuboCop indent 2 tabs instead of 1. I tried setting it to 0 but that does nothing instead. I figure these two bugs are closely related so it's not worth creating a second ticket for. If that's not the case, just let me know and I will create a separate ticket for that bug.
Expected behavior
Rubocop automatically indents lines with tabs just as it would with spaces
Actual behavior
Run:
Output:
Steps to reproduce the problem
Add the following to
.rubocopy.yml
RuboCop version
Potential Solutions
Automatically set
IndentationWidth
to 1 whenEnforcedStyle
istabs
Document that
IndentationWidth
must be set towhen
EnforcedStyleis
tabs`(Secondary bug) Make sure tab indentations are only 1 width (not 2), potentially ignoring any option other than 1 for tabs