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

Performance/StringIdentifierArgument autocorrect broke nokogiri parsing of html #278

Closed
ShockwaveNN opened this issue Dec 27, 2021 · 0 comments · Fixed by #279
Closed

Performance/StringIdentifierArgument autocorrect broke nokogiri parsing of html #278

ShockwaveNN opened this issue Dec 27, 2021 · 0 comments · Fixed by #279
Assignees
Labels
bug Something isn't working

Comments

@ShockwaveNN
Copy link

Steps to reproduce the problem

  1. Create file with code code.rb:
# frozen_string_literal: true

require 'nokogiri'

html_doc = Nokogiri::HTML("<html data='value'><body><h1>Mr. Belvedere Fan Club</h1></body></html>")
puts html_doc.xpath('//html').attr('data')

and .rubocop.yml:

require:
  - rubocop-performance

AllCops:
  NewCops: enable
  1. run it - it will return value:
$ ruby code.rb 
value
  1. rubocop -A:
rubocop -A
Inspecting 1 file
C

Offenses:

code.rb:6:36: C: [Corrected] Performance/StringIdentifierArgument: Use :data instead of 'data'.
puts html_doc.xpath('//html').attr('data')
                                   ^^^^^^

1 file inspected, 1 offense detected, 1 offense corrected
  1. run file - it will fail
.rvm/gems/ruby-3.0.3/gems/nokogiri-1.12.5-x86_64-linux/lib/nokogiri/xml/node_set.rb:209:in `attribute': no implicit conversion of Symbol into String (TypeError)

RuboCop version

$ [bundle exec] rubocop -V
1.24.0 (using Parser 3.0.3.2, rubocop-ast 1.15.0, running on ruby 3.0.3 x86_64-linux)
  - rubocop-performance 1.13.0

@koic koic added the bug Something isn't working label Dec 27, 2021
@koic koic self-assigned this Dec 27, 2021
koic added a commit to koic/rubocop-performance that referenced this issue Dec 27, 2021
…ierArgument`

Fixes rubocop#278.

This PR fixes a false positive for `Performance/StringIdentifierArgument` when using `attr`.
`attr` may not be used because `Style/Attr` registers an offense.
koic added a commit to koic/rubocop-performance that referenced this issue Dec 27, 2021
…ierArgument`

Fixes rubocop#278.

This PR fixes a false positive for `Performance/StringIdentifierArgument` when using `attr`.
`attr` may not be used because `Style/Attr` registers an offense.
gildesmarais added a commit to html2rss/html2rss that referenced this issue Dec 30, 2021
Disable Performance/StringIdentifierArgument because of
rubocop/rubocop-performance#278
breaking the specs.
gildesmarais added a commit to html2rss/html2rss that referenced this issue Dec 30, 2021
Disable Performance/StringIdentifierArgument because of
rubocop/rubocop-performance#278
breaking the specs.
gildesmarais added a commit to html2rss/html2rss-configs that referenced this issue Dec 30, 2021
gildesmarais added a commit to html2rss/html2rss-configs that referenced this issue Dec 30, 2021
@koic koic closed this as completed in #279 Dec 31, 2021
koic added a commit that referenced this issue Dec 31, 2021
…string_identifier_argument

[Fix #278] Fix a false positive for `Performance/StringIdentifierArgument`
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