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

0 files inspected? #6722

Closed
Ifiht opened this issue Feb 1, 2019 · 1 comment · Fixed by #6727
Closed

0 files inspected? #6722

Ifiht opened this issue Feb 1, 2019 · 1 comment · Fixed by #6727
Labels

Comments

@Ifiht
Copy link

Ifiht commented Feb 1, 2019

Expected rubocop to parse and identify errors in the ruby file, as it does when I use no options or the -x option. Instead, when running "rubocop -a" I get the following output:

PS C:\Users\myself\Desktop\userfoo> rubocop -a
Inspecting 1 file


0 files inspected, no offenses detected
undefined method `type' for nil:NilClass
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/lib/rubocop/cop/style/one_line_conditional.rb:74:in `requires_parentheses?'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/lib/rubocop/cop/style/one_line_conditional.rb:70:in `expr_replacement'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/lib/rubocop/cop/style/one_line_conditional.rb:65:in `to_ternary'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/lib/rubocop/cop/style/one_line_conditional.rb:60:in `replacement'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/lib/rubocop/cop/style/one_line_conditional.rb:39:in `block in autocorrect'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/lib/rubocop/cop/corrector.rb:64:in `block (2 levels) in rewrite'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/parser-2.6.0.0/lib/parser/source/tree_rewriter.rb:220:in `transaction'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/lib/rubocop/cop/corrector.rb:63:in `block in rewrite'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/lib/rubocop/cop/corrector.rb:61:in `each'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/lib/rubocop/cop/corrector.rb:61:in `rewrite'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/lib/rubocop/cop/team.rb:128:in `autocorrect_all_cops'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/lib/rubocop/cop/team.rb:72:in `autocorrect'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/lib/rubocop/cop/team.rb:100:in `block in offenses'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/lib/rubocop/cop/team.rb:117:in `investigate'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/lib/rubocop/cop/team.rb:96:in `offenses'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/lib/rubocop/cop/team.rb:44:in `inspect_file'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/lib/rubocop/runner.rb:280:in `inspect_file'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/lib/rubocop/runner.rb:227:in `block in do_inspection_loop'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/lib/rubocop/runner.rb:259:in `block in iterate_until_no_changes'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/lib/rubocop/runner.rb:252:in `loop'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/lib/rubocop/runner.rb:252:in `iterate_until_no_changes'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/lib/rubocop/runner.rb:223:in `do_inspection_loop'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/lib/rubocop/runner.rb:126:in `block in file_offenses'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/lib/rubocop/runner.rb:144:in `file_offense_cache'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/lib/rubocop/runner.rb:124:in `file_offenses'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/lib/rubocop/runner.rb:112:in `process_file'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/lib/rubocop/runner.rb:89:in `block in each_inspected_file'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/lib/rubocop/runner.rb:86:in `each'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/lib/rubocop/runner.rb:86:in `reduce'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/lib/rubocop/runner.rb:86:in `each_inspected_file'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/lib/rubocop/runner.rb:76:in `inspect_files'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/lib/rubocop/runner.rb:48:in `run'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/lib/rubocop/cli.rb:174:in `execute_runner'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/lib/rubocop/cli.rb:75:in `execute_runners'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/lib/rubocop/cli.rb:47:in `run'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/exe/rubocop:13:in `block in <top (required)>'
C:/Ruby25-x64/lib/ruby/2.5.0/benchmark.rb:308:in `realtime'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.63.1/exe/rubocop:12:in `<top (required)>'
C:/Ruby25-x64/bin/rubocop:23:in `load'
C:/Ruby25-x64/bin/rubocop:23:in `<main>'
PS C:\Users\myself\Desktop\userfoo>

Reproduce by running rubocop on the following code:

def revalue_hash(a_hash)
  b_hash = a_hash.sort.group_by { |k, v| v }.each_with_object(Hash.new) { |(k, v), h| h[v.map { |e| e.first }.join(', ')] = k }
  b_hash.keys.each do |bk, _| # USER
    if b_hash[bk]
      c_hash = b_hash[bk]
      c_hash.keys.each do |ck, _| # DOMAIN
        if c_hash[ck]
          d_hash = c_hash[ck]
          d_hash.keys.each do |dk, _| # NODE
            if d_hash[dk].first then else d_hash.delete(dk) end
          end
          if not d_hash.empty?
            c_hash[ck] = d_hash.sort.group_by { |k, v| v }.each_with_object(Hash.new) { |(k, v), h| h[v.map { |e| e.first }.join(', ')] = k }
            if c_hash[ck].count == 1 then c_hash[ck]["All Nodes:"] = c_hash[ck].delete(c_hash[ck].keys.first) end
          else
            c_hash.delete(ck)
          end
        else
          c_hash.delete(ck)
        end
      end
      if not c_hash.empty?
        b_hash[bk] = c_hash.sort.group_by { |k, v| v }.each_with_object(Hash.new) { |(k, v), h| h[v.map { |e| e.first }.join(', ')] = k }
      else
        b_hash.delete(bk)
      end
    else
      b_hash.delete(bk)
    end
  end
  return b_hash
end

RuboCop version: 0.63.1 (using Parser 2.6.0.0, running on ruby 2.5.3 x64-mingw32)

@koic koic added the bug label Feb 1, 2019
koic added a commit to koic/rubocop that referenced this issue Feb 4, 2019
Fixes rubocop#6722.

This PR fixes an error for `Style/OneLineConditional` when
`then` branch has no body. The following is an error case.

```ruby
# example.rb
if cond then else dont end
```

The following is a reproduction step.

```console
% rubocop -v
0.63.1

% rubocop -a example.rb --only Style/OneLineConditional
Inspecting 1 file

0 files inspected, no offenses detected
undefined method `type' for nil:NilClass
/Users/koic/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/cop/style/one_line_conditional.rb:74:in
`requires_parentheses?'
/Users/koic/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/cop/style/one_line_conditional.rb:70:in
`expr_replacement'
/Users/koic/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/cop/style/one_line_conditional.rb:65:in
`to_ternary'

(snip)
```

This PR auto-corrected to the following code.

```ruby
cond ? nil : dont
```

Actually the above code is the same behavior as `unless` modifier.
But this PR aims auto-corrected to an equivalent code without causing an error.
@koic
Copy link
Member

koic commented Feb 4, 2019

Thanks for the feedback. I opened a PR #6727.

Drenmi added a commit that referenced this issue Feb 4, 2019
[Fix #6722] Fix an error for `Style/OneLineConditional`
@Drenmi Drenmi mentioned this issue Feb 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants