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] @property is ignored #1269

Closed
regseb opened this issue Jul 20, 2024 · 6 comments · Fixed by #1271 · 4 remaining pull requests
Closed

[check-template-names] @property is ignored #1269

regseb opened this issue Jul 20, 2024 · 6 comments · Fixed by #1271 · 4 remaining pull requests

Comments

@regseb
Copy link
Contributor

regseb commented Jul 20, 2024

Expected behavior

eslint-plugin-jsdoc should support two @template in one file.

Actual behavior

Oops! Something went wrong! :(

ESLint: 9.7.0

Error: No parslet found for token: 'EOF'
Occurred while linting /home/regseb/testcase/index.js:1
Rule: "jsdoc/check-template-names"
    at Parser.parseIntermediateType (/home/regseb/testcase/node_modules/jsdoc-type-pratt-parser/dist/index.js:364:23)
    at Parser.parseType (/home/regseb/testcase/node_modules/jsdoc-type-pratt-parser/dist/index.js:355:42)
    at Parser.parse (/home/regseb/testcase/node_modules/jsdoc-type-pratt-parser/dist/index.js:345:33)
    at parse (/home/regseb/testcase/node_modules/jsdoc-type-pratt-parser/dist/index.js:1599:68)
    at iterateJsdoc.iterateAllJsdocs (file:///home/regseb/testcase/node_modules/eslint-plugin-jsdoc/src/rules/checkTemplateNames.js:70:5)
    at iterate (file:///home/regseb/testcase/node_modules/eslint-plugin-jsdoc/src/iterateJsdoc.js:2049:3)
    at callIterator (file:///home/regseb/testcase/node_modules/eslint-plugin-jsdoc/src/iterateJsdoc.js:2225:7)
    at Program:exit (file:///home/regseb/testcase/node_modules/eslint-plugin-jsdoc/src/iterateJsdoc.js:2318:11)
    at ruleErrorHandler (/home/regseb/testcase/node_modules/eslint/lib/linter/linter.js:1117:48)
    at /home/regseb/testcase/node_modules/eslint/lib/linter/safe-emitter.js:45:58

ESLint Config

import jsdoc from "eslint-plugin-jsdoc";

export default [
    {
        plugins: { jsdoc },
        rules: {
            "jsdoc/check-template-names": "error",
        }
    }
];

ESLint sample

/**
 * @template {Object} T
 * @typedef Foo<T>
 * @prop {T} bar
 */

/**
 * @template {Object} T
 * @typedef Baz<T>
 * @prop {T} qux
 */

Environment

  • Node version: v22.4.1
  • ESLint version: v9.7.0
  • eslint-plugin-jsdoc version: 48.8.1
@brettz9
Copy link
Collaborator

brettz9 commented Jul 20, 2024

The issue is apparently instead that a generic cannot be indicated in the name like this: @typedef Foo<T>. See the other examples for what is currently allowable.

Does TypeScript accept this form of JSDoc? I don't see it at https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html#template .

@regseb
Copy link
Contributor Author

regseb commented Jul 20, 2024

You're right, the error is reported with a single @typedef.

I tested the following file in TS Playground. Without a generic or with an invalid generic, TypeScript returns the same errors (number not assignable to string). The <T> shouldn't be added to the @typedef.

/**
 * @template {Object} T
 * @typedef Foo<OUPS_I_MAKE_A_TYPO>
 * @prop {T} bar
 */

/**
 * @type {Foo<string>}
 */
const fooValid = { bar: "" };

/**
 * @type {Foo<string>}
 */
const fooInvalid = { bar: 0 };
//                   ~~~


/**
 * @template {Object} T
 * @typedef Baz
 * @prop {T} qux
 */

/**
 * @type {Baz<string>}
 */
const bazValid = { qux: "" };

/**
 * @type {Baz<string>}
 */
const bazInvalid = { qux: 0 };
//                   ~~~

eslint-plugin-jsdoc should report a syntax error for a JSDoc comment with <T>.

@brettz9
Copy link
Collaborator

brettz9 commented Jul 20, 2024

Yeah, I think that is a dupe of #374.

@regseb
Copy link
Contributor Author

regseb commented Jul 20, 2024

The No parslet found for token: 'EOF' error isn't related to @template. I have the error with the following code.

/**
 * @typedef Foo
 * @prop {string} bar
 */

And no error with:

/**
 * @typedef {Object} Foo
 * @prop {string} bar
 */

In the examples in the TypeScript documentation, the type is always specified. But tsc supports when it's not specified.

@brettz9
Copy link
Collaborator

brettz9 commented Jul 20, 2024

Ah, great to know the playground can have tsconfig set to JavaScript. Wasn't aware of that.

I have confirmed the bug as you report now, yes. For now, I can change to silently ignore such parse errors here as when there is no type present, but I'll leave the issue open to try to handle the case for use of @property types. That sound reasonable?

brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Jul 20, 2024
brettz9 added a commit that referenced this issue Jul 20, 2024
…h missing or bad typedef type; partial fix for #1269
@brettz9 brettz9 changed the title [check-template-names] two @template in one file [check-template-names] @property is ignored Jul 20, 2024
brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Jul 20, 2024
Copy link

🎉 This issue has been resolved in version 48.8.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

This was referenced Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment