Page MenuHomeWildfire Games

Linting: Remove "no-lone-blocks" rule for ESLint
ClosedPublic

Authored by Krinkle on Dec 5 2019, 11:49 PM.

Details

Reviewers
Imarok
Group Reviewers
Restricted Owners Package(Owns No Changed Paths)
Commits
rP23261: Linting: Remove "no-lone-blocks" rule for ESLint
Trac Tickets
#5524
Summary

Originally added by rP20364 (D213).

Per discussion on rP23172:

@elexis wrote:

I disagree with this eslint warning and wrote the code intentionally this way.
[…]
Just because there is no let keyword doesn't mean that the block is useless.

This can be useful also in context of ProfileStart/ProfileEnd block to make
it clear what code it is meant to encapsulate. It is effectively similar
to how code can be split into separate functions without there necessarily
being something in the code that makes use of JS features unique to
function scope. It is a way of organising the code.

While it is possible that blocks are sometimes left behind by refactoring,
I suppose we prefer to catch the bad things in code review, instead of
having to tell the linter with inline structions to whitelist the cases
where it is intended.

Background

This follows-up rP23172, which introduced the following ESLint warnings:

binaries/data/mods/public/gui/lobby/LobbyPage/Game.js
  153:3  warning  Nested block is redundant  no-lone-blocks
  202:3  warning  Nested block is redundant  no-lone-blocks

binaries/data/mods/public/gui/lobby/LobbyPage/GameList.js
  110:3  warning  Nested block is redundant  no-lone-blocks

Alternatives

If we keep this in our ruleset, there are two other ways to address it:

  1. Make an inline exemption, e.g. like so:
 		// eslint-disable-next-line no-lone-bocks
 		{
			foo.bar();
 		}
  1. Or, adapt the code to follow the rule by removing the curly braces.
Test Plan

Happy Coala bears.

Diff Detail

Repository
rP 0 A.D. Public Repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

Krinkle created this revision.Dec 5 2019, 11:49 PM
Owners added a subscriber: Restricted Owners Package.Dec 5 2019, 11:49 PM

Successful build - Chance fights ever on the side of the prudent.

Link to build: https://jenkins.wildfiregames.com/job/vs2015-differential/684/display/redirect

Successful build - Chance fights ever on the side of the prudent.

Link to build: https://jenkins.wildfiregames.com/job/docker-differential/1200/display/redirect

Krinkle updated this revision to Diff 10522.Dec 7 2019, 10:03 PM
Krinkle edited the summary of this revision. (Show Details)
Krinkle added a subscriber: elexis.
Owners added a subscriber: Restricted Owners Package.Dec 7 2019, 10:03 PM
Krinkle retitled this revision from lobby: Fix remaining ESLint warnings to Linting: Remove "no-lone-blocks" rule for ESLint.Dec 7 2019, 10:05 PM
Krinkle edited the summary of this revision. (Show Details)
Krinkle updated the Trac tickets for this revision.

Successful build - Chance fights ever on the side of the prudent.

Link to build: https://jenkins.wildfiregames.com/job/vs2015-differential/711/display/redirect

Successful build - Chance fights ever on the side of the prudent.

Link to build: https://jenkins.wildfiregames.com/job/docker-differential/1227/display/redirect

Imarok accepted this revision.Dec 19 2019, 3:45 PM
Imarok added a subscriber: Imarok.

I'm ok with removing that rule.
I understand elexis reasoning and I think the cases where such blocks are code-wise useless and don't help with understanding the code are very seldom and easy to spot.

This revision is now accepted and ready to land.Dec 19 2019, 3:45 PM
This revision was automatically updated to reflect the committed changes.