[−][src]Struct rslint_core::groups::errors::UseIsnan
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]
Trait Implementations
impl Clone for UseIsnan
[src]
impl CstRule for UseIsnan
[src]
fn check_node(&self, node: &SyntaxNode, ctx: &mut RuleCtx) -> Option<()>
[src]
fn check_token(&self, token: &SyntaxToken, ctx: &mut RuleCtx) -> Option<()>
[src]
fn check_root(&self, root: &SyntaxNode, ctx: &mut RuleCtx) -> Option<()>
[src]
impl Debug for UseIsnan
[src]
impl Default for UseIsnan
[src]
impl<'de> Deserialize<'de> for UseIsnan where
UseIsnan: Default,
[src]
UseIsnan: Default,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl Rule for UseIsnan
[src]
impl Serialize for UseIsnan
[src]
Auto Trait Implementations
impl RefUnwindSafe for UseIsnan
impl Send for UseIsnan
impl Sync for UseIsnan
impl Unpin for UseIsnan
impl UnwindSafe for UseIsnan
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> DynClone for T where
T: Clone,
[src]
T: Clone,
impl<T> Erasable for T
unsafe fn unerase(this: NonNull<Erased>) -> NonNull<T>
const ACK_1_1_0: bool
fn erase(this: NonNull<Self>) -> NonNull<Erased>
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Serialize for T where
T: Serialize + ?Sized,
[src]
T: Serialize + ?Sized,
fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<Ok, Error>
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,