-
-
Notifications
You must be signed in to change notification settings - Fork 159
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
Support typescript contexts for recommended rules #615
Comments
i'd be willing to help implement some of this if the maintainers wanted to provide some guidance on which direction to take. also @obvioussean, have you found any workarounds in the meantime? |
We currently use The problem with adding all contexts is that, besides the performance issues it may cause, it probably won't be so easy to come to an agreement about which additional contexts are even desirable. For example, does one want But I would agree that we could have more reasonable defaults, e.g., that publicly exported interfaces or whatever should be allowed. But as one who is not a regular TS user, I don't have as strong of a sense of this, and I think people supporting this can present their arguments in this issue or in the PR and negotiate with the rest of the community (or Gajus of course) as to what is considered reasonable. |
here's one idea: we can build new rules for typescript contexts that "extend" from the existing rules. these new rules would have additional options regarding which contexts they would apply to, but the defaults would express what the community thinks make sense for each particular rule. they would support all existing options from the parent rule, and delegate to that rule when possible (so we don't end up duplicating logic unless its necessary). last, we aggregate all these new rules in a config called i think this solves the issues where there isn't a uniform set of contexts that makes sense for all rules, allows users not to have to select contexts manually, and provides extension points for those who want to configure their rules a bit differently. |
We could take such an approach, sure, but I don't see a need for it at this point. Auto-detection and "typescript" My issue is more that For example, one project might want all type Constructor = new (...args: any[]) => {}; Another project might only want those types which were exported to be annotated. And another project might not want these annotated at all, focusing only on say the public API. |
@brettz9 got it! how would you recommend we move forward then? i recognize the issue around varied contexts across projects that you brought up. my idea tries to address that very issue which is what i referred to with "provides extension points for those who want to configure their rules a bit differently". my hope is that someone can simply extend from a built-in config (whether that be |
None of the "recommended" rules currently set any options (we only have this one config currently and each rule can internally default to the recommended behavior). However, configs can enable rules with their own options, e.g., if we were to add additional configs. So there could be a typescript config or configs which prepopulated with its own reasonable options, e.g., one config adding a But if we only come up with one reasonable TypeScript behavior, we might just want to allow the user to avoid even needing to choose a "recommended-typescript" config and just continue to use the "typescript" mode for this purpose, as it acts independently of the configs. For example, One could similarly detect "typescript" mode behind the scenes and auto-insert some However, if it seems like we desire say a "typescript-heavy-documentation" config whereby rules would require or check many types of TS AST, then it might make sense to add this as a separate config which sets everything by explicit options. But we probably wouldn't want to start a plain "typescript" config now, not only because So my suggestion is:
|
I have the same desire here: I'd like to use this plugin's recommended ruleset, except for the rules that are made redundant by TypeScript. How about exposing an equivalent to recommended that does that? "extends": "plugin:jsdoc/recommended-typescript" |
I think the only rule changes needed for {
"jsdoc/no-types": "warn",
"jsdoc/require-param-type": "off",
"jsdoc/require-property-type": "off",
"jsdoc/require-returns-type": "off",
} |
An update for this issue is that those not wanting to set individual contexts for each rule can now set them through: {
settings: {
jsdoc: {
contexts: [/*...*/]
}
}
} @JoshuaKGoldberg : Yes, I am open to a PR, though I hope a regular TS user gives good thought to each rule so we hopefully won't have to tweak the ruleset much later. Note that if someone has changes related to the JSDoc TS flavor (e.g., which tags, types, or tag name/description structure are allowed or anything which every TS user will absolutely want done a particular way including those using TS within JavaScript), this can instead be handled with our internal use of the "typescript" mode. Btw, we are currently using |
👍 awesome thanks. I won't be able to spend the time for |
Ok, thank you @JoshuaKGoldberg for the PR, and @RebeccaStevens for the rule suggestions. Re: the Since as mentioned there is now an opportunity for global contexts, and I'm not convinced a single combination of contexts would appeal across project, I think we can close this issue. If someone wants an issue for providing aliases whereby one alias could target a related group of contexts, I'd be open to a separate issue/PR (or we could wrap it into #384). |
Oh, and if one is having to add TS contexts for specific rules which really should be supported in all projects, feel free to submit an issue for such change(s). |
Motivation
I really want to use the jsdoc/recommended ruleset for my typescript project, but that means quite a few rules that support the contexts param won't run correctly. An example is interfaces, which require me to pass TSInterfaceDeclaration to contexts.
Current behavior
For each rule that in the recommended list I need to also include in the rules section and pass a long list of contexts.
Desired behavior
Either just always include the impacted typescript contexts if typescript parser is being used, or support a settings which holds the default contexts for any rule that supports a context parameter.
Alternatives considered
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: