`prefer-single-boolean-return` fix removes comments
andreww2012 opened this issue · comments
Hello. After applying a fix suggested by prefer-single-boolean-return
, comments within if
block get lost. This is dangerous because one may run eslint to fix all auto-fixable problems and lose valuable comments.
Reproducer
// Input code:
const test = () => {
const condition = Math.random() > 0.5;
if (condition) {
// any comments here...
return false;
// or here...
}
return true;
};
// After applying the fix:
const test = () => {
const condition = Math.random() > 0.5;
return !(condition);
};
Expected behavior
Somehow preserve the comments (or perhaps refuse to auto-fix if there are some)?
eslint-plugin-sonarjs version: 0.24.0
eslint version: 8.56.0
Node.js version: 18.18.0
Rule key: prefer-single-boolean-return
Hi @andreww2012,
Thanks for the feedback. We'll check internally how feasible is to keep the comments. Or if just an exception should be added in case comments are inside the block.
This issue has been migrated to Jira. ESLINTJS-34