Warn on unrecognized config keys with a "did you mean" suggestion#3966
Open
markselby9 wants to merge 1 commit into
Open
Warn on unrecognized config keys with a "did you mean" suggestion#3966markselby9 wants to merge 1 commit into
markselby9 wants to merge 1 commit into
Conversation
A config key Pyrefly doesn't recognize — a typo like `check-unannotated-def`, or a key copied from another tool — is swept into serde's `flatten` catch-all and was surfaced only as a single lumped "Extra keys found" line, giving no hint about what the user likely meant. Emit one warning per unrecognized key and, when a known option is within a small edit distance, suggest it (e.g. "Did you mean `check-unannotated-defs`?"). Top-level and `[[sub-config]]` keys are matched against the options valid in their own scope, so a sub-config typo never suggests a project-only key. The suggestion reuses the edit-distance ranking already used for identifier typos in `pyrefly_util::suggest`, generalized to plain strings so the config and identifier paths share one implementation. Closes facebook#3943
c1e7715 to
a94469b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #3943.
When a
pyrefly.toml/[tool.pyrefly]contains a key Pyrefly doesn't recognize, serde's#[serde(flatten)]catch-all silently swept it intoextras, andfrom_filesurfaced it only as a single lumped line:That tells you something is wrong but not what you meant. This PR replaces it with one warning per unrecognized key and a "did you mean" suggestion when a known option is close:
(As the issue notes, unknown error kinds already fail to parse — this brings unknown config keys closer to that behavior, while still only warning so users can intentionally share a config across tools.)
Details
ConfigBasesettings;[[sub-config]]keys are matched againstmatches+ConfigBaseonly — so a sub-config typo never suggests a project-only key likeproject-includes.pyrefly_util::suggest. I generalized that module's internals into one privateclosest<T>and exposed abest_suggestion_strfor plain strings;best_suggestion(used by 6 call sites) now delegates to it with unchanged behavior.python_version) are accepted by serde, so they never reachextrasand are never flagged.Test plan
crates/pyrefly_config/src/config.rs:[[sub-config]]→ warns with the sub-config context + suggestiontest_known_config_keys_cover_serialized_fields: a sync guard so newly-added (serialized) config fields must be added to the candidate listscargo test -p pyrefly_config— 224 passed.cargo test -p pyrefly_util— 71 passed (guards the shared helper refactor).test::attributes(187),test::typed_dict(161),test::scope(96),test::enums(61),test::calls(47) — all green.python3 test.py --no-test --no-tensor-shapes --no-conformance --no-jsonschema— clean.