Closed Bug 1616608 Opened 4 years ago Closed 4 years ago

comm/eslintrc.js causes broken eslint behavior, e.g. --fix removes }

Categories

(Thunderbird :: General, task)

task
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
Thunderbird 75.0

People

(Reporter: KaiE, Assigned: darktrojan)

Details

Attachments

(4 files)

Attached file test.js

I'll attach sample JS code, which contains an expression
try { if () { action }} catch () {}

eslint --fix has a bug, and changes it to
try { if () { action } catch () {}

and reports
error Parsing error: Unexpected token catch (eslint)

Note that I've reduced the sample as much as possible, so please ignore that the code doesn't make sense.

Attached file test2.js

Here's an additional test scenario, which also removes a closing }. This time it isn't with try/catch, but with if/for.

I talked to Mark (Standard8). He noticed that the false behavior is likely caused by rules in comm/.eslintrc.js

When placing the test file outside comm, inside top mozilla, the problem cannot be reproduced.

Quoting him:
"There is a prettier config plugin that turns these off but I think the overrides there are turning them on and conflicting.
...
here's the list of rules that conflict with prettier, basically comm should just remove all references to them: https://github.com/prettier/eslint-config-prettier/blob/master/index.js "

Summary: eslint --fix removes } → comm/eslintrc.js causes broken eslint behavior, e.g. --fix removes }

Removing the brace-style rule fixes the problem, for both attachments.

Could we remove it from eslintrc.js ?

Flags: needinfo?(geoff)

Basically all of this lot should be removed from the .eslintrc.js:

https://searchfox.org/comm-central/rev/6e3eab6ebb0852188e87a2a7251a986c696242e6/.eslintrc.js#37-60

Otherwise there's potential conflicts with prettier.

This also conflicts: https://searchfox.org/comm-central/rev/6e3eab6ebb0852188e87a2a7251a986c696242e6/mailnews/extensions/newsblog/.eslintrc.js#28

Whilst I'm here, I'll just note that calendar/.eslintrc.js also looks like it needs updating on multiple fronts - especially as extending from toolkit/.eslintrc.js isn't really sensible today (note: eslint inherits rules from the levels above).

It should definitely have the rules in eslint-prettier-config's index.js removed.

Assignee: nobody → geoff
Status: NEW → ASSIGNED
Flags: needinfo?(geoff)
Attachment #9127742 - Flags: review?(mkmelin+mozilla)

This removes calendar/.eslintrc.js and fixes the errors (done with mach eslint --fix) so there's probably no need for a detailed inspection.

I've set the global config for the complexity rule to 80 (less strict than the default) because there are many calendar functions with more than the default. (Let's be honest, we mostly ignore this rule anyway.)

Attachment #9127743 - Flags: review?(mkmelin+mozilla)
Comment on attachment 9127742 [details] [diff] [review]
1616608-conflicting-rules-1.diff

Review of attachment 9127742 [details] [diff] [review]:
-----------------------------------------------------------------

Looks good, and thanks Mark for the input!

I'm not sure, but maybe some of these were leftovers since IIRC there were situations especially with braces (lack of such) that prettier wouldn't make right, only keep correct once they were there. So a double pass was needed, first eslint and then prettier.
Attachment #9127742 - Flags: review?(mkmelin+mozilla) → review+
Component: Lint and Formatting → General
Product: Firefox Build System → Thunderbird
Comment on attachment 9127743 [details] [diff] [review]
1616608-remove-calendar-rules-1.diff

Review of attachment 9127743 [details] [diff] [review]:
-----------------------------------------------------------------

LGTM
Attachment #9127743 - Flags: review?(paul)
Attachment #9127743 - Flags: review?(mkmelin+mozilla)
Attachment #9127743 - Flags: feedback+

Quite nice to get all the no-else after returns handled.

Comment on attachment 9127743 [details] [diff] [review]
1616608-remove-calendar-rules-1.diff

Review of attachment 9127743 [details] [diff] [review]:
-----------------------------------------------------------------

Looks good.  Nice to have more standardization of the styles across the code base.  (Just as an aside, it's unfortunate that the new JS syntax for defining functions as object properties is identical to the syntax for calling functions.  It's more concise, but makes it harder to locate where a function is defined when searching the code base.)
Attachment #9127743 - Flags: review?(paul) → review+

Pushed by geoff@darktrojan.net:
https://hg.mozilla.org/comm-central/rev/7c243455ebe5
Remove ESLint rules that conflict with Prettier. r=mkmelin
https://hg.mozilla.org/comm-central/rev/f61f27a35d89
Remove separate ESLint rules in calendar. r=mkmelin,pmorris,fallen

Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → Thunderbird 75.0
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: