You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
JSLint famously enforced a (non-configurable) requirement that operators must obscured and dangle at the end of line, because this would avoid bugs in "old parsers" (presumably older minifiers and other tooling that for some reason did not or could not follow the ECMAScript spec correctly?). Evidence of which parsers suffered, appears to be lost to time. I tried to git-blame the jslint codebase, but its author doesn't write meaningful commit messages. Discourse elsewhere only repeats the vague claim above.
[Line breaks before operators] may cause problems like semi colon insertion and old javascript parsers breaking.
When JSHint came about, it inherited this stylistic quirk default, although it quickly introduced the laxbreak option to disable this. https://jshint.com/docs/options/#laxbreak
laxbreak. Suppresses warnings about "possibly unsafe line breakings".
MediaWiki code has historically preferred leading symbols for readability. I believe (although I have no evidence of this) that this generally allows for faster comprehension and reduces ambiguity and cognitive overhead. It displays in a consistent visual position what operation is being performed, makes clear for ternaries which that the value is mutually exclusive and where this starts and ends. In particular, it avoids muddying the otherwise reasonable assumption that a line containing a literal expression, is its own used value. For example, multi-line arrays and objects (one value per line), multi-line function calls (one arg per line), and so on. In PHP, this remains our enforced coding style to date. https://www.mediawiki.org/wiki/Manual:Coding_conventions/PHP
When I adopted JSHint for MediaWiki in July 2012, this was our convention in JavaScript as well. I asked upstream JSHint how to make our coding style pass under JSHint. jshint/jshint#557:
You should use laxbreak. Default behavior is (historically) what Crockford recommended.
By 2014, we were using JSCS for most coding style rules, and likewise there we did not enforce line breaks after +, ?, :, &&, or || operators there either. In fact, the only thing we enforced was that for . chaining, the line break must be before it.
I think this might have been intentionally omitted because people tend to put the ? and : at the front of lines even when everything else is at the end.
The rule was changed in the next release to be able to enforce it both ways, with ternaries kept off by default.
Ironically, Crockford himself has since abandoned this peculiar style in 2017. He now embraces the opposite, same as MediaWiki PHP and Standard JS. jslint-org/jslint@c08484f
What
Currently required:
Proposed:
History
JSLint famously enforced a (non-configurable) requirement that operators must obscured and dangle at the end of line, because this would avoid bugs in "old parsers" (presumably older minifiers and other tooling that for some reason did not or could not follow the ECMAScript spec correctly?). Evidence of which parsers suffered, appears to be lost to time. I tried to git-blame the jslint codebase, but its author doesn't write meaningful commit messages. Discourse elsewhere only repeats the vague claim above.
jshint/jshint#60 (comment)
When JSHint came about, it inherited this stylistic quirk default, although it quickly introduced the
laxbreak
option to disable this. https://jshint.com/docs/options/#laxbreakMediaWiki code has historically preferred leading symbols for readability. I believe (although I have no evidence of this) that this generally allows for faster comprehension and reduces ambiguity and cognitive overhead. It displays in a consistent visual position what operation is being performed, makes clear for ternaries which that the value is mutually exclusive and where this starts and ends. In particular, it avoids muddying the otherwise reasonable assumption that a line containing a literal expression, is its own used value. For example, multi-line arrays and objects (one value per line), multi-line function calls (one arg per line), and so on. In PHP, this remains our enforced coding style to date. https://www.mediawiki.org/wiki/Manual:Coding_conventions/PHP
When I adopted JSHint for MediaWiki in July 2012, this was our convention in JavaScript as well. I asked upstream JSHint how to make our coding style pass under JSHint. jshint/jshint#557:
And so we did! https://gerrit.wikimedia.org/r/c/mediawiki/core/+/14017
By 2014, we were using JSCS for most coding style rules, and likewise there we did not enforce line breaks after
+
,?
,:
,&&
, or||
operators there either. In fact, the only thing we enforced was that for.
chaining, the line break must be before it.https://github.com/jscs-dev/node-jscs/blob/cf60723df58e435f39c7a769b7c74c1b8a3726a7/presets/wikimedia.json
In 2016, Oleg (former JSCS lead) created for us the first version of eslint-config-wikimedia, as part of merging JSCS into ESLint. I believe that he accidentally introduced this rule for us, perhaps based on misreading what we set
disallowOperatorBeforeLineBreak
to, or perhaps based on the historical JSLint/JSHint preference and presuming that as a common style preference. https://github.com/wikimedia/eslint-config-wikimedia/blob/v0.1.0/.eslintrc.json#L106-L108We deployed this a few weeks later and auto-fixed our code base. https://gerrit.wikimedia.org/r/c/mediawiki/core/+/321732
This ESLint rule originally did not reject ternary operators. Someone asked for it in 2015. eslint/eslint#3274
ESLint lead Nicholas Zachas confirms: eslint/eslint#3274 (comment)
The rule was changed in the next release to be able to enforce it both ways, with ternaries kept off by default.
eslint/eslint#4294
https://eslint.org/docs/latest/rules/operator-linebreak
Unfortunately, because projects tend to hardcoded the defaults, this meant anyone that configured
["error", "after"]
would change their behaviour since setting this replaces any "default override". As an example the JavaScript Standard Style quickly applied this opt-out to avoid a regression after upgrading ESLint. standard/eslint-config-standard@a78c4bb Latest version: https://github.com/standard/eslint-config-standard/blob/v16.0.3/eslintrc.json#L194Ironically, Crockford himself has since abandoned this peculiar style in 2017. He now embraces the opposite, same as MediaWiki PHP and Standard JS. jslint-org/jslint@c08484f
Proposal
https://eslint.org/docs/latest/rules/operator-linebreak
I suggest we do one of two things:
1. Set it to
"before"
as override for?
and:
This would match the default that ESLint and Standard JS already set.
2. Set it to
"before"
in generalThis would match what we do in MediaWiki PHP via PHPCS.
The text was updated successfully, but these errors were encountered: