rubocop-petal 0.3.0 → 0.4.1
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 +12 -0
- data/Gemfile.lock +2 -2
- data/config/default.yml +8 -1
- data/lib/rubocop/cop/rspec/stub_products.rb +51 -0
- data/lib/rubocop/petal/version.rb +1 -1
- metadata +3 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 27cd3572987b7a6238883f593b73622d58c578dd2c3c71b242b218dc2acabba9
         | 
| 4 | 
            +
              data.tar.gz: 28eaba65472713af02487e2b2d7c058cd6cd0442a023347d29d02d55684d1329
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 9634d631a31346febfa80b63603c46865866502b9bfbbc7db6e6ef7136fba7e0fd1a44b226fde3cb680521d94a6d9d61cf427d57cb76712688b1f0f0c95a0864
         | 
| 7 | 
            +
              data.tar.gz: 80d383f97fe9f0b3a7bb2c8df6c1be422168fc3a5a025e4c8c0c810931871dd929216a0624a3d377b5d2c72534984675ba009e3aaaf1175eee93504a5aabd42b
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -2,6 +2,18 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            # main
         | 
| 4 4 |  | 
| 5 | 
            +
            #v0.4.1
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            * Fix typo default config SafeAutoCorrect RSpec/StubProducts ([#19](https://github.com/petalmd/rubocop-petal/pull/19))
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            #v0.4.0
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            * Added cop `RSpec/StubProducts` ([#18](https://github.com/petalmd/rubocop-petal/pull/18))
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            # v0.3.1
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            * Correct cop name `Migration/SchemaStatementsMethods` in config ([#17](https://github.com/petalmd/rubocop-petal/pull/17))
         | 
| 16 | 
            +
             | 
| 5 17 | 
             
            # v0.3.0
         | 
| 6 18 |  | 
| 7 19 | 
             
            * Added cop `Added Migration/ForeignKeyOption` ([#11](https://github.com/petalmd/rubocop-petal/pull/11))
         | 
    
        data/Gemfile.lock
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            PATH
         | 
| 2 2 | 
             
              remote: .
         | 
| 3 3 | 
             
              specs:
         | 
| 4 | 
            -
                rubocop-petal (0. | 
| 4 | 
            +
                rubocop-petal (0.4.1)
         | 
| 5 5 | 
             
                  rubocop (>= 1.7.0, < 2.0)
         | 
| 6 6 | 
             
                  rubocop-rails (~> 2.10)
         | 
| 7 7 |  | 
| @@ -51,7 +51,7 @@ GEM | |
| 51 51 | 
             
                  unicode-display_width (>= 1.4.0, < 3.0)
         | 
| 52 52 | 
             
                rubocop-ast (1.15.0)
         | 
| 53 53 | 
             
                  parser (>= 3.0.1.1)
         | 
| 54 | 
            -
                rubocop-rails (2. | 
| 54 | 
            +
                rubocop-rails (2.14.2)
         | 
| 55 55 | 
             
                  activesupport (>= 4.2.0)
         | 
| 56 56 | 
             
                  rack (>= 1.1)
         | 
| 57 57 | 
             
                  rubocop (>= 1.7.0, < 2.0)
         | 
    
        data/config/default.yml
    CHANGED
    
    | @@ -11,7 +11,7 @@ Migration/ForeignKeyOption: | |
| 11 11 | 
             
              Include:
         | 
| 12 12 | 
             
                - db/migrate/**
         | 
| 13 13 |  | 
| 14 | 
            -
            Migration/ | 
| 14 | 
            +
            Migration/SchemaStatementsMethods:
         | 
| 15 15 | 
             
              Description: 'Suggest to use SchemaStatements methods already defined in a migration class.'
         | 
| 16 16 | 
             
              Enabled: true
         | 
| 17 17 | 
             
              Include:
         | 
| @@ -30,6 +30,13 @@ RSpec/CreateListMax: | |
| 30 30 | 
             
              Include:
         | 
| 31 31 | 
             
                - spec/**/*
         | 
| 32 32 |  | 
| 33 | 
            +
            RSpec/StubProducts:
         | 
| 34 | 
            +
              Description: 'Suggest to use stub_products instead of veil/unveil_product.'
         | 
| 35 | 
            +
              Enabled: true
         | 
| 36 | 
            +
              SafeAutoCorrect: false
         | 
| 37 | 
            +
              Include:
         | 
| 38 | 
            +
                - spec/**/*
         | 
| 39 | 
            +
             | 
| 33 40 | 
             
            Grape/HelpersIncludeModule:
         | 
| 34 41 | 
             
              Description: 'Prevent using helpers with block to include module'
         | 
| 35 42 | 
             
              Enabled: true
         | 
| @@ -0,0 +1,51 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module RuboCop
         | 
| 4 | 
            +
              module Cop
         | 
| 5 | 
            +
                module RSpec
         | 
| 6 | 
            +
                  # Suggest to use stub_products instead of veil/unveil_product
         | 
| 7 | 
            +
                  # which queries the database and can cause flaky tests.
         | 
| 8 | 
            +
                  #
         | 
| 9 | 
            +
                  #   # bad
         | 
| 10 | 
            +
                  #   unveil_product('MY_PRODUCT')
         | 
| 11 | 
            +
                  #   veil_product('MY_PRODUCT')
         | 
| 12 | 
            +
                  #
         | 
| 13 | 
            +
                  #   # good
         | 
| 14 | 
            +
                  #   stub_products('MY_PRODUCT' => true)
         | 
| 15 | 
            +
                  #   stub_products('MY_PRODUCT' => false)
         | 
| 16 | 
            +
                  #   stub_products('MY_PRODUCT' => group)
         | 
| 17 | 
            +
                  #   stub_products('MY_PRODUCT' => [group1, group2])
         | 
| 18 | 
            +
                  #   stub_products(MY_PRODUCT: true)
         | 
| 19 | 
            +
                  #
         | 
| 20 | 
            +
                  class StubProducts < Base
         | 
| 21 | 
            +
                    extend AutoCorrector
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                    MSG = 'Use `stub_products` instead of veil/unveil_product.'
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                    def_node_search :veil_product?, <<~PATTERN
         | 
| 26 | 
            +
                      (send nil? :veil_product _)
         | 
| 27 | 
            +
                    PATTERN
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                    def_node_search :unveil_product?, <<~PATTERN
         | 
| 30 | 
            +
                      (send nil? :unveil_product _)
         | 
| 31 | 
            +
                    PATTERN
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                    def on_send(node)
         | 
| 34 | 
            +
                      return unless veil_product?(node) || unveil_product?(node)
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                      add_offense(node) do |corrector|
         | 
| 37 | 
            +
                        if (match = /^\S*\s+(\S+)|\(([^)]+)\)/.match(node.source))
         | 
| 38 | 
            +
                          match1, match2 = match.captures
         | 
| 39 | 
            +
                          product_code = match1 || match2
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                          product_is_available = !veil_product?(node)
         | 
| 42 | 
            +
                          subst = "stub_products(#{product_code} => #{product_is_available})"
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                          corrector.replace(node, subst)
         | 
| 45 | 
            +
                        end
         | 
| 46 | 
            +
                      end
         | 
| 47 | 
            +
                    end
         | 
| 48 | 
            +
                  end
         | 
| 49 | 
            +
                end
         | 
| 50 | 
            +
              end
         | 
| 51 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: rubocop-petal
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.4.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Jean-Francis Bastien
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2022- | 
| 11 | 
            +
            date: 2022-04-12 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rubocop
         | 
| @@ -77,6 +77,7 @@ files: | |
| 77 77 | 
             
            - lib/rubocop/cop/rails/table_name.rb
         | 
| 78 78 | 
             
            - lib/rubocop/cop/rspec/authenticated_as.rb
         | 
| 79 79 | 
             
            - lib/rubocop/cop/rspec/create_list_max.rb
         | 
| 80 | 
            +
            - lib/rubocop/cop/rspec/stub_products.rb
         | 
| 80 81 | 
             
            - lib/rubocop/petal.rb
         | 
| 81 82 | 
             
            - lib/rubocop/petal/inject.rb
         | 
| 82 83 | 
             
            - lib/rubocop/petal/version.rb
         |