eslint-plugin-unicorn
eslint-plugin-unicorn copied to clipboard
`no-negated-condition`: option to ignore lines less than `threshold`
Description
I very much like the no-negated-condition rule in almost all cases. There are however cases where the negation improves readability: when having a very short negation condition and a long positive condition. By checking the long condition first, I have to scroll to understand the code. It would of course be best to prevent such code in the first place and to refactor that while we also all work in code that we have not created and might not be able to refactor all the time.
Adding an option to allow such situations (e.g., with a fixed number of lines for each condition as threshold) would therefore improve the readability in such code bases. It should only apply if the negated side is below e.g., 10 lines and the other side above 10 lines.
Examples
// ❌
if (!foo) {
... 15 lines of code ...
} else {
... 3 lines of code ...
}
// ✅
if (!foo) {
... 3 lines of code ...
} else {
... 15 lines of code ...
}
Additional Info
No response