Skip to content

feat(BREAKING): evaluate associations and override files in order where the last match wins - #1258

Merged
dsherret merged 2 commits into
mainfrom
feat/ordered-associations
Sep 28, 2026
Merged

dsherret merged 2 commits into
mainfrom
feat/ordered-associations

Conversation

@dsherret

@dsherret dsherret commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Plugin associations and the files of plugin configuration overrides are now evaluated like includes and excludes (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.toml files with the toml plugin:

{
  "toml": {
    "associations": ["!**/*.toml", "Cargo.toml"]
  }
}

Previously this formatted nothing (!**/*.toml also excluded Cargo.toml). Now Cargo.toml files in any directory are formatted and other .toml files 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 format legacy/file.other and now do, and override files of ["!legacy/**", "**/package.json"] now apply the override to legacy/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 replaces get_patterns_as_glob_matcher, which split the patterns into includes and excludes so a negated pattern always won.
  • GlobMatcher::exclude_detail exposes the order aware exclude result for a path.
  • PluginNameResolutionMaps uses it for claiming files by associations and for excluding a plugin from its default file matching.
  • PluginConfigOverride uses it for the override's files.
  • Tests for opting into specific files after a negated association and for override files evaluated in order (both fail before this change), and for a negated association after a pattern still excluding.

…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.
@dsherret dsherret changed the title feat(BREAKING): evaluate plugin associations in order where the last match wins feat(BREAKING): evaluate associations and override files in order where the last match wins Sep 28, 2026
@dsherret
dsherret merged commit 55f58e7 into main Sep 28, 2026
17 checks passed
@dsherret
dsherret deleted the feat/ordered-associations branch September 28, 2026 15:41
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.

1 participant