-
Notifications
You must be signed in to change notification settings - Fork 122
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
Bust erblilnt cache on rubocop config changes via linter checksum #373
base: main
Are you sure you want to change the base?
Conversation
I have signed the CLA! |
@oehlschl not at a computer right now but as the person who finished up the initial caching PR this looks directionally right to me. I wouldn't consider this a review but I think writing specs at this point would be worth it. You're probably right that some methods are due for a refactor but maybe a separate PR makes sense for that. |
@@ -76,7 +80,7 @@ def checksum(filename, file_content) | |||
mode = File.stat(filename).mode | |||
|
|||
digester.update( | |||
"#{mode}#{config.to_hash}#{ERBLint::VERSION}#{file_content}", | |||
"#{mode}#{config.to_hash}#{ERBLint::VERSION}#{@runner_checksum}#{file_content}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this will bust all caches on release since Runner#checksum
will return Digest::SHA1.new.hexdigest
even if there are no linters with checksum methods. That method can be refactored to return nil
in the default / empty case if desired.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this idea better than #300, it makes sense that each linter could have its own cache invalidation, like the rubocop linter shows.
Let's add some specs!
@@ -67,6 +67,10 @@ def clear | |||
FileUtils.rm_r(@cache_dir) | |||
end | |||
|
|||
def set_runner_checksum(checksum) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def set_runner_checksum(checksum) | |
def runner_checksum=(checksum) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, thanks for the feedback @etiennebarrie . Will do.
@@ -63,6 +63,15 @@ def autocorrect(processed_source, offense) | |||
end | |||
end | |||
|
|||
def checksum |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's call this something more intention-revealing. Rails calls something similar cache_key
, that might work.
Fixes #299.
Alternative implementation of #300, as discussed here: #300 (comment)
This PR introduces a new
checksum
property to Linters, exposed in aggregate through the Runner, to enable busting the cache when linter config and dependencies not represented in the gloabl erb_lint config change.Specifically, it adds logic to the Rubocop linter to handle both explicit config changes in the rubocop config (.rubocop.yml, or however that config is sourced) and implicit config changes in the versions of rubcop and any rubocop plugin gems (via Gemfile.lock).
I tested this locally to confirm that:
I haven't yet added specs, since I wanted to submit this for directional feedback before further investment. I'm happy to change method names, patterns, etc., and I also wrote this PR to be additive and minimally invasive. (Other options would have included more refactor of the Cache class, likely to add the checksum as an initializer arg and defer instantiation until after the Runner was set up; I'm happy to make those changes as well, but I was not sure how much appetite or concern there was for changing interfaces in this lib.)