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

feat(eslint-plugin): add prefer-string-starts-ends-with rule (fixes #285) #289

Merged
merged 24 commits into from Apr 11, 2019

Conversation

mysticatea
Copy link
Member

Fixes #285.

This PR adds a new rule: @typescript-eslint/prefer-string-starts-ends-with.
(probably there are better names)

  • This PR adds two dependencies: eslint-utils and regexpp. Don't warry, eslint has depended on those packages already, so this add will not increase install time and disk size.
  • This PR fixes some internal types for more correct.

@mysticatea mysticatea added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin enhancement: new plugin rule New rule request for eslint-plugin labels Feb 16, 2019
@codecov
Copy link

codecov bot commented Feb 16, 2019

Codecov Report

Merging #289 into master will increase coverage by 0.17%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master     #289      +/-   ##
==========================================
+ Coverage   96.96%   97.14%   +0.17%     
==========================================
  Files          72       73       +1     
  Lines        2705     2868     +163     
  Branches      436      473      +37     
==========================================
+ Hits         2623     2786     +163     
  Misses         49       49              
  Partials       33       33
Impacted Files Coverage Δ
...plugin/src/rules/prefer-string-starts-ends-with.ts 100% <100%> (ø)

sindresorhus and others added 4 commits February 19, 2019 16:17
…th.md

Co-Authored-By: mysticatea <star.ctor@gmail.com>
some test cases were rejected by node selectors unintentionally.
…s-ends-with/new

# Conflicts:
#	packages/eslint-plugin/package.json
#	packages/eslint-plugin/typings/ts-eslint.d.ts
j-f1 and others added 4 commits February 22, 2019 13:48
…h.ts

Co-Authored-By: mysticatea <star.ctor@gmail.com>
…h.ts

Co-Authored-By: mysticatea <star.ctor@gmail.com>
…th.md

Co-Authored-By: mysticatea <star.ctor@gmail.com>
…th.md

Co-Authored-By: mysticatea <star.ctor@gmail.com>
@mysticatea
Copy link
Member Author

Thank you for the review!
I updated this PR.

…s-ends-with/new

# Conflicts:
#	packages/eslint-plugin/package.json
@mysticatea
Copy link
Member Author

@JamesHenry Would you review again?

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.

two nits otherwise LGTM

JamesHenry
JamesHenry previously approved these changes Apr 4, 2019
Copy link
Member

@JamesHenry JamesHenry left a comment

Choose a reason for hiding this comment

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

If @bradzacher comments could be addressed and the conflicts resolved then this looks great!

@JamesHenry JamesHenry added the awaiting response Issues waiting for a reply from the OP or another party label Apr 4, 2019
@mysticatea
Copy link
Member Author

I apologize for my late response. I updated this PR.

@bradzacher bradzacher merged commit 5592a2c into master Apr 11, 2019
@bradzacher bradzacher deleted the prefer-string-starts-ends-with/new branch April 11, 2019 01:18
@teppeis
Copy link
Contributor

teppeis commented Apr 25, 2019

@fregante
Copy link
Contributor

This rule can now also extended to include string | undefined:

/^wow/.test(stringOrUndefined!);
// becomes
stringOrUndefined?.startsWith('wow')

@fregante
Copy link
Contributor

On second thought, no, because the former returns boolean while the latter is boolean | undefined

@bradzacher bradzacher removed the awaiting response Issues waiting for a reply from the OP or another party label Apr 13, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 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 package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rule proposal: Prefer String#startsWith() and String#endsWith()
10 participants