-
-
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): create ban-ts-comment
rule
#1361
feat(eslint-plugin): create ban-ts-comment
rule
#1361
Conversation
Thanks for the PR, @G-Rath! 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. |
ban-ts-nocheck
ruleban-ts-nocheck
rule
I don't think there's a hard-and-fast rule. Having one rule makes it easy to for a user to turn on everything at once, lets you deduplicate code, etc, but it comes with the drawback of only allowing a single level for the options - it's all an error, or it's all a warning. Having two rules makes it harder for the user, as they have to review more docs, and it means you have to work harder to deduplicate code, etc, but it means that users can independently configure the level of each. It entirely depends on the use case. If you think people will want individual levels, then two rules make sense. If you think people will not care, then one rule makes sense. Examples: For naming conventions, there is In the case of type assertions, in In this example - it could go either way, it could be valid that someone might want error level for But I highly doubt anyone would want that. |
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.
Following on from that big spiel, I think it makes sense to have a single rule for the @ts-
directives.
Could you please merge this and ban-ts-ignore
together, and deprecate ban-ts-ignore
?
I'm thinking a simple object option:
interface Option {
'ts-ignore'?: boolean;
'ts-nocheck'?: boolean;
'ts-check'?: boolean;
}
const defaultOptions: [Options] = [
{
'ts-ignore': true,
'ts-nocheck': true,
'ts-check': false,
}
];
Naming wise, up to you - ban-ts-directive
, ban-ts-directive-comment
, ban-ts-comment
, they're all fine.
I think I prefer the verbose but explicit ban-ts-directive-comment
, but I'm not sold. IDK if people know what a directive
is, so maybe just ban-ts-comment
is better...
Thanks for taking the time write up such a detailed response - it's pretty much the same as what I've been thinking in my head, but it's useful to hear independently aligns with a repo of this scale.
Sure thing - I'll do that when I get home in a few hours :) (or tomorrow) I think I prefer the simpler "comment" over "directive", just for ease of spelling & less technical. |
I might have slightly forgotten about this 😬 I'll try and get it done over this weekend, so that it's ready in time for #1423 |
ban-ts-nocheck
ruleban-ts-comment
rule
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.
#1318 has landed, which included a fix for the recommended config generator.
So please re-run the generator and it'll create the correct config for 2.x.
With 3.0.0 we will remove ban-ts-ignore
and add ban-ts-comment
as a recommended.
One nit with naming - backticks are so much nicer.
Otherwise LGTM - thanks for doing this!
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.
woops was supposed to RC sorry
Co-Authored-By: Brad Zacher <[email protected]>
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! Great work
BREAKING CHANGE: new rule @typescript-eslint/ban-ts-comment typescript-eslint/typescript-eslint#1361 BREAKING CHANGE: new rule @typescript-eslint/prefer-as-const typescript-eslint/typescript-eslint#1431 Closes #218.
Pretty much a clone of
ban-ts-ignore
- it might be nice to merge them into some form ofban-ts-control-comments
rule 🤔On a general aside, I'm interested in hearing what you've found better overall: lots of small nice rules, or a couple of big (but ideally still relatively straightforward in layout) rules, as it's a thought I'd had a couple of times as part of maintaining
eslint-plugin-jest
.I think this could be worth having in the
recommended
list, w/warn
level.