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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(eslint-plugin): add prefer-for-of rule #338

Merged
merged 6 commits into from Apr 7, 2019

Conversation

edsrzf
Copy link
Contributor

@edsrzf edsrzf commented Mar 7, 2019

This rule provides functionality equivalent to TSLint's prefer-for-of rule. Test cases are mostly taken from TSLint, but I added others that I thought of while implementing.

Note that this implementation still falls into palantir/tslint#2021, false positives on non-Arrays that are still indexable and have a length property, such as typed arrays. We'd need type-checking to do better than this.

This is the first attempt I've made at writing a lint, so bear that in mind. 馃槃

This rule is intended to provide functionality equivalent to TSLint's
prefer-for-of rule.
@bradzacher bradzacher added the enhancement: new plugin rule New rule request for eslint-plugin label Mar 15, 2019
Copy link
Member

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few changes, but otherwise LGTM.

Note - also needs to add link to the rule doc in the README.md

packages/eslint-plugin/src/rules/prefer-for-of.ts Outdated Show resolved Hide resolved
packages/eslint-plugin/src/rules/prefer-for-of.ts Outdated Show resolved Hide resolved
packages/eslint-plugin/src/rules/prefer-for-of.ts Outdated Show resolved Hide resolved
@edsrzf
Copy link
Contributor Author

edsrzf commented Apr 6, 2019

Thanks for the review! Updated.

While updating the README I also noticed I have the option of using type information, which would allow us to fix palantir/tslint#2021. Would it be worth it?

Copy link
Member

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work! LGTM

@bradzacher
Copy link
Member

@edsrzf - you could use the type information if you want. I don't know how necessary that is immediately considering that is a bit of an edge case.
I would consider doing it as a separate PR, if anything.

@codecov
Copy link

codecov bot commented Apr 7, 2019

Codecov Report

Merging #338 into master will decrease coverage by 0.09%.
The diff coverage is 92.45%.

@@            Coverage Diff            @@
##           master     #338     +/-   ##
=========================================
- Coverage   96.96%   96.87%   -0.1%     
=========================================
  Files          69       70      +1     
  Lines        2572     2625     +53     
  Branches      408      424     +16     
=========================================
+ Hits         2494     2543     +49     
- Misses         46       49      +3     
- Partials       32       33      +1
Impacted Files Coverage 螖
packages/eslint-plugin/src/rules/prefer-for-of.ts 92.45% <92.45%> (酶)

@bradzacher bradzacher merged commit 3e26ab6 into typescript-eslint:master Apr 7, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement: new plugin rule New rule request for eslint-plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants