[][src]Struct rslint_core::groups::errors::UseIsnan

pub struct UseIsnan {
    pub enforce_for_switch_case: bool,
    pub enforce_for_index_of: bool,
}

Disallow incorrect comparisons against NaN.

NaN is a special Number value used to represent "not a number" results in calculations. This value is specified in the IEEE Standard for Binary Floating-Point-Arithmetic.

In JavaScript, NaN is unique, it is not equal to anything, including itself! therefore any comparisons to it will either always yield true or false. Therefore you should use isNaN(/* num */) instead to test if a value is NaN. This rule is aimed at removing this footgun.

Invalid Code Examples

if (foo == NaN) {
    // unreachable
}

if (NaN != NaN) {
    // always runs
}

Correct Code Examples

if (isNaN(foo)) {
    /* */
}

if (!isNaN(foo)) {
    /* */
}

Fields

enforce_for_switch_case: bool

Switch statements use === internally to match an expression, therefore switch (NaN) and case NaN will never match. This rule disables uses like that which are always incorrect (true by default)

enforce_for_index_of: bool

Index functions like indexOf and lastIndexOf use === internally, therefore matching them against NaN will always yield -1. This option disallows using indexOf(NaN) and lastIndexOf(NaN) (false by default)

Implementations

impl UseIsnan[src]

pub fn new() -> Self[src]

Trait Implementations

impl Clone for UseIsnan[src]

impl CstRule for UseIsnan[src]

impl Debug for UseIsnan[src]

impl Default for UseIsnan[src]

impl<'de> Deserialize<'de> for UseIsnan where
    UseIsnan: Default
[src]

impl Rule for UseIsnan[src]

impl Serialize for UseIsnan[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> DynClone for T where
    T: Clone
[src]

impl<T> Erasable for T

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Serialize for T where
    T: Serialize + ?Sized
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.