rubocop 0.9.1 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rubocop might be problematic. Click here for more details.

Files changed (149) hide show
  1. data/.travis.yml +3 -1
  2. data/CHANGELOG.md +38 -0
  3. data/README.md +34 -0
  4. data/Rakefile +3 -0
  5. data/config/default.yml +14 -1
  6. data/config/enabled.yml +30 -7
  7. data/lib/rubocop.rb +15 -0
  8. data/lib/rubocop/cli.rb +48 -154
  9. data/lib/rubocop/config.rb +19 -22
  10. data/lib/rubocop/config_store.rb +2 -4
  11. data/lib/rubocop/cop/commissioner.rb +90 -0
  12. data/lib/rubocop/cop/cop.rb +38 -31
  13. data/lib/rubocop/cop/corrector.rb +84 -0
  14. data/lib/rubocop/cop/lint/assignment_in_condition.rb +0 -3
  15. data/lib/rubocop/cop/lint/block_alignment.rb +151 -0
  16. data/lib/rubocop/cop/lint/empty_ensure.rb +18 -0
  17. data/lib/rubocop/cop/lint/end_alignment.rb +0 -124
  18. data/lib/rubocop/cop/lint/end_in_method.rb +0 -2
  19. data/lib/rubocop/cop/lint/ensure_return.rb +3 -3
  20. data/lib/rubocop/cop/lint/eval.rb +0 -2
  21. data/lib/rubocop/cop/lint/handle_exceptions.rb +0 -2
  22. data/lib/rubocop/cop/lint/literal_in_condition.rb +0 -10
  23. data/lib/rubocop/cop/lint/loop.rb +0 -2
  24. data/lib/rubocop/cop/lint/rescue_exception.rb +0 -2
  25. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +2 -2
  26. data/lib/rubocop/cop/lint/unreachable_code.rb +0 -2
  27. data/lib/rubocop/cop/lint/unused_local_variable.rb +2 -2
  28. data/lib/rubocop/cop/lint/void.rb +0 -2
  29. data/lib/rubocop/cop/offence.rb +9 -0
  30. data/lib/rubocop/cop/rails/validation.rb +2 -1
  31. data/lib/rubocop/cop/style/access_control.rb +4 -3
  32. data/lib/rubocop/cop/style/alias.rb +2 -4
  33. data/lib/rubocop/cop/style/align_parameters.rb +0 -2
  34. data/lib/rubocop/cop/style/and_or.rb +4 -6
  35. data/lib/rubocop/cop/style/ascii_comments.rb +2 -2
  36. data/lib/rubocop/cop/style/ascii_identifiers.rb +2 -2
  37. data/lib/rubocop/cop/style/attr.rb +0 -2
  38. data/lib/rubocop/cop/style/avoid_class_vars.rb +0 -1
  39. data/lib/rubocop/cop/style/avoid_for.rb +0 -2
  40. data/lib/rubocop/cop/style/avoid_global_vars.rb +3 -7
  41. data/lib/rubocop/cop/style/avoid_perl_backrefs.rb +0 -2
  42. data/lib/rubocop/cop/style/avoid_perlisms.rb +2 -4
  43. data/lib/rubocop/cop/style/begin_block.rb +0 -2
  44. data/lib/rubocop/cop/style/block_comments.rb +2 -2
  45. data/lib/rubocop/cop/style/block_nesting.rb +3 -3
  46. data/lib/rubocop/cop/style/blocks.rb +0 -2
  47. data/lib/rubocop/cop/style/case_equality.rb +0 -2
  48. data/lib/rubocop/cop/style/case_indentation.rb +0 -2
  49. data/lib/rubocop/cop/style/character_literal.rb +10 -6
  50. data/lib/rubocop/cop/style/class_and_module_camel_case.rb +0 -4
  51. data/lib/rubocop/cop/style/class_methods.rb +1 -1
  52. data/lib/rubocop/cop/style/collection_methods.rb +3 -5
  53. data/lib/rubocop/cop/style/colon_method_call.rb +3 -3
  54. data/lib/rubocop/cop/style/comment_annotation.rb +44 -0
  55. data/lib/rubocop/cop/style/constant_name.rb +0 -2
  56. data/lib/rubocop/cop/style/def_parentheses.rb +0 -8
  57. data/lib/rubocop/cop/style/documentation.rb +6 -2
  58. data/lib/rubocop/cop/style/dot_position.rb +0 -2
  59. data/lib/rubocop/cop/style/empty_line_between_defs.rb +0 -2
  60. data/lib/rubocop/cop/style/empty_lines.rb +10 -8
  61. data/lib/rubocop/cop/style/empty_literal.rb +3 -1
  62. data/lib/rubocop/cop/style/encoding.rb +7 -6
  63. data/lib/rubocop/cop/style/end_block.rb +0 -2
  64. data/lib/rubocop/cop/style/end_of_line.rb +4 -3
  65. data/lib/rubocop/cop/style/favor_join.rb +0 -2
  66. data/lib/rubocop/cop/style/favor_modifier.rb +9 -9
  67. data/lib/rubocop/cop/style/favor_sprintf.rb +0 -2
  68. data/lib/rubocop/cop/style/favor_unless_over_negated_if.rb +0 -2
  69. data/lib/rubocop/cop/style/hash_syntax.rb +0 -2
  70. data/lib/rubocop/cop/style/if_then_else.rb +0 -2
  71. data/lib/rubocop/cop/style/lambda.rb +0 -2
  72. data/lib/rubocop/cop/style/leading_comment_space.rb +2 -2
  73. data/lib/rubocop/cop/style/line_continuation.rb +4 -3
  74. data/lib/rubocop/cop/style/line_length.rb +4 -3
  75. data/lib/rubocop/cop/style/method_and_variable_snake_case.rb +4 -3
  76. data/lib/rubocop/cop/style/method_call_parentheses.rb +0 -2
  77. data/lib/rubocop/cop/style/method_length.rb +0 -4
  78. data/lib/rubocop/cop/style/not.rb +0 -2
  79. data/lib/rubocop/cop/style/op_method.rb +0 -2
  80. data/lib/rubocop/cop/style/parameter_lists.rb +0 -2
  81. data/lib/rubocop/cop/style/parentheses_around_condition.rb +12 -6
  82. data/lib/rubocop/cop/style/proc.rb +0 -2
  83. data/lib/rubocop/cop/style/reduce_arguments.rb +0 -2
  84. data/lib/rubocop/cop/style/redundant_begin.rb +45 -0
  85. data/lib/rubocop/cop/style/redundant_return.rb +59 -0
  86. data/lib/rubocop/cop/style/redundant_self.rb +83 -0
  87. data/lib/rubocop/cop/style/regexp_literal.rb +0 -2
  88. data/lib/rubocop/cop/style/rescue_modifier.rb +13 -21
  89. data/lib/rubocop/cop/style/semicolon.rb +15 -9
  90. data/lib/rubocop/cop/style/single_line_methods.rb +0 -4
  91. data/lib/rubocop/cop/style/space_after_comma_etc.rb +2 -2
  92. data/lib/rubocop/cop/style/space_after_control_keyword.rb +0 -1
  93. data/lib/rubocop/cop/style/string_literals.rb +5 -2
  94. data/lib/rubocop/cop/style/surrounding_space.rb +106 -91
  95. data/lib/rubocop/cop/style/tab.rb +4 -3
  96. data/lib/rubocop/cop/style/ternary_operator.rb +0 -4
  97. data/lib/rubocop/cop/style/trailing_whitespace.rb +4 -3
  98. data/lib/rubocop/cop/style/trivial_accessors.rb +51 -6
  99. data/lib/rubocop/cop/style/unless_else.rb +0 -2
  100. data/lib/rubocop/cop/style/variable_interpolation.rb +0 -2
  101. data/lib/rubocop/cop/style/when_then.rb +3 -3
  102. data/lib/rubocop/cop/style/while_until_do.rb +3 -5
  103. data/lib/rubocop/cop/style/word_array.rb +0 -2
  104. data/lib/rubocop/cop/util.rb +0 -4
  105. data/lib/rubocop/formatter/file_list_formatter.rb +18 -0
  106. data/lib/rubocop/formatter/formatter_set.rb +2 -1
  107. data/lib/rubocop/processed_source.rb +27 -0
  108. data/lib/rubocop/rake_task.rb +50 -0
  109. data/lib/rubocop/source_parser.rb +105 -0
  110. data/lib/rubocop/target_finder.rb +67 -0
  111. data/lib/rubocop/token.rb +22 -0
  112. data/lib/rubocop/version.rb +1 -1
  113. data/rubocop.gemspec +5 -3
  114. data/spec/project_spec.rb +0 -11
  115. data/spec/rubocop/cli_spec.rb +112 -6
  116. data/spec/rubocop/config_spec.rb +13 -17
  117. data/spec/rubocop/config_store_spec.rb +8 -23
  118. data/spec/rubocop/cops/commissioner_spec.rb +72 -0
  119. data/spec/rubocop/cops/corrector_spec.rb +63 -0
  120. data/spec/rubocop/cops/lint/assignment_in_condition_spec.rb +2 -2
  121. data/spec/rubocop/cops/lint/block_alignment_spec.rb +357 -0
  122. data/spec/rubocop/cops/lint/empty_ensure_spec.rb +33 -0
  123. data/spec/rubocop/cops/lint/end_alignment_spec.rb +0 -263
  124. data/spec/rubocop/cops/lint/ensure_return_spec.rb +6 -9
  125. data/spec/rubocop/cops/offence_spec.rb +28 -0
  126. data/spec/rubocop/cops/style/and_or_spec.rb +21 -11
  127. data/spec/rubocop/cops/style/ascii_identifiers_spec.rb +14 -0
  128. data/spec/rubocop/cops/style/avoid_global_vars_spec.rb +10 -14
  129. data/spec/rubocop/cops/style/character_literal_spec.rb +17 -2
  130. data/spec/rubocop/cops/style/colon_method_call_spec.rb +20 -15
  131. data/spec/rubocop/cops/style/comment_annotation_spec.rb +62 -0
  132. data/spec/rubocop/cops/style/encoding_spec.rb +7 -0
  133. data/spec/rubocop/cops/style/parentheses_around_condition_spec.rb +37 -9
  134. data/spec/rubocop/cops/style/redundant_begin_spec.rb +63 -0
  135. data/spec/rubocop/cops/style/redundant_return_spec.rb +64 -0
  136. data/spec/rubocop/cops/style/redundant_self_spec.rb +76 -0
  137. data/spec/rubocop/cops/style/string_literals_spec.rb +18 -13
  138. data/spec/rubocop/cops/style/trivial_accessors_spec.rb +110 -52
  139. data/spec/rubocop/cops/style/when_then_spec.rb +14 -7
  140. data/spec/rubocop/cops/style/while_until_do_spec.rb +12 -0
  141. data/spec/rubocop/cops/variable_inspector_spec.rb +3 -5
  142. data/spec/rubocop/formatter/file_list_formatter_spec.rb +33 -0
  143. data/spec/rubocop/processed_source_spec.rb +67 -0
  144. data/spec/rubocop/source_parser_spec.rb +141 -0
  145. data/spec/rubocop/target_finder_spec.rb +180 -0
  146. data/spec/rubocop/token_spec.rb +27 -0
  147. data/spec/spec_helper.rb +24 -4
  148. metadata +108 -18
  149. checksums.yaml +0 -7
@@ -8,8 +8,8 @@ module Rubocop
8
8
  class AsciiComments < Cop
9
9
  MSG = 'Use only ascii symbols in comments.'
10
10
 
11
- def inspect(source_buffer, source, tokens, ast, comments)
12
- comments.each do |comment|
11
+ def investigate(processed_source)
12
+ processed_source.comments.each do |comment|
13
13
  if comment.text =~ /[^\x00-\x7f]/
14
14
  add_offence(:convention, comment.loc, MSG)
15
15
  end
@@ -9,8 +9,8 @@ module Rubocop
9
9
  class AsciiIdentifiers < Cop
10
10
  MSG = 'Use only ascii symbols in identifiers.'
11
11
 
12
- def inspect(source_buffer, source, tokens, ast, comments)
13
- tokens.each do |t|
12
+ def investigate(processed_source)
13
+ processed_source.tokens.each do |t|
14
14
  if t.type == :tIDENTIFIER && t.text =~ /[^\x00-\x7f]/
15
15
  add_offence(:convention, t.pos, MSG)
16
16
  end
@@ -11,8 +11,6 @@ module Rubocop
11
11
  if command?(:attr, node)
12
12
  add_offence(:convention, node.loc.selector, MSG)
13
13
  end
14
-
15
- super
16
14
  end
17
15
  end
18
16
  end
@@ -12,7 +12,6 @@ module Rubocop
12
12
  def on_cvasgn(node)
13
13
  class_var, = *node
14
14
  add_offence(:convention, node.loc.name, sprintf(MSG, class_var))
15
- super
16
15
  end
17
16
  end
18
17
  end
@@ -9,8 +9,6 @@ module Rubocop
9
9
 
10
10
  def on_for(node)
11
11
  add_offence(:convention, node.loc.keyword, MSG)
12
-
13
- super
14
12
  end
15
13
  end
16
14
  end
@@ -34,26 +34,22 @@ module Rubocop
34
34
  $' $POSTMATCH
35
35
  $+ $LAST_PAREN_MATCH
36
36
  $stdin $stdout $stderr
37
- $DEBUG $FILENAME $VERBOSE
37
+ $DEBUG $FILENAME $VERBOSE $SAFE
38
38
  $-0 $-a $-d $-F $-i $-I $-l $-p $-v $-w
39
- )
39
+ ).map(&:to_sym)
40
40
 
41
41
  def on_gvar(node)
42
42
  check(node)
43
-
44
- super
45
43
  end
46
44
 
47
45
  def on_gvasgn(node)
48
46
  check(node)
49
-
50
- super
51
47
  end
