Class: RuboCop::MCP::Scope Private
| Relationships & Source Files | |
| Inherits: | Object |
| Defined in: | lib/rubocop/mcp/scope.rb |
Overview
What a request asks RuboCop to look at: which cops run, as --only and
--except choose them, and, when checking files, whether to stick to the
ones git says changed, as --changed does.
Constant Summary
-
PROPERTIES =
# File 'lib/rubocop/mcp/scope.rb', line 10{ only: { type: 'array', items: { type: 'string' }, description: 'Run only these cops or departments, ' \ 'such as `Style/StringLiterals` or `Lint`.' }, except: { type: 'array', items: { type: 'string' }, description: 'Run every cop except these cops or departments.' }, changed: { type: %w[boolean string], description: 'Check only the files git says changed: `true` for changes since the ' \ 'last commit, or a revision to compare against, such as `main`.' } }.freeze
Class Method Summary
-
.new(inline:, only: nil, except: nil, changed: nil) ⇒ Scope
constructor
Internal use only
An empty list would select no cops at all rather than leave the choice alone, so it counts as no list.
Instance Method Summary
- #cop_options ⇒ Hash Internal use only
- #select_files(files) Internal use only
-
#validate(inline)
private
Internal use only
Refuses what the command line refuses for the same options.
Constructor Details
.new(inline:, only: nil, except: nil, changed: nil) ⇒ Scope
An empty list would select no cops at all rather than leave the choice alone, so it counts as no list.
# File 'lib/rubocop/mcp/scope.rb', line 31
def initialize(inline:, only: nil, except: nil, changed: nil) @only = only if only&.any? @except = except if except&.any? @changed = changed == true ? ChangedFiles::DEFAULT_REVISION : changed validate(inline) end
Instance Method Details
#cop_options ⇒ Hash
# File 'lib/rubocop/mcp/scope.rb', line 39
def { only: @only, except: @except }.compact end
#select_files(files)
[ GitHub ]# File 'lib/rubocop/mcp/scope.rb', line 43
def select_files(files) @changed ? ChangedFiles.new(@changed).filter(files) : files end
#validate(inline) (private)
Refuses what the command line refuses for the same options. Cop names
are left to the runner, which checks them the way --only does: short
names allowed, and only once the configuration naming a plugin’s cops
has been loaded.
# File 'lib/rubocop/mcp/scope.rb', line 53
def validate(inline) raise Error, '`changed` only applies when checking files.' if inline && @changed raise Error, '`changed` takes `true` or a git revision.' if @changed == '' validator = OptionsValidator.new() if validator.only_includes_redundant_disable? raise Error, 'Lint/RedundantCopDisableDirective cannot be used with `only`.' end raise Error, 'Syntax checking cannot be turned off.' if validator.except_syntax? end