Last active
September 12, 2020 19:11
-
-
Save michaelfig/dc4c5665e9259f5316e35885567daa6b to your computer and use it in GitHub Desktop.
eslint-plugin-jsdoc doesn't pick up global JSDocs like Typescript does
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @typedef {123} Bar | |
*/ | |
// Bar is a "global JSDoc type" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
soil:t michael$ yarn lint | |
yarn run v1.22.4 | |
$ eslint '**/*.js' | |
/Users/michael/t/expected-error.js | |
4:0 warning The type 'Bar' is undefined jsdoc/no-undefined-types | |
/Users/michael/t/foo.js | |
4:0 warning The type 'Bar' is undefined jsdoc/no-undefined-types | |
✖ 2 problems (0 errors, 2 warnings) | |
✨ Done in 0.75s. | |
soil:t michael$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @ts-check | |
/** | |
* @type {Bar} | |
*/ | |
export const err = 99; | |
// Would expect no ESLint warnings, but we get: | |
// /Users/michael/t/expected-error.js | |
// 4:0 warning The type 'Bar' is undefined jsdoc/no-undefined-types | |
// | |
// As expected from Typescript: | |
// expected-error.js:6:14 - error TS2322: Type '99' is not assignable to type '123'. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @ts-check | |
/** | |
* @type {Bar} | |
*/ | |
export const foo = 123; | |
// Would expect no errors or warnings from ESLint, but instead we get | |
// /Users/michael/t/foo.js | |
// 4:0 warning The type 'Bar' is undefined jsdoc/no-undefined-types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
// This file can contain .js-specific Typescript compiler config. | |
{ | |
"compilerOptions": { | |
"target": "esnext", | |
"noEmit": true, | |
"downlevelIteration": true, | |
"strictNullChecks": true, | |
"moduleResolution": "node", | |
}, | |
"include": ["**/*.js"], | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "t", | |
"version": "1.0.0", | |
"private": true, | |
"main": "foo.js", | |
"author": "Michael FIG <michael+eslint@fig.org>", | |
"license": "MIT", | |
"devDependencies": { | |
"@typescript-eslint/parser": "^4.1.0", | |
"eslint": "^7.8.1", | |
"eslint-plugin-jsdoc": "^30.4.2", | |
"typescript": "^4.0.2" | |
}, | |
"scripts": { | |
"lint": "eslint '**/*.js'", | |
"lint:types": "tsc -p jsconfig.json" | |
}, | |
"eslintConfig": { | |
"extends": [ | |
"plugin:jsdoc/recommended" | |
], | |
"parser": "@typescript-eslint/parser", | |
"env": { | |
"es6": true | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment