rubocop-kanso 1.0.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 +7 -0
 - data/lib/config/default.yml +15 -0
 - data/lib/rubocop/cop/kanso/no_rails_helper_require.rb +49 -0
 - data/lib/rubocop/cop/kanso/no_rspec_describe.rb +25 -0
 - data/lib/rubocop/cop/kanso_cops.rb +2 -0
 - data/lib/rubocop/kanso/inject.rb +14 -0
 - data/lib/rubocop/kanso/plugin.rb +28 -0
 - data/lib/rubocop/kanso/version.rb +5 -0
 - data/lib/rubocop/kanso.rb +9 -0
 - data/lib/rubocop-kanso.rb +5 -0
 - metadata +94 -0
 
    
        checksums.yaml
    ADDED
    
    | 
         @@ -0,0 +1,7 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ---
         
     | 
| 
      
 2 
     | 
    
         
            +
            SHA256:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 910ab5b15db7363d252c4dc3223683c3f160704667ab58c5175288c8228fced4
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: abbdd4e0a7dc33cdba401ca61cb88a8d8b2fd9d32562d4579dc03a7783cf2c3a
         
     | 
| 
      
 5 
     | 
    
         
            +
            SHA512:
         
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: b1c4473924f20aa5b934244097920c132d34664317ff266be1ee5c7691b384dd797c971ddbe53ce2269ed9aaff8e8b69ed15723dbe8b66952ab2413491ed2017
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 2c35aa3a09baa4a9aeed17215d132cdd1f6afc60125e6ec7bbbc80002f886a9cf334fbbfb0020cfe93ab3ca57a29983b7f4d9c7fd695f3a87a14539ad30ba259
         
     | 
| 
         @@ -0,0 +1,15 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            Kanso/NoRailsHelperRequire:
         
     | 
| 
      
 2 
     | 
    
         
            +
              Description: 'Disallows requiring rails_helper in specs'
         
     | 
| 
      
 3 
     | 
    
         
            +
              Enabled: true
         
     | 
| 
      
 4 
     | 
    
         
            +
              VersionAdded: '1.0.0'
         
     | 
| 
      
 5 
     | 
    
         
            +
              Include:
         
     | 
| 
      
 6 
     | 
    
         
            +
                - '**/*_spec.rb'
         
     | 
| 
      
 7 
     | 
    
         
            +
                - '**/spec/**/*.rb'
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            Kanso/NoRSpecDescribe:
         
     | 
| 
      
 10 
     | 
    
         
            +
              Description: 'Enforces using describe instead of RSpec.describe'
         
     | 
| 
      
 11 
     | 
    
         
            +
              Enabled: true
         
     | 
| 
      
 12 
     | 
    
         
            +
              VersionAdded: '1.0.0'
         
     | 
| 
      
 13 
     | 
    
         
            +
              Include:
         
     | 
| 
      
 14 
     | 
    
         
            +
                - '**/*_spec.rb'
         
     | 
| 
      
 15 
     | 
    
         
            +
                - '**/spec/**/*.rb'
         
     | 
| 
         @@ -0,0 +1,49 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module RuboCop
         
     | 
| 
      
 2 
     | 
    
         
            +
              module Cop
         
     | 
| 
      
 3 
     | 
    
         
            +
                module Kanso
         
     | 
| 
      
 4 
     | 
    
         
            +
                  class NoRailsHelperRequire < Base
         
     | 
| 
      
 5 
     | 
    
         
            +
                    extend AutoCorrector
         
     | 
| 
      
 6 
     | 
    
         
            +
                    include RangeHelp
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
                    MSG = 'Do not require "rails_helper" in spec files. ' \
         
     | 
| 
      
 9 
     | 
    
         
            +
                          'Configure .rspec file with `--require spec_helper` and `--require rails_helper` instead.'.freeze
         
     | 
| 
      
 10 
     | 
    
         
            +
                    RESTRICT_ON_SEND = [:require].freeze
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                    def_node_matcher :rails_helper_require?, <<~PATTERN
         
     | 
