Merge pull request #4152 from GauthamGoli/lines-cop-depends-audit
lines_cop: Add deprected options audit for depends_on
This commit is contained in:
		
						commit
						2d9cc7ea1c
					
				@ -58,7 +58,7 @@ module RuboCop
 | 
				
			|||||||
      # Returns all string nodes among the descendants of given node
 | 
					      # Returns all string nodes among the descendants of given node
 | 
				
			||||||
      def find_strings(node)
 | 
					      def find_strings(node)
 | 
				
			||||||
        return [] if node.nil?
 | 
					        return [] if node.nil?
 | 
				
			||||||
        return node if node.str_type?
 | 
					        return [node] if node.str_type?
 | 
				
			||||||
        node.each_descendant(:str)
 | 
					        node.each_descendant(:str)
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -228,12 +228,15 @@ module RuboCop
 | 
				
			|||||||
          end
 | 
					          end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          find_every_method_call_by_name(body_node, :depends_on).each do |method|
 | 
					          find_every_method_call_by_name(body_node, :depends_on).each do |method|
 | 
				
			||||||
            next if modifier?(method.parent)
 | 
					 | 
				
			||||||
            param = parameters(method).first
 | 
					            param = parameters(method).first
 | 
				
			||||||
            dep, option = hash_dep(param)
 | 
					            dep, option_child_nodes = hash_dep(param)
 | 
				
			||||||
            next if dep.nil? || option.nil?
 | 
					            next if dep.nil? || option_child_nodes.empty?
 | 
				
			||||||
            offending_node(param)
 | 
					            option_child_nodes.each do |option|
 | 
				
			||||||
            problem "Dependency #{string_content(dep)} should not use option #{string_content(option)}"
 | 
					              find_strings(option).each do |dependency|
 | 
				
			||||||
 | 
					                next unless match = regex_match_group(dependency, /(with(out)?-\w+|c\+\+11)/)
 | 
				
			||||||
 | 
					                problem "Dependency #{string_content(dep)} should not use option #{match[0]}"
 | 
				
			||||||
 | 
					              end
 | 
				
			||||||
 | 
					            end
 | 
				
			||||||
          end
 | 
					          end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          find_instance_method_call(body_node, :version, :==) do |method|
 | 
					          find_instance_method_call(body_node, :version, :==) do |method|
 | 
				
			||||||
@ -363,10 +366,8 @@ module RuboCop
 | 
				
			|||||||
              (send nil? :depends_on $({str sym} _)))}
 | 
					              (send nil? :depends_on $({str sym} _)))}
 | 
				
			||||||
        EOS
 | 
					        EOS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Match depends_on with hash as argument
 | 
					 | 
				
			||||||
        def_node_matcher :hash_dep, <<~EOS
 | 
					        def_node_matcher :hash_dep, <<~EOS
 | 
				
			||||||
          {(hash (pair $(str _) $(str _)))
 | 
					          (hash (pair $(str _) $...))
 | 
				
			||||||
           (hash (pair $(str _) (array $(str _) ...)))}
 | 
					 | 
				
			||||||
        EOS
 | 
					        EOS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        def_node_matcher :destructure_hash, <<~EOS
 | 
					        def_node_matcher :destructure_hash, <<~EOS
 | 
				
			||||||
 | 
				
			|||||||
@ -693,13 +693,27 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do
 | 
				
			|||||||
      RUBY
 | 
					      RUBY
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    it "dependencies with invalid options" do
 | 
					    it "dependencies with invalid options which lead to force rebuild" do
 | 
				
			||||||
      expect_offense(<<~RUBY)
 | 
					      expect_offense(<<~RUBY)
 | 
				
			||||||
        class Foo < Formula
 | 
					        class Foo < Formula
 | 
				
			||||||
          desc "foo"
 | 
					          desc "foo"
 | 
				
			||||||
          url 'http://example.com/foo-1.0.tgz'
 | 
					          url 'http://example.com/foo-1.0.tgz'
 | 
				
			||||||
          depends_on "foo" => "with-bar"
 | 
					          depends_on "foo" => "with-bar"
 | 
				
			||||||
                     ^^^^^^^^^^^^^^^^^^^ Dependency foo should not use option with-bar
 | 
					                               ^^^^^^^^ Dependency foo should not use option with-bar
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
 | 
					      RUBY
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    it "dependencies with invalid options in array value which lead to force rebuild" do
 | 
				
			||||||
 | 
					      expect_offense(<<~RUBY)
 | 
				
			||||||
 | 
					        class Foo < Formula
 | 
				
			||||||
 | 
					          desc "foo"
 | 
				
			||||||
 | 
					          url 'http://example.com/foo-1.0.tgz'
 | 
				
			||||||
 | 
					          depends_on "httpd" => [:build, :test]
 | 
				
			||||||
 | 
					          depends_on "foo" => [:optional, "with-bar"]
 | 
				
			||||||
 | 
					                                           ^^^^^^^^ Dependency foo should not use option with-bar
 | 
				
			||||||
 | 
					          depends_on "icu4c" => [:optional, "c++11"]
 | 
				
			||||||
 | 
					                                             ^^^^^ Dependency icu4c should not use option c++11
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
      RUBY
 | 
					      RUBY
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user