Module: AnnotateRb::ModelAnnotator::FileParser::MagicComment

Defined in:
lib/annotate_rb/model_annotator/file_parser/magic_comment.rb

Constant Summary collapse

DIRECTIVE_KEYS =
%w[
  encoding
  coding
  frozen_string_literal
  warn_indent
  shareable_constant_value
  typed
  rbs_inline
].freeze
SIMPLE =
/\A\s*#\s*(?<key>[A-Za-z][A-Za-z0-9_-]*)\s*:\s*\S/
EMACS =
/\A\s*#\s*-\*-.*-\*-\s*\z/
VIM =
/\A\s*#\s*vim:\s/

Class Method Summary collapse

Class Method Details

.match?(line) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
# File 'lib/annotate_rb/model_annotator/file_parser/magic_comment.rb', line 21

def self.match?(line)
  if (m = SIMPLE.match(line))
    key = m[:key].downcase.tr("-", "_")
    return true if DIRECTIVE_KEYS.include?(key)
  end

  EMACS.match?(line) || VIM.match?(line)
end