diff options
| author | Mike McQuaid | 2017-04-24 10:06:41 +0100 |
|---|---|---|
| committer | GitHub | 2017-04-24 10:06:41 +0100 |
| commit | ceb1629ad7aeec4c9e9c264efb29b59a96f8556c (patch) | |
| tree | d7fb1f9379f58d15deea3af428d9232970c23bee /Library/Homebrew/rubocops/components_redundancy_cop.rb | |
| parent | cf01485318ba8be4785cf04c35ae30e20e0e1177 (diff) | |
| parent | 413a7e5daebb93f75f8b4839dfd61e42d49b070e (diff) | |
| download | brew-ceb1629ad7aeec4c9e9c264efb29b59a96f8556c.tar.bz2 | |
Merge pull request #2465 from GauthamGoli/audit_components_port_rubocop
audit: audit_components method to rubocops and tests
Diffstat (limited to 'Library/Homebrew/rubocops/components_redundancy_cop.rb')
| -rw-r--r-- | Library/Homebrew/rubocops/components_redundancy_cop.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/Library/Homebrew/rubocops/components_redundancy_cop.rb b/Library/Homebrew/rubocops/components_redundancy_cop.rb new file mode 100644 index 000000000..3d95d6c05 --- /dev/null +++ b/Library/Homebrew/rubocops/components_redundancy_cop.rb @@ -0,0 +1,33 @@ +require_relative "./extend/formula_cop" + +module RuboCop + module Cop + module Homebrew + # This cop checks if redundant components are present and other component errors + # + # - `url|checksum|mirror` should be inside `stable` block + # - `head` and `head do` should not be simultaneously present + # - `bottle :unneeded/:disable` and `bottle do` should not be simultaneously present + + class ComponentsRedundancy < FormulaCop + HEAD_MSG = "`head` and `head do` should not be simultaneously present".freeze + BOTTLE_MSG = "`bottle :modifier` and `bottle do` should not be simultaneously present".freeze + + def audit_formula(_node, _class_node, _parent_class_node, formula_class_body_node) + stable_block = find_block(formula_class_body_node, :stable) + if stable_block + [:url, :sha256, :mirror].each do |method_name| + problem "`#{method_name}` should be put inside `stable` block" if method_called?(formula_class_body_node, method_name) + end + end + + problem HEAD_MSG if method_called?(formula_class_body_node, :head) && + find_block(formula_class_body_node, :head) + + problem BOTTLE_MSG if method_called?(formula_class_body_node, :bottle) && + find_block(formula_class_body_node, :bottle) + end + end + end + end +end |
