turboladen / tailor

A RubyGem that allows for checking standard styling of Ruby files.
146 stars 18 forks source link

Line continuation with backslash triggers false indentation warning #153

Open twforeman opened 10 years ago

twforeman commented 10 years ago

If you continue a string with a backslash onto multiple lines, the first and last lines show as an error with incorrect indentation.

Code sample:

windows_task 'chef-client' do
  run_level :highest
  command "#{node['chef_client']['ruby_bin']} #{node['chef_client']['bin']} \
  -L #{File.join(node['chef_client']['log_dir'], 'client.log')} \
  -c #{File.join(node['chef_client']['conf_dir'], 'client.rb')} \
  -s #{node['chef_client']['splay']}"
  frequency :minute
  frequency_modifier(node['chef_client']['interval'].to_i / 60)
end

Error shows:

# Problems:
#  1.
#    * position:  3:5
#    * property:  indentation_spaces
#    * message:   Line is indented to column 5, but should be at 2.
#  2.
#    * position:  6:5
#    * property:  indentation_spaces
#    * message:   Line is indented to column 5, but should be at 2.

Pushing the continued lines to the left margin still shows the error, but says they are in column 3 instead of 5.

The only clues I see in debug mode is at the end of line 3 it says:

[2013-12-19 13:28:00]  <Lexer> 3[75]: TSTRING_CONTENT: ' # TAILOR REMOVED BACKSLASH
[2013-12-19 13:28:00]    -L '

And at the end of line 6 it says:

[2013-12-19 13:28:00]  <IndentationManager> Updated :next after closing; it's now 2
[2013-12-19 13:28:00]  <Lexer> 6[36]: TSTRING_END: '"'
[2013-12-19 13:28:00]  <IndentationSpacesRuler> Measuring...
[2013-12-19 13:28:00]  <Problem> 3[5]: ERROR[:indentation_spaces] Line is indented to column 5, but should be at 2.
[2013-12-19 13:28:00]  <IndentationManager> Starting indentation ruling.
[2013-12-19 13:28:00]  <IndentationManager> Next check should be at 2
[2013-12-19 13:28:00]  <Lexer> 6[37]: NL
[2013-12-19 13:28:00]  <AllowTrailingLineSpacesRuler> Last event: [[6, 36], :on_tstring_end, "\""]
[2013-12-19 13:28:00]  <AllowTrailingLineSpacesRuler> Line ends with space: false
[2013-12-19 13:28:00]  <IndentationSpacesRuler> indent reasons on entry: [{:event_type=>:on_kw, :token=>"do", :lineno=>1, :should_be_at=>0}]
[2013-12-19 13:28:00]  <IndentationManager> Actual indentation: 5
[2013-12-19 13:28:00]  <IndentationManager> Amount to change this line: 0
[2013-12-19 13:28:00]  <IndentationSpacesRuler> Measuring...
[2013-12-19 13:28:00]  <Problem> 6[5]: ERROR[:indentation_spaces] Line is indented to column 5, but should be at 2.
[2013-12-19 13:28:00]  <IndentationSpacesRuler> indent reasons on exit: [{:event_type=>:on_kw, :token=>"do", :lineno=>1, :should_be_at=>0}]
[2013-12-19 13:28:00]  <IndentationManager> Resetting change_this to 0.
[2013-12-19 13:28:00]  <IndentationManager> Setting @proper[:this_line] = that of :next_line
[2013-12-19 13:28:00]  <IndentationManager> Transitioning @proper[:this_line] to 2
[2013-12-19 13:28:00]  <SpacesAfterCommaRuler> Commas found at: [47, 48]
[2013-12-19 13:28:00]  <SpacesAfterCommaRuler> Event index is nil.  Weird...