Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: one statement per line #798

Closed
tunnckoCore opened this issue Feb 21, 2017 · 8 comments

Comments

@tunnckoCore
Copy link

commented Feb 21, 2017

Digging more and more in ESLint rules, i found some good ones which enforces good style and more readable code. This issue is for max-statements-per-line rule - not fixable.

Suggested configuration.

{
  "max-statements-per-line": ["error", { "max": 1 }]
}

Invalid

var bar; var baz

if (condition) bar = 1; if (condition) baz = 2

for (var i = 0; i < length; ++i) { bar = 1 }

switch (discriminant) { default: break }

function foo () { var bar = 1 }

Valid

var bar, baz

if (condition) bar = 1

for (var i = 0; i < length; ++i);

switch (discriminant) { default: }

function foo () { }

Semicolon in for is required, since it will be autofixed by other rule to

for (var i = 0; i < length; ++i) { switch (discriminant) { default: } }

@feross feross added the enhancement label Feb 21, 2017

@dcousens

This comment has been minimized.

Copy link
Member

commented Feb 22, 2017

ACK, provided the following is possible:

for (var i = 0; i < length; ++i) bar++
@tunnckoCore

This comment has been minimized.

Copy link
Author

commented Feb 22, 2017

Yea it is, that's good example too.

@timoxley

This comment has been minimized.

Copy link
Contributor

commented Feb 22, 2017

I think this is decent. Interested in ecosystem impact.

@ghost

This comment has been minimized.

Copy link

commented Mar 22, 2017

FWIW, in CoffeeScript, I write my early terminations like unless bar; return. IMHO the more "rules" we pile into Standard the less portable it becomes. And I get CoffeeScript lacks hype any longer, but please note it's the primary authoring language of Framerjs and a great way to get designers coding.

@feross

This comment has been minimized.

Copy link
Member

commented Apr 4, 2017

This rule would disrupt the way that too many people write code and it doesn't prevent bugs or improve code consistency enough to justify the cost to users, in my opinion.

Here are the results of the test suite: 24% breakage.

# tests 238
# pass  182
# fail  56

@feross feross closed this Apr 4, 2017

@dcousens

This comment has been minimized.

Copy link
Member

commented Apr 5, 2017

@feross what were some of those failures? OOI

@yoshuawuyts

This comment has been minimized.

Copy link
Contributor

commented Apr 5, 2017

@feross

This comment has been minimized.

Copy link
Member

commented Apr 5, 2017

@dcousens I can't remember... From memory, things like:

if (condition) { foo() } else { bar() }

And certain for loops.

@lock lock bot locked as resolved and limited conversation to collaborators May 10, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
5 participants
You can’t perform that action at this time.