File tree Expand file tree Collapse file tree 2 files changed +10
-20
lines changed Expand file tree Collapse file tree 2 files changed +10
-20
lines changed Original file line number Diff line number Diff line change @@ -6,28 +6,13 @@ def initialize(code_to_analyze)
6
6
@code_to_analyze = code_to_analyze
7
7
end
8
8
9
- # REFACTOR: This could be refactored to strip blank
10
- # lines and then use each_cons(2).
11
9
def indentation_is_sensible?
12
- previous_line = nil
13
- code_to_analyze . lines . each do |line |
14
- # If the previous line or this line is
15
- # just a whitespace line, don't consider it
16
- # when checking for indentation
17
- unless previous_line . nil? ||
18
- previous_line =~ /^\s *\n *$/ ||
19
- line =~ /^\s *\n *$/
10
+ code_to_analyze . lines . reject { |line | line =~ /^\s *\n *$/ } . each_cons ( 2 ) . all? do |lines |
11
+ line_1_space = lines . first [ /^ */ ] . size
12
+ line_2_space = lines . last [ /^ */ ] . size
20
13
21
- previous_line_lspace = previous_line [ /^ */ ] . size
22
- line_lspace = line [ /^ */ ] . size
23
-
24
- return false if ( previous_line_lspace - line_lspace ) . abs > 2
25
- end
26
-
27
- previous_line = line
14
+ [ 0 , 2 ] . include? ( line_2_space - line_1_space ) . abs
28
15
end
29
-
30
- true
31
16
end
32
17
33
18
def has_target_module?
Original file line number Diff line number Diff line change @@ -336,7 +336,12 @@ def self.two_fer(name="you")
336
336
"One for %s, one for me." % name
337
337
end
338
338
end
339
- ' ] . each . with_index do |source , idx |
339
+ ' , '
340
+ class TwoFer
341
+ def self.two_fer(name="you")
342
+ "One for %s, one for me." % name
343
+ end
344
+ end' ] . each . with_index do |source , idx |
340
345
define_method "test_incorrect_indentation_#{ idx } " do
341
346
# skip
342
347
results = TwoFer ::Analyze . ( source )
You can’t perform that action at this time.
0 commit comments