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
merged 1 commit into from Oct 25, 2020
Merged

feat(eslint-plugin): [ban-types] support banning [] #2704

merged 1 commit into from Oct 25, 2020

Conversation

sonallux
Copy link
Contributor

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
Contributor

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 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%> (ø)

@bradzacher bradzacher added the enhancement: plugin rule option New rule option for an existing eslint-plugin rule label Oct 24, 2020
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.

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
@papb
Copy link
Contributor

papb commented Oct 26, 2020

Thank you very much!! 🚀

@dimitropoulos
Copy link
Contributor

@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 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.
Labels
enhancement: plugin rule option New rule option for an existing eslint-plugin rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ban-types] support banning []
5 participants