-
Clone gist:
$ git clone [email protected]:c65abfdd6e2bf36dcadc9b5364a0b741.git rubocop-style-safe-naviation-error $ cd rubocop-style-safe-naviation-error
-
Bundle install:
$ bundle install
-
Run Rubocop:
$ bundle exec rubocop Inspecting 2 files C. Offenses: foobar.rb:3:1: C: Use safe navigation (&.) instead of checking if an object exists before calling the method. foo[bar] if foo ^^^^^^^^^^^^^^^ 2 files inspected, 1 offense detected
-
Run Rubocop auto-correct:
$ bundle exec rubocop --auto-correct Inspecting 2 files 0 files inspected, no offenses detected undefined method `begin' for nil:NilClass /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/parser-2.4.0.0/lib/parser/source/rewriter.rb:67:in `insert_before' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.50.0/lib/rubocop/cop/corrector.rb:78:in `insert_before' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.50.0/lib/rubocop/cop/style/safe_navigation.rb:99:in `block in autocorrect' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.50.0/lib/rubocop/cop/corrector.rb:56:in `block (2 levels) in rewrite' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/parser-2.4.0.0/lib/parser/source/rewriter.rb:194:in `transaction' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.50.0/lib/rubocop/cop/corrector.rb:55:in `block in rewrite' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.50.0/lib/rubocop/cop/corrector.rb:53:in `each' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.50.0/lib/rubocop/cop/corrector.rb:53:in `rewrite' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.50.0/lib/rubocop/cop/team.rb:126:in `autocorrect_all_cops' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.50.0/lib/rubocop/cop/team.rb:70:in `autocorrect' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.50.0/lib/rubocop/cop/team.rb:98:in `block in offenses' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.50.0/lib/rubocop/cop/team.rb:115:in `investigate' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.50.0/lib/rubocop/cop/team.rb:94:in `offenses' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.50.0/lib/rubocop/cop/team.rb:44:in `inspect_file' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.50.0/lib/rubocop/runner.rb:258:in `inspect_file' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.50.0/lib/rubocop/runner.rb:205:in `block in do_inspection_loop' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.50.0/lib/rubocop/runner.rb:237:in `block in iterate_until_no_changes' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.50.0/lib/rubocop/runner.rb:230:in `loop' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.50.0/lib/rubocop/runner.rb:230:in `iterate_until_no_changes' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.50.0/lib/rubocop/runner.rb:201:in `do_inspection_loop' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.50.0/lib/rubocop/runner.rb:111:in `block in file_offenses' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.50.0/lib/rubocop/runner.rb:121:in `file_offense_cache' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.50.0/lib/rubocop/runner.rb:109:in `file_offenses' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.50.0/lib/rubocop/runner.rb:100:in `process_file' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.50.0/lib/rubocop/runner.rb:78:in `block in each_inspected_file' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.50.0/lib/rubocop/runner.rb:75:in `each' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.50.0/lib/rubocop/runner.rb:75:in `reduce' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.50.0/lib/rubocop/runner.rb:75:in `each_inspected_file' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.50.0/lib/rubocop/runner.rb:67:in `inspect_files' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.50.0/lib/rubocop/runner.rb:39:in `run' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.50.0/lib/rubocop/cli.rb:86:in `execute_runner' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.50.0/lib/rubocop/cli.rb:32:in `run' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.50.0/bin/rubocop:13:in `block in <top (required)>' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/2.4.0/benchmark.rb:308:in `realtime' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.50.0/bin/rubocop:12:in `<top (required)>' /Users/jimeh/.rbenv/versions/2.4.1/bin/rubocop:22:in `load' /Users/jimeh/.rbenv/versions/2.4.1/bin/rubocop:22:in `<top (required)>' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/cli/exec.rb:74:in `load' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/cli/exec.rb:74:in `kernel_load' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/cli/exec.rb:27:in `run' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/cli.rb:362:in `exec' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/cli.rb:22:in `dispatch' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/cli.rb:13:in `start' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/exe/bundle:30:in `block in <top (required)>' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/friendly_errors.rb:121:in `with_friendly_errors' /Users/jimeh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/exe/bundle:22:in `<top (required)>' /Users/jimeh/.rbenv/versions/2.4.1/bin/bundle:22:in `load' /Users/jimeh/.rbenv/versions/2.4.1/bin/bundle:22:in `<main>'
Last active
September 18, 2017 11:20
-
-
Save jimeh/c65abfdd6e2bf36dcadc9b5364a0b741 to your computer and use it in GitHub Desktop.
Error in Rubocop 0.50.0's Style/SafeNavigation cop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AllCops: | |
TargetRubyVersion: 2.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
foo[bar] if foo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
source 'https://rubygems.org/' | |
gem 'rubocop', '0.50.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GEM | |
remote: https://rubygems.org/ | |
specs: | |
ast (2.3.0) | |
parallel (1.12.0) | |
parser (2.4.0.0) | |
ast (~> 2.2) | |
powerpack (0.1.1) | |
rainbow (2.2.2) | |
rake | |
rake (12.1.0) | |
rubocop (0.50.0) | |
parallel (~> 1.10) | |
parser (>= 2.3.3.1, < 3.0) | |
powerpack (~> 0.1) | |
rainbow (>= 2.2.2, < 3.0) | |
ruby-progressbar (~> 1.7) | |
unicode-display_width (~> 1.0, >= 1.0.1) | |
ruby-progressbar (1.8.3) | |
unicode-display_width (1.3.0) | |
PLATFORMS | |
ruby | |
DEPENDENCIES | |
rubocop (= 0.50.0) | |
BUNDLED WITH | |
1.15.4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment