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

crash in Performance/DeletePrefix with 1.6.0 #111

Closed
modosc opened this issue May 21, 2020 · 3 comments · Fixed by #113
Closed

crash in Performance/DeletePrefix with 1.6.0 #111

modosc opened this issue May 21, 2020 · 3 comments · Fixed by #113
Labels
bug Something isn't working

Comments

@modosc
Copy link

modosc commented May 21, 2020

with rubocop-performance-1.6.0 this crash just started occurring on this line:

      start_hours  = time.strftime('%I').gsub(/^0/, '')

Expected behavior

no crash

Actual behavior

a crash

Steps to reproduce the problem

given a filefoo.rb which contains just this line:

      start_hours  = time.strftime('%I').gsub(/^0/, '')
$ rubocop -ad foo.rb
For /Users/jon/git/swoop: configuration from /Users/jon/git/swoop/.rubocop.yml
configuration from /Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-performance-1.6.0/config/default.yml
configuration from /Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-performance-1.6.0/config/default.yml
Default configuration from /Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/config/default.yml
configuration from /Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-rails-2.5.2/config/default.yml
configuration from /Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-rails-2.5.2/config/default.yml
Inheriting configuration from /Users/jon/git/swoop/.rubocop/default.yml
Inheriting configuration from /Users/jon/git/swoop/.rubocop/rubocop-airbnb.yml
Inheriting configuration from /Users/jon/git/swoop/.rubocop/rubocop-bundler.yml
Inheriting configuration from /Users/jon/git/swoop/.rubocop/rubocop-gemspec.yml
Inheriting configuration from /Users/jon/git/swoop/.rubocop/rubocop-layout.yml
Inheriting configuration from /Users/jon/git/swoop/.rubocop/rubocop-lint.yml
Inheriting configuration from /Users/jon/git/swoop/.rubocop/rubocop-metrics.yml
Inheriting configuration from /Users/jon/git/swoop/.rubocop/rubocop-naming.yml
Inheriting configuration from /Users/jon/git/swoop/.rubocop/rubocop-performance.yml
Inheriting configuration from /Users/jon/git/swoop/.rubocop/rubocop-rails.yml
Inheriting configuration from /Users/jon/git/swoop/.rubocop/rubocop-rspec.yml
configuration from /Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-rspec-1.39.0/config/default.yml
configuration from /Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-rspec-1.39.0/config/default.yml
Inheriting configuration from /Users/jon/git/swoop/.rubocop/rubocop-security.yml
Inheriting configuration from /Users/jon/git/swoop/.rubocop/rubocop-style.yml
Inheriting configuration from /Users/jon/git/swoop/.rubocop_todo.yml
.rubocop.yml: AllCops:Exclude overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: Style/FrozenStringLiteralComment:Enabled overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: Style/HashSyntax:Enabled overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: Style/StringLiterals:Enabled overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: Style/StringLiteralsInInterpolation:Enabled overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: RSpec/BeforeAfterAll:Exclude overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: RSpec/ExpectInHook:Enabled overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: RSpec/LeadingSubject:Enabled overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: Rails/FindEach:Enabled overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: Rails/FindEach:Include overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: Rails/HasAndBelongsToMany:Enabled overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: Rails/HasAndBelongsToMany:Include overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: Rails/InverseOf:Enabled overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: Rails/RequestReferer:Enabled overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: Rails/SaveBang:Enabled overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: Rails/TimeZone:Enabled overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: Performance/Caller:Enabled overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: Performance/CompareWithBlock:Enabled overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: Performance/FlatMap:Enabled overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: Performance/InefficientHashSearch:Enabled overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: Performance/RedundantBlockCall:Enabled overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: Performance/RedundantMatch:Enabled overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: Performance/RedundantMerge:Enabled overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: Performance/RegexpMatch:Enabled overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: Performance/ReverseEach:Enabled overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: Performance/Size:Enabled overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: Performance/StartWith:Enabled overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: Performance/StringReplacement:Enabled overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: Naming/PredicateName:Enabled overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: Naming/PredicateName:NamePrefix overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: Naming/PredicateName:ForbiddenPrefixes overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: Naming/RescuedExceptionsVariableName:Enabled overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: Lint/BigDecimalNew:Enabled overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: Layout/DotPosition:EnforcedStyle overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: Layout/EmptyLinesAroundClassBody:EnforcedStyle overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: Layout/EmptyLinesAroundClassBody:SupportedStyles overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: Layout/EmptyLinesAroundModuleBody:EnforcedStyle overrides the same parameter in .rubocop_todo.yml
.rubocop.yml: Layout/EmptyLinesAroundModuleBody:SupportedStyles overrides the same parameter in .rubocop_todo.yml
Inspecting 1 file
Scanning /Users/jon/git/swoop/foo.rb
An error occurred while Performance/DeletePrefix cop was inspecting /Users/jon/git/swoop/foo.rb:1:21.
undefined method `source_buffer' for #<RuboCop::AST::SendNode:0x00007fbb2daf6e38>
Did you mean?  source_range
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/cop/corrector.rb:157:in `validate_range'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/cop/corrector.rb:109:in `replace'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/delete_prefix.rb:65:in `block (2 levels) in autocorrect'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/cop/cop.rb:36:in `call'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/cop/corrector.rb:63:in `block (2 levels) in rewrite'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/parser-2.7.1.2/lib/parser/source/tree_rewriter.rb:253:in `transaction'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/cop/corrector.rb:62:in `block in rewrite'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/cop/corrector.rb:60:in `each'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/cop/corrector.rb:60:in `rewrite'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/cop/team.rb:136:in `autocorrect_all_cops'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/cop/team.rb:72:in `autocorrect'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/cop/team.rb:108:in `block in offenses'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/cop/team.rb:125:in `investigate'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/cop/team.rb:104:in `offenses'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/cop/team.rb:44:in `inspect_file'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/runner.rb:296:in `inspect_file'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/runner.rb:244:in `block in do_inspection_loop'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/runner.rb:276:in `block in iterate_until_no_changes'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/runner.rb:269:in `loop'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/runner.rb:269:in `iterate_until_no_changes'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/runner.rb:240:in `do_inspection_loop'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/runner.rb:119:in `block in file_offenses'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/runner.rb:143:in `file_offense_cache'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/runner.rb:117:in `file_offenses'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/runner.rb:108:in `process_file'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/runner.rb:87:in `block in each_inspected_file'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/runner.rb:86:in `each'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/runner.rb:86:in `reduce'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/runner.rb:86:in `each_inspected_file'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/runner.rb:73:in `inspect_files'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/runner.rb:39:in `run'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/cli/command/execute_runner.rb:21:in `execute_runner'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/cli/command/execute_runner.rb:13:in `run'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/cli/command.rb:10:in `run'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/cli/environment.rb:17:in `run'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/cli.rb:65:in `run_command'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/cli.rb:72:in `execute_runners'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/lib/rubocop/cli.rb:41:in `run'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/exe/rubocop:13:in `block in <top (required)>'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/benchmark-0.1.0/lib/benchmark.rb:308:in `realtime'
/Users/jon/.rvm/gems/ruby-2.6.6@swoop/gems/rubocop-0.81.0/exe/rubocop:12:in `<top (required)>'
/Users/jon/git/swoop/bin/rubocop:29:in `load'
/Users/jon/git/swoop/bin/rubocop:29:in `<main>'

RuboCop version

work ~/git/swoop [dependabot/bundler/rubocop-performance-1.6.0|…1⚑ 5]$ rubocop -V
0.81.0 (using Parser 2.7.1.2, running on ruby 2.6.6 x86_64-darwin19)
@marcandre
Copy link
Contributor

Thanks for the detailed bug report. Have you tried upgrading your version of RuboCop? 0.84 is the current one

@modosc
Copy link
Author

modosc commented May 21, 2020

it seems fixed with rubocop-0.82.0. maybe the gemspec needs to be updated to reflect this?

@marcandre
Copy link
Contributor

marcandre commented May 21, 2020

Yes, I can confirm this cop uses a feature introduced in 0.82. I've opened #112 so that we also change our CI to test against the minimum acceptable version of RuboCop

@koic koic added the bug Something isn't working label May 22, 2020
koic added a commit to koic/rubocop-performance that referenced this issue May 22, 2020
…ffix` cops

Fixes rubocop#111.

This PR fixes an error for `Performance/DeletePrefix` and `Performance/DeleteSuffix` cops
when using autocorrection with RuboCop 0.81 or lower.
koic added a commit to koic/rubocop-performance that referenced this issue May 22, 2020
…rformance/DeleteSuffix`

Fixes rubocop#111.

This PR fixes an error for `Performance/DeletePrefix` and `Performance/DeleteSuffix` cops
when using autocorrection with RuboCop 0.81 or lower.
@koic koic closed this as completed in #113 May 23, 2020
koic added a commit that referenced this issue May 23, 2020
…delete_suffix

[Fix #111] Fix an error for `Performance/DeletePrefix` and `Performance/DeleteSuffix` cops
koic added a commit to koic/rubocop-rails that referenced this issue Jun 8, 2020
Follow up to rubocop/rubocop-performance#111.

This PR prepares to use RuboCop's new development API.
koic added a commit to koic/rubocop-performance that referenced this issue Jun 10, 2020
Follow up to rubocop#111.

This PR prepares to use RuboCop's new development API.
koic added a commit to koic/rubocop-minitest that referenced this issue Jun 12, 2020
Follow up to rubocop/rubocop-performance#111.

This PR prepares to use RuboCop's new development API.
renawatson68 added a commit to renawatson68/performance-develop-rubyonrails that referenced this issue Sep 23, 2022
Follow up to rubocop/rubocop-performance#111.

This PR prepares to use RuboCop's new development API.
richardstewart0213 added a commit to richardstewart0213/performance-build-Performance-optimization-analysis- that referenced this issue Nov 4, 2022
Follow up to rubocop/rubocop-performance#111.

This PR prepares to use RuboCop's new development API.
MarttiCheng added a commit to MarttiCheng/Rubocop-Performance that referenced this issue Sep 28, 2023
Follow up to rubocop/rubocop-performance#111.

This PR prepares to use RuboCop's new development API.
SerhiiMisiura added a commit to SerhiiMisiura/Rubocop-Performance that referenced this issue Oct 5, 2023
Follow up to rubocop/rubocop-performance#111.

This PR prepares to use RuboCop's new development API.
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
3 participants