turboladen / tailor

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

Post loop is not known #122

Open ureczky opened 11 years ago

ureczky commented 11 years ago

Tailor doesnt recognise post-loop.

I have the following ruby code with a post loop:

a = 0
begin
  a += 1
end while a < 10
puts a

It's working, when I execute it, i get 10 as a result.

However, tailor cant recognise it:

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

It thinks that the while is a beginning of a block.

If there is an end somewhere later, it thinks theres a block between them:

class X
  def method1
    a = 0
    begin
      a += 1
    end while a < 10
    puts a
  end
  def method2
    puts '1'
    puts '2'
    puts '3'
    ...
    puts '30'
  end
end

It thinks the method1 is more than 35 lines, however nor the method1 nor the method2 greater than 35 lines. (And also produces a lot of indentation warnings)

# Problems:
#  1.
#    * position:  2:2
#    * property:  max_code_lines_in_method
#    * message:   Method has 40 code lines, but should have no more than 35.
#  2.
#    * position:  7:4
#    * property:  indentation_spaces
#    * message:   Line is indented to column 4, but should be at 6.
#  3.
#    * position:  8:2
#    * property:  indentation_spaces
#    * message:   Line is indented to column 2, but should be at 4.
#  4.
#    * position:  9:2
#    * property:  indentation_spaces
#    * message:   Line is indented to column 2, but should be at 4.
#  5.
#    * position:  10:4
#    * property:  indentation_spaces
#    * message:   Line is indented to column 4, but should be at 6.

...

#  34.
#    * position:  39:4
#    * property:  indentation_spaces
#    * message:   Line is indented to column 4, but should be at 6.
#  35.
#    * position:  40:2
#    * property:  indentation_spaces
#    * message:   Line is indented to column 2, but should be at 4.
#  36.
#    * position:  41:0
#    * property:  indentation_spaces
#    * message:   Line is indented to column 0, but should be at 2.

The problem is also appear if i change the ''while'' to ''unless''

I am using tailor 1.1.2

turboladen commented 11 years ago

Thanks for the nice write-up. I'd never seen this style of looping before, and thus didn't account for it. Glad to learn about it. Incorrect indentation errors are an unpleasant side effect of the case that the syntax isn't properly understood.

ureczky commented 11 years ago

Hi Steve! Are you planning to resolve this issue? Just because our company is struggling with the workarounds caused by issues like this. Post loop is an often used programming technique, when the program-structure follow this idea and it makes the code uggly and hardly understandable when we convert to other types of loop. After 3 month we are thinking of using other solutions. We follow thoughtfully the new build versions, but we never find these to make our work easier. The other major problem is the slowlyness, which causes lot of waiting after each git-commit, because we use tailor in a pre-commit-hook. We may have to start individual threads on each files, because we now have a bigger code-base and we are wasting a lot of time on waiting for results.

turboladen commented 11 years ago

Hi @ureczky... I'll be the first to admit: tailor is in much need of some love--especially with the indentation checking stuff. I'd love to say that I'll be sitting down to show it said love soon, but I can't say that right now. I can tell you that I do intend to fix this (as well as attend to the slowness), but I just don't know when.

I'm sorry that it's causing headaches for your business--I know what it's like to depend on open source tools to get your job done and the maintainer isn't fixing stuff you need fixed--such is the blessing and curse of open source software, no? :)

For what it's worth, the changes I've made to tailor recently have been either a) a result of someone's pull request, or b) low-hanging fruit (i.e. I'm confident I know where the problem is and have a good idea how to fix it). I'm not sure what the scope of the fix for this is and don't have the time right now to look into it. If you came up with a fix, I'd be more than happy to take a pull request...