Skip to content

Commit 36cd364

Browse files
committed
refactor(linter/js-plugins): clean up code (#12242)
Follow-on after #12160. Pure refactor. Various small code clean-ups: * Remove unnecessary type annotations. * Defererence early. * Improve doc comments. * Assertion error messages. * Remove unnecessary derives.
1 parent 8c02ebd commit 36cd364

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

crates/oxc_linter/src/external_plugin_store.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,12 @@ impl ExternalPluginStore {
5858
self.registered_plugin_paths.contains(plugin_path)
5959
}
6060

61+
/// Register plugin.
62+
///
6163
/// # Panics
62-
/// Panics if you use it wrong
64+
/// Panics if:
65+
/// - Plugin at `plugin_path` is already registered.
66+
/// - `offset` does not equal the number of registered rules.
6367
pub fn register_plugin(
6468
&mut self,
6569
plugin_path: String,
@@ -68,16 +72,16 @@ impl ExternalPluginStore {
6872
rules: Vec<String>,
6973
) {
7074
let newly_inserted = self.registered_plugin_paths.insert(plugin_path);
71-
assert!(newly_inserted);
75+
assert!(newly_inserted, "register_plugin: plugin already registered");
7276

73-
let plugin_id: ExternalPluginId = self
77+
let plugin_id = self
7478
.plugins
7579
.push(ExternalPlugin { name: plugin_name.clone(), rules: FxHashMap::default() });
7680
self.plugin_names.insert(plugin_name, plugin_id);
7781

7882
assert!(
7983
offset == self.rules.len(),
80-
"register_plugin: expected offset {}, but rule table is currently {} long",
84+
"register_plugin: received offset {}, but rule table is currently {} long",
8185
offset,
8286
self.rules.len()
8387
);
@@ -95,11 +99,11 @@ impl ExternalPluginStore {
9599
plugin_name: &str,
96100
rule_name: &str,
97101
) -> Result<ExternalRuleId, ExternalRuleLookupError> {
98-
let plugin_id: &ExternalPluginId = self.plugin_names.get(plugin_name).ok_or_else(|| {
102+
let plugin_id = *self.plugin_names.get(plugin_name).ok_or_else(|| {
99103
ExternalRuleLookupError::PluginNotFound { plugin: plugin_name.to_string() }
100104
})?;
101105

102-
self.plugins[*plugin_id].rules.get(rule_name).copied().ok_or_else(|| {
106+
self.plugins[plugin_id].rules.get(rule_name).copied().ok_or_else(|| {
103107
ExternalRuleLookupError::RuleNotFound {
104108
plugin: plugin_name.to_string(),
105109
rule: rule_name.to_string(),
@@ -137,13 +141,13 @@ impl fmt::Display for ExternalRuleLookupError {
137141

138142
impl std::error::Error for ExternalRuleLookupError {}
139143

140-
#[derive(Debug, Default)]
144+
#[derive(Debug)]
141145
struct ExternalPlugin {
142146
name: String,
143147
rules: FxHashMap<String, ExternalRuleId>,
144148
}
145149

146-
#[derive(Debug, Default, PartialEq, Eq)]
150+
#[derive(Debug)]
147151
struct ExternalRule {
148152
name: String,
149153
plugin_id: ExternalPluginId,

0 commit comments

Comments
 (0)