diff options
| author | Mike McQuaid | 2017-06-02 15:48:22 +0100 | 
|---|---|---|
| committer | GitHub | 2017-06-02 15:48:22 +0100 | 
| commit | ce80485aa4c1c0e6e2ee99414801937fa6c291d0 (patch) | |
| tree | aee7d68ca368ee35f0a965056c72092b3b923c01 /Library/Homebrew/rubocops/extend/formula_cop.rb | |
| parent | 760f92abbad0159fb522cca6a8555123e736e285 (diff) | |
| parent | cf848a14d2de60b425d6e279051a919ff6ad1e43 (diff) | |
| download | brew-ce80485aa4c1c0e6e2ee99414801937fa6c291d0.tar.bz2 | |
Merge pull request #2664 from GauthamGoli/audit_caveats_rubocop
audit: Port audit_caveats method to rubocop and add tests
Diffstat (limited to 'Library/Homebrew/rubocops/extend/formula_cop.rb')
| -rw-r--r-- | Library/Homebrew/rubocops/extend/formula_cop.rb | 19 | 
1 files changed, 18 insertions, 1 deletions
diff --git a/Library/Homebrew/rubocops/extend/formula_cop.rb b/Library/Homebrew/rubocops/extend/formula_cop.rb index d9940a037..75a3e72d5 100644 --- a/Library/Homebrew/rubocops/extend/formula_cop.rb +++ b/Library/Homebrew/rubocops/extend/formula_cop.rb @@ -24,7 +24,11 @@ module RuboCop          return unless match_object          node_begin_pos = start_column(node)          line_begin_pos = line_start_column(node) -        @column = node_begin_pos + match_object.begin(0) - line_begin_pos + 1 +        if node_begin_pos == line_begin_pos +          @column = node_begin_pos + match_object.begin(0) - line_begin_pos +        else +          @column = node_begin_pos + match_object.begin(0) - line_begin_pos + 1 +        end          @length = match_object.to_s.length          @line_no = line_number(node)          @source_buf = source_buffer(node) @@ -33,6 +37,12 @@ module RuboCop          match_object        end +      # Returns all string nodes among the descendants of given node +      def find_strings(node) +        return [] if node.nil? +        node.each_descendant(:str) +      end +        # Returns method_node matching method_name        def find_node_method_by_name(node, method_name)          return if node.nil? @@ -233,6 +243,11 @@ module RuboCop          true        end +      # Return all the caveats' string nodes in an array +      def caveats_strings +        find_strings(find_method_def(@body, :caveats)) +      end +        # Returns the array of arguments of the method_node        def parameters(method_node)          return unless method_node.send_type? @@ -308,6 +323,8 @@ module RuboCop            return node.each_child_node(:str).map(&:str_content).join("") if node.type == :dstr          when :const            return node.const_name if node.type == :const +        else +          ""          end        end  | 
