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

valid-types provides error with using import from other file #343

Closed
krutoo opened this issue Jul 17, 2019 · 11 comments
Closed

valid-types provides error with using import from other file #343

krutoo opened this issue Jul 17, 2019 · 11 comments
Labels

Comments

@krutoo
Copy link

krutoo commented Jul 17, 2019

Hi. Please help me resolve problem with "jsdoc/valid-types" rule. Import of types provides error:

image

error text: "JSDoc syntax error"

eslint-plugin-jsdoc version: 15.5.2
eslint version: 6.0.0

eslint rule configuration:

{
  // ...
  rules: {
    // ...
    "jsdoc/valid-types": "error"
  }
}
@gajus gajus added the question label Jul 17, 2019
@brettz9
Copy link
Collaborator

brettz9 commented Jul 17, 2019

Indeed, support for the TypeScript import() syntax has been added in the underlying jsdoctypeparser and testing this code in our testing environment (and checking the type in the jsdoctypeparser demo) reports no issues:

/**
       * Component.
       * @param {import('../properties-list/properties-list.jsx').PropertyType} prop Property.
       */
       const DownloadList = ({ files }) => {};

Please be sure to restart your IDE after you have installed updates to eslint-plugin-jsdoc. With the Atom linting package at least, it apparently caches the files.

@brettz9
Copy link
Collaborator

brettz9 commented Jul 17, 2019

I expect this is a stale files issue, so closing, but feel free to comment further and we can reopen if we can replicate.

@brettz9 brettz9 closed this as completed Jul 17, 2019
@krutoo
Copy link
Author

krutoo commented Jul 18, 2019

@brettz Thank you for answer. I have problem with lint in terminal by yarn.
It provides next error:
image

I don't use cache in ESLint. I restart my IDE (VS Code, PHPStorm) but i think that is independent things.

@brettz9
Copy link
Collaborator

brettz9 commented Jul 18, 2019

Ok, and you are sure you have updated to the latest eslint-plugin-jsdoc, along with its dependencies? Your yarn.lock file should be showing version "5.0.1" for the dependency "jsdoctypeparser" because earlier versions did not properly support import().

If you have confirmed this, can you reduce your test case to a single erring block, and reduce your .eslintrc to the minimum set of rules?

@brettz9 brettz9 reopened this Jul 18, 2019
@krutoo
Copy link
Author

krutoo commented Jul 18, 2019

@brettz9 here is screenshot of yarn.lock file:
image

I already have only one erring block now.

I understood that rule valid-jsdoc provides this error. After remove this rule i have no errors.

But this rule is necessary for my project. What can i do?

@brettz9
Copy link
Collaborator

brettz9 commented Jul 18, 2019

Ok, good to see you have the dependency, but by a single erring block, I mean you have no other code in the file that triggers the error. And to be safe, try removing all other eslint rules and configs/plugins and paste your exact code and config that still reproduces the issue.

@krutoo
Copy link
Author

krutoo commented Jul 18, 2019

That config (with old "valid-jsdoc" rule) provides error:

{
  "rules": {
    "valid-jsdoc": [
      "error",
      {
        "prefer": {
          "arg": "param",
          "argument": "param",
          "class": "constructor",
          "virtual": "abstract",
          "returns": "return"
        },
        "preferType": {
          "any": "*",
          "Null": "null",
          "Undefined": "undefined",
          "Boolean": "boolean",
          "Number": "number",
          "int": "number",
          "integer": "number",
          "float": "number",
          "String": "string",
          "Symbol": "symbol",
          "object": "Object",
          "array": "Array",
          "function": "Function"
        },
        "requireReturn": false,
        "requireReturnType": true,
        "requireParamType": true,
        "matchDescription": ".+",
        "requireParamDescription": true,
        "requireReturnDescription": true
      }
    ],
  }
}

In this code:

/**
 * Component.
 * @param {import('../properties-list/properties-list.jsx').PropertyType} prop Property.
 */
const DownloadList = ({ files }) => {/* ... */};

But i just remove "valid-jsdoc" rule and replace it on rules from this plugin. And it works without errors.
I non't now it issue is needed now, because "valid-jsdoc" is deprecated rule. Maybe it can be closed.

@brettz9
Copy link
Collaborator

brettz9 commented Jul 18, 2019

Ahh, I see, I mistook the "valid-jsdoc" in your previous post as being the same as valid-types, so yes, I think you are on the right track to remove it, and if you weren't aware, the wiki page at https://github.com/gajus/eslint-plugin-jsdoc/wiki/Comparison-with-deprecated-JSdoc-related-ESLint-rules shows the equivalent features of valid-jsdoc in eslint-plugin-jsdoc. Glad it's working!

@nemoDreamer
Copy link

nemoDreamer commented Jul 3, 2021

This is still happening on eslint-plugin-jsdoc@35.4.1 in VS Code:

image

But VS Code does correctly find the type this way:

image


I'm using

{
    extends: [
        "airbnb-base",
        "plugin:jsdoc/recommended",
        "plugin:prettier/recommended",
    ],
    rules: [
        // deprecated rule conflicting with `eslint-plugin-jsdoc`?
        "valid-jsdoc": "off",
        "require-jsdoc": "off",
    ],
}

... but also happens with only plugin:jsdoc/recommended...


Maybe this issue came back because of the switch to jsdoc-type-pratt-parser? 🤞

@brettz9
Copy link
Collaborator

brettz9 commented Jul 4, 2021

To avoid errors, you need to set settings.jsdoc.mode to "typescript" or to include @typescript/eslint-parser as your parser.

@brettz9 brettz9 closed this as completed Jul 4, 2021
@nemoDreamer
Copy link

Thank you, @brettz9, that was the missing piece!

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

4 participants