rubocop-yard 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -3
- data/lib/rubocop/cop/yard/collection_style.rb +6 -2
- data/lib/rubocop/cop/yard/collection_type.rb +2 -3
- data/lib/rubocop/cop/yard/{collection_helper.rb → helper.rb} +6 -2
- data/lib/rubocop/cop/yard/mismatch_name.rb +36 -13
- data/lib/rubocop/cop/yard/tag_type_syntax.rb +3 -11
- data/lib/rubocop/cop/yard_cops.rb +1 -1
- data/lib/rubocop/yard/version.rb +1 -1
- metadata +3 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: e5f138fd3b5b0c5eb5550b368164986ba104280ebb40af21d7b8fe843105dad3
         | 
| 4 | 
            +
              data.tar.gz: 2a237052e98046b9ac7ffcd72100fd1d96ad90164d8075e8f997981c73a78f98
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: fe3818daae4c2d4597a86ad8f1e1e6785a56e5c34e5e96b0b78be0b52b7cb219ce4d9f390ebac30af9ec844d5f2add8f4c7dfa7d5d4e6496543a0ab6a880980d
         | 
| 7 | 
            +
              data.tar.gz: fd20c16153f50987d92fe2c5a6af00ecf1fd274d29205d57e63c8c176a314555de9f9e926ae1bad5b7c5b18bf3d1e7adcca26e8ead35b0f8eacc55744fb4cabb
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    
| @@ -42,7 +42,7 @@ module RuboCop | |
| 42 42 | 
             
                  #   # good
         | 
| 43 43 | 
             
                  #   # @param [Array<String>]
         | 
| 44 44 | 
             
                  class CollectionStyle < Base
         | 
| 45 | 
            -
                    include YARD:: | 
| 45 | 
            +
                    include YARD::Helper
         | 
| 46 46 | 
             
                    include RangeHelp
         | 
| 47 47 | 
             
                    include ConfigurableEnforcedStyle
         | 
| 48 48 | 
             
                    extend AutoCorrector
         | 
| @@ -62,7 +62,7 @@ module RuboCop | |
| 62 62 | 
             
                      docstring = ::YARD::DocstringParser.new.parse(comment.text.gsub(/\A#\s*/, ''))
         | 
| 63 63 | 
             
                      each_types_explainer(docstring) do |type, types_explainer|
         | 
| 64 64 | 
             
                        correct_type = styled_string(types_explainer)
         | 
| 65 | 
            -
                        unless type == correct_type
         | 
| 65 | 
            +
                        unless ignore_whitespace(type) == ignore_whitespace(correct_type)
         | 
| 66 66 | 
             
                          add_offense(comment, message: "`#{type}` is using #{bad_style} style syntax") do |corrector|
         | 
| 67 67 | 
             
                            corrector.replace(comment, comment.source.sub(/\[(.*)\]/) { "[#{correct_type}]" })
         | 
| 68 68 | 
             
                          end
         | 
| @@ -70,6 +70,10 @@ module RuboCop | |
| 70 70 | 
             
                      end
         | 
| 71 71 | 
             
                    end
         | 
| 72 72 |  | 
| 73 | 
            +
                    def ignore_whitespace(str)
         | 
| 74 | 
            +
                      str.tr(' ', '')
         | 
| 75 | 
            +
                    end
         | 
| 76 | 
            +
             | 
| 73 77 | 
             
                    def bad_style
         | 
| 74 78 | 
             
                      if style == :long
         | 
| 75 79 | 
             
                        :short
         | 
| @@ -22,7 +22,7 @@ module RuboCop | |
| 22 22 | 
             
                  #   # good
         | 
| 23 23 | 
             
                  #   # @param [Hash{Symbol => String}]
         | 
| 24 24 | 
             
                  class CollectionType < Base
         | 
| 25 | 
            -
                    include YARD:: | 
| 25 | 
            +
                    include YARD::Helper
         | 
| 26 26 | 
             
                    include RangeHelp
         | 
| 27 27 | 
             
                    include ConfigurableEnforcedStyle
         | 
| 28 28 | 
             
                    extend AutoCorrector
         | 
| @@ -86,8 +86,7 @@ module RuboCop | |
| 86 86 | 
             
                        case types_explainer.name
         | 
| 87 87 | 
             
                        when 'Hash'
         | 
| 88 88 | 
             
                          if types_explainer.types.length == 2
         | 
| 89 | 
            -
                             | 
| 90 | 
            -
                            message = "`Hash<Key, Value>` is the documented hash specific syntax"
         | 
| 89 | 
            +
                            message = "`Hash<Key, Value>` is ambiguous syntax"
         | 
| 91 90 | 
             
                            add_offense(tag_range_for_comment(comment), message: message) do |corrector|
         | 
| 92 91 | 
             
                              hash_type = ::YARD::Tags::TypesExplainer::HashCollectionType.new(
         | 
| 93 92 | 
             
                                'Hash',
         | 
| @@ -3,7 +3,7 @@ | |
| 3 3 | 
             
            module RuboCop
         | 
| 4 4 | 
             
              module Cop
         | 
| 5 5 | 
             
                module YARD
         | 
| 6 | 
            -
                  module  | 
| 6 | 
            +
                  module Helper
         | 
| 7 7 | 
             
                    def extract_tag_types(tag)
         | 
| 8 8 | 
             
                      case tag
         | 
| 9 9 | 
             
                      when ::YARD::Tags::OptionTag
         | 
| @@ -13,12 +13,16 @@ module RuboCop | |
| 13 13 | 
             
                      end
         | 
| 14 14 | 
             
                    end
         | 
| 15 15 |  | 
| 16 | 
            +
                    def parse_type(type)
         | 
| 17 | 
            +
                      ::YARD::Tags::TypesExplainer::Parser.parse(type)
         | 
| 18 | 
            +
                    end
         | 
| 19 | 
            +
             | 
| 16 20 | 
             
                    def each_types_explainer(docstring, &block)
         | 
| 17 21 | 
             
                      docstring.tags.each do |tag|
         | 
| 18 22 | 
             
                        types = extract_tag_types(tag)
         | 
| 19 23 |  | 
| 20 24 | 
             
                        begin
         | 
| 21 | 
            -
                          types_explainers =  | 
| 25 | 
            +
                          types_explainers = parse_type(types.join(', '))
         | 
| 22 26 | 
             
                          types.zip(types_explainers).each do |type, types_explainer|
         | 
| 23 27 | 
             
                            block.call(type, types_explainer)
         | 
| 24 28 | 
             
                          end
         | 
| @@ -17,6 +17,7 @@ module RuboCop | |
| 17 17 | 
             
                  #   def foo(bar, opts = {}, *arg)
         | 
| 18 18 | 
             
                  #   end
         | 
| 19 19 | 
             
                  class MismatchName < Base
         | 
| 20 | 
            +
                    include YARD::Helper
         | 
| 20 21 | 
             
                    include RangeHelp
         | 
| 21 22 | 
             
                    include DocumentationComment
         | 
| 22 23 |  | 
| @@ -28,31 +29,49 @@ module RuboCop | |
| 28 29 |  | 
| 29 30 | 
             
                      yard_docstring = preceding_lines.map { |line| line.text.gsub(/\A#\s*/, '') }.join("\n")
         | 
| 30 31 | 
             
                      docstring = ::YARD::DocstringParser.new.parse(yard_docstring)
         | 
| 31 | 
            -
                       | 
| 32 | 
            -
                        next unless tag.tag_name == 'param' || tag.tag_name == 'option'
         | 
| 32 | 
            +
                      return false if include_overload_tag?(docstring)
         | 
| 33 33 |  | 
| 34 | 
            -
             | 
| 35 | 
            -
                         | 
| 34 | 
            +
                      each_tags_by_docstring(['param', 'option'], docstring) do |tags|
         | 
| 35 | 
            +
                        tags.each_with_index do |tag, i|
         | 
| 36 | 
            +
                          comment = find_by_tag(preceding_lines, tag, i)
         | 
| 37 | 
            +
                          next unless comment
         | 
| 36 38 |  | 
| 37 | 
            -
             | 
| 38 | 
            -
                          if tag. | 
| 39 | 
            -
             | 
| 40 | 
            -
                           | 
| 41 | 
            -
             | 
| 39 | 
            +
                          # YARD::Tags::RefTagList is not has name and types
         | 
| 40 | 
            +
                          next if tag.instance_of?(::YARD::Tags::RefTagList)
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                          types = extract_tag_types(tag)
         | 
| 43 | 
            +
                          unless tag.name && types
         | 
| 44 | 
            +
                            if tag.name.nil?
         | 
| 45 | 
            +
                              add_offense(comment, message: "No tag name is supplied in `@#{tag.tag_name}`")
         | 
| 46 | 
            +
                            elsif types.nil?
         | 
| 47 | 
            +
                              add_offense(comment, message: "No types are associated with the tag in `@#{tag.tag_name}`")
         | 
| 48 | 
            +
                            end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                            next
         | 
| 42 51 | 
             
                          end
         | 
| 43 52 |  | 
| 44 | 
            -
                          next
         | 
| 45 | 
            -
                        end
         | 
| 53 | 
            +
                          next unless node.arguments.none? { |arg_node| tag.name.to_sym == arg_node.name }
         | 
| 46 54 |  | 
| 47 | 
            -
             | 
| 55 | 
            +
                          begin
         | 
| 56 | 
            +
                            parse_type(types.join(', '))
         | 
| 57 | 
            +
                          rescue SyntaxError
         | 
| 58 | 
            +
                            next
         | 
| 59 | 
            +
                          end
         | 
| 48 60 |  | 
| 49 | 
            -
             | 
| 61 | 
            +
                          add_offense_to_tag(comment, tag)
         | 
| 62 | 
            +
                        end
         | 
| 50 63 | 
             
                      end
         | 
| 51 64 | 
             
                    end
         | 
| 52 65 | 
             
                    alias on_defs on_def
         | 
| 53 66 |  | 
| 54 67 | 
             
                    private
         | 
| 55 68 |  | 
| 69 | 
            +
                    def each_tags_by_docstring(tag_names, docstring)
         | 
| 70 | 
            +
                      tag_names.each do |tag_name|
         | 
| 71 | 
            +
                        yield docstring.tags.select { |tag| tag.tag_name == tag_name }
         | 
| 72 | 
            +
                      end
         | 
| 73 | 
            +
                    end
         | 
| 74 | 
            +
             | 
| 56 75 | 
             
                    def find_by_tag(preceding_lines, tag, i)
         | 
| 57 76 | 
             
                      count = -1
         | 
| 58 77 | 
             
                      preceding_lines.find do |line|
         | 
| @@ -69,6 +88,10 @@ module RuboCop | |
| 69 88 | 
             
                      range = source_range(processed_source.buffer, comment.location.line, offense_start..offense_end)
         | 
| 70 89 | 
             
                      add_offense(range, message: "`#{tag.name}` is not found in method arguments")
         | 
| 71 90 | 
             
                    end
         | 
| 91 | 
            +
             | 
| 92 | 
            +
                    def include_overload_tag?(docstring)
         | 
| 93 | 
            +
                      docstring.tags.any? { |tag| tag.tag_name == "overload" }
         | 
| 94 | 
            +
                    end
         | 
| 72 95 | 
             
                  end
         | 
| 73 96 | 
             
                end
         | 
| 74 97 | 
             
              end
         | 
| @@ -10,6 +10,7 @@ module RuboCop | |
| 10 10 | 
             
                  #   # good
         | 
| 11 11 | 
             
                  #   # @param [Integer, String]
         | 
| 12 12 | 
             
                  class TagTypeSyntax < Base
         | 
| 13 | 
            +
                    include YARD::Helper
         | 
| 13 14 | 
             
                    include RangeHelp
         | 
| 14 15 |  | 
| 15 16 | 
             
                    def on_new_investigation
         | 
| @@ -26,10 +27,10 @@ module RuboCop | |
| 26 27 | 
             
                    def check(comment)
         | 
| 27 28 | 
             
                      docstring = comment.text.gsub(/\A#\s*/, '')
         | 
| 28 29 | 
             
                      ::YARD::DocstringParser.new.parse(docstring).tags.each do |tag|
         | 
| 29 | 
            -
                        types =  | 
| 30 | 
            +
                        types = extract_tag_types(tag)
         | 
| 30 31 |  | 
| 31 32 | 
             
                        check_syntax_error(comment) do
         | 
| 32 | 
            -
                           | 
| 33 | 
            +
                          parse_type(types.join(', '))
         | 
| 33 34 | 
             
                        end
         | 
| 34 35 | 
             
                      end
         | 
| 35 36 | 
             
                    end
         | 
| @@ -42,15 +43,6 @@ module RuboCop | |
| 42 43 | 
             
                      end
         | 
| 43 44 | 
             
                    end
         | 
| 44 45 |  | 
| 45 | 
            -
                    def extract_tag_type(tag)
         | 
| 46 | 
            -
                      case tag
         | 
| 47 | 
            -
                      when ::YARD::Tags::OptionTag
         | 
| 48 | 
            -
                        tag.pair.types
         | 
| 49 | 
            -
                      else
         | 
| 50 | 
            -
                        tag.types
         | 
| 51 | 
            -
                      end
         | 
| 52 | 
            -
                    end
         | 
| 53 | 
            -
             | 
| 54 46 | 
             
                    def inline_comment?(comment)
         | 
| 55 47 | 
             
                      !comment_line?(comment.source_range.source_line)
         | 
| 56 48 | 
             
                    end
         | 
    
        data/lib/rubocop/yard/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: rubocop-yard
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.6.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - ksss
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2023-10- | 
| 11 | 
            +
            date: 2023-10-10 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rubocop
         | 
| @@ -51,9 +51,9 @@ files: | |
| 51 51 | 
             
            - README.md
         | 
| 52 52 | 
             
            - config/default.yml
         | 
| 53 53 | 
             
            - lib/rubocop-yard.rb
         | 
| 54 | 
            -
            - lib/rubocop/cop/yard/collection_helper.rb
         | 
| 55 54 | 
             
            - lib/rubocop/cop/yard/collection_style.rb
         | 
| 56 55 | 
             
            - lib/rubocop/cop/yard/collection_type.rb
         | 
| 56 | 
            +
            - lib/rubocop/cop/yard/helper.rb
         | 
| 57 57 | 
             
            - lib/rubocop/cop/yard/meaningless_tag.rb
         | 
| 58 58 | 
             
            - lib/rubocop/cop/yard/mismatch_name.rb
         | 
| 59 59 | 
             
            - lib/rubocop/cop/yard/tag_type_syntax.rb
         |