wikimedia / eslint-config-wikimedia

JavaScript style guide for Wikimedia.
https://www.mediawiki.org/wiki/Manual:Coding_conventions/JavaScript
MIT License
29 stars 20 forks source link

no-nested-ternary #567

Open NovemLinguae opened 6 months ago

NovemLinguae commented 6 months ago

Consider setting no-nested-ternary to warn or error. ESLint docs.

Would prevent stuff like this, which I find hard to read.

const test = sub ? ( sub.length ? 'test' : 'test2' ) : 'test3';

Here's some code searches. Codesearch 1. Codesearch 2. I excluded the folders modules, resources, lib, and dist, and files containing the word ".min.js". External code is much more likely to have nested ternaries due to minification or different code standards.

Would be good to keep it out of our codebase. I had several of these in Twinkle that I rewrote.

edg2s commented 6 months ago

I think that's too subjective. Some may find a single line double ternary easier to read. I don't know if we need to be opinionated about it at such a high level.