rubocop / rubocop-md

RuboCop for Markdown code snippets
MIT License
73 stars 14 forks source link

"undefined method `for' for nil:NilClass" occurs when the format option is specified #22

Closed sinsoku closed 1 year ago

sinsoku commented 1 year ago

Description

If you add rubocop-md to .rubocop.yml and run RuboCop with the format option, an error will occur.

$ bundle exec rubocop --format progress README.md
0 files inspected, no offenses detected
undefined method `for' for nil:NilClass

I was able to avoid the error by adding -r rubocop-md as a workaround.

$ bundle exec rubocop -r rubocop-md --format progress README.md

Expected behavior

no error occurs.

Actual behavior

"undefined method `for' for nil:NilClass" error occurs.

Steps to reproduce the problem

$ mkdir test-rubocop-md

$ cd test-rubocop-md

$ cat << EOS > Gemfile
source "https://rubygems.org"
gem "rubocop-md"
EOS

$ bundle install

$ touch README.md

$ cat << EOS > .rubocop.yml
require:
  - "rubocop-md"
EOS

$ bundle exec rubocop --format progress README.md
0 files inspected, no offenses detected
undefined method `for' for nil:NilClass
/Users/sinsoku/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-md-1.2.0/lib/rubocop/markdown/preprocess.rb:66:in `initialize'
/Users/sinsoku/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-md-1.2.0/lib/rubocop/markdown/rubocop_ext.rb:91:in `new'
/Users/sinsoku/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-md-1.2.0/lib/rubocop/markdown/rubocop_ext.rb:91:in `parse'
/Users/sinsoku/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/processed_source.rb:38:in `initialize'
/Users/sinsoku/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/processed_source.rb:23:in `new'
/Users/sinsoku/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/processed_source.rb:23:in `from_file'
/Users/sinsoku/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.56.4/lib/rubocop/runner.rb:478:in `get_processed_source'
/Users/sinsoku/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.56.4/lib/rubocop/runner.rb:273:in `do_inspection_loop'
/Users/sinsoku/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.56.4/lib/rubocop/runner.rb:164:in `block in file_offenses'
/Users/sinsoku/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.56.4/lib/rubocop/runner.rb:189:in `file_offense_cache'
/Users/sinsoku/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.56.4/lib/rubocop/runner.rb:163:in `file_offenses'
/Users/sinsoku/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.56.4/lib/rubocop/runner.rb:154:in `process_file'
/Users/sinsoku/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.56.4/lib/rubocop/runner.rb:135:in `block in each_inspected_file'
/Users/sinsoku/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.56.4/lib/rubocop/runner.rb:134:in `each'
/Users/sinsoku/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.56.4/lib/rubocop/runner.rb:134:in `reduce'
/Users/sinsoku/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.56.4/lib/rubocop/runner.rb:134:in `each_inspected_file'
/Users/sinsoku/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.56.4/lib/rubocop/runner.rb:120:in `inspect_files'
/Users/sinsoku/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.56.4/lib/rubocop/runner.rb:73:in `run'

System configuration

rubocop (1.56.4)
rubocop-md (1.2.0)
palkan commented 1 year ago

Thanks for the report and the reproducing. We'll take a look soon.

palkan commented 1 year ago

Thanks for the report. Fixed and released in 1.2.1