Skip to content

Commit

Permalink
feat(linter) eslint plugin unicorn: prefer modern math apis
Browse files Browse the repository at this point in the history
  • Loading branch information
camc314 committed Dec 26, 2023
1 parent de2f834 commit c943f74
Show file tree
Hide file tree
Showing 4 changed files with 594 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ impl<'a> Expression<'a> {
matches!(self, Self::NumberLiteral(lit) if lit.value == 0.0)
}

pub fn is_number(&self, val: f64) -> bool {
matches!(self, Self::NumberLiteral(lit) if (lit.value - val).abs() < f64::EPSILON)
}

/// Determines whether the given numeral literal's raw value is exactly val
pub fn is_specific_raw_number_literal(&self, val: &str) -> bool {
matches!(self, Self::NumberLiteral(lit) if lit.raw == val)
Expand Down
2 changes: 2 additions & 0 deletions crates/oxc_linter/src/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ mod unicorn {
pub mod prefer_logical_operator_over_ternary;
pub mod prefer_math_trunc;
pub mod prefer_modern_dom_apis;
pub mod prefer_modern_math_apis;
pub mod prefer_native_coercion_functions;
pub mod prefer_node_protocol;
pub mod prefer_number_properties;
Expand Down Expand Up @@ -417,6 +418,7 @@ oxc_macros::declare_all_lint_rules! {
unicorn::prefer_logical_operator_over_ternary,
unicorn::prefer_math_trunc,
unicorn::prefer_modern_dom_apis,
unicorn::prefer_modern_math_apis,
unicorn::prefer_native_coercion_functions,
unicorn::no_useless_spread,
unicorn::prefer_number_properties,
Expand Down
Loading

0 comments on commit c943f74

Please sign in to comment.