| 
      
 13 
     | 
    
         
            +
                      (send nil? :require
         
     | 
| 
      
 14 
     | 
    
         
            +
                        (str #rails_helper?))
         
     | 
| 
      
 15 
     | 
    
         
            +
                    PATTERN
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                    def rails_helper?(str)
         
     | 
| 
      
 18 
     | 
    
         
            +
                      str == 'rails_helper'
         
     | 
| 
      
 19 
     | 
    
         
            +
                    end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                    def on_send(node)
         
     | 
| 
      
 22 
     | 
    
         
            +
                      return unless rails_helper_require?(node)
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                      add_offense(node) do |corrector|
         
     | 
| 
      
 25 
     | 
    
         
            +
                        corrector.remove(removal_range(node))
         
     | 
| 
      
 26 
     | 
    
         
            +
                      end
         
     | 
| 
      
 27 
     | 
    
         
            +
                    end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                    private
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                    def removal_range(node)
         
     | 
| 
      
 32 
     | 
    
         
            +
                      range = range_by_whole_lines(node.source_range, include_final_newline: true)
         
     | 
| 
      
 33 
     | 
    
         
            +
                      extend_range_for_blank_line(range, node.source_range.source_buffer)
         
     | 
| 
      
 34 
     | 
    
         
            +
                    end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                    def extend_range_for_blank_line(range, source_buffer)
         
     | 
| 
      
 37 
     | 
    
         
            +
                      return range unless blank_line_follows?(range, source_buffer)
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                      Parser::Source::Range.new(source_buffer, range.begin_pos, range.end_pos + 1)
         
     | 
| 
      
 40 
     | 
    
         
            +
                    end
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                    def blank_line_follows?(range, source_buffer)
         
     | 
| 
      
 43 
     | 
    
         
            +
                      end_pos = range.end_pos
         
     | 
| 
      
 44 
     | 
    
         
            +
                      end_pos < source_buffer.source.length && source_buffer.source[end_pos] == "\n"
         
     | 
| 
      
 45 
     | 
    
         
            +
                    end
         
     | 
| 
      
 46 
     | 
    
         
            +
                  end
         
     | 
| 
      
 47 
     | 
    
         
            +
                end
         
     | 
| 
      
 48 
     | 
    
         
            +
              end
         
     | 
| 
      
 49 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,25 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module RuboCop
         
     | 
| 
      
 2 
     | 
    
         
            +
              module Cop
         
     | 
| 
      
 3 
     | 
    
         
            +
                module Kanso
         
     | 
| 
      
 4 
     | 
    
         
            +
                  class NoRSpecDescribe < Base
         
     | 
| 
      
 5 
     | 
    
         
            +
                    extend AutoCorrector
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                    MSG = 'Use `describe` instead of `RSpec.describe`.'.freeze
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                    def_node_matcher :rspec_describe?, <<~PATTERN
         
     | 
| 
      
 10 
     | 
    
         
            +
                      (send
         
     | 
| 
      
 11 
     | 
    
         
            +
                        (const nil? :RSpec) :describe
         
     | 
| 
      
 12 
     | 
    
         
            +
                        ...)
         
     | 
| 
      
 13 
     | 
    
         
            +
                    PATTERN
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                    def on_send(node)
         
     | 
| 
      
 16 
     | 
    
         
            +
                      return unless rspec_describe?(node)
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                      add_offense(node.loc.expression.begin.join(node.loc.selector)) do |corrector|
         
     | 
| 
      
 19 
     | 
    
         
            +
                        corrector.replace(node.loc.expression.begin.join(node.loc.selector), 'describe')
         
     | 
| 
      
 20 
     | 
    
         
            +
                      end
         
     | 
| 
      
 21 
     | 
    
         
            +
                    end
         
     | 
| 
      
 22 
     | 
    
         
            +
                  end
         
     | 
| 
      
 23 
     | 
    
         
            +
                end
         
     | 
| 
      
 24 
     | 
    
         
            +
              end
         
     | 
| 
      
 25 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,14 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module RuboCop
         
     | 
| 
      
 2 
     | 
    
         
            +
              module Kanso
         
     | 
| 
      
 3 
     | 
    
         
            +
                module Inject
         
     | 
| 
      
 4 
     | 
    
         
            +
                  def self.defaults!
         
     | 
| 
      
 5 
     | 
    
         
            +
                    path = CONFIG_DEFAULT.to_s
         
     | 
| 
      
 6 
     | 
    
         
            +
                    hash = ConfigLoader.send(:load_yaml_configuration, path)
         
     | 
| 
      
 7 
     | 
    
         
            +
                    config = Config.new(hash, path).tap(&:make_excludes_absolute)
         
     | 
| 
      
 8 
     | 
    
         
            +
                    puts "configuration from #{path}" if ConfigLoader.debug?
         
     | 
| 
      
 9 
     | 
    
         
            +
                    config = ConfigLoader.merge_with_default(config, path)
         
     | 
| 
      
 10 
     | 
    
         
            +
                    ConfigLoader.instance_variable_set(:@default_configuration, config)
         
     | 
| 
      
 11 
     | 
    
         
            +
                  end
         
     | 
| 
      
 12 
     | 
    
         
            +
                end
         
     | 
| 
      
 13 
     | 
    
         
            +
              end
         
     | 
| 
      
 14 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,28 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'lint_roller'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module RuboCop
         
     | 
| 
      
 4 
     | 
    
         
            +
              module Kanso
         
     | 
| 
      
 5 
     | 
    
         
            +
                class Plugin < LintRoller::Plugin
         
     | 
| 
      
 6 
     | 
    
         
            +
                  def about
         
     | 
| 
      
 7 
     | 
    
         
            +
                    LintRoller::About.new(
         
     | 
| 
      
 8 
     | 
    
         
            +
                      name: 'rubocop-kanso',
         
     | 
| 
      
 9 
     | 
    
         
            +
                      version: VERSION,
         
     | 
| 
      
 10 
     | 
    
         
            +
                      homepage: 'https://github.com/egracens/rubocop-kanso',
         
     | 
| 
      
 11 
     | 
    
         
            +
                      description: 'RuboCop extension focusing on simplicity and eliminating redundancy.'
         
     | 
| 
      
 12 
     | 
    
         
            +
                    )
         
     | 
| 
      
 13 
     | 
    
         
            +
                  end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                  def supported?(context)
         
     | 
| 
      
 16 
     | 
    
         
            +
                    context.engine == :rubocop
         
     | 
| 
      
 17 
     | 
    
         
            +
                  end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                  def rules(_context)
         
     | 
| 
      
 20 
     | 
    
         
            +
                    LintRoller::Rules.new(
         
     | 
| 
      
 21 
     | 
    
         
            +
                      type: :path,
         
     | 
| 
      
 22 
     | 
    
         
            +
                      config_format: :rubocop,
         
     | 
| 
      
 23 
     | 
    
         
            +
                      value: Pathname.new(__dir__).join('../../config/default.yml')
         
     | 
| 
      
 24 
     | 
    
         
            +
                    )
         
     | 
| 
      
 25 
     | 
    
         
            +
                  end
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
              end
         
     | 
| 
      
 28 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,9 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module RuboCop
         
     | 
| 
      
 2 
     | 
    
         
            +
              module Kanso
         
     | 
| 
      
 3 
     | 
    
         
            +
                PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
         
     | 
| 
      
 4 
     | 
    
         
            +
                CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
         
     | 
| 
      
 5 
     | 
    
         
            +
                CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                private_constant(:CONFIG_DEFAULT, :CONFIG)
         
     | 
| 
      
 8 
     | 
    
         
            +
              end
         
     | 
| 
      
 9 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,94 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: rubocop-kanso
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.0.0
         
     | 
| 
      
 5 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 6 
     | 
    
         
            +
            authors:
         
     | 
| 
      
 7 
     | 
    
         
            +
            - Vlad Petrovsky
         
     | 
| 
      
 8 
     | 
    
         
            +
            bindir: exe
         
     | 
| 
      
 9 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 10 
     | 
    
         
            +
            date: 2025-08-05 00:00:00.000000000 Z
         
     | 
| 
      
 11 
     | 
    
         
            +
            dependencies:
         
     | 
| 
      
 12 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 13 
     | 
    
         
            +
              name: lint_roller
         
     | 
| 
      
 14 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 15 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 16 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 17 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 18 
     | 
    
         
            +
                    version: '1.0'
         
     | 
| 
      
 19 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 20 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 21 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 22 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 23 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 24 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 25 
     | 
    
         
            +
                    version: '1.0'
         
     | 
| 
      
 26 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 27 
     | 
    
         
            +
              name: rubocop
         
     | 
| 
      
 28 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 29 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 30 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 31 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 32 
     | 
    
         
            +
                    version: '1.72'
         
     | 
| 
      
 33 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 34 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 35 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 36 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 37 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 38 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 39 
     | 
    
         
            +
                    version: '1.72'
         
     | 
| 
      
 40 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 41 
     | 
    
         
            +
              name: rubocop-rspec
         
     | 
| 
      
 42 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 43 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 44 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 45 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 46 
     | 
    
         
            +
                    version: '3.0'
         
     | 
| 
      
 47 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 48 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 49 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 50 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 51 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 52 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 53 
     | 
    
         
            +
                    version: '3.0'
         
     | 
| 
      
 54 
     | 
    
         
            +
            description: 'RuboCop extension focusing on simplicity and eliminating redundancy. '
         
     | 
| 
      
 55 
     | 
    
         
            +
            email:
         
     | 
| 
      
 56 
     | 
    
         
            +
            - egracens@gmail.com
         
     | 
| 
      
 57 
     | 
    
         
            +
            executables: []
         
     | 
| 
      
 58 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 59 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 60 
     | 
    
         
            +
            files:
         
     | 
| 
      
 61 
     | 
    
         
            +
            - lib/config/default.yml
         
     | 
| 
      
 62 
     | 
    
         
            +
            - lib/rubocop-kanso.rb
         
     | 
| 
      
 63 
     | 
    
         
            +
            - lib/rubocop/cop/kanso/no_rails_helper_require.rb
         
     | 
| 
      
 64 
     | 
    
         
            +
            - lib/rubocop/cop/kanso/no_rspec_describe.rb
         
     | 
| 
      
 65 
     | 
    
         
            +
            - lib/rubocop/cop/kanso_cops.rb
         
     | 
| 
      
 66 
     | 
    
         
            +
            - lib/rubocop/kanso.rb
         
     | 
| 
      
 67 
     | 
    
         
            +
            - lib/rubocop/kanso/inject.rb
         
     | 
| 
      
 68 
     | 
    
         
            +
            - lib/rubocop/kanso/plugin.rb
         
     | 
| 
      
 69 
     | 
    
         
            +
            - lib/rubocop/kanso/version.rb
         
     | 
| 
      
 70 
     | 
    
         
            +
            homepage: https://github.com/egracens/rubocop-kanso
         
     | 
| 
      
 71 
     | 
    
         
            +
            licenses:
         
     | 
| 
      
 72 
     | 
    
         
            +
            - MIT
         
     | 
| 
      
 73 
     | 
    
         
            +
            metadata:
         
     | 
| 
      
 74 
     | 
    
         
            +
              homepage_uri: https://github.com/egracens/rubocop-kanso
         
     | 
| 
      
 75 
     | 
    
         
            +
              rubygems_mfa_required: 'true'
         
     | 
| 
      
 76 
     | 
    
         
            +
              default_lint_roller_plugin: RuboCop::Kanso::Plugin
         
     | 
| 
      
 77 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 78 
     | 
    
         
            +
            require_paths:
         
     | 
| 
      
 79 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 80 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 81 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 82 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 83 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 84 
     | 
    
         
            +
                  version: 3.2.0
         
     | 
| 
      
 85 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 86 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 87 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 88 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 89 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 90 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 91 
     | 
    
         
            +
            rubygems_version: 3.6.2
         
     | 
| 
      
 92 
     | 
    
         
            +
            specification_version: 4
         
     | 
| 
      
 93 
     | 
    
         
            +
            summary: RuboCop cops for lightweight code - simplicity through elimination (簡素)
         
     | 
| 
      
 94 
     | 
    
         
            +
            test_files: []
         
     |