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

Bust erblilnt cache on rubocop config changes via linter checksum #373

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

oehlschl
Copy link

@oehlschl oehlschl commented Sep 8, 2024

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:

  • the Rubocop checksum is not computed when the linter is not enabled
  • the checksum changes when .rubocop.yml changes
  • the checksum changes when the Gemfile.lock changes

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.)

@oehlschl oehlschl marked this pull request as ready for review September 8, 2024 22:14
@oehlschl
Copy link
Author

oehlschl commented Sep 8, 2024

I have signed the CLA!

@zachfeldman
Copy link

zachfeldman commented Sep 9, 2024

@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}",
Copy link
Author

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.

Copy link
Member

@etiennebarrie etiennebarrie left a 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def set_runner_checksum(checksum)
def runner_checksum=(checksum)

Copy link
Author

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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cache ignores Rubocop version and rubocop.yml configuration.
3 participants