diff options
| author | Gautham Goli | 2017-05-24 13:04:55 +0530 |
|---|---|---|
| committer | Gautham Goli | 2017-07-07 20:46:57 +0530 |
| commit | 4ed34f91c26b3b3449d676fa2067222d318c4d3a (patch) | |
| tree | 8a92eee4adb12ba728070ed97600065c8389dd9f /Library/Homebrew/rubocops | |
| parent | b5529084906af89827f6d9befd613457a1615918 (diff) | |
| download | brew-4ed34f91c26b3b3449d676fa2067222d318c4d3a.tar.bz2 | |
audit: Port audit_conflicts method to rubocop and add tests
Diffstat (limited to 'Library/Homebrew/rubocops')
| -rw-r--r-- | Library/Homebrew/rubocops/conflicts_cop.rb | 27 | ||||
| -rw-r--r-- | Library/Homebrew/rubocops/extend/formula_cop.rb | 10 |
2 files changed, 37 insertions, 0 deletions
diff --git a/Library/Homebrew/rubocops/conflicts_cop.rb b/Library/Homebrew/rubocops/conflicts_cop.rb new file mode 100644 index 000000000..c1b801559 --- /dev/null +++ b/Library/Homebrew/rubocops/conflicts_cop.rb @@ -0,0 +1,27 @@ +require_relative "./extend/formula_cop" +require_relative "../extend/string" + +module RuboCop + module Cop + module FormulaAudit + # This cop audits versioned Formulae for `conflicts_with` + class Conflicts < FormulaCop + MSG = <<-EOS.undent + Versioned formulae should not use `conflicts_with`. + Use `keg_only :versioned_formula` instead. + EOS + + WHITELIST = %w[ + node@ + bash-completion@ + ].freeze + + def audit_formula(_node, _class_node, _parent_class_node, body) + return unless versioned_formula? + problem MSG if !formula_file_name.start_with?(*WHITELIST) && + method_called_ever?(body, :conflicts_with) + end + end + end + end +end diff --git a/Library/Homebrew/rubocops/extend/formula_cop.rb b/Library/Homebrew/rubocops/extend/formula_cop.rb index 439fde6a5..ddfb507d2 100644 --- a/Library/Homebrew/rubocops/extend/formula_cop.rb +++ b/Library/Homebrew/rubocops/extend/formula_cop.rb @@ -344,6 +344,16 @@ module RuboCop end end + # Returns true if the formula is versioned + def versioned_formula? + formula_file_name.include?("@") || @formula_name.match(/AT\d+/) + end + + # Returns filename of the formula without the extension + def formula_file_name + File.basename(processed_source.buffer.name, ".rb") + end + # Returns printable component name def format_component(component_node) return component_node.method_name if component_node.send_type? || component_node.block_type? |
