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

check-template-names reports on @template names that are not a single capital letter #1352

Closed
RobertAKARobin opened this issue Jan 25, 2025 · 4 comments · Fixed by #1353
Closed

Comments

@RobertAKARobin
Copy link

ESLint sample

/**
 * @template Input
 * @param {Input} input
 * @returns {Input}
 */
function echo(input) {
	return input;
}

const myString = echo(`hello`);
const myNum = echo(32);

Expected behavior

Expected no errors.

Actual behavior

check-template-names reports:

@template Input is not in use

ESLint Config

import jsdoc from 'eslint-plugin-jsdoc';

export default [
	{
		files: [`**/*.js`],
		plugins: {
			jsdoc,
		},
		rules: {
			'jsdoc/check-template-names': `error`,
		},
	},
];

Environment

  • Node version: 23.6.0
  • ESLint version 9.19.0
  • eslint-plugin-jsdoc version: 50.6.2
@RobertAKARobin
Copy link
Author

RobertAKARobin commented Jan 25, 2025

I believe the culprit is this RegEx, /^[A-Z]$/:

https://github.com/gajus/eslint-plugin-jsdoc/blob/main/src/rules/checkTemplateNames.js#L40

Many people name their type variables with a single capital letter, which would match this RegEx. However I find such variables very hard to read and so prefer to use more descriptive type names.

Oddly, it looks like descriptive template names are allowed but only in Typescript files:

https://github.com/gajus/eslint-plugin-jsdoc/blob/main/test/rules/assertions/checkTemplateNames.js#L538

brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Jan 25, 2025
…e letters; fixes gajus#1352

Single letters in JSDoc blocks still expected for template names in `require-template` rule.
brettz9 added a commit that referenced this issue Jan 25, 2025
…e letters; fixes #1352

Single letters in JSDoc blocks still expected for template names in `require-template` rule.
Copy link

🎉 This issue has been resolved in version 50.6.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@brettz9
Copy link
Collaborator

brettz9 commented Jan 25, 2025

This should now be fixed.

Note that when using templates within JSDoc types, the require-template rule still only checks for names that are a single letter. The reason for this is that we otherwise have no idea in that rule which name is a template and which is some other variable (we just hope the user doesn't use single letters for normal variables). But indeed, we don't need to restrict things in this rule.

@RobertAKARobin
Copy link
Author

Holy cow, that was fast! Thanks!

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