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): [ban-types] support banning `[]` #2704

Merged

Conversation

@jsone-studios
Copy link
Contributor

@jsone-studios jsone-studios commented Oct 24, 2020

fix #2582

This PR only adds support for banning the empty tuple type [], it does not change the default options of the ban-types rule.

I think it might also be worth adding [] to the default banned types. As this would be a breaking change, I would do it in another PR, if the maintainers are ok with that.

@typescript-eslint
Copy link

@typescript-eslint typescript-eslint bot commented Oct 24, 2020

Thanks for the PR, @jsone-studios!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day.

@codecov
Copy link

@codecov codecov bot commented Oct 24, 2020

Codecov Report

Merging #2704 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #2704   +/-   ##
=======================================
  Coverage   92.79%   92.79%           
=======================================
  Files         294      294           
  Lines        9682     9684    +2     
  Branches     2717     2718    +1     
=======================================
+ Hits         8984     8986    +2     
  Misses        330      330           
  Partials      368      368           
Flag Coverage Δ
#unittest 92.79% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
packages/eslint-plugin/src/rules/ban-types.ts 100.00% <100.00%> (ø)
Copy link
Member

@bradzacher bradzacher left a comment

I think it might also be worth adding [] to the default banned types.

I can understand why you might want to ban it in your codebase though IMO it doesn't belong in the defaults.

The defaults are setup to increase codebase standardisation and safety. Things like {} are banned because they work differently to how people think they work.

But [] works exactly as you'd expect - it's an empty array.


LGTM - thanks for your contribution!

@bradzacher bradzacher merged commit ef8b5a7 into typescript-eslint:master Oct 25, 2020
10 checks passed
10 checks passed
Typecheck
Details
Unit tests Unit tests
Details
Code style and lint
Details
Run integration tests on primary Node.js version
Details
Run unit tests on other Node.js versions (10.x)
Details
Run unit tests on other Node.js versions (14.x)
Details
Publish the latest code as a canary version
Details
Semantic Pull Request ready to be squashed
Details
codecov/patch 100.00% of diff hit (target 90.00%)
Details
codecov/project 92.79% (+0.00%) compared to e012049
Details
@papb
Copy link
Contributor

@papb papb commented Oct 26, 2020

Thank you very much!! 🚀

@dimitropoulos
Copy link
Contributor

@dimitropoulos dimitropoulos commented Oct 27, 2020

@bradzacher just for the your consideration, I've only ever seen [] used in one scenario - a junior developer (well, junior to TypeScript I mean, which we all were in the not too distant past) trying to express something like any[], not realizing that it means "empty tuple" (often, not even being aware of what tuples are). What's the use of declaring an empty tuple literal anyway? I'll be the last to argue about it if this is the default you think is best but I thought you'd at least appreciate hearing what a sample-size-of-one can say about seeing this used in the wild.

@papb
Copy link
Contributor

@papb papb commented Oct 27, 2020

@dimitropoulos The only time I saw the empty tuple being used was exactly the way you described as well. I couldn't imagine a natural situation in which [] would be needed, and I think it would be reasonable to use an eslint-disable comment in the rare situations it actually makes sense. To me it also makes sense for it to become banned by default.

This was referenced Oct 27, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

4 participants
You can’t perform that action at this time.