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

Fix max-statements-per-line #7051

Closed
nzakas opened this issue Sep 3, 2016 · 11 comments
Closed

Fix max-statements-per-line #7051

nzakas opened this issue Sep 3, 2016 · 11 comments
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly good first issue Good for people who haven't worked on ESLint before rule Relates to ESLint's core rules

Comments

@nzakas
Copy link
Member

nzakas commented Sep 3, 2016

While reviewing #7044, I find that max-statements-per-line has an undocumented and confusing behavior. For some reason, we allow an option of max: 0, which seems like a mistake (though intentional because there are tests). It looks like the only time this is triggered is when there's an empty blocks statement and there's a special case for that in the code: https://github.com/eslint/eslint/blob/master/lib/rules/max-statements-per-line.js#L167

This seems very broken because it doesn't make sense to ever have max statements be 0 per line, and we already have no-empty to catch empty blocks.

I think we should fix this by:

  1. Ensuring max is 1 or larger
  2. Removing the empty block check

This would be semver-patch because we are reducing the number of warnings this rule produces.

@mysticatea @scriptdaemon

@nzakas nzakas added bug ESLint is working incorrectly rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion labels Sep 3, 2016
@btmills
Copy link
Member

btmills commented Sep 4, 2016

@nzakas what is the desired behavior when max is 0? Does it silently ignore that setting?

@alberto alberto added the good first issue Good for people who haven't worked on ESLint before label Sep 4, 2016
@sstern6
Copy link
Contributor

sstern6 commented Sep 6, 2016

@nzakas I would like to make a PR for this, this will be my first PR in the code base if you are ok with me taking this on.

Thank you

@ilyavolodin
Copy link
Member

@btmills I think what @nzakas means is we should tweak schema to not allow 0 value at all.

@sstern6 Go for it! We are always glad to accept contributions from new people!

@sstern6
Copy link
Contributor

sstern6 commented Sep 6, 2016

@ilyavolodin thank you, will hopefully have a PR open in a few days. Will let you know if I have any questions about execution etc.

@nzakas
Copy link
Member Author

nzakas commented Sep 6, 2016

@btmills yes, what @ilyavolodin said. The minimum for max should be set to 1 in the schema.

@platinumazure
Copy link
Member

@sstern6 Thanks for volunteering to take this on! If you have questions, feel free to either leave a comment in the issue or stop by our Gitter chat.

@btmills
Copy link
Member

btmills commented Sep 6, 2016

@ilyavolodin @nzakas got it, thanks! If we're making the schema more restrictive, then this should be a semver-minor change, right?

@ilyavolodin
Copy link
Member

@btmills Was just about to say that. I'm actually not sure if even semver-minor would be enough, since it's a breaking change for anyone using max: 0... Granted, max: 0 doesn't make a whole lot of sense to begin with, so there shouldn't be anyone using it, but you never know.

@nzakas
Copy link
Member Author

nzakas commented Sep 7, 2016

I can't see a scenario where someone is using max:0, because you can't write code with zero statements per line. (Can someone verify that?)

@platinumazure
Copy link
Member

platinumazure commented Sep 7, 2016

@nzakas Confirmed on online demo:

/* eslint max-statements-per-line: ["error", { "max": 0 }] */

something();

Result:

3:1 - This line has too many statements. Maximum allowed is 0. (max-statements-per-line)

Now that I've seen this behavior, I agree it's useless and buggy and does not need a semver-major release to fix.

@ilyavolodin
Copy link
Member

In that case, I'm perfectly fine calling this a bug and doing as a semver-patch

sstern6 added a commit to sstern6/eslint that referenced this issue Sep 9, 2016
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly good first issue Good for people who haven't worked on ESLint before rule Relates to ESLint's core rules
Projects
None yet
Development

No branches or pull requests

6 participants