-
-
Notifications
You must be signed in to change notification settings - Fork 163
require-jsdoc exemptEmptyFunctions and class constructors #600
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
Comments
I've now added // Allow getter/setters to be exempted
if (jsdocUtils.exemptSpeciaMethods(...)) {
return;
}
// Only if the option is enabled, prevent empty regular functions and constructors from needing jsdocs
if (exemptEmptyFunctions && (isFunctionContext || jsdocUtils.isConstructor())) {
const functionParameterNames = jsdocUtils.getFunctionParameterNames(node);
if (!functionParameterNames.length && !jsdocUtils.hasReturnValue(node, context)) {
return;
}
} |
But I think changing the default of |
If I'm reading it right, with
Using If you think changing Btw, thanks for the fast reply :D! |
There are two changes in the code above:
So I guess the code block may instead become: // For those who have options configured against ANY constructors (or setters or getters) being reported
if (jsdocUtils.exemptSpeciaMethods(...)) {
return;
}
if (
// Avoid reporting param-less, return-less functions (when `exemptEmptyFunctions` option is set)
(exemptEmptyFunctions && isFunctionContext) ||
// Avoid reporting param-less, return-less constructor methods (when `exemptEmptyConstructors` option is set)
(exemptEmptyConstructors && jsdocUtils.isConstructor())
) {
// Code to check the function/method is indeed param-less/return-less
} Sound good? @golopot, it'd be good to have your input here before I prepare a PR, if you have time these days to review. |
I agree with “1.”, it aligns with the other rules’ options and makes sense.
Regarding the “2.”, yes, I didn’t consider people who would want to enforce
descriptions on constructors even when there are no parameters, so the
`excemptEmptyConstructors` makes more sense now.
I also agree with your personal opinion about not exempting non-param empty
functions, I always try to document everything, but I don’t like writing
unnecessary comments either: this was forcing me to write “Class
constructor” as description just to keep the option as false and not
trigger it.
The change looks good to me :D.
Thanks!!
(I’m trying to incorporate the plugin to the defaults of the configurations
I use for my personal projects :D)
…On Thu, Jul 2, 2020 at 9:40 PM Brett Zamir ***@***.***> wrote:
There are two changes in the code above:
1. The jsdocUtils.exemptSpeciaMethods() checks for the options
checkConstructors, checkGetters, and checkSetters, and if any of those
constructs exist when the options are true, it will exit early and not
report. Note that this checkConstructors is for disabling the need for
documenting constructors entirely, even if they have parameters. This
change is, I know, not really related to your request but I mention it as
it is somewhat on topic (and would be a natural addition given how it fits
with the preparatory refactoring I have done for your desired change
anyways). The idea here is to bring parity with some of our other rules
which have these options.
2. if (exemptEmptyFunctions && (isFunctionContext ||
jsdocUtils.isConstructor())) {. This differs from your proposal in not
automatically disabling checks for constructors (some projects might always
wish constructors to be documented). It does change the existing behavior
too in that if exemptEmptyFunctions is true, constructors will be
exempted as well. However, I do see you may not want to exempt empty
functions but do want to exempt empty constructors, so
exemptyEmptyConstructors (with a default of true) does seem to be a
good idea. This discussion also raises the question of whether all methods
(including constructors) should be exempted by exemptEmptyFunctions.
While exempting non-param constructors makes sense, I would personally not
want to exempt non-param empty functions (unless completely empty), so I'm
not sure whether people who want this option would also want it to apply to
methods as well. I guess they would since the logic is apparently that "I
am only interested in documenting params and return values". But that can
be another issue if someone wants it.
So I guess the code block may instead become:
// For those who have options configured against ANY constructors (or setters or getters) being reportedif (jsdocUtils.exemptSpeciaMethods(...)) {
return;}if (
// For param-less, return-less functions
(exemptEmptyFunctions && isFunctionContext) ||
// For param-less, return-less constructor methods
(exemptyEmptyConstructors && jsdocUtils.isConstructor())) {}
Sound good?
@golopot <https://github.com/golopot>, it'd be good to have your input
here before I prepare a PR, if you have time these days to review.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#600 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABVATPVOKJ6ZOEVHUSSXMH3RZUSI5ANCNFSM4OOSHM5Q>
.
|
:-) We tend to be open to the possibility of breaking changes, preferring to have things make better sense, so feel free to suggest any other default changes that may appeal to others. |
Great :D! And don't worry, I also maintain a few projects, so I know what it means respecting semver :P. I found another "issue", super unrelated to this one, and I can fix it using the plugin settings, so you tell me if I should create a new issue or not:
The VSCode intellisense doesn't recognises I know VSCode uses the TS-Server behind the curtains and that on TS, Maybe the preferred type for |
Yeah, jsdoc comes across more fundamentally I think more as a documentation tool than a precise specification even while it has served as a specification for other tools or specifications that have built on top of it. Of course, it is good to follow it, but the jsdoc tool is often more forgiving than the docs, and the docs are not always clear. For jsdoc type parsing, it is a bit more clear, as there is jsdoc's
I do recall they are different in TS but don't recall the differences (and being behind the GFW, I can't easily Google now).
If this is more suitable for TS, we can change it for "typescript" mode (which is now auto-set when the As far as changing for non-TS users, we had previously actually used "Object" but switched to "object" for the reasons outlined at https://github.com/gajus/eslint-plugin-jsdoc#why-not-capital-case-everything . |
I'm not a TypeScript user, I mentioned it because VSCode uses the TS-Server to pick JSDoc comments for the intellisense and that's was kind of the reason for me wanting to "fix and normalize" all my projects' documentation. I'm not sure if changing the default preferred type for the TypeScript mode would be the best, as you said it, there's a difference: During the day (it's 5AM), I'll ask some friends that work with TypeScript for their opinion, because changing it "may not be the best solution", but at the same time, it may be irrelevant for TS users, as I believe they usually use I'll let you know, and depending on what they tell me, I may send the PR during the weekend. Thanks!! |
I’m an idiot, I spent so much time looking for the differences between If you want to type a dictionary, you use /**
* A map-like object that maps arbitrary `string` properties to `number`s.
*
* @type {Object.<string, number>}
*/
var stringToNumber; I’ll try to send the PR during the weekend. Another issue I’m having, even more unrelated than the previous, is with I have a This is the syntax I’m using: /**
* @module node/logger
*/
/**
* @typedef {Object.<string,string> Somethig
* @memberof {module:node/logger}
*/ I didn’t research it a lot, it took me some time to realize I needed the brackets for TypeScript, and when I found the second error I had to leave the computer for a couple of hours :P. Any ideas? Thanks! |
Re: See #601 re: a Discord chat I started for jsdoc-related discussions. No promises I can reply to all, but should be a good place for such questions, I'd think. |
And thanks for the info on Object/object! |
Great about the discord, I'll join tonight :D. Regarding the JSDoc import, I know TS doesn’t support it and I’m already using (I’m probably missing the point that the |
Not sure I fully get you, but:
If you want to mix-and-match your syntaxes--not recommended--you can set your If your parser is TypeScript-based (even if you're using for JS), I guess you should be using "typescript" mode. If TypeScript expects |
(Sorry for the short answer, I'm on the phone) I’m using the typescript mode and using the import syntax that’s not supported by JSDoc , both the linter and vscode accept it, and for the site generation I wrote a small plugin that removes those lines. When I said that typescript required the brackets wasn’t because I checked the docs, my fault (sorry); I ran the parser with the code and setting the mode to typescript and it didn’t generate any error, but the plugin does an extra validation that fails (sorry I can’t remember the error, it was something like it was missing the type). |
Feel free to file an issue with the code that generates the issue and the specific rule that gets reported. |
Sorry, I couldn't make the PR; I've believe I identified where the modification should be made, but the only way I could fix it would be with an awful patch and I would reject it if were to review it :P.
All of sudden, I went from wanting to add an Regarding the other things, I'll give you a little bit more context on what I was trying to achieve so you could better understand my crazy messages: I'm migrating from ESDoc, so I wanted to use proper JSDoc (thus the use of this plugin) for comments and for site generation... and at the same time, I wanted to use it on a way that the VSCode's TS Server would pick my types for the intellisense, so, yes... I'm mixing a little bit of JSDoc with TypeScript. To import definitions, I'm using Then I wanted to group different things from a same file under the same module on the generated site, that's why I started using I ended up going the "hack route": Instead of using I'm not entirely sure if the issue with Thanks! |
I can prepare a PR myself for #600 (comment) As far as As far as your latter issue, that is working as intended. If you ever want to use jsdoc for documentation, you will presumably want a jsdoc dialect which can be understood by the parser that does the documentation (I believe you can use TypeScript to document pure JavaScript+jsdoc, but using their dialect). While some of these parsers may be forgiving of your use of distinct parsers, for example, a regular jsdoc parser for documentation and a TypeScript parser for IDE use, this is not recommended because:
Nevertheless, if you really want to try to accommodate both, you can set Going forward, please let us not discussing these unrelated items here further. If you want an extended discussion, please use the chat rooms, or file a new issue. Of course, feel free to add comments here though if related to the original issue. |
…s default; fixes gajus#600 If `true` will prevent empty constructors from needing documentation. Also adds `checkConstructors`, `checkGetters`, and `checkSetters` options (default `true`) to allow the complete disabling of checks on these methods as per other require-* rules.
…s default; fixes gajus#600 If `true` will prevent empty constructors from needing documentation. Also adds `checkConstructors`, `checkGetters`, and `checkSetters` options (default `true`) to allow the complete disabling of checks on these methods as per other require-* rules.
…s default; fixes gajus#600 If `true` will prevent empty constructors from needing documentation. Also adds `checkConstructors`, `checkGetters`, and `checkSetters` options (default `true`) to allow the complete disabling of checks on these methods as per other require-* rules.
…s default; fixes gajus#600 If `true` will prevent empty constructors from needing documentation. Also adds `checkConstructors`, `checkGetters`, and `checkSetters` options (default `true`) to allow the complete disabling of checks on these methods as per other require-* rules.
…s default; fixes #600 If `true` will prevent empty constructors from needing documentation. Also adds `checkConstructors`, `checkGetters`, and `checkSetters` options (default `true`) to allow the complete disabling of checks on these methods as per other require-* rules.
🎉 This issue has been resolved in version 28.7.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
In addition to the implementation of this feature, there is now also (per 82ca868 ) the ability to selectively enable object and Object (enabled by default in "typescript" mode / with the To do so in "jsdoc" mode requires this trick (at least until such time as we may settle on some formal options for it): settings: {
jsdoc: {
preferredTypes: {
object: 'Object',
Object: 'object',
},
}, Other built-in types with fixed casing can be permitted in a similar manner. |
@brettz9 yay! thank you so much :D!! |
Expected behavior
A class constructor without parameters shouldn't require a JSDoc comment block.
Actual behavior
Since the default value of
require-jsdoc.exemptEmptyFunctions
isfalse
, functions/methods with no parameters or no return require a JSDoc block, but class constructors with no parameters will also trigger the rule, and most of the times it may no be necessary.ESLint Config
ESLint sample
Environment
eslint-plugin-jsdoc
version: 28.6.1I think this can be easily fixed by modifying this validation:
I couldn't figure out how to pull the
isConstructor
from the iterator utilities, so just for the sake of testing it, I copied the function into therequireJsdoc.js
file, modified theif
and everything worked as a charm:Thanks!
The text was updated successfully, but these errors were encountered: