Skip to content

Commit 3b5eb8f

Browse files
feat: Add LintOptionsConfig.plugins (#145)
Ref denoland/deno#27203 --------- Co-authored-by: Marvin Hagemeister <[email protected]>
1 parent 00bac96 commit 3b5eb8f

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

src/deno_json/mod.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ struct SerializedLintConfig {
112112
#[serde(rename = "files")]
113113
pub deprecated_files: serde_json::Value,
114114
pub report: Option<String>,
115+
pub plugins: Vec<String>,
115116
}
116117

117118
impl SerializedLintConfig {
@@ -125,7 +126,10 @@ impl SerializedLintConfig {
125126
log::warn!( "Warning: \"files\" configuration in \"lint\" was removed in Deno 2, use \"include\" and \"exclude\" instead.");
126127
}
127128
Ok(LintConfig {
128-
options: LintOptionsConfig { rules: self.rules },
129+
options: LintOptionsConfig {
130+
rules: self.rules,
131+
plugins: self.plugins,
132+
},
129133
files: files.into_resolved(config_file_specifier)?,
130134
})
131135
}
@@ -134,6 +138,7 @@ impl SerializedLintConfig {
134138
#[derive(Clone, Debug, Default, Hash, PartialEq)]
135139
pub struct LintOptionsConfig {
136140
pub rules: LintRulesConfig,
141+
pub plugins: Vec<String>,
137142
}
138143

139144
#[derive(Clone, Debug, Hash, PartialEq)]
@@ -1970,6 +1975,7 @@ mod tests {
19701975
exclude: None,
19711976
tags: Some(vec!["recommended".to_string()]),
19721977
},
1978+
plugins: vec![],
19731979
}
19741980
}
19751981
);

src/workspace/mod.rs

+45-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use discovery::ConfigFileDiscovery;
1818
use discovery::ConfigFolder;
1919
use discovery::DenoOrPkgJson;
2020
use indexmap::IndexMap;
21+
use indexmap::IndexSet;
2122
use std::borrow::Cow;
2223
use std::collections::BTreeMap;
2324
use std::collections::HashSet;
@@ -1442,11 +1443,38 @@ impl WorkspaceDirectory {
14421443
None => return Ok(member_config),
14431444
};
14441445
// combine the configs
1446+
let root_opts = root_config.options;
1447+
let member_opts = member_config.options;
1448+
1449+
// 1. Merge workspace root + member plugins
1450+
// 2. Workspace member can filter out plugins by negating
1451+
// like this: `!my-plugin`
1452+
// 3. Remove duplicates in case a plugin was defined in both
1453+
// workspace root and member.
1454+
let excluded_plugins: HashSet<String> = HashSet::from_iter(
1455+
member_opts
1456+
.plugins
1457+
.iter()
1458+
.filter(|plugin| plugin.starts_with('!'))
1459+
.map(|plugin| plugin[1..].to_string()),
1460+
);
1461+
1462+
let filtered_plugins = IndexSet::<String>::from_iter(
1463+
root_opts
1464+
.plugins
1465+
.into_iter()
1466+
.chain(member_opts.plugins)
1467+
.filter(|plugin| {
1468+
!plugin.starts_with('!') && !excluded_plugins.contains(plugin)
1469+
}),
1470+
)
1471+
.into_iter()
1472+
.collect::<Vec<_>>();
1473+
14451474
Ok(LintConfig {
14461475
options: LintOptionsConfig {
1476+
plugins: filtered_plugins,
14471477
rules: {
1448-
let root_opts = root_config.options;
1449-
let member_opts = member_config.options;
14501478
LintRulesConfig {
14511479
tags: combine_option_vecs(
14521480
root_opts.rules.tags,
@@ -2761,6 +2789,7 @@ mod test {
27612789
"include": ["rule1"],
27622790
"exclude": ["rule2"],
27632791
},
2792+
"plugins": ["jsr:@deno/test-plugin1", "jsr:@deno/test-plugin3"]
27642793
}
27652794
}),
27662795
json!({
@@ -2770,7 +2799,12 @@ mod test {
27702799
"rules": {
27712800
"tags": ["tag1"],
27722801
"include": ["rule2"],
2773-
}
2802+
},
2803+
"plugins": [
2804+
"jsr:@deno/test-plugin1",
2805+
"jsr:@deno/test-plugin2",
2806+
"!jsr:@deno/test-plugin3"
2807+
]
27742808
}
27752809
}),
27762810
);
@@ -2800,6 +2834,10 @@ mod test {
28002834
include: Some(vec!["rule1".to_string(), "rule2".to_string()]),
28012835
exclude: Some(vec![])
28022836
},
2837+
plugins: vec![
2838+
"jsr:@deno/test-plugin1".to_string(),
2839+
"jsr:@deno/test-plugin2".to_string()
2840+
],
28032841
},
28042842
files: FilePatterns {
28052843
base: root_dir().join("member"),
@@ -2827,6 +2865,10 @@ mod test {
28272865
include: Some(vec!["rule1".to_string()]),
28282866
exclude: Some(vec!["rule2".to_string()])
28292867
},
2868+
plugins: vec![
2869+
"jsr:@deno/test-plugin1".to_string(),
2870+
"jsr:@deno/test-plugin3".to_string()
2871+
]
28302872
},
28312873
files: FilePatterns {
28322874
base: root_dir(),

0 commit comments

Comments
 (0)