Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 6 additions & 39 deletions crates/oxc_linter/src/external_plugin_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,14 @@ use std::fmt;

use rustc_hash::{FxHashMap, FxHashSet};

use nonmax::NonMaxU32;
use oxc_index::{Idx, IndexVec};

#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ExternalPluginId(NonMaxU32);

impl Idx for ExternalPluginId {
#[expect(clippy::cast_possible_truncation)]
fn from_usize(idx: usize) -> Self {
assert!(idx < u32::MAX as usize);
// SAFETY: We just checked `idx` is valid for `NonMaxU32`
Self(unsafe { NonMaxU32::new_unchecked(idx as u32) })
}
use oxc_index::{IndexVec, define_index_type};

fn index(self) -> usize {
self.0.get() as usize
}
define_index_type! {
pub struct ExternalPluginId = u32;
}

#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ExternalRuleId(NonMaxU32);

impl Idx for ExternalRuleId {
#[expect(clippy::cast_possible_truncation)]
fn from_usize(idx: usize) -> Self {
assert!(idx < u32::MAX as usize);
// SAFETY: We just checked `idx` is valid for `NonMaxU32`
Self(unsafe { NonMaxU32::new_unchecked(idx as u32) })
}

fn index(self) -> usize {
self.0.get() as usize
}
}

impl ExternalRuleId {
#[inline]
pub fn as_u32(self) -> u32 {
self.0.get()
}
define_index_type! {
pub struct ExternalRuleId = u32;
}

#[derive(Debug, Default)]
Expand Down Expand Up @@ -112,8 +80,7 @@ impl ExternalPluginStore {
}

pub fn resolve_plugin_rule_names(&self, external_rule_id: u32) -> Option<(&str, &str)> {
let external_rule =
self.rules.get(NonMaxU32::new(external_rule_id).map(ExternalRuleId)?)?;
let external_rule = self.rules.get(ExternalRuleId::from_raw(external_rule_id))?;
let plugin = &self.plugins[external_rule.plugin_id];

Some((&plugin.name, &external_rule.name))
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl Linter {
let result = (external_linter.run)(
#[expect(clippy::missing_panics_doc)]
path.to_str().unwrap().to_string(),
external_rules.iter().map(|(rule_id, _)| rule_id.as_u32()).collect(),
external_rules.iter().map(|(rule_id, _)| rule_id.raw()).collect(),
);
match result {
Ok(diagnostics) => {
Expand Down
Loading