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

Rule Idea: no-break, no-if, no-loops #54

Open
kevinSuttle opened this issue Sep 28, 2017 · 7 comments
Open

Rule Idea: no-break, no-if, no-loops #54

kevinSuttle opened this issue Sep 28, 2017 · 7 comments
Labels
fixed in eslint port This issue has been fixed in github.com/jonaskello/eslint-plugin-ts-immutable help wanted

Comments

@kevinSuttle
Copy link

https://hackernoon.com/rethinking-javascript-eliminate-the-switch-statement-for-better-code-5c81c044716d

"no-break": [true, {"ignore-switch": "true"}], // maybe continue is included here or a separate rule?
"no-if": "true", // or maybe "prefer-ternary"?
"no-loops": [
     true, 
     "while",
     "for",
      "do"
]
@jonaskello
Copy link
Owner

This seems like some nice additions to the functional style rules :-).

@jonaskello
Copy link
Owner

I'm think about how the options for no-loops would work.

"no-loops": [true]

That would disable all loops, including while, for, do.

"no-loops": [true, "while"]

That would only disable while leaving for and do available?

I'm thinking maybe it is more logical to have ignore options, like ignore-for, ignore-while etc.

Also not sure if do is needed as an option? If the while keyword is banned then do would not be useful anyway? And in that case maybe two separate rules named no-for and no-while would make more sense?

@kevinSuttle
Copy link
Author

You’re right. I like the last option. Agree it’s more logical. I like tailoring rules based on how frequently a part of code is likely to be used.

@kevinSuttle
Copy link
Author

kevinSuttle commented Oct 9, 2017

FWIW: the standard lib has a no-for-in rule: https://palantir.github.io/tslint/rules/no-for-in-array/

Also, it has prefer-for-of, but that's still a loop. https://palantir.github.io/tslint/rules/prefer-for-of/

Maybe ban? https://palantir.github.io/tslint/rules/ban/

@jonaskello
Copy link
Owner

So I'm thinking about implementing these rules:

  • no-loop-break (does not check in switch)
  • no-continue
  • no-if
  • no-switch (which implicitly bans break in switch)
  • no-for
  • no-while covers both while() {} and do {} while()

I think this would be a good division, but not 100% sure about no-loop-break and no-while. They could be implemented differently, for example no-break with option ignore-switch as in the original post. Also no-continue could be named no-loop-continue just for duality with no-loop-break.

@jonaskello
Copy link
Owner

I published 4.5.0 with the following new rules:

  • no-loop
  • no-if-statement

In order to keep the amount of rules and documentation down I went back to the original suggestion of no-loop which includes all loop types.

These rules remains to be implemented:

  • no-loop-break
  • no-loop-continue
  • no-switch

If anyone care to implement them I'm open for a PR on any or all of the above rules :-).

@kevinSuttle
Copy link
Author

Awesome! Thank you!

@RebeccaStevens RebeccaStevens added the fixed in eslint port This issue has been fixed in github.com/jonaskello/eslint-plugin-ts-immutable label Jul 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in eslint port This issue has been fixed in github.com/jonaskello/eslint-plugin-ts-immutable help wanted
Projects
None yet
Development

No branches or pull requests

3 participants