Struct rslint_core::groups::errors::NoCondAssign [−][src]
pub struct NoCondAssign {
pub allow_parens: bool,
}
Expand description
Forbid the use of assignment expressions in conditions which may yield unwanted behavior.
Assignment expressions return the value assigned:
let foo = 5;
console.log(foo = 8); // 8
console.log(foo += 4) // foo + 4 (12 in this case)
Users often make a typo and end up using =
instead of ==
or ===
in conditions in statements
like if
, while
, do_while
, and for
. This is erroneous and is most likely unwanted behavior
since the condition used will actually be the value assigned.
Incorrect Code Examples
let foo = 5;
if (foo = 6) {
// ^^^ assignments return the value assigned, therefore the condition checks `6`
// `6` is always truthy, therefore the if statement always runs even if we dont want it to.
} else {}
//^^^^ it makes this else unreachable
foo // 6
Fields
allow_parens: bool
Allow an assignment if they are enclosed in parentheses to allow things like reassigning a variable.
Implementations
Trait Implementations
Check an individual node in the syntax tree.
You can use the match_ast
macro to make matching a node to an ast node easier.
The reason this uses nodes and not a visitor is because nodes are more flexible,
converting them to an AST node has zero cost and you can easily traverse surrounding nodes.
Defaults to doing nothing. Read more
Check an individual token in the syntax tree. Defaults to doing nothing. Read more
Check the root of the tree one time.
This method is guaranteed to only be called once.
The root’s kind will be either SCRIPT
or MODULE
.
Defaults to doing nothing. Read more
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
A list of tags present on this rule. Empty by default.
Whether this rule is recommended, this is a simple helper around Self::tags
.
Auto Trait Implementations
impl RefUnwindSafe for NoCondAssign
impl Send for NoCondAssign
impl Sync for NoCondAssign
impl Unpin for NoCondAssign
impl UnwindSafe for NoCondAssign
Blanket Implementations
Mutably borrows from an owned value. Read more
Whether this implementor has acknowledged the 1.1.0 update to
unerase
’s documented implementation requirements. Read more