flyerhzm / rails_best_practices

a code metric tool for rails projects
http://rails-bestpractices.com
MIT License
4.16k stars 276 forks source link

Assign the last class as current class when exit from a nested class #398

Closed KeiSakam closed 1 year ago

KeiSakam commented 1 year ago

Motivation

I want to fix the current class as existing when exit from some current class.

For this nested situation, current class is set to nil. But, that can exists: wrapping class.

Background

My team encountered the situation like a below example.

In the UsersController class,

when we set UnexpectedError class definition above the create action, we warned about RestrictAutoGeneratedRoutesCheck . I think the create action was not recognized.

But when we set UnexpectedError class definition below the create action, we were not warned.

Rails.application.routes.draw do
  resources 'users', :only=> [:create]
end

class UsersController < ApplicationController
  class UnexpectedError < StandardError; end # restrict auto-generated routes users (only: [])
  def create; end
end

class UsersController < ApplicationController
  def create; end
  class UnexpectedError < StandardError; end # no warning
end
KeiSakam commented 1 year ago

@flyerhzm Could you check this pull request??? 🙏

flyerhzm commented 1 year ago

@KeiSakam it's merged