Avoid duplicate assignment in Typescript

Avoid assigning values to the same variable multiple times in succession without using the variable in between.
Bad:
```typescript
let count = 0
count = 1 // Duplicate assignment without using the initial value
count = 2 // Another duplicate assignment
```

Install this rule for wispbit Cloud

Add this rule to wispbit and it will run when you open a pull request

Install this rule with wispbit CLI

Run this command in your terminal to install the rule locally

npx @wispbit/cli rule install typescript-duplicate-assignment

Install this rule for Coderabbit

Copy the configuration below and add it to your repository as .coderabbit.yml in your project root.

reviews:
  path_instructions:
    - path: "*.ts"
      instructions: |
                
        Avoid assigning values to the same variable multiple times in succession without using the variable in between.
        
        Bad:
        
        ```typescript
        let count = 0
        count = 1 // Duplicate assignment without using the initial value
        count = 2 // Another duplicate assignment
        ```
        
        Good:
        
        ```typescript
        let count = 2 // Direct assignment to final value
        ```
        

Install this rule for Greptile

Greptile rules can be added through the web interface. Please see this documentation for details on how to add custom rules and context.

Avoid assigning values to the same variable multiple times in succession without using the variable in between.
Bad:
```typescript
let count = 0
count = 1 // Duplicate assignment without using the initial value
count = 2 // Another duplicate assignment
```
Good:
```typescript
let count = 2 // Direct assignment to final value
```

File Path Patterns:

*.ts

Install this rule for GitHub Copilot

Copilot instructions can be added through the interface. See the documentation for details on how to create coding guidelines.

Avoid assigning values to the same variable multiple times in succession without using the variable in between.
Bad:
```typescript
let count = 0
count = 1 // Duplicate assignment without using the initial value
count = 2 // Another duplicate assignment
```
Good:
```typescript
let count = 2 // Direct assignment to final value
```

File Path Patterns:

*.ts

Install this rule for Graphite Diamond

Diamond custom rules can be added through the interface. See the documentation for details on how to create custom rules.

Avoid assigning values to the same variable multiple times in succession without using the variable in between.
Bad:
```typescript
let count = 0
count = 1 // Duplicate assignment without using the initial value
count = 2 // Another duplicate assignment
```
Good:
```typescript
let count = 2 // Direct assignment to final value
```

File Path Patterns:

*.ts

Use with Cline

Copy the rule below and ask Cline to review your code using this rule

Avoid assigning values to the same variable multiple times in succession without using the variable in between.
Bad:
```typescript
let count = 0
count = 1 // Duplicate assignment without using the initial value
count = 2 // Another duplicate assignment
```
Good:
```typescript
let count = 2 // Direct assignment to final value
```

Use with OpenAI Codex

Copy the rule below and ask OpenAI Codex to review your code using this rule

Avoid assigning values to the same variable multiple times in succession without using the variable in between.
Bad:
```typescript
let count = 0
count = 1 // Duplicate assignment without using the initial value
count = 2 // Another duplicate assignment
```
Good:
```typescript
let count = 2 // Direct assignment to final value
```

Use with Cursor

Copy the rule below and ask Cursor to review your code using this rule

Avoid assigning values to the same variable multiple times in succession without using the variable in between.
Bad:
```typescript
let count = 0
count = 1 // Duplicate assignment without using the initial value
count = 2 // Another duplicate assignment
```
Good:
```typescript
let count = 2 // Direct assignment to final value
```

Use with Claude Code

Copy the rule below and ask Claude Code to review your code using this rule

Avoid assigning values to the same variable multiple times in succession without using the variable in between.
Bad:
```typescript
let count = 0
count = 1 // Duplicate assignment without using the initial value
count = 2 // Another duplicate assignment
```
Good:
```typescript
let count = 2 // Direct assignment to final value
```

Install this rule for Windsurf

To set up rules for Windsurf Reviews, please see this documentation

Avoid assigning values to the same variable multiple times in succession without using the variable in between.
Bad:
```typescript
let count = 0
count = 1 // Duplicate assignment without using the initial value
count = 2 // Another duplicate assignment
```
Good:
```typescript
let count = 2 // Direct assignment to final value
```