New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
arrow_alignment --fix
doesn't indent keys when introducing line breaks; erroneously reports success
#506
Comments
arrow_alignment --fix
erroneously reports success when it introduces linebreaksarrow_alignment --fix
doesn't indent keys when introducing line breaks; erroneously reports success
So I'm not entirely sure what the fix to this is, but I can show that it's frustratingly nontrivial as there are several issues in flight here. scratch.pp
Using the patch diff --git a/lib/puppet-lint/plugins/check_whitespace.rb b/lib/puppet-lint/plugins/check_whitespace.rb
index ec27831..ba09c34 100644
--- a/lib/puppet-lint/plugins/check_whitespace.rb
+++ b/lib/puppet-lint/plugins/check_whitespace.rb
@@ -131,9 +131,8 @@ PuppetLint.new_check(:arrow_alignment) do
resource_tokens.each_with_index do |token, idx|
if token.type == :FARROW
(level_tokens[indent_depth_idx] ||= []) << token
- prev_indent_token = resource_tokens[0..idx].rindex { |t| t.type == :INDENT }
- indent_token_length = prev_indent_token.nil? ? 0 : resource_tokens[prev_indent_token].to_manifest.length
- indent_length = indent_token_length + token.prev_code_token.to_manifest.length + 2
+ whitespace_padding = token.prev_token.type == :INDENT ? token.prev_token.value.length : 0
+ indent_length = token.column + 1 - whitespace_padding
if indent_depth[indent_depth_idx] < indent_length
indent_depth[indent_depth_idx] = indent_length Running
So the first problem here, addressed by the pasted patch, is that the existing implementation assumes the code token preceding is the full width of the line preceding the The patch in this comment fixes this, by realizing that we can infer the total width of all the preceding text on the line by taking the column of the But something else is screwy here. Either the tokenizer is doing something wacky with line number information, because the reported arrow line numbers are totally wrong here and suggest that several lines are being re-indented repeatedly. |
@arrdem Have you had any chance to revisit this since PuppetConf? |
@rnelson0 I haven't. I'll try and make some time for it this week. |
This is now a little better and a little worse. Starting with the original sample:
The 2nd line of java_args isn't thrown all the way too the left, but it isn't correct, either. Further fix attempts do not change this.
In this case, proxy_pass entries are properly split by lines and correctly aligned.
This one gets interesting if you fix it a few more times:
It rotates between those two results now. Clearly recent fixes have not resolved all of the issues. |
Ahh arrow alignment. Simple for humans but quite problematic to handle all the possible cases in code. Seeing as I dug into it most recently for a different issue, I'll check this one out on the plane tomorrow. |
Fix for arrow_alignment bugs in #506
I installed 2.0.0 and ran
bundle exec puppet-lint --only-checks arrow_alignment --fix
on our puppet repo. After running again without the --fix flag four instances were still failing. Running a second time with the with the --fix flag resulted in all four of those being reported fixed, but two of them still fail on subsequent checks.The two pieces of code that continue to fail had newlines introduced by the --fix flag, and I believe the alignment fails because the initial indentation of the keys do not match. Here's the patches:
And here is the other:
I tried to additionally activate the 2sp_soft_tabs check, but although it complains about the newly introduced lines, it does not succeed in fixing them. However, when I manually indented the keys so they start in the same column then subsequent --fix runs work as expected.
The text was updated successfully, but these errors were encountered: