Class: RuboCop::Cop::FileAnnotate::FirstLineComment

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/file_annotate/first_line_comment.rb

Overview

檢查檔案開頭的相對路徑註解是否符合設定

Constant Summary collapse

MSG_MISSING =
"Missing file path comment."
MSG_FORBIDDEN =
"File path comment is forbidden on the first line."

Instance Method Summary collapse

Instance Method Details

#on_new_investigationObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rubocop/cop/file_annotate/first_line_comment.rb', line 15

def on_new_investigation
  return if processed_source.lines.empty?

  @project_root = Pathname.pwd
  @absolute_path = Pathname.new(processed_source.file_path)
  @relative_path = @absolute_path.relative_path_from(@project_root).to_s
  @expected_comment = "# #{@relative_path}"

  case enforced_style
  when :required
    check_required
  when :forbidden
    check_forbidden
  end
end