Skip to content

Rails/Output cop recognises p wraper method of the HTML paragraph tag(from phlex-rails) as a stdout writer method p and replaces it with Rails.logger.debug #1041

@sbezugliy

Description

@sbezugliy

I'm using phlex(https://github.com/phlex-ruby/phlex-rails) as HTML page renderer, as full replacement of the ActionView for Rails 7 view templates.

Expected behavior

Rails/Output cop should skip replacement of the p tag wrapper method with 'Rails.logger.debug' for templates of phlex-rails gem. As I suppose, for cases when it is not methods writing to the stdout, with predefined implementation class/module.

Actual behavior

Rubocop-Rails recognises p method wrapping paragraph tag as an stdout writer method p, so replaces it with Rails.logger.debug:

As, example

div do  
  p { "Some text" }
  p(){ "Some text" }
end

Replaces with:

div do  
  Rails.logger.debug { "Some text" }
  Rails.logger.debug { "Some text" }
end

Outup of the command bundle exec rubocop -A

app/views/components/component_partials/example_partial.rb:19:13: C: [Corrected] Rails/Output: Do not write to stdout. Use Rails's logger if you want to log.

Solved it excluding Rails/Output cop as next at the .rubocop.yml:

require:
  - rubocop
  - rubocop-rspec
  - rubocop-rails

#...

Rails/Output:
  Enabled: true
  Exclude:
    - app/views/**/*.rb

Steps to reproduce the problem

  1. Add phlex-rails, rubocop and rubocop-rails gems to the Ruby on Rails project.
  2. Generate any controller using rails g phlex:controller Hello index.
  3. Add line p { "Some text" } to the template method of the index action of the Hello controller, expected file path is /app/views/hello/index_view.rb.
  4. Execute $ bundle exec rubocop -A at the root of the project.
  5. See results at the console and browser.

RuboCop version

  • rubocop-capybara 2.18.0
  • rubocop-factory_bot 2.23.1
  • rubocop-rails 2.20.2
  • rubocop-rake 0.6.0
  • rubocop-rspec 2.22.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions