Skip to content

Why import type syntax marked as invalid? #677

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

Closed
krutoo opened this issue Jan 22, 2021 · 1 comment
Closed

Why import type syntax marked as invalid? #677

krutoo opened this issue Jan 22, 2021 · 1 comment
Labels

Comments

@krutoo
Copy link

krutoo commented Jan 22, 2021

Hi, i have two files with code:

// event.js
export class CustomEvent {}

// index.js
/**
 * @param {import('./event').CustomEvent} event Event.
 */
export function main (event) {
  console.log(event);
}

and config like:

module.exports = {
  // ...
  rules: {
    // ...
    'jsdoc/check-param-names': 'error',
    'jsdoc/valid-types': 'error',
  },
};

in terminal i have error:

> eslint ./src

/home/petrov_dm/Projects/eslint-plugin-jsdoc-tests/src/index.js
  2:0  error  Syntax error in type: import('./event').CustomEvent  jsdoc/valid-types

✖ 1 problem (1 error, 0 warnings)

there is repo with clean example of code:
https://github.com/krutoo/eslint-plugin-jsdoc-tests

Why this code is marked as with syntax error?
(this worked differently in previous plugin versions)

readme.md tells that is valid type syntax:
https://github.com/gajus/eslint-plugin-jsdoc#why-not-capital-case-everything

The following patterns are not considered problems:

with this code example:

/**
 * @param {import('./foo').bar.baz} foo
 */
function qux(foo) {
}
@brettz9
Copy link
Collaborator

brettz9 commented Jan 22, 2021

You need either parser: '@typescript-eslint/parser' or settings: {jsdoc: {mode: 'typescript'}} in your ESLint config since plain jsdoc does not support that import syntax; see, e.g., jsdoc/jsdoc#1632 and jsdoc/jsdoc#1645 . The reason the README accepts that without settings is because for the check-types rule, it is only checking for things like the casing of "Object".

Or as the docs for check-types put it:

Note that if there is an error parsing
types for a tag, the function will silently ignore that tag, leaving it to
the valid-types rule to report parsing errors.

For valid-types, you need proper parsing suitable for the mode (which defaults to "jsdoc" which supports module: syntax instead).

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

No branches or pull requests

2 participants