Rubocop: Style/RedundantBegin raises errors because of a missing method (stabby_lambda?)

Created on 10 Sep 2018  路  1Comment  路  Source: rubocop-hq/rubocop

As stated in the title, rubocop raises NoMethodErrors because of a missing stabby_lambda? for Rubocop::AST::SuperNode.


Expected behavior

Rubocop should not raise an error.

Actual behavior

Rubocop raises errors in multiple files.

Steps to reproduce the problem

One example file:

# frozen_string_literal: true

module SynTrans
  module DataTypes
    module ColumnTypes
      module Mixins
        # Provides functionality to replace newlines in Strings with
        # backslashes. It is meant to `extend` {ColumnType} instances.
        # @author Kai Moschcau [email protected]
        module BackslashNewline
          class << self
            # Checks the extended Class. Prints a warning, if the extended Class
            # is not a {CharLimitedStrings}.
            # @param [ColumnType] base The ColumnType that is extended.
            # @raise [TypeError] If the extended Class is not a {ColumnType}.
            # @return [void]
            def extended(base)
              raise(TypeError, 'the extended class has to be a ColumnType')\
                unless base.is_a? ColumnType
              warn 'BackslashNewline should extend CharLimitedStrings' unless
                base.is_a? CharLimitedStrings
            end
          end

          # Replaces newlines with backslashes before the normal transformation.
          # @param (see ColumnType#transform_value)
          # @param [String] column_name The column name of the field to limit.
          # @return (see ColumnType#transform_value)
          # @see CharLimitedStrings#transform_value
          # @yieldparam (see ColumnType#transform_value)
          def transform_value(value, column_name)
            super(value&.gsub(/\r?\n/, '\\'), column_name) { |w| yield w }
          end
        end
      end
    end
  end
end

Stacktrace:

An error occurred while Style/RedundantBegin cop was inspecting /home/kmoschcau/Code/synxis-transformer/lib/data_types/column_types/mixins/backslash_newline.rb:32:12.
undefined method `stabby_lambda?' for #<RuboCop::AST::SuperNode:0x000055dca54b2ff8>
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/cop/style/redundant_begin.rb:68:in `on_block'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/cop/commissioner.rb:58:in `block (2 levels) in trigger_responding_cops'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/cop/commissioner.rb:106:in `with_cop_error_handling'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/cop/commissioner.rb:57:in `block in trigger_responding_cops'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/cop/commissioner.rb:56:in `each'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/cop/commissioner.rb:56:in `trigger_responding_cops'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/cop/commissioner.rb:34:in `block (2 levels) in <class:Commissioner>'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/ast/traversal.rb:100:in `on_def'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/cop/commissioner.rb:35:in `block (2 levels) in <class:Commissioner>'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/ast/traversal.rb:50:in `block in on_begin'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/ast/traversal.rb:50:in `each'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/ast/traversal.rb:50:in `on_begin'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/cop/commissioner.rb:35:in `block (2 levels) in <class:Commissioner>'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/ast/traversal.rb:150:in `on_while'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/cop/commissioner.rb:35:in `block (2 levels) in <class:Commissioner>'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/ast/traversal.rb:150:in `on_while'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/cop/commissioner.rb:35:in `block (2 levels) in <class:Commissioner>'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/ast/traversal.rb:150:in `on_while'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/cop/commissioner.rb:35:in `block (2 levels) in <class:Commissioner>'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/ast/traversal.rb:150:in `on_while'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/cop/commissioner.rb:35:in `block (2 levels) in <class:Commissioner>'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/ast/traversal.rb:150:in `on_while'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/cop/commissioner.rb:35:in `block (2 levels) in <class:Commissioner>'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/ast/traversal.rb:13:in `walk'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/cop/commissioner.rb:46:in `investigate'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/cop/team.rb:115:in `investigate'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/cop/team.rb:103:in `offenses'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/cop/team.rb:44:in `inspect_file'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/runner.rb:269:in `inspect_file'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/runner.rb:216:in `block in do_inspection_loop'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/runner.rb:248:in `block in iterate_until_no_changes'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/runner.rb:241:in `loop'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/runner.rb:241:in `iterate_until_no_changes'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/runner.rb:212:in `do_inspection_loop'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/runner.rb:115:in `block in file_offenses'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/runner.rb:133:in `file_offense_cache'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/runner.rb:113:in `file_offenses'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/runner.rb:101:in `process_file'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/runner.rb:78:in `block in each_inspected_file'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/runner.rb:75:in `each'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/runner.rb:75:in `reduce'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/runner.rb:75:in `each_inspected_file'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/runner.rb:67:in `inspect_files'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/runner.rb:39:in `run'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/cli.rb:157:in `execute_runner'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/cli.rb:85:in `execute_runners'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/lib/rubocop/cli.rb:41:in `run'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/exe/rubocop:13:in `block in <top (required)>'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/2.5.0/benchmark.rb:308:in `realtime'
/home/kmoschcau/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.0/exe/rubocop:12:in `<top (required)>'
/home/kmoschcau/.rbenv/versions/2.5.1/bin/rubocop:23:in `load'
/home/kmoschcau/.rbenv/versions/2.5.1/bin/rubocop:23:in `<main>'

RuboCop version

$ [bundle exec] rubocop -V
0.59.0 (using Parser 2.5.1.2, running on ruby 2.5.1 x86_64-linux)

Most helpful comment

Bitten by this one too this morning after updating to the latest Rubocop 0.59.

In my case, Devise controllers recommend overwriting their behaviour using super blocks i.e.

def new
    # Insert our behaviour into the
    # basic Devise registration process.
    super do |resource|
        # So stuff...
    end
end

The new stabby_lambda scan get's upset by this. Anyone else using/customizing Devise will come accross similar issues.

>All comments

Bitten by this one too this morning after updating to the latest Rubocop 0.59.

In my case, Devise controllers recommend overwriting their behaviour using super blocks i.e.

def new
    # Insert our behaviour into the
    # basic Devise registration process.
    super do |resource|
        # So stuff...
    end
end

The new stabby_lambda scan get's upset by this. Anyone else using/customizing Devise will come accross similar issues.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bquorning picture bquorning  路  3Comments

bbugh picture bbugh  路  3Comments

benoittgt picture benoittgt  路  3Comments

tedPen picture tedPen  路  3Comments

mikegee picture mikegee  路  3Comments