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
enhance require-jsdoc to recognize function expressions #5867
Comments
I'm 👍 to the suggestion. |
This is trickier than it seems, which is why it is not done yet. :) We can't just flag any function expression, because it might not be considered a method. For instance, should this be flagged? var foo = function() {}; How about this? somethingFunction({
apply: function() {}
}); I'm not opposed to exploring this, I just think we need to be very specific about the patterns we should and should not flag because it's not as simple as requested. |
@nzakas - I guess if we find a reliable way to detect in-place callback definitions which I think is possible I think all others should be documented. We may have sub-options, say for methods to allow the rule behave a bit more relaxed. Makes sense? |
If I got it right, we should take a look at https://github.com/jscs-dev/jscs-jsdoc/blob/master/lib/rules/validate-jsdoc/enforce-existence.js with their options (since this rule was bundled into jscs package). We got there 'exports' and 'paramless-procedures': jscs-dev/jscs-jsdoc#139. |
Yeah, sure. By default it reports any function without bound jsdoc-block except E.g.: /**
* File overview
*/
var fn = function() {
} /* nothing here */
/**
* Function description
*/
var fn = function() {
} And next to it there are several filters:
I'm not sure these are the best ones. But it's what we have in |
@zxqfox - Wanna give this a shot? Otherwise I'll go ahead and try to implement it. |
Not now :-( Go ahead! |
Marking as accepted because we need these changes for JSCS compat. |
+1 |
Somewhat related is the situation of functions within objects. I expected the following to be flagged by the /*
eslint "require-jsdoc": ["error", {
"require": {
"FunctionDeclaration": true,
"MethodDefinition": true,
"ClassDeclaration": true
}
}]
*/
export default {
foo: false,
// these are not the docs you are looking for
bar: function () {
this.foo = true;
},
// sorry, but the docs are in another castle
baz() { // ES6-style method shortcut
this.foo = false;
},
}; |
@zxqfox are you planning on addressing this? |
Wow. Yeah, I'll try to give this a shot! |
Pinging this so people know there is still interest. All I care about is: B) |
+1 I'm looking for it to flag returning a named function so that it works with my AMD solution. Currently the following code is OK even though I have require-jsdoc: define(function() {
return function Foo() {
// code
}
}) However this similar code fails linting: define(function() {
function Foo() {
// code
}
return Foo;
}) |
The code I would like this to work for looks like this: const Actions = {
actions: new Set(),
register(name) {
...
},
}; Similar to what everyone else is presenting except instead of |
+1 |
Could we augment the rule to support selectors? That way, people could enforce documentation on whatever function node types they want to (including only ones that are part of assignments, or part of object expressions, or...). |
If I'm not mistaken, selectors wouldn't be an immediate solution to this problem because we would still have to match the JSDoc comment to the function expression itself. (This issue isn't asking for more configurability -- it's asking for functionality that isn't implemented yet.) |
I started looking at this, but it doesn't look like we actually decided on an implementation (it was accepted because it was needed for JSCS compatibility). My understanding is that we want options to enforce JSDocs on the following:
Assuming my understanding is correct (let me know if it's not!), it seems like these would need to be two new options (turning them on by default would be breaking and could potentially cause a lot of errors). @eslint/eslint-team Let's hash this out and I'll get to work! |
Could you clarify what the two options would do? I might be missing something, but I only see a need for one new option (to control whether function expressions are checked). |
Sorry that wasn't clear. After my initial reading, seemed like the two asks are to be able to require JSDocs for function expressions in assignments and object methods (both function expressions and object method shorthand syntax). I feel like it would be counter-intuitive to lump the object shorthand syntax in with a function expression option, but if everyone else is fine with that, I won't object. More concerned with getting this implemented for JSCS compatibility than anything else! |
I'm going to implement this with a |
ESLint-version: 1.10.3, default parser
configuration:
Running eslint (from a grunt task), I would expect this to cause an error:
Instead, it passes through fine.
So that's why I would propose an enhancement to the require-jsdoc rule to also recognise missing JSDoc blocks in functional expressions such as the above.
All of the below should pass through fine:
The text was updated successfully, but these errors were encountered: