Skip to content

Conversation

@wanghaoPolar
Copy link
Contributor

@wanghaoPolar wanghaoPolar commented May 22, 2025

Related: #5953

Summary

Allow add plugins that runs only in certain files.

{
  "plugins": [
    "./biome-rules/custom-card-rule.grit",
    // ...
  ],
  "overrides": [{
    "includes": ["src/routes/**"],
    "plugins": ["./biome-rules/no-components-in-routes.grit"]
  }]
}

Changes

  1. crates/biome_configuration/src/overrides.rs : add a new field plugins to overrides settings
  2. crates/biome_service/src/settings.rs :
  • add method as_all_plugins, traverse settings to collect all plugins (including global plugins and all plugins in overrides)
  • add method as_plugins, take path as parameter, this method return applicable plugins for the path. (including global plugins and matched plugins in overrides)
  1. crates/biome_plugin_loader/src/plugin_cache.rs
  • change method get_analyzer_plugins, add plugins as parameter, it no longer return all BiomePlugins stored in cache. Now it only returns BiomePlugins specified in the parameter plugins
  1. crates/biome_service/src/workspace/server.rs
  • self.load_plugins now loads settings.as_all_plugins() instead of settings.plugins. This ensures all plugins (global + overrides) are all loaded here.
  • Whenever need plugins (fix_file, pull_diagnostics), call settings.as_plugins(&path) to get list of plugins needed, then pass to get_analyzer_plugins_for_project -> plugin_cache.get_analyzer_plugins. This way we'll have the BiomePlugins needed for a file (global + overrides matched by path)

Test Plan

Add test to check basic plugins override
crates/biome_service/src/workspace.tests.rs correctly_apply_plugins_in_override

@github-actions github-actions bot added the A-Project Area: project label May 22, 2025
@wanghaoPolar wanghaoPolar force-pushed the feat/override-plugins branch from 4ba588b to 7cf5588 Compare May 22, 2025 13:51
Copy link
Contributor

@arendjr arendjr left a comment

Choose a reason for hiding this comment

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

Good stuff! Looks like you found your way well around the important pieces 💪

result.extend_from_slice(&plugin.analyzer_plugins);
}
None => {
panic!("plugin not loaded: {plugin_path}")
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like something that should be gracefully handled still.

Comment on lines 223 to 224
/// Return plugins taking overrides into account
pub fn as_plugins(&self, path: &Utf8Path) -> Cow<Plugins> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// Return plugins taking overrides into account
pub fn as_plugins(&self, path: &Utf8Path) -> Cow<Plugins> {
/// Returns the plugins that should be enabled for the given `path`, taking overrides into account.
pub fn get_plugins_for_path(&self, path: &Utf8Path) -> Cow<Plugins> {


for pattern in &self.override_settings.patterns {
if pattern.is_file_included(path) {
result.to_mut().0.extend_from_slice(&pattern.plugins.0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should have a Deref implementation on Plugins? Not a fan of those .0 accesses, as it obscures what exactly is being accessed.

@codspeed-hq
Copy link

codspeed-hq bot commented May 22, 2025

CodSpeed Performance Report

Merging #6117 will not alter performance

Comparing wanghaoPolar:feat/override-plugins (92e1dda) with main (c113eb6)

Summary

✅ 95 untouched benchmarks

@wanghaoPolar
Copy link
Contributor Author

Thanks for help review! I've made some changes accordingly and add a test.

Look like there is some snapshot test need to be update, I'll check on those later.

@wanghaoPolar wanghaoPolar force-pushed the feat/override-plugins branch from 7fcb3c5 to e528a3d Compare May 28, 2025 13:22
@wanghaoPolar wanghaoPolar force-pushed the feat/override-plugins branch from e528a3d to 9c77d21 Compare May 28, 2025 13:41
@wanghaoPolar wanghaoPolar changed the title WIP config: add plugins to override config feat: add plugins to override config May 28, 2025
Copy link
Contributor

@arendjr arendjr left a comment

Choose a reason for hiding this comment

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

Thanks a lot!

@arendjr arendjr merged commit de98918 into biomejs:main May 28, 2025
14 of 15 checks passed
ematipico pushed a commit that referenced this pull request May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Project Area: project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants