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

Way to lint typos in param types? #52

Closed
pdehaan opened this issue Dec 1, 2017 · 6 comments
Closed

Way to lint typos in param types? #52

pdehaan opened this issue Dec 1, 2017 · 6 comments

Comments

@pdehaan
Copy link
Contributor

pdehaan commented Dec 1, 2017

I have a few code bases which have JSDoc comments with typos, similar to the following:

 * @param  {Orbject} weightedVariations Weight of a variant.

Is there any way to check that a param's type is valid, and not some clumsy typo like "Orbject" or "stirng"?

@tdmalone
Copy link

@pdehaan
Copy link
Contributor Author

pdehaan commented Dec 16, 2017

@tdmalone I wasn't able to get "jsdoc/check-types" to catch my clumsy typo errors:

// index.js
/**
 * What a useless method...
 * @param  {string}  a First string.
 * @param  {String}  b Second string.
 * @param  {srtring} c Third string.
 * @return {HelloWorld}    Concatenated string.
 */
function func1(a, b, c) {
  return a + b + c;
}

module.exports = func1;
// .eslintrc.js
module.exports = {
  env: {
    es6: true,
    node: true
  },

  plugins: [
    'jsdoc'
  ],

  root: true,

  rules: {
    'jsdoc/check-types': 'error'
  }
};
{
  "name": "jsdoc-testr",
  "version": "1.0.0",
  "author": "Peter deHaan",
  "devDependencies": {
    "eslint": "4.13.1",
    "eslint-plugin-jsdoc": "3.3.0"
  },
  "scripts": {
    "test": "eslint ."
  }
}

Now, running $ npm test triggers ESLint and gives me the following output:

$ npm test

> jsdoc-testr@1.0.0 test /Users/pdehaan/dev/tmp/del/jsdoc-testr
> eslint .

/Users/pdehaan/dev/tmp/del/jsdoc-testr/index.js
  1:1  error  Invalid JSDoc @param "b" type "String"  jsdoc/check-types

✖ 1 problem (1 error, 0 warnings)
  1 error, 0 warnings potentially fixable with the `--fix` option.

npm ERR! Test failed.  See above for more details.

So if I understand correctly, jsdoc/check-types is only checking the native object types against a list of valid values, and therefore it catches my "string" vs "String" error. But it isn't catching my {srtring} typo, or wildly random {HelloWorld} data type.

@tdmalone
Copy link

I do apologise - I misunderstood the intent of check-types!

@pdehaan
Copy link
Contributor Author

pdehaan commented Dec 16, 2017

I do apologise - I misunderstood the intent of check-types!

Me too! I had to do a lot of digging and reading of source code to try and figure out what was going on and why it wasn't doing what I naively expected. I was hoping there was an option or other rule for strict data type validation so it'd only recognize native data types, and force me to explicitly specify other data types.

PS: This plugin rocks! A huge thanks to everybody involved for working on it!

@brettz9
Copy link
Collaborator

brettz9 commented May 14, 2019

You can use no-undefined-types. However, to add awareness of the existence of your HelloWorld type, you'd either need to define it in the document, add it within /* globals */, or give us a PR for #99. :)

@brettz9
Copy link
Collaborator

brettz9 commented May 14, 2019

I therefore think this issue can be closed.

@gajus gajus closed this as completed May 15, 2019
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

4 participants