lib/rubocop/cop/layout/initial_indentation.rb in rubocop-0.52.1 vs lib/rubocop/cop/layout/initial_indentation.rb in rubocop-0.53.0
- old
+ new
@@ -3,11 +3,25 @@
module RuboCop
module Cop
module Layout
# This cops checks for indentation of the first non-blank non-comment
# line in a file.
+ #
+ # @example
+ # # bad
+ # class A
+ # def foo; end
+ # end
+ #
+ # # good
+ # class A
+ # def foo; end
+ # end
+ #
class InitialIndentation < Cop
+ include RangeHelp
+
MSG = 'Indentation of first line in file detected.'.freeze
def investigate(_processed_source)
space_before(first_token) do |space|
add_offense(space, location: first_token.pos)
@@ -19,10 +33,10 @@
end
private
def first_token
- processed_source.tokens.find { |t| !t.text.start_with?('#') }
+ processed_source.find_token { |t| !t.text.start_with?('#') }
end
def space_before(token)
return unless token
return if token.column.zero?