Class: RuboCop::Options Private

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/options.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

This class handles command line options.

Constant Summary collapse

E_STDIN_NO_PATH =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'-s/--stdin requires exactly one path, relative to the ' \
'root of the project. RuboCop will use this path to determine which ' \
'cops are enabled (via eg. Include/Exclude), and so that certain cops ' \
'like Naming/FileName can be checked.'
EXITING_OPTIONS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

%i[version verbose_version show_cops show_docs_url lsp].freeze
DEFAULT_MAXIMUM_EXCLUSION_ITEMS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

15

Instance Method Summary collapse

Constructor Details

#initializeOptions

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Options.



22
23
24
25
# File 'lib/rubocop/options.rb', line 22

def initialize
  @options = {}
  @validator = OptionsValidator.new(@options)
end

Instance Method Details

#parse(command_line_args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rubocop/options.rb', line 27

def parse(command_line_args)
  args_from_file = ArgumentsFile.read_as_arguments
  args_from_env = ArgumentsEnv.read_as_arguments
  args = args_from_file.concat(args_from_env).concat(command_line_args)

  define_options.parse!(args)

  @validator.validate_compatibility

  if @options[:stdin]
    # The parser will put the file name given after --stdin into
    # @options[:stdin]. If it did, then the args array should be empty.
    raise OptionArgumentError, E_STDIN_NO_PATH if args.any?

    # We want the STDIN contents in @options[:stdin] and the file name in
    # args to simplify the rest of the processing.
    args = [@options[:stdin]]
    @options[:stdin] = $stdin.binmode.read
  end

  [@options, args]
end