Class: RuboCop::MagicComment::VimComment

Inherits:
EditorComment show all
Defined in:
lib/rubocop/magic_comment.rb

Overview

Wrapper for Vim style magic comments.

Examples:

Vim style comment

comment = RuboCop::MagicComment.parse(
  '# vim: filetype=ruby, fileencoding=ascii-8bit'
)

comment.encoding # => 'ascii-8bit'

Constant Summary collapse

REGEXP =
/#\s*vim:\s*(?<token>.+)/.freeze
FORMAT =
'# vim: %s'
SEPARATOR =
', '
OPERATOR =
'='
KEYWORDS =
MagicComment::KEYWORDS.merge(encoding: 'fileencoding').freeze

Constants inherited from RuboCop::MagicComment

TOKEN

Instance Method Summary collapse

Methods inherited from EditorComment

#without

Methods inherited from RuboCop::MagicComment

#any?, #encoding_specified?, #frozen_string_literal?, #frozen_string_literal_specified?, #initialize, parse, #shareable_constant_value_specified?, #typed, #typed_specified?, #valid?, #valid_literal_value?, #valid_shareable_constant_value?

Constructor Details

This class inherits a constructor from RuboCop::MagicComment

Instance Method Details

#encodingObject

For some reason the fileencoding keyword only works if there is at least one other token included in the string. For example

# works
  # vim: foo=bar, fileencoding=ascii-8bit

# does nothing
  # vim: foo=bar, fileencoding=ascii-8bit


234
235
236
# File 'lib/rubocop/magic_comment.rb', line 234

def encoding
  super if tokens.size > 1
end

#extract_typedObject

Vim comments cannot specify Sorbet typechecking behavior.



245
# File 'lib/rubocop/magic_comment.rb', line 245

def extract_typed; end

#frozen_string_literalObject

Vim comments cannot specify frozen string literal behavior.



239
# File 'lib/rubocop/magic_comment.rb', line 239

def frozen_string_literal; end

#shareable_constant_valueObject

Vim comments cannot specify shareable constant values behavior.



242
# File 'lib/rubocop/magic_comment.rb', line 242

def shareable_constant_value; end