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

Unify Settings and AllSettings #7532

Merged
merged 1 commit into from
Sep 20, 2023
Merged

Conversation

MichaReiser
Copy link
Member

@MichaReiser MichaReiser commented Sep 20, 2023

Summary

This PR merges AllSettings and Settings (by merging CliSettings into Settings). The main motivation is to avoid the confusion of why the two settings exist, which still isn't entirely clear to me.
Here's what I understand today (I am happy to close this PR if we can get to the bottom of why the two structs exist)

#1891 split Settings into AllSettings and Settings

We want to automatically derive Hash for the library settings, which
requires us to split off all the settings unused by the library
(since these shouldn't affect the hash used by ruff_cli::cache).

I solved this by extending the CacheKey derive macro to support the cache_key(ignore) field attribute to ignore individual fields. We can keep the automatically derived CacheKey implementation and explicitly mark the excluded fields.

There has been some argument whether the two settings exist because the CliSettings are only respected for the "root" configuration. This holds true for all CliSettings except cache-dir as #7520 showed. Meaning that distinction may have been true but no longer is.

My final guess is that the CliSettings used to be unique to using ruff from the cli. I think this is still mostly true (although most of the resolver code now lives inside ruff_workspace). However, I don't think it is sufficient reason to separate the two structs, especially considering that we could show diagnostics in our playground similar to biome (see console tab) where we would want to respect the output-format configuration (and --show-sources etc). fix, fix-only and cache-dir likely remain CLI only settings but, IMO, don't justify the cognitive load of having multiple settings structs.

The main justification for me to keep the separate settings struct is that the linter doesn't need the CliSettings. These are settings that only concern the diagnostic rendering, and file traversal (although the same is true for exclude, respect_gitignore and other global settings). That's why I plan to split settings in more semantic sub-settings:

  • Linter settings
  • Formatter settings
  • common / shared settings
  • Maybe; Resolver settings?

Test Plan

cargo test

@MichaReiser MichaReiser added the internal An internal refactor or improvement label Sep 20, 2023
@MichaReiser MichaReiser force-pushed the merge-settings-and-all-settings branch 2 times, most recently from c13f93f to acd6576 Compare September 20, 2023 07:33
@github-actions
Copy link
Contributor

github-actions bot commented Sep 20, 2023

PR Check Results

Ecosystem

✅ ecosystem check detected no changes.

Self {
cache_dir: cache_dir(&project_root),
Copy link
Member

Choose a reason for hiding this comment

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

Nit: maybe a comment on why these are separated from the rest? Same with other instantiations.

Copy link
Member Author

@MichaReiser MichaReiser Sep 20, 2023

Choose a reason for hiding this comment

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

I'll leave it as is because these will be moved to their own struct in a PR higher in the stack, making the reason clear

@MichaReiser MichaReiser enabled auto-merge (squash) September 20, 2023 13:48
@MichaReiser MichaReiser merged commit b19eec9 into main Sep 20, 2023
16 checks passed
@MichaReiser MichaReiser deleted the merge-settings-and-all-settings branch September 20, 2023 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal An internal refactor or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants