diff options
Diffstat (limited to 'Library/Homebrew/cmd/style.rb')
| -rw-r--r-- | Library/Homebrew/cmd/style.rb | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/Library/Homebrew/cmd/style.rb b/Library/Homebrew/cmd/style.rb index 4410f0feb..640ec8010 100644 --- a/Library/Homebrew/cmd/style.rb +++ b/Library/Homebrew/cmd/style.rb @@ -1,4 +1,4 @@ -#: * `style` [`--fix`] [`--display-cop-names`] [<files>|<taps>|<formulae>]: +#: * `style` [`--fix`] [`--display-cop-names`] [`--only-cops=`[COP1,COP2..]|`--except-cops=`[COP1,COP2..]] [<files>|<taps>|<formulae>]: #: Check formulae or files for conformance to Homebrew style guidelines. #: #: <formulae> and <files> may not be combined. If both are omitted, style will run @@ -11,6 +11,10 @@ #: If `--display-cop-names` is passed, the RuboCop cop name for each violation #: is included in the output. #: +#: If `--only-cops` is passed, only the given Rubocop cop(s)' violations would be checked. +#: +#: If `--except-cops` is passed, the given Rubocop cop(s)' checks would be skipped. +#: #: Exits with a non-zero status if any style violations are found. require "utils" @@ -32,7 +36,20 @@ module Homebrew ARGV.formulae.map(&:path) end - Homebrew.failed = check_style_and_print(target, fix: ARGV.flag?("--fix")) + only_cops = ARGV.value("only-cops").to_s.split(",") + except_cops = ARGV.value("except-cops").to_s.split(",") + if !only_cops.empty? && !except_cops.empty? + odie "--only-cops and --except-cops cannot be used simultaneously!" + end + + options = { fix: ARGV.flag?("--fix") } + if !only_cops.empty? + options[:only_cops] = only_cops + elsif !except_cops.empty? + options[:except_cops] = except_cops + end + + Homebrew.failed = check_style_and_print(target, options) end # Checks style for a list of files, printing simple RuboCop output. @@ -56,18 +73,22 @@ module Homebrew ] args << "--auto-correct" if fix - if options[:exclude].eql?(:FormulaAuditStrict) && !(options.key?(:except) || options.key?(:only)) - args << "--except" << :FormulaAuditStrict - end + if options[:except_cops] + options[:except_cops].map! { |cop| RuboCop::Cop::Cop.registry.qualified_cop_name(cop, "") } + cops_to_exclude = options[:except_cops].select do |cop| + RuboCop::Cop::Cop.registry.names.include?(cop) || + RuboCop::Cop::Cop.registry.departments.include?(cop.to_sym) + end - if options[:except] - cops_to_exclude = options[:except].select { |cop| RuboCop::Cop::Cop.registry.names.include?(cop) } - args << "--except" << cops_to_exclude.join(" ") unless cops_to_exclude.empty? - end + args << "--except" << cops_to_exclude.join(",") unless cops_to_exclude.empty? + elsif options[:only_cops] + options[:only_cops].map! { |cop| RuboCop::Cop::Cop.registry.qualified_cop_name(cop, "") } + cops_to_include = options[:only_cops].select do |cop| + RuboCop::Cop::Cop.registry.names.include?(cop) || + RuboCop::Cop::Cop.registry.departments.include?(cop.to_sym) + end - if options[:only] - cops_to_include = options[:only].select { |cop| RuboCop::Cop::Cop.registry.names.include?(cop) } - args << "--only" << cops_to_include.join(" ") unless cops_to_include.empty? + args << "--only" << cops_to_include.join(",") unless cops_to_include.empty? end if files.nil? |
