Closed
Description
Before You File a Bug Report Please Confirm You Have Done The Following...
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I have searched for related issues and found none that matched my issue.
- I have read the FAQ and my problem is not listed.
Issue Description
Running eslint --fix
breaks code when the rule @typescript-eslint/strict-boolean-expressions
has the option allowNullableObject
set to false
Code before fix
type Items = {
foo: string
}
const items: Items[] = [
{foo: 'bar'},
{foo: 'bar'},
]
function someFn (items?: Items[]) {
return JSON.parse(
JSON.stringify(items || []),
);
}
const test = someFn(items)
console.log(test); // [ { foo: 'bar' }, { foo: 'bar' } ]
code after fix
function someFn (items?: Items[]) {
return JSON.parse(
JSON.stringify((items != null) || []),
);
}
const test = someFn(items)
console.log(test); // true
What did you expect to happen?
Code gets changed with the ??
operator or not changed at all
Reproduction Repository Link
https://github.com/fasenderos/typescript-eslint-strict-boolean
Repro Steps
Clone the repo and run npm install
, then try the code before fix
npm run build
npm start
The output will be [ { foo: 'bar' }, { foo: 'bar' } ]
Now run the fix and try again
npm run lint:fix
npm run build
npm start
The output will be true
Versions
package | version |
---|---|
@typescript-eslint/eslint-plugin |
^6.2.0 |
@typescript-eslint/parser |
^6.2.0 |
TypeScript |
^5.1.6 |
ESLint |
^8.45.0 |
node |
18.16.1 |