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

no-case-declarations examples are very similar and hard to distinguish #6716

Closed
philiiiiiipp opened this issue Jul 19, 2016 · 10 comments · Fixed by singapore/lint-condo#218 or renovatebot/renovate#63 · May be fixed by iamhunter/teammates#4
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 documentation Relates to ESLint's documentation enhancement This change enhances an existing feature of ESLint good first issue Good for people who haven't worked on ESLint before help wanted The team would welcome a contribution from the community for this issue rule Relates to ESLint's core rules

Comments

@philiiiiiipp
Copy link

Hey,

looking at http://eslint.org/docs/rules/no-case-declarations#rule-details I cannot really see the difference between correct and incorrect code. Either I am missing something or the declarations should be removed there.

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Jul 19, 2016
@platinumazure
Copy link
Member

@philiiiiiipp Thanks for reporting this-- at a quick glance I have to agree that there's a problem. Just wondering, why did you close this?

@platinumazure platinumazure added enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules documentation Relates to ESLint's documentation evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon enhancement This change enhances an existing feature of ESLint labels Jul 19, 2016
@platinumazure
Copy link
Member

platinumazure commented Jul 19, 2016

Never mind, I see it-- it's the braces. The point is that case declarations don't in themselves introduce a new block scope, so you need braces to create a new block scope.

That's extremely subtle and I think it could be improved. I'm going to reopen the issue, if that's okay.

EDIT: Oh, and I edited the title. Sorry, I just really want to make sure this gets addressed without any more silly questions being asked 😄

@platinumazure platinumazure reopened this Jul 19, 2016
@platinumazure platinumazure changed the title no-case-declarations examples are the same no-case-declarations examples are very similar and hard to distinguish Jul 19, 2016
@nzakas
Copy link
Member

nzakas commented Jul 20, 2016

@platinumazure how would you improve the examples?

@platinumazure
Copy link
Member

platinumazure commented Jul 20, 2016

@nzakas A couple of things come to mind:

  1. Have some declarations outside of the switch, to show those are okay
  2. Add comments to point out the new block scope being introduced with braces
  3. Use var in case statements and explain that that is valid due to function-scope hoisting

Also in general, I would simplify the examples by having only one switch/case (or default) per example declaration, so that it's easier to tell what is different. Right now, there are two big switch statements and literally 6 brace characters are the only difference-- even the variable names, switch values, etc. are the same.

Okay if I try to show what I mean with a PR?

@philiiiiiipp
Copy link
Author

  1. The option of making the declarations outside seems obvious, but is probably nevertheless good to have in a complete example.
  2. A comment about the braces would have solved some confusion for me in an instant.
  3. You would then violate the vars-on-top rule though.

I am not sure if I find it any better or worse to use only one case, since multiple cases are the more likely real world example.

@nzakas nzakas added enhancement This change enhances an existing feature of ESLint accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Jul 20, 2016
@nzakas
Copy link
Member

nzakas commented Jul 20, 2016

@platinumazure sounds good, feel free to open a PR (documentation improvements are always welcome).

I also think that the introduction could be expanded to include an example or two -- right now it's pretty bare.

@philiiiiiipp we don't have to worry about violating other rules because we don't know which ones a user will have enabled.

@kaicataldo kaicataldo added the help wanted The team would welcome a contribution from the community for this issue label Dec 23, 2016
@kaicataldo kaicataldo added the good first issue Good for people who haven't worked on ESLint before label Jan 8, 2017
@venikx
Copy link
Contributor

venikx commented Jan 12, 2017

I can try to pick this up, as I would like to start contributing to eslint, this sounds like a good introduction to the eslint-project. If no-one is busy with it of course.

As for the change in documentation. Would you prefer 1 single example and explaining with comments, which is good an bad?
Or would you prefer multiple example for (1) var in case being always valid, (2) declarations outside the switch being always valid and (3) and example as the current one, but with added comments when the braces are introduced?

@not-an-aardvark
Copy link
Member

@rangelke Thanks for contributing!

There's no hard and fast rule for how to arrange the examples. Personally, I think the second option (a different example for each of the cases) sounds like it would be clearer, but anything that clearly indicates what the rule is doing would be fine.

@venikx
Copy link
Contributor

venikx commented Jan 12, 2017

Alright. I'll take this on me then! I have to setup the project first though!

@vitorbal
Copy link
Member

@rangelke Thanks! You can always drop by our gitter chat if you need help setting anything up.

@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 documentation Relates to ESLint's documentation enhancement This change enhances an existing feature of ESLint good first issue Good for people who haven't worked on ESLint before help wanted The team would welcome a contribution from the community for this issue rule Relates to ESLint's core rules
Projects
None yet
8 participants