Problem with yamllint configuration file
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 16
- Forks
- 39
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 8
Description
Processing a repository which does not have specified rules in `.yamllint` configuration file will result in:
```
Called from /root/.rbenv/versions/2.3.6/lib/ruby/gems/2.3.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:240:in `load_dependency'
2018-04-21T12:59:14.996Z 3748 TID-grgzknuxk CommitMonitorHandlers::CommitRange::RubocopChecker JID-5e5788c93fcadd6dc8e7ba96 INFO: fail: 3.448 sec
2018-04-21T12:59:14.997Z 3748 TID-grgzknuxk WARN: {"class":"CommitMonitorHandlers::CommitRange::RubocopChecker","args":[2,["265235e76fa59718486c042a0650443d18400e6e"]],"retry":true,"queue":"miq_bot_glacial","jid":"5e5788c93fcadd6dc8e7ba96","created_at":1524315367.5318902,"enqueued_at":1524315551.5467553,"error_message":"undefined method `captures' for nil:NilClass\nDid you mean? capture","error_class":"NoMethodError","failed_at":1524315372.3904035,"retry_count":1,"retried_at":1524315554.9960437}
2018-04-21T12:59:14.997Z 3748 TID-grgzknuxk WARN: NoMethodError: undefined method `captures' for nil:NilClass
Did you mean? capture
2018-04-21T12:59:14.997Z 3748 TID-grgzknuxk WARN: /root/miq_bot/lib/linter/yaml.rb:44:in `line_to_hash'
/root/miq_bot/lib/linter/yaml.rb:7:in `block in parse_output'
/root/miq_bot/lib/linter/yaml.rb:7:in `collect'
/root/miq_bot/lib/linter/yaml.rb:7:in `parse_output'
/root/miq_bot/lib/linter/base.rb:31:in `run'
/root/miq_bot/app/workers/concerns/code_analysis_mixin.rb:26:in `run_all_linters'
/root/miq_bot/app/workers/concerns/code_analysis_mixin.rb:12:in `merged_linter_results'
/root/miq_bot/app/workers/commit_monitor_handlers/commit_range/rubocop_checker.rb:25:in `process_branch'
/root/miq_bot/app/workers/commit_monitor_handlers/commit_range/rubocop_checker.rb:19:in `perform'
/root/.rbenv/versions/2.3.6/lib/ruby/gems/2.3.0/gems/sidekiq-4.1.4/lib/sidekiq/processor.rb:152:in `execute_job'
/root/.rbenv/versions/2.3.6/lib/ruby/gems/2.3.0/gems/sidekiq-4.1.4/lib/sidekiq/processor.rb:134:in `block (2 levels) in process'
/root/.rbenv/versions/2.3.6/lib/ruby/gems/2.3.0/gems/sidekiq-4.1.4/lib/sidekiq/middleware/chain.rb:128:in `block in invoke'
/root/.rbenv/versions/2.3.6/lib/ruby/gems/2.3.0/gems/sidetiq-0.7.2/lib/sidetiq/middleware/history.rb:8:in `call'
/root/.rbenv/versions/2.3.6/lib/ruby/gems/2.3.0/gems/sidekiq-4.1.4/lib/sidekiq/middleware/chain.rb:130:in `block in invoke'
/root/.rbenv/versions/2.3.6/lib/ruby/gems/2.3.0/gems/sidekiq-4.1.4/lib/sidekiq/middleware/server/active_record.rb:6:in `call'
/root/.rbenv/versions/2.3.6/lib/ruby/gems/2.3.0/gems/sidekiq-4.1.4/lib/sidekiq/middleware/chain.rb:130:in `block in invoke'
/root/.rbenv/versions/2.3.6/lib/ruby/gems/2.3.0/gems/sidekiq-4.1.4/lib/sidekiq/middleware/server/retry_jobs.rb:74:in `call'
/root/.rbenv/versions/2.3.6/lib/ruby/gems/2.3.0/gems/sidekiq-4.1.4/lib/sidekiq/middleware/chain.rb:130:in `block in invoke'
/root/.rbenv/versions/2.3.6/lib/ruby/gems/2.3.0/gems/sidekiq-4.1.4/lib/sidekiq/middleware/server/logging.rb:11:in `block in call'
/root/.rbenv/versions/2.3.6/lib/ruby/gems/2.3.0/gems/sidekiq-4.1.4/lib/sidekiq/logging.rb:32:in `with_context'
/root/.rbenv/versions/2.3.6/lib/ruby/gems/2.3.0/gems/sidekiq-4.1.4/lib/sidekiq/middleware/server/logging.rb:7:in `call'
/root/.rbenv/versions/2.3.6/lib/ruby/gems/2.3.0/gems/sidekiq-4.1.4/lib/sidekiq/middleware/chain.rb:130:in `block in invoke'
/root/.rbenv/versions/2.3.6/lib/ruby/gems/2.3.0/gems/sidekiq-4.1.4/lib/sidekiq/middleware/chain.rb:133:in `invoke'
/root/.rbenv/versions/2.3.6/lib/ruby/gems/2.3.0/gems/sidekiq-4.1.4/lib/sidekiq/processor.rb:129:in `block in process'
/root/.rbenv/versions/2.3.6/lib/ruby/gems/2.3.0/gems/sidekiq-4.1.4/lib/sidekiq/processor.rb:168:in `stats'
/root/.rbenv/versions/2.3.6/lib/ruby/gems/2.3.0/gems/sidekiq-4.1.4/lib/sidekiq/processor.rb:128:in `process'
/root/.rbenv/versions/2.3.6/lib/ruby/gems/2.3.0/gems/sidekiq-4.1.4/lib/sidekiq/processor.rb:80:in `process_one'
/root/.rbenv/versions/2.3.6/lib/ruby/gems/2.3.0/gems/sidekiq-4.1.4/lib/sidekiq/processor.rb:68:in `run'
/root/.rbenv/versions/2.3.6/lib/ruby/gems/2.3.0/gems/sidekiq-4.1.4/lib/sidekiq/util.rb:17:in `watchdog'
/root/.rbenv/versions/2.3.6/lib/ruby/gems/2.3.0/gems/sidekiq-4.1.4/lib/sidekiq/util.rb:25:in `block in safe_thread'
```
**NOTE**: yamllint has its default rules see [here](https://yamllint.readthedocs.io/en/stable/configuration.html#default-configuration).
The problem starts at [line number 7 in `lib/linter/yaml.rb`](https://github.com/ManageIQ/miq_bot/blob/master/lib/linter/yaml.rb#L7):
```ruby
parsed = lines.collect { |line| line_to_hash(line) }
```
```
[1] pry(#)> lines
=> ["{\"files\":[{\"path\":\"\\\\*\\\\*\",\"offenses\":[{\"severity\":\"fatal\",\"message\":\"Linter::Yaml STDERR:\\n```\\ninvalid config: not a dict\\n\\n```\",\"cop_name\":\"Linter/Yaml\"}]}],\"summary\":{\"offense_count\":1,\"target_file_count\":3,\"inspected_file_count\":3}}"]
```
in `line_to_hash(line)` at:
```ruby
severity, message = severity_message.match(/\[(.*)\] (.*)/).captures
```
where `.captures` is called on `nil:NilClass`:
```
[3] pry(#)> severity_message
=> "[{\"severity\":\"fatal\",\"message\":\"Linter::Yaml STDERR:\\n```\\ninvalid config: not a dict\\n\\n```\",\"cop_name\":\"Linter/Yaml\"}]}],\"summary\":{\"offense_count\":1,\"target_file_count\":3,\"inspected_file_count\":3}}"
```
```
[4] pry(#)> severity_message.match(/\[(.*)\] (.*)/)
=> nil
```
**Related issue**: https://github.com/ManageIQ/miq_bot/issues/392
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in lib/linter/yaml.rb, especially line 7 where lines are parsed and line 44 where the severity message is matched. Reproduce processing a repository without specified yamllint rules and inspect the resulting linter output. Done means this configuration is handled without the NoMethodError and the linter result remains usable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100