Skip to content

Commit

Permalink
[Fix rubocop#8842] Debug outputs cache used info
Browse files Browse the repository at this point in the history
* When rubocop is ran in debug mode (`--debug`) and rubocop uses a cache, output the location of cache used. (This is to inform about possible differences between runs..)
* Encourage users submitting bugs to use debug mode.
  • Loading branch information
ofir-petrushka committed Oct 5, 2020
1 parent 4f101b6 commit da3833e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Expand Up @@ -23,6 +23,7 @@ Describe here how you expected RuboCop to behave in this particular situation.
## Actual behavior

Describe here what actually happened.
Please use `rubocop --debug` when pasting rubocop output as it contains additional information.

## Steps to reproduce the problem

Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@

* [#8796](https://github.com/rubocop-hq/rubocop/pull/8796): Add new `Lint/HashCompareByIdentity` cop. ([@fatkodima][])
* [#8668](https://github.com/rubocop-hq/rubocop/pull/8668): Add new `Lint/RedundantSafeNavigation` cop. ([@fatkodima][])
* [#8842](https://github.com/rubocop-hq/rubocop/issues/8842): Add notification about cache being used to debug mode. ([@hatkyinc2][])

### Bug fixes

Expand Down Expand Up @@ -4952,3 +4953,4 @@
[@pbernays]: https://github.com/pbernays
[@rdunlop]: https://github.com/rdunlop
[@ghiculescu]: https://github.com/ghiculescu
[@hatkyinc2]: https://github.com/hatkyinc2
6 changes: 6 additions & 0 deletions lib/rubocop/result_cache.rb
Expand Up @@ -95,13 +95,19 @@ def initialize(file, team, options, config_store, cache_root = nil)
context_checksum(team, options),
file_checksum(file, config_store))
@cached_data = CachedData.new(file)
@debug = options[:debug]
end

def debug?
@debug
end

def valid?
File.exist?(@path)
end

def load
puts "Loading cache from #{@path}" if debug?
@cached_data.from_json(IO.read(@path, encoding: Encoding::UTF_8))
end

Expand Down

0 comments on commit da3833e

Please sign in to comment.