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

Prohibit nullish coalescing operators #534

Closed jdlrobson closed 1 year ago

jdlrobson commented 1 year ago

Either I've been writing too much PHP code or my IDE is playing up but I was surprised to see code make it through our linters into production that caused the following bug: https://phabricator.wikimedia.org/T350519 (see fix https://gerrit.wikimedia.org/r/c/mediawiki/skins/Vector/+/971997)

I am not too familiar with existing plugins we load, and available rules but it seems like something like this rule would be helpful: https://eslint-plugin-es.mysticatea.dev/rules/no-nullish-coalescing-operators.html

edg2s commented 1 year ago

This should already be disabled by our language rules...

edg2s commented 1 year ago

We use the https://github.com/eslint-community/eslint-plugin-es-x fork as eslint-plugin-es is unmaintained, but this rule (https://eslint-community.github.io/eslint-plugin-es-x/rules/no-nullish-coalescing-operators.html) is included in our language/es6.json rules via plugin:es/restrict-to-es2015. Not sure why it isn't triggering in the example given.

edg2s commented 1 year ago

With most of the syntactic fetaures, you should also get a parsing error before you get an ESLint error.

edg2s commented 1 year ago

The errors aren't triggering because you added the files to .eslintignore: https://gerrit.wikimedia.org/r/c/mediawiki/skins/Vector/+/967991/9/.eslintignore

jdlrobson commented 1 year ago

Thanks for the detective work! That was very helpful!