diff --git a/Library/.rubocop.yml b/Library/.rubocop.yml index 07f9cc84fa..442315e6b0 100644 --- a/Library/.rubocop.yml +++ b/Library/.rubocop.yml @@ -8,16 +8,16 @@ AllCops: require: ./Homebrew/rubocops.rb -FormulaAuditStrict/CorrectBottleBlock: +FormulaAuditStrict/BottleBlock: Enabled: true -FormulaAuditStrict/FormulaDesc: +FormulaAuditStrict/Desc: Enabled: true -Homebrew/FormulaComponentsOrder: +FormulaAuditStrict/ComponentsOrder: Enabled: true -Homebrew/ComponentsRedundancy: +FormulaAuditStrict/ComponentsRedundancy: Enabled: true Metrics/AbcSize: diff --git a/Library/Homebrew/cmd/style.rb b/Library/Homebrew/cmd/style.rb index 4410f0febc..640ec8010f 100644 --- a/Library/Homebrew/cmd/style.rb +++ b/Library/Homebrew/cmd/style.rb @@ -1,4 +1,4 @@ -#: * `style` [`--fix`] [`--display-cop-names`] [||]: +#: * `style` [`--fix`] [`--display-cop-names`] [`--only-cops=`[COP1,COP2..]|`--except-cops=`[COP1,COP2..]] [||]: #: Check formulae or files for conformance to Homebrew style guidelines. #: #: and 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? diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index e96d4cf4cd..013c1355ab 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -1,4 +1,4 @@ -#: * `audit` [`--strict`] [`--fix`] [`--online`] [`--new-formula`] [`--display-cop-names`] [`--display-filename`] [`--only=`|`--except=`]: +#: * `audit` [`--strict`] [`--fix`] [`--online`] [`--new-formula`] [`--display-cop-names`] [`--display-filename`] [`--only=`|`--except=`] [`--only-cops=`[COP1,COP2..]|`--except-cops=`[COP1,COP2..]] []: #: Check for Homebrew coding style violations. This should be #: run before submitting a new formula. #: @@ -27,9 +27,9 @@ #: #: If `--except` is passed, the methods named `audit_` will not be run. #: -#: If `--only-cops` is passed, only the mentioned cops' violations would be checked. +#: If `--only-cops` is passed, only the given Rubocop cop(s)' violations would be checked. #: -#: If `--except-cops` is passed, the mentioned cops' checks would be skipped. +#: If `--except-cops` is passed, the given Rubocop cop(s)' checks would be skipped. #: #: `audit` exits with a non-zero status if any errors are found. This is useful, #: for instance, for implementing pre-commit hooks. @@ -76,17 +76,21 @@ module Homebrew 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 simulataneously!" + odie "--only-cops and --except-cops cannot be used simultaneously!" + elsif (!only_cops.empty? || !except_cops.empty?) && strict + odie "--only-cops/--except-cops and --strict cannot be used simultaneously" end - if strict - options = { fix: ARGV.flag?("--fix"), realpath: true } - else - options = { fix: ARGV.flag?("--fix"), realpath: true, exclude: :FormulaAuditStrict } + options = { fix: ARGV.flag?("--fix"), realpath: true } + + if !only_cops.empty? + options[:only_cops] = only_cops + elsif !except_cops.empty? + options[:except_cops] = except_cops + elsif !strict + options[:except_cops] = [:FormulaAuditStrict] end - options[:only] = only_cops unless only_cops.empty? - options[:except] = except_cops unless except_cops.empty? # Check style in a single batch run up front for performance style_results = check_style_json(files, options) @@ -1272,7 +1276,7 @@ class FormulaAuditor only_audits = ARGV.value("only").to_s.split(",") except_audits = ARGV.value("except").to_s.split(",") if !only_audits.empty? && !except_audits.empty? - odie "--only and --except cannot be used simulataneously!" + odie "--only and --except cannot be used simultaneously!" end methods.map(&:to_s).grep(/^audit_/).each do |audit_method_name| diff --git a/Library/Homebrew/rubocops/bottle_block_cop.rb b/Library/Homebrew/rubocops/bottle_block_cop.rb index 2d6289cbb9..f0c7d59bb1 100644 --- a/Library/Homebrew/rubocops/bottle_block_cop.rb +++ b/Library/Homebrew/rubocops/bottle_block_cop.rb @@ -7,7 +7,7 @@ module RuboCop # # - `rebuild` should be used instead of `revision` in `bottle` block - class CorrectBottleBlock < FormulaCop + class BottleBlock < FormulaCop MSG = "Use rebuild instead of revision in bottle block".freeze def audit_formula(_node, _class_node, _parent_class_node, formula_class_body_node) diff --git a/Library/Homebrew/rubocops/components_order_cop.rb b/Library/Homebrew/rubocops/components_order_cop.rb index c66b5614ea..a6259133d3 100644 --- a/Library/Homebrew/rubocops/components_order_cop.rb +++ b/Library/Homebrew/rubocops/components_order_cop.rb @@ -2,12 +2,12 @@ require_relative "./extend/formula_cop" module RuboCop module Cop - module Homebrew + module FormulaAuditStrict # This cop checks for correct order of components in a Formula # # - component_precedence_list has component hierarchy in a nested list # where each sub array contains components' details which are at same precedence level - class FormulaComponentsOrder < FormulaCop + class ComponentsOrder < FormulaCop def audit_formula(_node, _class_node, _parent_class_node, formula_class_body_node) component_precedence_list = [ [{ name: :include, type: :method_call }], diff --git a/Library/Homebrew/rubocops/components_redundancy_cop.rb b/Library/Homebrew/rubocops/components_redundancy_cop.rb index 3d95d6c053..52dba4718f 100644 --- a/Library/Homebrew/rubocops/components_redundancy_cop.rb +++ b/Library/Homebrew/rubocops/components_redundancy_cop.rb @@ -2,7 +2,7 @@ require_relative "./extend/formula_cop" module RuboCop module Cop - module Homebrew + module FormulaAuditStrict # This cop checks if redundant components are present and other component errors # # - `url|checksum|mirror` should be inside `stable` block diff --git a/Library/Homebrew/rubocops/formula_desc_cop.rb b/Library/Homebrew/rubocops/formula_desc_cop.rb index d72fa53cc3..1fbf1ddbfc 100644 --- a/Library/Homebrew/rubocops/formula_desc_cop.rb +++ b/Library/Homebrew/rubocops/formula_desc_cop.rb @@ -11,7 +11,7 @@ module RuboCop # - Checks if `desc` begins with an article # - Checks for correct usage of `command-line` in `desc` # - Checks if `desc` contains the formula name - class FormulaDesc < FormulaCop + class Desc < FormulaCop def audit_formula(_node, _class_node, _parent_class_node, body) desc_call = find_node_method_by_name(body, :desc) diff --git a/Library/Homebrew/test/rubocops/bottle_block_cop_spec.rb b/Library/Homebrew/test/rubocops/bottle_block_cop_spec.rb index a7ae0c6ac9..a775b0b175 100644 --- a/Library/Homebrew/test/rubocops/bottle_block_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/bottle_block_cop_spec.rb @@ -3,7 +3,7 @@ require "rubocop/rspec/support" require_relative "../../extend/string" require_relative "../../rubocops/bottle_block_cop" -describe RuboCop::Cop::FormulaAuditStrict::CorrectBottleBlock do +describe RuboCop::Cop::FormulaAuditStrict::BottleBlock do subject(:cop) { described_class.new } context "When auditing Bottle Block" do diff --git a/Library/Homebrew/test/rubocops/components_order_cop_spec.rb b/Library/Homebrew/test/rubocops/components_order_cop_spec.rb index a424da8635..05ff53d8f8 100644 --- a/Library/Homebrew/test/rubocops/components_order_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/components_order_cop_spec.rb @@ -3,7 +3,7 @@ require "rubocop/rspec/support" require_relative "../../extend/string" require_relative "../../rubocops/components_order_cop" -describe RuboCop::Cop::Homebrew::FormulaComponentsOrder do +describe RuboCop::Cop::FormulaAuditStrict::ComponentsOrder do subject(:cop) { described_class.new } context "When auditing formula components order" do diff --git a/Library/Homebrew/test/rubocops/components_redundancy_cop_spec.rb b/Library/Homebrew/test/rubocops/components_redundancy_cop_spec.rb index 5637330d83..fd635a1264 100644 --- a/Library/Homebrew/test/rubocops/components_redundancy_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/components_redundancy_cop_spec.rb @@ -3,7 +3,7 @@ require "rubocop/rspec/support" require_relative "../../extend/string" require_relative "../../rubocops/components_redundancy_cop" -describe RuboCop::Cop::Homebrew::ComponentsRedundancy do +describe RuboCop::Cop::FormulaAuditStrict::ComponentsRedundancy do subject(:cop) { described_class.new } context "When auditing formula components common errors" do diff --git a/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb b/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb index 7a30267032..5816679359 100644 --- a/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb @@ -3,7 +3,7 @@ require "rubocop/rspec/support" require_relative "../../extend/string" require_relative "../../rubocops/formula_desc_cop" -describe RuboCop::Cop::FormulaAuditStrict::FormulaDesc do +describe RuboCop::Cop::FormulaAuditStrict::Desc do subject(:cop) { described_class.new } context "When auditing formula desc" do diff --git a/docs/Manpage.md b/docs/Manpage.md index 4e173668a3..fcc6cf4a0c 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -402,7 +402,7 @@ With `--verbose` or `-v`, many commands print extra debugging information. Note If `--env=std` is passed, use the standard `PATH` instead of superenv's. - * `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 @@ -415,6 +415,10 @@ With `--verbose` or `-v`, many commands print extra debugging information. Note 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. * `switch` `name` `version`: @@ -606,7 +610,7 @@ With `--verbose` or `-v`, many commands print extra debugging information. Note ## DEVELOPER COMMANDS - * `audit` [`--strict`] [`--fix`] [`--online`] [`--new-formula`] [`--display-cop-names`] [`--display-filename`] [`--only=``method`|`--except=``method] [\fR will be If \fB\-\-except\fR is passed, the methods named \fBaudit_\fR will not be run\. . .IP -If \fB\-\-only\-cops\fR is passed, only the mentioned cops\' violations would be checked\. +If \fB\-\-only\-cops\fR is passed, only the given Rubocop cop(s)\' violations would be checked\. . .IP -If \fB\-\-except\-cops\fR is passed, the mentioned cops\' checks would be skipped\. +If \fB\-\-except\-cops\fR is passed, the given Rubocop cop(s)\' checks would be skipped\. . .IP \fBaudit\fR exits with a non\-zero status if any errors are found\. This is useful, for instance, for implementing pre\-commit hooks\.