Skip to content

Commit

Permalink
docs: no_cond_assign (denoland#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
DomParfitt committed Oct 1, 2020
1 parent 7d2f205 commit 7a6f33f
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/rules/no_cond_assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,42 @@ impl LintRule for NoCondAssign {
let mut visitor = NoCondAssignVisitor::new(context);
visitor.visit_module(module, module);
}

fn docs(&self) -> &'static str {
r#"Disallows the use of the assignment operator, `=`, in conditional statements.
Use of the assignment operator within a conditional statement is often the result of mistyping the equality operator, `==`. If an assignment within a conditional statement is required then this rule allows it by wrapping the assignment in parentheses.
### Valid:
```typescript
var x;
if (x === 0) {
var b = 1;
}
```
```typescript
function setHeight(someNode) {
do {
someNode.height = "100px";
} while ((someNode = someNode.parentNode));
}
```
### Invalid:
```typescript
var x;
if (x = 0) {
var b = 1;
}
```
```typescript
function setHeight(someNode) {
do {
someNode.height = "100px";
} while (someNode = someNode.parentNode);
}
```"#
}
}

struct NoCondAssignVisitor {
Expand Down

0 comments on commit 7a6f33f

Please sign in to comment.