Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Layout/BlockAlignment Cop breaks in Ruby 3.1.2 #10664

Closed
coding-bunny opened this issue May 24, 2022 · 3 comments
Closed

Layout/BlockAlignment Cop breaks in Ruby 3.1.2 #10664

coding-bunny opened this issue May 24, 2022 · 3 comments

Comments

@coding-bunny
Copy link

Expected behavior

I expect the Cop to just work when upgrading Ruby from 3.0.x to 3.1.2

Actual behavior

The Cop throws out errors for various files that passed checks perfectly fine before the Ruby upgrade.

An error occurred while Layout/BlockAlignment cop was inspecting /Users/olivar/RubymineProjects/application-service-catalog/spec/factories/technologies.rb:5:0.
undefined method `op_asgn_type?' for [s(:block,
  s(:send,
    s(:const,
      s(:cbase), :FactoryBot), :define),
  s(:args),
  s(:block,
    s(:send, nil, :factory,
      s(:sym, :technology)),
    s(:args),
    s(:begin,
      s(:block,
        s(:send, nil, :name),
        s(:args),
        s(:send,
          s(:send,
            s(:const,
              s(:const,
                s(:cbase), :Faker), :ProgrammingLanguage), :unique,
            s(:int, 3)), :name)),
      s(:block,
        s(:send, nil, :trait,
          s(:sym, :ruby)),
        s(:args),
        s(:block,
          s(:send, nil, :name),
          s(:args),
          s(:str, "Ruby"))),
      s(:block,
        s(:send, nil, :trait,
          s(:sym, :nodejs)),
        s(:args),
        s(:block,
          s(:send, nil, :name),
          s(:args),
          s(:str, "NodeJS"))))))]:Array

          result, = *result while result.op_asgn_type? || result.masgn_type?
                                        ^^^^^^^^^^^^^^

The above seems to be the recurring issue.

Steps to reproduce the problem

  • Upgrade Ruby to 3.1.2

RuboCop version

 bundle exec rubocop -V     
1.22.1 (using Parser 3.1.2.0, rubocop-ast 1.12.0, running on ruby 3.1.2 x86_64-darwin21)
  - rubocop-performance 1.11.5
  - rubocop-rails 2.12.4
  - rubocop-rake 0.6.0
  - rubocop-rspec 2.5.0

@koic
Copy link
Member

koic commented May 24, 2022

Can you provide a reproduction code for the issue?

@coding-bunny
Copy link
Author

coding-bunny commented May 24, 2022

Sure, here's some of the files that the cop seems to have issues with:

  1. app/views/api/technologies/index.json.jbuilder
# frozen_string_literal: true

json.technologies do
  json.array!(@technologies, partial: 'model', as: :technology)
end
  1. config/initializers/is_it_working.rb
# frozen_string_literal: true

# This initializer configures the is_it_working gem, and specifies what checks need to pass in order to
# consider the application to be "working"
::Rails.configuration.middleware.use(::IsItWorking::Handler) do |handler|
  # Check the ActiveRecord database connection without spawning a new thread
  handler.check(:active_record, async: true)
end
  1. config/initializers/wrap_parameters.rb
# frozen_string_literal: true

# Be sure to restart your server when you modify this file.

# This file contains settings for ActionController::ParamsWrapper which
# is enabled by default.

# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
::ActiveSupport.on_load(:action_controller) do
  wrap_parameters format: [:json]
end

# To enable root element in JSON for ActiveRecord objects.
# ActiveSupport.on_load(:active_record) do
#   self.include_root_in_json = true
# end
  1. spec/factories/technologies.rb
# frozen_string_literal: true

# This Factory constructs Technology objects that can be used during testing.
# These objects always contain randomly generated data unless specific traits are specified.
::FactoryBot.define do
  factory :technology do
    name { ::Faker::ProgrammingLanguage.unique(3).name }

    trait :ruby do
      name { 'Ruby' }
    end

    trait :nodejs do
      name { 'NodeJS' }
    end
  end
end

I don't see a direct correlation between any of the files.
My first thought was that it trips over the :: with the classes and looking up the constants,
but that doesn't explain the jbuilder views failing.

@koic
Copy link
Member

koic commented May 24, 2022

Probably the same problem as #10258. Can you upgrade RuboCop to the latest version?

@koic koic added the duplicate label May 24, 2022
@koic koic closed this as completed May 24, 2022
@koic koic closed this as not planned Won't fix, can't repro, duplicate, stale May 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants