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

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

Closed
sbezugliy opened this issue Jul 1, 2023 · 0 comments · Fixed by #1141
Labels
bug Something isn't working

Comments

@sbezugliy
Copy link

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
@sbezugliy sbezugliy changed the title Rails/Output cop recognises p method wrapping paragraph tag as an stdout writer method p and replaces it with Rails.logger.debug Rails/Output cop recognises p method wrapping paragraph tag(from phlex-rails) as a stdout writer method p and replaces it with Rails.logger.debug Jul 1, 2023
@sbezugliy sbezugliy changed the title Rails/Output cop recognises p method wrapping paragraph tag(from phlex-rails) as a stdout writer method p and replaces it with Rails.logger.debug Rails/Output cop recognises p method wrapping HTML paragraph tag(from phlex-rails) as a stdout writer method p and replaces it with Rails.logger.debug Jul 1, 2023
@sbezugliy sbezugliy changed the title Rails/Output cop recognises p method wrapping HTML paragraph tag(from phlex-rails) as a stdout writer method p and replaces it with Rails.logger.debug 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 Jul 1, 2023
@koic koic added the bug Something isn't working label Oct 5, 2023
koic added a commit to koic/rubocop-rails that referenced this issue Oct 5, 2023
Fixes rubocop#1041.

This PR fixes a false positive for `Rails/Output`
when output method is called with block argument.

The output method for the bad case is not designed to take a block argument.
Thus, by ignoring this, it can likely reduce false positives.
koic added a commit to koic/rubocop-rails that referenced this issue Oct 5, 2023
Fixes rubocop#1041.

This PR fixes a false positive for `Rails/Output`
when output method is called with block argument.

The output method for the bad case is not designed to take a block argument.
Thus, by ignoring this, it can likely reduce false positives.
@koic koic closed this as completed in #1141 Oct 6, 2023
koic added a commit that referenced this issue Oct 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants