Repository navigation
feat(BREAKING): evaluate associations and override files in order where the last match wins - #1258
Merged
Merged
Conversation
…match wins Plugin associations are now evaluated like `excludes`: in order, where the last matching pattern wins. This allows opting into specific files after a negated pattern, for example only formatting `Cargo.toml` files with the toml plugin via `["!**/*.toml", "Cargo.toml"]`. Previously a negated pattern always won regardless of its position.
…t match wins The `files` of plugin configuration overrides are now evaluated in order like includes, excludes, and associations, where the last matching pattern wins. Associations and override files now share an OrderedPatternsMatcher.
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.
Plugin
associationsand thefilesof plugin configurationoverridesare now evaluated likeincludesandexcludes(gitignore style): in order, where the last matching pattern wins. With this, every pattern list in the config works the same way. This makes it possible to opt into specific files after a negated pattern, which wasn't possible before because a negated pattern always won regardless of where it was in the list.For example, to only format
Cargo.tomlfiles with the toml plugin:{ "toml": { "associations": ["!**/*.toml", "Cargo.toml"] } }Previously this formatted nothing (
!**/*.tomlalso excludedCargo.toml). NowCargo.tomlfiles in any directory are formatted and other.tomlfiles aren't.Breaking change
A negated pattern followed by a pattern matching the same file now matches it. For example, associations of
["!legacy/**", "**/*.other"]previously didn't formatlegacy/file.otherand now do, and overridefilesof["!legacy/**", "**/package.json"]now apply the override tolegacy/package.json. To keep excluding it, put the negated pattern last (["**/*.other", "!legacy/**"]). Lists with negated patterns last, like the example in the docs (["**/*.other", "!**/*.js"]), behave the same.Changes
OrderedPatternsMatcher(patterns.rs) builds a single ordered gitignore-style matcher from the patterns with inverted polarity, so the last matching pattern decides: a pattern means it matches (matches) and a negated pattern means it's excluded (is_excluded). It replacesget_patterns_as_glob_matcher, which split the patterns into includes and excludes so a negated pattern always won.GlobMatcher::exclude_detailexposes the order aware exclude result for a path.PluginNameResolutionMapsuses it for claiming files by associations and for excluding a plugin from its default file matching.PluginConfigOverrideuses it for the override'sfiles.