Skip to content
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

publicOnly ignored when inside public functions that are missing jsdoc #812

Closed
FTWinston opened this issue Dec 14, 2021 · 9 comments
Closed

Comments

@FTWinston
Copy link

When the publicOnly option is specified, the rule seems to be triggered for local functions within public members, if the public member itself lacks jsdoc. This is similar to #654, but with an extra caveat.

Expected behavior

Local (nested) functions should not trigger a linter failure if not documented, regardless of whether the enclosing public function is missing required jsdoc.

Actual behavior

Local (nested) functions trigger a linter failure if not documented, but only when the enclosing public function is missing required jsdoc.

ESLint Config

module.exports = {
	plugins: ['jsdoc'],
	rules: {
		'jsdoc/require-jsdoc': [
			'error',
			{
				publicOnly: true,
				require: {
					ClassDeclaration: true,
					ClassExpression: true,
					ArrowFunctionExpression: true,
					FunctionDeclaration: true,
					FunctionExpression: true,
					MethodDefinition: true,
				},
			},
		],
	},
};

ESLint sample

The inner function here triggers the rule:

export function outer() {
    function inner() {
        console.log('foo');
    }

    inner();
}

But the inner function here does not:

/**
 *
 */
export function outer() {
    function inner() {
        console.log('foo');
    }

    inner();
}

Environment

  • Node version: 16.13.0
  • ESLint version: 7.32.0
  • eslint-plugin-jsdoc version: 37.2.0
@FTWinston
Copy link
Author

This is a bit of an edge case, and only really relevant when applying eslint-plugin-jsdoc to code that didn't already use it.

@brettz9
Copy link
Collaborator

brettz9 commented Dec 15, 2021

The applying of eslint-plugin-jsdoc to code that didn't already use it is handled within the jsdoc/require-jsdoc rule specifically.

Since the other example should trigger the rule since the main export is missing jsdoc, it appears you mean that what is happening is that we are misreporting the line number for jsdoc/require-jsdoc as coming from the inner function when it should be reporting the outer public one. Is that correct?

@brettz9
Copy link
Collaborator

brettz9 commented Dec 15, 2021

Ah testing locally, it appears instead that we are reporting both the inner and outer in such a case when we should only be reporting one...

@FTWinston
Copy link
Author

FTWinston commented Dec 15, 2021

Yes, that's what I'd meant. Sorry for the confusion!

Outer correctly reports an error, but inner also reports an error, incorrectly.

It's only really an issue when the fixer is enabled, as it creates an extra comment block.

@brettz9
Copy link
Collaborator

brettz9 commented Dec 15, 2021

This is somewhat of a hackish solution, but will hopefully do the trick.

@gajus
Copy link
Owner

gajus commented Dec 15, 2021

🎉 This issue has been resolved in version 37.2.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@gajus gajus added the released label Dec 15, 2021
@FTWinston
Copy link
Author

Wow that was fast, thanks!

That's fixed the problem with nested function declarations, but an equivalent problem still occurs with nested arrow functions.

i.e. with inner here:

export const outer = () => {
    const inner = () => {
        console.log('foo');
    };

    inner();
};

and here:

export function outer() {
    const inner = () => {
        console.log('foo');
    };

    inner();
};

but not here:

export const outer = () => {
    function inner() {
        console.log('foo');
    }

    inner();
};

My apologies for not mentioning arrow functions previously. Would you like me to raise a separate ticket?

brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Dec 15, 2021
@gajus
Copy link
Owner

gajus commented Dec 15, 2021

🎉 This issue has been resolved in version 37.2.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@FTWinston
Copy link
Author

Superb, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants