Class: RuboCop::OptionsValidator
- Inherits:
-
Object
- Object
- RuboCop::OptionsValidator
- Defined in:
- lib/rubocop/options.rb
Overview
Validates option arguments and the options’ compatibility with each other.
Class Method Summary collapse
-
.validate_cop_list(names) ⇒ Object
Cop name validation must be done later than option parsing, so it’s not called from within Options.
Instance Method Summary collapse
- #boolean_or_empty_cache? ⇒ Boolean
- #except_syntax? ⇒ Boolean
- #incompatible_options ⇒ Object
-
#initialize(options) ⇒ OptionsValidator
constructor
A new instance of OptionsValidator.
- #no_offense_counts_without_auto_gen_config? ⇒ Boolean
- #only_includes_unneeded_disable? ⇒ Boolean
-
#validate_compatibility ⇒ Object
rubocop:disable Metrics/MethodLength.
- #validate_exclude_limit_option(args) ⇒ Object
Constructor Details
#initialize(options) ⇒ OptionsValidator
Returns a new instance of OptionsValidator.
191 192 193 |
# File 'lib/rubocop/options.rb', line 191 def initialize() = end |
Class Method Details
.validate_cop_list(names) ⇒ Object
Cop name validation must be done later than option parsing, so it’s not called from within Options.
178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/rubocop/options.rb', line 178 def self.validate_cop_list(names) return unless names namespaces = Cop::Cop.all.types.map { |t| t.to_s.capitalize } names.each do |name| next if Cop::Cop.all.any? { |c| c.cop_name == name } next if namespaces.include?(name) next if %w(Syntax Lint/Syntax).include?(name) raise ArgumentError, "Unrecognized cop or namespace: #{name}." end end |
Instance Method Details
#boolean_or_empty_cache? ⇒ Boolean
224 225 226 |
# File 'lib/rubocop/options.rb', line 224 def boolean_or_empty_cache? !.key?(:cache) || %w(true false).include?([:cache]) end |
#except_syntax? ⇒ Boolean
219 220 221 222 |
# File 'lib/rubocop/options.rb', line 219 def except_syntax? .key?(:except) && ([:except] & %w(Lint/Syntax Syntax)).any? end |
#incompatible_options ⇒ Object
232 233 234 |
# File 'lib/rubocop/options.rb', line 232 def ||= .keys & Options::EXITING_OPTIONS end |
#no_offense_counts_without_auto_gen_config? ⇒ Boolean
228 229 230 |
# File 'lib/rubocop/options.rb', line 228 def no_offense_counts_without_auto_gen_config? .key?(:no_offense_counts) && !.key?(:auto_gen_config) end |
#only_includes_unneeded_disable? ⇒ Boolean
214 215 216 217 |
# File 'lib/rubocop/options.rb', line 214 def only_includes_unneeded_disable? .key?(:only) && ([:only] & %w(Lint/UnneededDisable UnneededDisable)).any? end |
#validate_compatibility ⇒ Object
rubocop:disable Metrics/MethodLength
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/rubocop/options.rb', line 195 def validate_compatibility # rubocop:disable Metrics/MethodLength if only_includes_unneeded_disable? raise ArgumentError, 'Lint/UnneededDisable can not be used with --only.' end if except_syntax? raise ArgumentError, 'Syntax checking can not be turned off.' end unless boolean_or_empty_cache? raise ArgumentError, '-C/--cache argument must be true or false' end if no_offense_counts_without_auto_gen_config? raise ArgumentError, '--no-offense-counts can only be used together ' \ 'with --auto-gen-config.' end return if .size <= 1 raise ArgumentError, 'Incompatible cli options: ' \ "#{incompatible_options.inspect}" end |
#validate_exclude_limit_option(args) ⇒ Object
236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/rubocop/options.rb', line 236 def validate_exclude_limit_option(args) if [:exclude_limit] !~ /^\d+$/ # Emulate OptionParser's behavior to make failures consistent regardless # of option order. raise OptionParser::MissingArgument end # --exclude-limit is valid if there's a parsed or yet unparsed # --auto-gen-config. return if [:auto_gen_config] || args.include?('--auto-gen-config') raise ArgumentError, '--exclude-limit can only be used with --auto-gen-config.' end |