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

Unable to parse namepath with readonly #104

Open
dhurlburtusa opened this issue Dec 15, 2021 · 4 comments
Open

Unable to parse namepath with readonly #104

dhurlburtusa opened this issue Dec 15, 2021 · 4 comments

Comments

@dhurlburtusa
Copy link

The following should all be valid JSDoc:

/**
 * @param readonly
 */
/**
 * @param {boolean} readonly
 */
/**
 * @param {object} params
 * @param {boolean} params.readonly
 */

in jsdoc or typescript (maybe closure too) mode but they fail to parse.

When running tryParse with 'readonly' or 'params.readonly'`, it errors with "Error: No parslet found for token: 'readonly' with value 'readonly'".

tryParse('readonly');
// Error: No parslet found for token: \'readonly\' with value \'readonly\'
tryParse('params.readonly');
// Error: No parslet found for token: \'readonly\' with value \'readonly\'

Note that the following both run without error:

tryParse('readOnly')
tryParse('params.readOnly')

I believe this was caused by PR #98.

@simonseyock
Copy link
Member

This has similar problems as #102

Imagine: @type {readonly}. This expression is not valid typescript.

The problem is that eslint-plugin-jsdoc parses type and name independently with jsdoc-type-pratt-parser and the parser does not provide different modes for the type and the name.

@jdatskuid
Copy link

I ran into this error today in a typedef. We have an object with a property named "readonly" and I get this error.

ESLint v7.7.0

Example:

/**
 * An object interface
 * @typedef  {Object} FooBar
 * @property {boolean} readonly
 * @property {boolean} private
 * @property {boolean} public
 * @property {boolean} constant
 */

Error:

32:0  error  Syntax error in namepath: readonly          jsdoc/valid-types

My only workaround was to disable the valid-types rule for the JSDoc comment:

/* eslint-disable jsdoc/valid-types */
/**
 * An object interface
 * @typedef  {Object} FooBar
 * @property {boolean} readonly
 * @property {boolean} private
 * @property {boolean} public
 * @property {boolean} constant
 */
/* eslint-enable */

@dysphasia
Copy link

I also received this issue when defining an object with the property name "is"

/**
 * @param {object} props
 * @param {string} props.is
 */ 
3:1  warning  Syntax error in namepath: props.is  jsdoc/valid-types

This workaround removed the ESLint error

/**
 * @param {object} props
 * @param {string} props."is"
 */ 

Package Versions:

  • eslint: 8.37.0
  • eslint-plugin-jsdoc: 40.1.1

@brettz9
Copy link
Collaborator

brettz9 commented Apr 4, 2024

For eslint-plugin-jsdoc v48.2.3, I've at least added support for the few problematic keywords I could detect ("readonly", "is", "import", "typeof"). I just check if the name is a direct match and if so, forego checking. This does not handle nested cases which still require escaping ala obj."readonly".

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

No branches or pull requests

5 participants