salsify_rubocop 0.47.1.rc0 → 0.47.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 +2 -0
- data/conf/rubocop_rails50.yml +8 -0
- data/config/default.yml +4 -0
- data/lib/rubocop/cop/salsify/rails_application_record.rb +53 -0
- data/lib/salsify_rubocop.rb +1 -0
- data/lib/salsify_rubocop/version.rb +1 -1
- metadata +6 -4
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: a235a0d2d7c100c09da10c768f5a7e8384d30b8c
         | 
| 4 | 
            +
              data.tar.gz: f1c310ca03dea3a45efc6b0c104a5b8411a827ae
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 9c788c146e8be102a39e8340c22c1b391a2fbaef4e6cfae70c93142414af839dd69625e4cdd9f897846d43e1fa602c866e4351f624124f2ba4dab31ed193ccfd
         | 
| 7 | 
            +
              data.tar.gz: d445a00088b9745687e1a2f1670e91d3b736d927b96081dfc23d3721cf75c731fbb587d09cc11b98a3cd4013e94d064e69442bd64dc96b4d9a758be5fc502f6b
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -2,6 +2,8 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            ## v0.47.1
         | 
| 4 4 | 
             
            - Add `Salsify/StyleDig` cop to recommend using `#dig` for deeply nested access.
         | 
| 5 | 
            +
            - Add `Salsify/RailsApplicationRecord` cop.
         | 
| 6 | 
            +
            - Add new `rubocop_rails50` configuration for use with Rails 5.0 apps.
         | 
| 5 7 |  | 
| 6 8 | 
             
            ## v0.47.0
         | 
| 7 9 | 
             
            - Update to `rubocop` v0.47.1 and `rubocop-rspec` v1.10.0.
         | 
    
        data/config/default.yml
    CHANGED
    
    
| @@ -0,0 +1,53 @@ | |
| 1 | 
            +
            # encoding: utf-8
         | 
| 2 | 
            +
            require 'rubocop'
         | 
| 3 | 
            +
            module RuboCop
         | 
| 4 | 
            +
              module Cop
         | 
| 5 | 
            +
                module Salsify
         | 
| 6 | 
            +
                  # Check that models subclass ApplicationRecord with Rails 5.0
         | 
| 7 | 
            +
                  #
         | 
| 8 | 
            +
                  # @example
         | 
| 9 | 
            +
                  #
         | 
| 10 | 
            +
                  #  # good
         | 
| 11 | 
            +
                  #  class Tesla < ApplicationRecord
         | 
| 12 | 
            +
                  #    ...
         | 
| 13 | 
            +
                  #  end
         | 
| 14 | 
            +
                  #
         | 
| 15 | 
            +
                  #  # bad
         | 
| 16 | 
            +
                  #  class Yugo < ActiveRecord::Base
         | 
| 17 | 
            +
                  #    ...
         | 
| 18 | 
            +
                  #  end
         | 
| 19 | 
            +
                  class RailsApplicationRecord < Cop
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                    MSG = 'Models must subclass ApplicationRecord'.freeze
         | 
| 22 | 
            +
                    APPLICATION_RECORD = 'ApplicationRecord'.freeze
         | 
| 23 | 
            +
                    ACTIVE_RECORD_BASE_PATTERN = '(const (const nil :ActiveRecord) :Base)'.freeze
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                    def_node_matcher :model_class_definition, <<-PATTERN
         | 
| 26 | 
            +
                    (class (const _ !:ApplicationRecord) #{ACTIVE_RECORD_BASE_PATTERN} ...)
         | 
| 27 | 
            +
                    PATTERN
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                    def_node_matcher :class_new_definition, <<-PATTERN
         | 
| 30 | 
            +
                    [!^(casgn nil :ApplicationRecord ...) (send (const nil :Class) :new #{ACTIVE_RECORD_BASE_PATTERN})]
         | 
| 31 | 
            +
                    PATTERN
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                    def on_class(node)
         | 
| 34 | 
            +
                      model_class_definition(node) do
         | 
| 35 | 
            +
                        add_offense(node.children[1], :expression, MSG)
         | 
| 36 | 
            +
                      end
         | 
| 37 | 
            +
                    end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                    def on_send(node)
         | 
| 40 | 
            +
                      class_new_definition(node) do
         | 
| 41 | 
            +
                        add_offense(node.children.last, :expression, MSG)
         | 
| 42 | 
            +
                      end
         | 
| 43 | 
            +
                    end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                    def autocorrect(node)
         | 
| 46 | 
            +
                      lambda do |corrector|
         | 
| 47 | 
            +
                        corrector.replace(node.source_range, APPLICATION_RECORD)
         | 
| 48 | 
            +
                      end
         | 
| 49 | 
            +
                    end
         | 
| 50 | 
            +
                  end
         | 
| 51 | 
            +
                end
         | 
| 52 | 
            +
              end
         | 
| 53 | 
            +
            end
         | 
    
        data/lib/salsify_rubocop.rb
    CHANGED
    
    | @@ -13,6 +13,7 @@ config = RuboCop::ConfigLoader.merge_with_default(config, path) | |
| 13 13 | 
             
            RuboCop::ConfigLoader.instance_variable_set(:@default_configuration, config)
         | 
| 14 14 |  | 
| 15 15 | 
             
            # cops
         | 
| 16 | 
            +
            require 'rubocop/cop/salsify/rails_application_record'
         | 
| 16 17 | 
             
            require 'rubocop/cop/salsify/rspec_doc_string'
         | 
| 17 18 | 
             
            require 'rubocop/cop/salsify/rspec_string_literals'
         | 
| 18 19 | 
             
            require 'rubocop/cop/salsify/style_dig'
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: salsify_rubocop
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.47.1 | 
| 4 | 
            +
              version: 0.47.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Salsify, Inc
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2017-03- | 
| 11 | 
            +
            date: 2017-03-07 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         | 
| @@ -100,8 +100,10 @@ files: | |
| 100 100 | 
             
            - bin/setup
         | 
| 101 101 | 
             
            - conf/rubocop.yml
         | 
| 102 102 | 
             
            - conf/rubocop_rails.yml
         | 
| 103 | 
            +
            - conf/rubocop_rails50.yml
         | 
| 103 104 | 
             
            - conf/rubocop_without_rspec.yml
         | 
| 104 105 | 
             
            - config/default.yml
         | 
| 106 | 
            +
            - lib/rubocop/cop/salsify/rails_application_record.rb
         | 
| 105 107 | 
             
            - lib/rubocop/cop/salsify/rspec_doc_string.rb
         | 
| 106 108 | 
             
            - lib/rubocop/cop/salsify/rspec_string_literals.rb
         | 
| 107 109 | 
             
            - lib/rubocop/cop/salsify/style_dig.rb
         | 
| @@ -125,9 +127,9 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 125 127 | 
             
                  version: '0'
         | 
| 126 128 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 127 129 | 
             
              requirements:
         | 
| 128 | 
            -
              - - " | 
| 130 | 
            +
              - - ">="
         | 
| 129 131 | 
             
                - !ruby/object:Gem::Version
         | 
| 130 | 
            -
                  version:  | 
| 132 | 
            +
                  version: '0'
         | 
| 131 133 | 
             
            requirements: []
         | 
| 132 134 | 
             
            rubyforge_project: 
         | 
| 133 135 | 
             
            rubygems_version: 2.6.10
         |