Closed krutoo closed 3 months ago
This code provides 4 errors in the latest version (including above baz
).
I think the issue may be that your config has changed. You are using require-jsdoc
, and it should be jsdoc/require-jsdoc
. ESLint has its own version of the function, but it was deprecated and removed in ESLint 9.
@brettz9 Oh, its true, I mixed up require-jsdoc
and jsdoc/require-jsdoc
, sorry
Previously I used plugin:jsdoc/recommended
and require-jsdoc
Now I remove require-jsdoc
because its deprecated
Is it possible to make jsdoc/require-jsdoc
works as require-jsdoc
?
Yes, jsdoc/require-jsdoc
should work similar to require-jsdoc
, just with more features. It inherited some of the same codebase and just expanded on it.
@brettz9 Looks like jsdoc/require-jsdoc
now provides error for arrow functions in properties of objects
{
// Error: Requires JSDoc (I don`t need it here)
foo: () => 123,
// Error: Requires JSDoc (But here is ok, i need it here)
bar () {
return 234;
}
}
Can you suggest how to configure this rule for disable requiring JSDoc in such cases?
You can add the following object option:
{
contexts: [
':not(Property) > ArrowFunctionExpression',
],
require: {
ArrowFunctionExpression: false,
ClassDeclaration: true,
FunctionDeclaration: true,
FunctionExpression: true,
MethodDefinition: true,
},
}
@brettz9 can you provide some docs about expressions in contexts option?
Looks like your example dont works as well (maybe i did something wrong):
Also now I have some new places where JSDoc is required:
in default values of destructured object argument:
function MyReactComponent ({
getName = data => data.name // Error: Missing JSDoc (but I dont need it here)
}) {
// ...
}
For arrow functions as arguments:
[1,2,3].map(() => {}); // Error: Missing JSDoc (but I dont need it here)
@brettz9 can you provide some docs about expressions in contexts option?
The advanced page of our docs covers this a little, but as mentioned in the docs, your best bet is probably just experimenting with https://astexplorer.net/
Looks like your example dont works as well (maybe i did something wrong):
I can't see the full object to know exactly what you're working with.
Also now I have some new places where JSDoc is required:
- in default values of destructured object argument:
function MyReactComponent ({ getName = data => data.name // Error: Missing JSDoc (but I dont need it here) }) { // ... }
- For arrow functions as arguments:
[1,2,3].map(() => {}); // Error: Missing JSDoc (but I dont need it here)
While you could exclude more types than Property
, you might just want to whitelist the types of allowing parents. You can add additional contexts
to do so. The following mimics how the rule probably worked when it was part of ESLint (i.e., without the Property
parent).
{
contexts: [
'VariableDeclarator > ArrowFunctionExpression',
'AssignmentExpression > ArrowFunctionExpression',
'ExportDefaultDeclaration > ArrowFunctionExpression',
],
require: {
ArrowFunctionExpression: false,
ClassDeclaration: true,
FunctionDeclaration: true,
FunctionExpression: true,
MethodDefinition: true,
},
}
I can't see the full object to know exactly what you're working with.
@brettz9 You don`t need full object, the error is exactly on this line with arrow function as default value (If I understand what do you mean)
Closing as the above should resolve, but feel free to comment further as needed.
Hi, today I upgraded
eslint-plugin-jsdoc
from^46.8.2
to^48.11.0
I noticed that now
require-jsdoc
rule works differently.Previously I used this config for
require-jsdoc
:In old version this code provides error:
But now all this arrow functions don't provides errors about JSDoc missing.
How can I restore behavior from version
^46.8.2
?