52
48
 
53
49
  def check(node)
54
50
  global_var, = *node
55
51
 
56
- unless BUILT_IN_VARS.include?(global_var.to_s)
52
+ unless BUILT_IN_VARS.include?(global_var)
57
53
  add_offence(:convention,
58
54
  node.loc.name,
59
55
  MSG)
@@ -12,8 +12,6 @@ module Rubocop
12
12
  add_offence(:convention,
13
13
  node.loc.expression,
14
14
  "Prefer the use of MatchData over $#{backref}.")
15
-
16
- super
17
15
  end
18
16
  end
19
17
  end
@@ -28,11 +28,11 @@ module Rubocop
28
28
  '$`' => '$PREMATCH from English library',
29
29
  '$\'' => '$POSTMATCH from English library',
30
30
  '$+' => '$LAST_PAREN_MATCH from English library'
31
- }
31
+ }.symbolize_keys
32
32
 
33
33
  def on_gvar(node)
34
34
  global_var, = *node
35
- global_var = global_var.to_s
35
+ global_var = global_var
36
36
 
37
37
  if PREFERRED_VARS[global_var]
38
38
  add_offence(
@@ -41,8 +41,6 @@ module Rubocop
41
41
  "Prefer #{PREFERRED_VARS[global_var]} over #{global_var}."
42
42
  )
43
43
  end
44
-
45
- super
46
44
  end
47
45
  end
48
46
  end
@@ -9,8 +9,6 @@ module Rubocop
9
9
 
10
10
  def on_preexe(node)
11
11
  add_offence(:convention, node.loc.keyword, MSG)
12
-
13
- super
14
12
  end
15
13
  end
16
14
  end
@@ -7,8 +7,8 @@ module Rubocop
7
7
  class BlockComments < Cop
8
8
  MSG = 'Do not use block comments.'
9
9
 
10
- def inspect(source_buffer, source, tokens, ast, comments)
11
- comments.each do |comment|
10
+ def investigate(processed_source)
11
+ processed_source.comments.each do |comment|
12
12
  if comment.text.start_with?('=begin')
13
13
  add_offence(:convention, comment.loc, MSG)
14
14
  end
@@ -12,10 +12,10 @@ module Rubocop
12
12
  NESTING_BLOCKS = [:case, :if, :while, :while_post, :until, :until_post,
13
13
  :for, :resbody]
14
14
 
15
- def inspect(source_buffer, source, tokens, ast, comments)
16
- return unless ast
15
+ def investigate(processed_source)
16
+ return unless processed_source.ast
17
17
  max = BlockNesting.config['Max']
18
- check_nesting_level(ast, max, 0)
18
+ check_nesting_level(processed_source.ast, max, 0)
19
19
  end
20
20
 
21
21
  private
@@ -18,8 +18,6 @@ module Rubocop
18
18
  elsif block_length == 0 && block_begin != '{'
19
19
  add_offence(:convention, node.loc.begin, SINGLE_LINE_MSG)
20
20
  end
21
-
22
- super
23
21
  end
24
22
  end
25
23
  end
@@ -13,8 +13,6 @@ module Rubocop
13
13
  if method_name == :===
14
14
  add_offence(:convention, node.loc.selector, MSG)
15
15
  end
16
-
17
- super
18
16
  end
19
17
  end
20
18
  end
@@ -19,8 +19,6 @@ module Rubocop
19
19
  pos = when_node.loc.keyword
20
20
  add_offence(:convention, pos, MSG) if pos.column != case_column
21
21
  end
22
-
23
- super
24
22
  end
25
23
  end
26
24
  end
@@ -11,9 +11,11 @@ module Rubocop
11
11
  # Constants like __FILE__ are handled as strings,
12
12
  # but don't respond to begin.
13
13
  return unless node.loc.respond_to?(:begin)
14
+ return if part_of_ignored_node?(node)
14
15
 
15
16
  # we don't register an offence for things like ?\C-\M-d
16
- if node.loc.begin.is?('?') && node.loc.expression.source.size < 4
17
+ if node.loc.begin.is?('?') &&
18
+ node.loc.expression.source.size.between?(2, 3)
17
19
  add_offence(:convention, node.loc.expression, MSG)
18
20
  do_autocorrect(node)
19
21
  end
@@ -23,12 +25,14 @@ module Rubocop
23
25
  alias_method :on_regexp, :ignore_node
24
26
 
25
27
  def autocorrect_action(node)
26
- string = node.loc.expression.source[1..-1]
28
+ @corrections << lambda do |corrector|
29
+ string = node.loc.expression.source[1..-1]
27
30
 
28
- if string.length == 1 # normal character
29
- replace(node.loc.expression, "'#{string}'")
30
- elsif string.length == 2 # special character like \n
31
- replace(node.loc.expression, %Q("#{string}"))
31
+ if string.length == 1 # normal character
32
+ corrector.replace(node.loc.expression, "'#{string}'")
33
+ elsif string.length == 2 # special character like \n
34
+ corrector.replace(node.loc.expression, %Q("#{string}"))
35
+ end
32
36
  end
33
37
  end
34
38
  end
@@ -10,14 +10,10 @@ module Rubocop
10
10
 
11
11
  def on_class(node)
12
12
  check_name(node)
13
-
14
- super
15
13
  end
16
14
 
17
15
  def on_module(node)
18
16
  check_name(node)
19
-
20
- super
21
17
  end
22
18
 
23
19
  private
@@ -8,7 +8,7 @@ module Rubocop
8
8
  class ClassMethods < Cop
9
9
  MSG = 'Prefer self over class/module for class/module methods.'
10
10
 
11
- # TODO - check if we're in a class/module
11
+ # TODO: Check if we're in a class/module
12
12
  def on_defs(node)
13
13
  definee, _name, _args, _body = *node
14
14
 
@@ -13,15 +13,15 @@ module Rubocop
13
13
  MSG = 'Prefer %s over %s.'
14
14
 
15
15
  def self.preferred_methods
16
- Util.symbolize_keys(config['PreferredMethods'])
16
+ if config['PreferredMethods']
17
+ config['PreferredMethods'].symbolize_keys
18
+ end
17
19
  end
18
20
 
19
21
  def on_block(node)
20
22
  method, _args, _body = *node
21
23
 
22
24
  check_method_node(method)
23
-
24
- super
25
25
  end
26
26
 
27
27
  def on_send(node)
@@ -30,8 +30,6 @@ module Rubocop
30
30
  if args.size == 1 && args.first.type == :block_pass
31
31
  check_method_node(node)
32
32
  end
33
-
34
- super
35
33
  end
36
34
 
37
35
  private
@@ -16,12 +16,12 @@ module Rubocop
16
16
  add_offence(:convention, node.loc.dot, MSG)
17
17
  do_autocorrect(node)
18
18
  end
19
-
20
- super
21
19
  end
22
20
 
23
21
  def autocorrect_action(node)
24
- replace(node.loc.dot, '.')
22
+ @corrections << lambda do |corrector|
23
+ corrector.replace(node.loc.dot, '.')
24
+ end
25
25
  end
26
26
  end
27
27
  end
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+
3
+ module Rubocop
4
+ module Cop
5
+ module Style
6
+ # This cop checks that comment annotation keywords are written according
7
+ # to guidelines.
8
+ class CommentAnnotation < Cop
9
+ MSG = 'Annotation keywords shall be all upper case, followed by a ' +
10
+ 'colon and a space, then a note describing the problem.'
11
+ KEYWORDS = %w(TODO FIXME OPTIMIZE HACK REVIEW)
12
+
13
+ def investigate(processed_source)
14
+ processed_source.comments.each do |comment|
15
+ match = comment.text.match(/^(# ?)([A-Za-z]+)(\s*:)?(\s+)?(\S+)?/)
16
+ if match
17
+ margin, first_word, colon, space, note = *match.captures
18
+ if annotation?(first_word, colon, space, note) &&
19
+ !correct_annotation?(first_word, colon, space, note)
20
+ start = comment.loc.begin_pos + margin.length
21
+ length = first_word.length + (colon || '').length
22
+ range = Parser::Source::Range.new(processed_source.buffer,
23
+ start,
24
+ start + length)
25
+ add_offence(:convention, range, MSG)
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def annotation?(first_word, colon, space, note)
34
+ KEYWORDS.include?(first_word.upcase) && (colon || space || !note)
35
+ end
36
+
37
+ def correct_annotation?(first_word, colon, space, note)
38
+ KEYWORDS.include?(first_word) &&
39
+ (colon && space && note || !colon && !note)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -22,8 +22,6 @@ module Rubocop
22
22
  add_offence(:convention, node.loc.name, MSG)
23
23
  end
24
24
  end
25
-
26
- super
27
25
  end
28
26
  end
29
27
  end
@@ -20,8 +20,6 @@ module Rubocop
20
20
  if args.children == [] && args.loc.begin
21
21
  add_offence(:convention, args.loc.begin, MSG)
22
22
  end
23
-
24
- super
25
23
  end
26
24
 
27
25
  def on_defs(node)
@@ -34,8 +32,6 @@ module Rubocop
34
32
  if args.children == [] && args.loc.begin
35
33
  add_offence(:convention, args.loc.begin, MSG)
36
34
  end
37
-
38
- super
39
35
  end
40
36
  end
41
37
 
@@ -51,8 +47,6 @@ module Rubocop
51
47
  if args.children.size > 0 && args.loc.begin.nil?
52
48
  add_offence(:convention, args.loc.expression, MSG)
53
49
  end
54
-
55
- super
56
50
  end
57
51
 
58
52
  def on_defs(node)
@@ -61,8 +55,6 @@ module Rubocop
61
55
  if args.children.size > 0 && args.loc.begin.nil?
62
56
  add_offence(:convention, args.loc.expression, MSG)
63
57
  end
64
-
65
- super
66
58
  end
67
59
  end
68
60
  end
@@ -10,10 +10,14 @@ module Rubocop
10
10
  class Documentation < Cop
11
11
  MSG = 'Missing top-level %s documentation comment.'
12
12
 
13
- def inspect(source_buffer, source, tokens, ast, comments)
13
+ def investigate(processed_source)
14
+ ast = processed_source.ast
14
15
  return unless ast
15
16
 
16
- ast_with_comments = Parser::Source::Comment.associate(ast, comments)
17
+ ast_with_comments = Parser::Source::Comment.associate(
18
+ ast,
19
+ processed_source.comments
20
+ )
17
21
 
18
22
  check_classes(ast, ast_with_comments)
19
23
  check_modules(ast, ast_with_comments)
@@ -13,8 +13,6 @@ module Rubocop
13
13
  unless proper_dot_position?(node)
14
14
  add_offence(:convention, node.loc.dot, MSG)
15
15
  end
16
-
17
- super
18
16
  end
19
17
 
20
18
  private
@@ -17,8 +17,6 @@ module Rubocop
17
17
  end
18
18
 
19
19
  @prev_def_end = def_end
20
-
21
- super
22
20
  end
23
21
  end
24
22
  end
@@ -8,12 +8,12 @@ module Rubocop
8
8
  MSG = 'Extra blank line detected.'
9
9
  LINE_OFFSET = 2
10
10
 
11
- def inspect(source_buffer, source, tokens, ast, comments)
12
- return if tokens.empty?
11
+ def investigate(processed_source)
12
+ return if processed_source.tokens.empty?
13
13
 
14
14
  prev_line = 1
15
15
 
16
- tokens.each do |token|
16
+ processed_source.tokens.each do |token|
17
17
  cur_line = token.pos.line
18
18
  line_diff = cur_line - prev_line
19
19
 
@@ -22,11 +22,13 @@ module Rubocop
22
22
  # don't show up in the tokens
23
23
  ((prev_line + 1)...cur_line).each do |line|
24
24
  # we check if the prev and current lines are empty
25
- if source[line - 2].empty? && source[line - 1].empty?
26
- add_offence(:convention,
27
- source_range(source_buffer,
28
- source[0...(line - 1)], 0, 1),
29
- MSG)
25
+ if processed_source[line - 2].empty? &&
26
+ processed_source[line - 1].empty?
27
+ range = source_range(processed_source.buffer,
28
+ processed_source[0...(line - 1)],
29
+ 0,
30
+ 1)
31
+ add_offence(:convention, range, MSG)
30
32
  end
31
33
  end
32
34
  end