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

rule no-undefined-types does not work #109

Closed
DarkPark opened this issue Dec 3, 2018 · 22 comments · Fixed by #222
Closed

rule no-undefined-types does not work #109

DarkPark opened this issue Dec 3, 2018 · 22 comments · Fixed by #222

Comments

@DarkPark
Copy link

DarkPark commented Dec 3, 2018

eslint version: 5.9.0
eslint-plugin-jsdoc version: 3.9.1
Config:

'jsdoc/check-param-names': 1,
'jsdoc/check-tag-names': 1,
'jsdoc/check-types': 1,
'jsdoc/newline-after-description': 1,
'jsdoc/no-undefined-types': 1,
'jsdoc/require-description': 0,
'jsdoc/require-description-complete-sentence': 0,
'jsdoc/require-example': 0,
'jsdoc/require-hyphen-before-param-description': 1,
'jsdoc/require-param': 1,
'jsdoc/require-param-description': 1,
'jsdoc/require-param-name': 1,
'jsdoc/require-param-type': 1,
'jsdoc/require-returns-description': 1,
'jsdoc/require-returns-type': 1,
'jsdoc/valid-types': 1

Your own example:

const MyType = require('my-library').MyType;

/**
 * @param {MyType} foo - Bar.
 */
function quux(foo) {

}

gives the error warning The type 'MyType' is undefined jsdoc/no-undefined-types

@bary12
Copy link
Contributor

bary12 commented Dec 3, 2018

How come the test passes but the actual behavior is different? Is this a problem with the test suite?

@brettz9
Copy link
Collaborator

brettz9 commented May 14, 2019

I'm no longer seeing this issue. @DarkPark , can you confirm?

@brettz9
Copy link
Collaborator

brettz9 commented May 14, 2019

(This test is now a part of the suite, so I assume it has since been fixed.)

@DarkPark
Copy link
Author

@brettz9 unfortunately the problem remains.

$ eslint/bin/eslint.js -v
v5.16.0

Run check with the config.js:

$ eslint/bin/eslint.js -c config.js test.js
v5.16.0

Result:

test.js
  3:7   error    'MyType' is assigned a value but never used  no-unused-vars
  6:0   warning  The type 'MyType' is undefined               jsdoc/no-undefined-types
  8:10  error    'quux' is defined but never used             no-unused-vars
  8:17  error    'foo' is defined but never used              no-unused-vars
  8:23  error    Unexpected empty function 'quux'             no-empty-function

✖ 5 problems (4 errors, 1 warning)

There are some other unrelated expected issues here, please ignore them.

@brettz9
Copy link
Collaborator

brettz9 commented May 14, 2019

Did you check against master? The latest commit was made 6 days ago.

@DarkPark
Copy link
Author

no
this check was done with the latest npm version

@brettz9
Copy link
Collaborator

brettz9 commented May 14, 2019

Ok, well, you can try changing to the following (and running npm install) to confirm:

"devDependencies": {
    "eslint-plugin-jsdoc": "https://github.com/gajus/eslint-plugin-jsdoc"
}

@DarkPark
Copy link
Author

strange but your advice doesn't work at all

Oops! Something went wrong! :(

ESLint: 5.16.0.
ESLint couldn't find the plugin "eslint-plugin-jsdoc". This can happen for a couple different reasons:
...

There are only 3 files in node_modules/eslint-plugin-jsdoc:

LICENSE
package.json
README.md

@DarkPark
Copy link
Author

anyway I've used npm package "eslint-plugin-jsdoc": "^4.8.4"
it was released 3 days ago

@brettz9
Copy link
Collaborator

brettz9 commented May 14, 2019

Oh, my apologies! 4.8.4 should be ok and the Github address won't work as the dist files aren't on Github.

@brettz9
Copy link
Collaborator

brettz9 commented May 14, 2019

And you ran npm i against 4.8.4?

@DarkPark
Copy link
Author

yes

    "dependencies": {
        "eslint": "^5.16.0",
        "eslint-plugin-jsdoc": "^4.8.4"
    }

@brettz9
Copy link
Collaborator

brettz9 commented May 14, 2019

I set up a local repository with this .eslintrc.js config:

module.exports = {
    parserOptions: {
        "ecmaVersion": 6
    },
    plugins: ['jsdoc'],
    rules: {
        'jsdoc/check-param-names': 1,
        'jsdoc/check-tag-names': 1,
        'jsdoc/check-types': 1,
        'jsdoc/newline-after-description': 1,
        'jsdoc/no-undefined-types': 1,
        'jsdoc/require-description': 0,
        'jsdoc/require-description-complete-sentence': 0,
        'jsdoc/require-example': 0,
        'jsdoc/require-hyphen-before-param-description': 1,
        'jsdoc/require-param': 1,
        'jsdoc/require-param-description': 1,
        'jsdoc/require-param-name': 1,
        'jsdoc/require-param-type': 1,
        'jsdoc/require-returns-description': 1,
        'jsdoc/require-returns-type': 1,
        'jsdoc/valid-types': 1
    }
}

and this test file, test.js:

const MyType = require('my-library').MyType;

/**
 * @param {MyType} foo - Bar.
 */
function quux(foo) {

}

and this package.json with all the init defaults besides dependencies:

{
  "name": "eslint-plugin-jsdoc-test-109",
  "version": "1.0.0",
  "description": "",
  "main": ".eslintrc.js",
  "scripts": {
    "eslint": "eslint .",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "eslint": "^5.16.0",
    "eslint-plugin-jsdoc": "^4.8.4"
  }
}

and running ./node_modules/.bin/eslint test.js from the command line gives no errors.

@brettz9
Copy link
Collaborator

brettz9 commented May 14, 2019

Just making sure you actually ran npm install again after changing it in dependencies, as one can sometimes forget to do this...

@DarkPark
Copy link
Author

@brettz9 thanks
your example helped to find a culprit
in my config i use environment setup:

env: {
    commonjs: true,
    es6: true,
    node: true
}

commenting these two lines:

commonjs: true,
node: true

resolves the issue though I don't understand how it works

@brettz9
Copy link
Collaborator

brettz9 commented May 14, 2019

Ok, and I see jsdoc/no-undefined-types': 1 as the sole rule is enough to show the problem. And it is apparently because in Node, const doesn't set variables as globals, which is what the rule is checking for. I'll see about taking a look.

@DarkPark
Copy link
Author

thank you, as I really need to use node env

@brettz9
Copy link
Collaborator

brettz9 commented May 14, 2019

I've submitted PR #222 as a fix; it is now passing in Node/commonjs in my testing added to the PR, so we'll see about it possibly getting merged.

@DarkPark
Copy link
Author

thanks

@gajus
Copy link
Owner

gajus commented May 21, 2019

🎉 This issue has been resolved in version 6.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@gajus gajus added the released label May 21, 2019
@DarkPark
Copy link
Author

it works
thank you

@brettz9
Copy link
Collaborator

brettz9 commented May 22, 2019

Excellent!

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

Successfully merging a pull request may close this issue.

4 participants