Prettier removing a piece of code when formatting multi-line conditions #532
Open
Description
Maybe this isn't a bug, but it's a scenario where prettier is changing code, and in your documentation, you said if prettier changes code, it shouldn't, so it should be reported.
Hence I am reporting.
If I have several "Anded" expressions, split across multiple lines (in my real example its quite long), prettier suggests a fix of "Replace &&·values.myProperty2
with ··values.myProperty2·&&
eslintprettier/prettier"
However this fix removes a required "&&".
Yes, it turns out I should have my "&&"s on the same line (though I prefer them at the beginning, perhaps that is a different debate). But should prettier remove a required one ?
Hope this helps.
Prettier 2.8.1
Playground link
Input:
const values = {
myProperty1: true,
myProperty2: false,
myProperty3: true,
myProperty4: false,
myProperty5: true,
myProperty6: false,
srvsys_sc_files_otherorgsdata_to_nfd_notingroup: true,
srvsys_sc_search_owncustomers_against_nfd: true,
srvsys_sc_search_othercustomers_nfd_ingroup: false,
srvsys_sc_search_otherorgcustomers_nfd_notingroup: true
};
setValue(!values.myProperty1
&& values.myProperty2
&& !values.myProperty3
&& !values.myProperty4
&& values.myProperty5
&& !values.myProperty6
);
function setValue(newValue: boolean) {
//do something
console.log(newValue);
}
//Prettier suggested fix would remove the 1st &&
//Replace `&&·values.myProperty2` with `··values.myProperty2·&&`eslintprettier/prettier
Output:
setValue(!values.myProperty1
values.myProperty2 &&
&& !values.myProperty3
&& !values.myProperty4
&& values.myProperty5
&& !values.myProperty6
);
Expected behavior:
Metadata
Assignees
Labels
No labels