gitlab-styles 2.2.0 → 2.3.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
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 7c8bcbe5bc056a0c4862e87c4fb7936bd6cb257477b61bcdd2bd446e7cd2dc11
         | 
| 4 | 
            +
              data.tar.gz: 01e72c7ddc449062470f216f166cc37e02d794c64f69758bb56d4ab2485560b1
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 9a3214afbb65c6c79246a72fb4b1ac38715032e3635ed2b4c0a72bddb7a6512bc6122d432c86ddac89a3e405ce41522e0c7af8bf9015fe513b3804ed12f43c69
         | 
| 7 | 
            +
              data.tar.gz: 70a068513cfb5a4937e59cc26a24728fcc1222a6960d3f89f59711b46281e7c3ad6adff5423ec3c334c377aed43530c242408befd2ada70ee256eed90166b46c
         | 
| @@ -7,6 +7,7 @@ require 'gitlab/styles/rubocop/cop/active_record_dependent' | |
| 7 7 | 
             
            require 'gitlab/styles/rubocop/cop/in_batches'
         | 
| 8 8 | 
             
            require 'gitlab/styles/rubocop/cop/line_break_after_guard_clauses'
         | 
| 9 9 | 
             
            require 'gitlab/styles/rubocop/cop/rspec/single_line_hook'
         | 
| 10 | 
            +
            require 'gitlab/styles/rubocop/cop/rspec/verbose_include_metadata'
         | 
| 10 11 |  | 
| 11 12 | 
             
            module Gitlab
         | 
| 12 13 | 
             
              module Styles
         | 
| @@ -0,0 +1,76 @@ | |
| 1 | 
            +
            require 'rubocop-rspec'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Gitlab
         | 
| 4 | 
            +
              module Styles
         | 
| 5 | 
            +
                module Rubocop
         | 
| 6 | 
            +
                  module Cop
         | 
| 7 | 
            +
                    module RSpec
         | 
| 8 | 
            +
                      # Checks for verbose include metadata used in the specs.
         | 
| 9 | 
            +
                      #
         | 
| 10 | 
            +
                      # @example
         | 
| 11 | 
            +
                      #   # bad
         | 
| 12 | 
            +
                      #   describe MyClass, js: true do
         | 
| 13 | 
            +
                      #   end
         | 
| 14 | 
            +
                      #
         | 
| 15 | 
            +
                      #   # good
         | 
| 16 | 
            +
                      #   describe MyClass, :js do
         | 
| 17 | 
            +
                      #   end
         | 
| 18 | 
            +
                      class VerboseIncludeMetadata < RuboCop::Cop::Cop
         | 
| 19 | 
            +
                        MSG = 'Use `%s` instead of `%s`.'.freeze
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                        SELECTORS = %i[describe context feature example_group it specify example scenario its].freeze
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                        def_node_matcher :include_metadata, <<-PATTERN
         | 
| 24 | 
            +
                          (send {(const nil? :RSpec) nil?} {#{SELECTORS.map(&:inspect).join(' ')}}
         | 
| 25 | 
            +
                            !const
         | 
| 26 | 
            +
                            ...
         | 
| 27 | 
            +
                            (hash $...))
         | 
| 28 | 
            +
                        PATTERN
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                        def_node_matcher :invalid_metadata?, <<-PATTERN
         | 
| 31 | 
            +
                          (pair
         | 
| 32 | 
            +
                            (sym $...)
         | 
| 33 | 
            +
                            (true))
         | 
| 34 | 
            +
                        PATTERN
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                        def on_send(node)
         | 
| 37 | 
            +
                          invalid_metadata_matches(node) do |match|
         | 
| 38 | 
            +
                            add_offense(node, location: :expression, message: format(MSG, good(match), bad(match)))
         | 
| 39 | 
            +
                          end
         | 
| 40 | 
            +
                        end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                        def autocorrect(node)
         | 
| 43 | 
            +
                          lambda do |corrector|
         | 
| 44 | 
            +
                            invalid_metadata_matches(node) do |match|
         | 
| 45 | 
            +
                              corrector.replace(match.loc.expression, good(match))
         | 
| 46 | 
            +
                            end
         | 
| 47 | 
            +
                          end
         | 
| 48 | 
            +
                        end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                        private
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                        def invalid_metadata_matches(node)
         | 
| 53 | 
            +
                          include_metadata(node) do |matches|
         | 
| 54 | 
            +
                            matches.select(&method(:invalid_metadata?)).each do |match|
         | 
| 55 | 
            +
                              yield match
         | 
| 56 | 
            +
                            end
         | 
| 57 | 
            +
                          end
         | 
| 58 | 
            +
                        end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                        def bad(match)
         | 
| 61 | 
            +
                          "#{metadata_key(match)}: true"
         | 
| 62 | 
            +
                        end
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                        def good(match)
         | 
| 65 | 
            +
                          ":#{metadata_key(match)}"
         | 
| 66 | 
            +
                        end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                        def metadata_key(match)
         | 
| 69 | 
            +
                          match.children[0].source
         | 
| 70 | 
            +
                        end
         | 
| 71 | 
            +
                      end
         | 
| 72 | 
            +
                    end
         | 
| 73 | 
            +
                  end
         | 
| 74 | 
            +
                end
         | 
| 75 | 
            +
              end
         | 
| 76 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: gitlab-styles
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 2. | 
| 4 | 
            +
              version: 2.3.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - GitLab
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2018-01-17 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rubocop
         | 
| @@ -125,6 +125,7 @@ files: | |
| 125 125 | 
             
            - lib/gitlab/styles/rubocop/cop/polymorphic_associations.rb
         | 
| 126 126 | 
             
            - lib/gitlab/styles/rubocop/cop/redirect_with_status.rb
         | 
| 127 127 | 
             
            - lib/gitlab/styles/rubocop/cop/rspec/single_line_hook.rb
         | 
| 128 | 
            +
            - lib/gitlab/styles/rubocop/cop/rspec/verbose_include_metadata.rb
         | 
| 128 129 | 
             
            - lib/gitlab/styles/rubocop/migration_helpers.rb
         | 
| 129 130 | 
             
            - lib/gitlab/styles/rubocop/model_helpers.rb
         | 
| 130 131 | 
             
            - lib/gitlab/styles/version.rb
         |