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

[Fix #10842] Make server mode aware of CacheRootDirectory and two env vars #10852

Merged

Conversation

koic
Copy link
Member

@koic koic commented Aug 2, 2022

Fixes #10842 and follow up #10849.

This PR makes server mode aware of CacheRootDirectory config option value, RUBOCOP_CACHE_ROOT, and XDG_CACHE_HOME environment variables.

RuboCop::ConfigLoader and RuboCop::ResultCache classes to get these values has many dependencies. So, it is not suitable for use in server mode where speed is required.

This solution is to extract ConfigPathFinder class from ConfigLoader class and CacheRoot class from ResultCache class. This allows server mode to depend on lightweight ConfigPathFinder and CacheRoot classes.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@koic koic force-pushed the make_server_mode_aware_of_cache_root_directory branch 5 times, most recently from e2aeaf4 to 66b8845 Compare August 2, 2022 10:24
@koic koic changed the title [Fix #10842] Make RuboCop server mode aware of CacheRootDirectory and two env vars [Fix #10842] Make server mode aware of CacheRootDirectory and two env vars Aug 3, 2022
@koic koic force-pushed the make_server_mode_aware_of_cache_root_directory branch from 66b8845 to e3c05aa Compare August 3, 2022 05:03
module RuboCop
# This class has methods related to finding configuration path.
# @api private
class ConfigPathFinder
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps just ConfigFinder?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the suggestion! I've update this class name.

module RuboCop
# This class represents the cache root of the caching RuboCop runs.
# @api private
class CacheRoot
Copy link
Collaborator

Choose a reason for hiding this comment

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

CacheRoot seems a bit too specific to me to warrant a class - maybe this should be CacheConfig or something like this?

Copy link
Member Author

Choose a reason for hiding this comment

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

CacheConfig looks good! Also changed the class method name from CacheRoot.dir to CacheConfig.root_dir.

…d two env vars

Fixes rubocop#10842 and follow up rubocop#10849.

This PR makes server mode aware of `CacheRootDirectory` config option value,
`RUBOCOP_CACHE_ROOT`, and `XDG_CACHE_HOME` environment variables.

`RuboCop::ConfigLoader` and `RuboCop::ResultCache` classes to get these values has many dependencies.
So, it is not suitable for use in server mode where speed is required.

This solution is to extract `ConfigPathFinder` class from `ConfigLoader` class and `CacheRoot` class
from `ResultCache` class.
This allows server mode to depend on lightweight `ConfigPathFinder` and `CacheRoot` classes.
@koic koic force-pushed the make_server_mode_aware_of_cache_root_directory branch from e3c05aa to 651ba56 Compare August 3, 2022 06:14
@bbatsov bbatsov merged commit 6b6d554 into rubocop:master Aug 3, 2022
@bbatsov
Copy link
Collaborator

bbatsov commented Aug 3, 2022

Thanks!

@koic koic deleted the make_server_mode_aware_of_cache_root_directory branch August 3, 2022 07:35
WJWH pushed a commit to WJWH/rubocop that referenced this pull request Aug 8, 2022
…d two env vars (rubocop#10852)

Fixes rubocop#10842 and follow up rubocop#10849.

This PR makes server mode aware of `CacheRootDirectory` config option value,
`RUBOCOP_CACHE_ROOT`, and `XDG_CACHE_HOME` environment variables.

`RuboCop::ConfigLoader` and `RuboCop::ResultCache` classes to get these values has many dependencies.
So, it is not suitable for use in server mode where speed is required.

This solution is to extract `ConfigFinder` class from `ConfigLoader` class and `CacheConfig` class
from `ResultCache` class.
This allows server mode to depend on lightweight `ConfigFinder` and `CacheConfig` classes.
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.

Server Does not Appear to Work
2 participants