Skip to content

Commit

Permalink
perf(linter): add Set
Browse files Browse the repository at this point in the history
  • Loading branch information
DonIsaac committed Aug 6, 2024
1 parent 06efae6 commit 21086ad
Show file tree
Hide file tree
Showing 5 changed files with 489 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use oxc_ast::AstKind;
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use oxc_span::{CompactStr, Span};
use serde_json::Value;

use self::listener_map::ListenerMap;
use crate::{
context::LintContext,
rule::Rule,
utils::{ModuleFunctions, NodeListenerOptions, WhitelistModule},
utils::{ModuleFunctions, NodeListenerOptions, Set, WhitelistModule},
};

mod listener_map;
Expand Down Expand Up @@ -103,7 +103,7 @@ impl std::ops::Deref for NoSideEffectsInInitialization {

#[derive(Debug, Default, Clone)]
pub struct NoSideEffectsInInitiallizationOptions {
functions: Vec<String>,
functions: Set<CompactStr>,
modules: Vec<WhitelistModule>,
}

Expand Down Expand Up @@ -183,7 +183,7 @@ declare_oxc_lint!(

impl Rule for NoSideEffectsInInitialization {
fn from_configuration(value: serde_json::Value) -> Self {
let mut functions = vec![];
let mut functions: Vec<CompactStr> = vec![];
let mut modules = vec![];

if let Value::Array(arr) = value {
Expand All @@ -194,7 +194,7 @@ impl Rule for NoSideEffectsInInitialization {

// { "function": "Object.freeze" }
if let Some(name) = obj.get("function").and_then(Value::as_str) {
functions.push(name.to_string());
functions.push(name.into());
continue;
}

Expand All @@ -206,8 +206,8 @@ impl Rule for NoSideEffectsInInitialization {
let val = arr
.iter()
.filter_map(Value::as_str)
.map(String::from)
.collect::<Vec<_>>();
.map(CompactStr::from)
.collect::<Set<_>>();
Some(ModuleFunctions::Specific(val))
}
Some(Value::String(str)) => {
Expand All @@ -226,7 +226,10 @@ impl Rule for NoSideEffectsInInitialization {
}
}

Self(Box::new(NoSideEffectsInInitiallizationOptions { functions, modules }))
Self(Box::new(NoSideEffectsInInitiallizationOptions {
functions: functions.into(),
modules,
}))
}

fn run_once(&self, ctx: &LintContext) {
Expand Down
3 changes: 2 additions & 1 deletion crates/oxc_linter/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ mod jsdoc;
mod nextjs;
mod react;
mod react_perf;
mod set;
mod tree_shaking;
mod unicorn;

pub use self::{
jest::*, jsdoc::*, nextjs::*, react::*, react_perf::*, tree_shaking::*, unicorn::*,
jest::*, jsdoc::*, nextjs::*, react::*, react_perf::*, set::*, tree_shaking::*, unicorn::*,
};

/// Check if the Jest rule is adapted to Vitest.
Expand Down
Loading

0 comments on commit 21086ad

Please sign in to comment.