-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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): added new rule no-untyped-public-signature #801
Conversation
…oject` set (#760) BREAKING CHANGE: by default we will now throw when a file is not in the `project` provided
The "(prefer-readonly)" part wasn't in the title.
Thanks for the PR, @eranshabi! 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 |
How is this different from |
This rule is for public methods. Public methods are meant to be used in scopes external to the class itself, and having them typed makes them more readable and easier to use. Sometimes you don't want to type everything but only what you think is important. Also this rule has the option to ignore specific methods which you don't care to type (in our case we use it for react lifecycle hooks). |
Put another way, the intention here is to provide a way to enforce explicit typing of module boundaries so that you can be sure of the exact types you're exposing. In the same vein as @octogonz's question - would this be better served as an option on |
Thanks for the feedback. |
I realised that a little after I wrote the comment (but I wasn't at my keyboard), sorry. It is probably worth keeping this rule as is. In future we can augment it (and rename it) so that it supports more cases of explicitly typing module boundaries. |
BTW it's worth pointing out that TSLint's typedef handled all the different kinds of type annotations (parameters, return values, properties, variables, etc). I always found a little strange for ESLint to treat them as separate rules. If we followed TSLint's model, then "don't require types for private members" could be an option for the one rule, rather than having these criteria split across 3 rules. For the end user experience, it might make configuration easier, since people wouldn't have to understand the exclusive-or between |
The TL;DR is that nobody wanted to implement the full Most of But ~2 years ago someone saw value in enforcing efrt, and so that got implemented. I tend to want to avoid monolithic rules as well. It sounds great being able to configure a single rule to do all of these things, but users often avoid the rules because they're big and scary (documentation is long, and there are many options to configure), and maintaining the rule can be hard because you're putting X distinct code paths into a single file. There's tradeoffs to both approaches. |
so if I understand you correctly @bradzacher, this can be merged? |
I haven't had a chance to review the code yet, sorry. |
fixed the build 🙃 |
@bradzacher please? |
This PR is in the queue for me to review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
few comments, code otherwise looks good.
Thanks for your contribution!
packages/eslint-plugin/src/rules/no-untyped-public-signature.ts
Outdated
Show resolved
Hide resolved
packages/eslint-plugin/src/rules/no-untyped-public-signature.ts
Outdated
Show resolved
Hide resolved
packages/eslint-plugin/src/rules/no-untyped-public-signature.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for this
Codecov Report
@@ Coverage Diff @@
## master #801 +/- ##
==========================================
+ Coverage 94.02% 94.05% +0.03%
==========================================
Files 122 123 +1
Lines 5253 5283 +30
Branches 1456 1468 +12
==========================================
+ Hits 4939 4969 +30
Misses 179 179
Partials 135 135
|
Your new change @bradzacher breaks consctuctor description:
|
please raise a new issue for this. |
A rule we use in our company with good benefit.
This rule prevents adding a public method with untyped parameters or return type.
Public methods are meant to be used in scopes external to the class itself, and having them typed makes them more readable and easier to use.
There is also the
ignoredMethods
option so that you can ignore methods you don't care to explicit type (for example react lifecycle hooks)"@typescript-eslint/no-untyped-public-signature": ["error", { "ignoredMethods": ["ignoredMethodName"] }]