Skip to content

linter: no-cond-assign: false positive #6656

@bensaufley

Description

@bensaufley

What version of Oxlint are you using?

0.9.10

What command did you run?

oxlint -c .oxlintrc.json -- path/to/example.ts

What does your .oxlint.json config file look like?

{
"rules": {
"no-cond-assign": ["error", "always"]
}
}

What happened?

Same-line conditional blocks that contain an assignment falsely trigger the no-cond-assign rule, when they do not in ESLint:

const value: string = 'a';
let newValue = '';
if (['a', 'b', 'c', 'd'].includes(value)) newValue = value;
else newValue = 'default';
console.log(newValue);

Lines 3 and 4 both produce a rule violation:

  × eslint(no-cond-assign): Expected a conditional expression and instead saw an assignment
   ╭─[path/to/example.ts:3:52]
 2 │ let newValue = '';
 3 │ if (['a', 'b', 'c', 'd'].includes(value)) newValue = value;
   ·                                                    ─
 4 │ else newValue = 'default';
   ╰────
  help: Consider wrapping the assignment in additional parentheses

  × eslint(no-cond-assign): Expected a conditional expression and instead saw an assignment
   ╭─[path/to/example.ts:4:15]
 3 │ if (['a', 'b', 'c', 'd'].includes(value)) newValue = value;
 4 │ else newValue = 'default';
   ·               ─
 5 │ console.log(newValue);

The ESLint rule is intended to catch things like if (foo = 'bar'), where an assignment happens inside a conditional block; this is catching things after that block.

Metadata

Metadata

Assignees

Labels

A-linterArea - LinterC-bugCategory - Bug

Type

No type

Priority

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions