Skip to content

Commit 82f8b9f

Browse files
committed
refactor(linter/plugins): store rule options as Vecs (#16336)
Follow-on after #16215. Options for each rule is always an array. Enforce this in type system by storing options as `Vec<serde_json::Value>` instead of a single `serde_json::Value` which is always a `Value::Array`. I'll try to alter `ESLintRule`'s `config` field to be a `Vec<serde_json::Value>` too in another PR to follow.
1 parent f564687 commit 82f8b9f

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

crates/oxc_linter/src/external_plugin_store.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub struct ExternalPluginStore {
3434
plugins: IndexVec<ExternalPluginId, ExternalPlugin>,
3535
plugin_names: FxHashMap<String, ExternalPluginId>,
3636
rules: IndexVec<ExternalRuleId, ExternalRule>,
37-
options: IndexVec<ExternalOptionsId, serde_json::Value>,
37+
options: IndexVec<ExternalOptionsId, Vec<serde_json::Value>>,
3838

3939
// `true` for `oxlint`, `false` for language server
4040
is_enabled: bool,
@@ -48,7 +48,7 @@ impl Default for ExternalPluginStore {
4848

4949
impl ExternalPluginStore {
5050
pub fn new(is_enabled: bool) -> Self {
51-
let options = index_vec![serde_json::json!([])];
51+
let options = index_vec![vec![]];
5252

5353
Self {
5454
registered_plugin_paths: FxHashSet::default(),
@@ -141,13 +141,12 @@ impl ExternalPluginStore {
141141
/// `options` must be a `serde_json::Value::Array`.
142142
///
143143
/// # Panics
144-
/// Panics in debug build if `options` is not an array or is an empty array.
144+
/// Panics if `options` is not an array.
145145
pub fn add_options(&mut self, options: serde_json::Value) -> ExternalOptionsId {
146-
debug_assert!(options.is_array(), "`options` should be an array");
147-
debug_assert!(
148-
!options.as_array().unwrap().is_empty(),
149-
"`options` should never be an empty `Vec`"
150-
);
146+
let serde_json::Value::Array(options) = options else {
147+
panic!("`options` must be an array");
148+
};
149+
debug_assert!(!options.is_empty(), "`options` should never be an empty `Vec`");
151150
self.options.push(options)
152151
}
153152

0 commit comments

Comments
 (0)