Skip to content

Commit 0f4a878

Browse files
authored
Merge pull request #146 from sandersn/parse-typescript-types
feat: test typeof and import types from Typescript
2 parents ea84996 + a99dc37 commit 0f4a878

File tree

4 files changed

+86
-7
lines changed

4 files changed

+86
-7
lines changed

README.md

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ function quux (foo) {
10161016
}
10171017
// Settings: {"jsdoc":{"additionalTagNames":{"customTags":["baz","bar"]}}}
10181018

1019-
/**
1019+
/**
10201020
* @abstract
10211021
* @access
10221022
* @alias
@@ -1104,9 +1104,9 @@ RegExp
11041104
<a name="eslint-plugin-jsdoc-rules-check-types-why-not-capital-case-everything"></a>
11051105
#### Why not capital case everything?
11061106

1107-
Why are `boolean`, `number` and `string` exempt from starting with a capital letter? Let's take `string` as an example. In Javascript, everything is an object. The string Object has prototypes for string functions such as `.toUpperCase()`.
1107+
Why are `boolean`, `number` and `string` exempt from starting with a capital letter? Let's take `string` as an example. In Javascript, everything is an object. The string Object has prototypes for string functions such as `.toUpperCase()`.
11081108

1109-
Fortunately we don't have to write `new String()` everywhere in our code. Javascript will automatically wrap string primitives into string Objects when we're applying a string function to a string primitive. This way the memory footprint is a tiny little bit smaller, and the [GC](https://en.wikipedia.org/wiki/Garbage_collection_(computer_science)) has less work to do.
1109+
Fortunately we don't have to write `new String()` everywhere in our code. Javascript will automatically wrap string primitives into string Objects when we're applying a string function to a string primitive. This way the memory footprint is a tiny little bit smaller, and the [GC](https://en.wikipedia.org/wiki/Garbage_collection_(computer_science)) has less work to do.
11101110

11111111
So in a sense, there two types of strings in Javascript; `{string}` literals, also called primitives and `{String}` Objects. We use the primitives because it's easier to write and uses less memory. `{String}` and `{string}` are technically both valid, but they are not the same.
11121112

@@ -1208,6 +1208,30 @@ function quux (foo, bar, baz) {
12081208
*/
12091209
function quux (foo, bar, baz) {
12101210

1211+
}
1212+
1213+
/**
1214+
* @param {typeof bar} foo
1215+
*/
1216+
function qux(foo) {
1217+
}
1218+
1219+
/**
1220+
* @param {import('./foo').bar.baz} foo
1221+
*/
1222+
function qux(foo) {
1223+
}
1224+
1225+
/**
1226+
* @param {(x: number, y: string) => string} foo
1227+
*/
1228+
function qux(foo) {
1229+
}
1230+
1231+
/**
1232+
* @param {() => string} foo
1233+
*/
1234+
function qux(foo) {
12111235
}
12121236
````
12131237

@@ -2457,6 +2481,16 @@ function quux (foo) {
24572481
*/
24582482
const quux = () => {}
24592483
// Message: Present JSDoc @returns declaration but not available return expression in function.
2484+
2485+
/**
2486+
* @returns {undefined} Foo.
2487+
* @returns {String} Foo.
2488+
*/
2489+
function quux () {
2490+
2491+
return foo;
2492+
}
2493+
// Message: Found more than one @returns declaration.
24602494
````
24612495

24622496
The following patterns are not considered problems:
@@ -2497,15 +2531,23 @@ function quux () {
24972531
*/
24982532
const quux = () => foo;
24992533

2500-
/**
2534+
/**
25012535
* @returns {Promise<void>}
25022536
*/
25032537
async function quux() {}
25042538

2505-
/**
2539+
/**
25062540
* @returns {Promise<void>}
25072541
*/
25082542
async () => {}
2543+
2544+
/**
2545+
* @returns Foo.
2546+
* @abstract
2547+
*/
2548+
function quux () {
2549+
throw new Error('must be implemented by subclass!');
2550+
}
25092551
````
25102552

25112553

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
},
77
"dependencies": {
88
"comment-parser": "^0.5.4",
9-
"jsdoctypeparser": "^2.0.0-alpha-8",
9+
"jsdoctypeparser": "3.1.0",
1010
"lodash": "^4.17.11"
1111
},
1212
"description": "JSDoc linting rules for ESLint.",
@@ -58,7 +58,7 @@
5858
"build": "rm -fr ./dist && NODE_ENV=production babel ./src --out-dir ./dist --copy-files --source-maps",
5959
"create-readme": "gitdown ./.README/README.md --output-file ./README.md && npm run add-assertions",
6060
"lint": "eslint ./src ./test",
61-
"test": "mocha --recursive --require @babel/register"
61+
"test": "mocha --recursive --require @babel/register --reporter progress"
6262
},
6363
"version": "1.0.0"
6464
}

src/rules/checkIndentation.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default iterateJsdoc(({
77
}) => {
88
const reg = new RegExp(/^[ \t]+\*[ \t]{2}/m);
99
const text = sourceCode.getText(jsdocNode);
10+
1011
if (reg.test(text)) {
1112
report('There must be no indentation.');
1213
}

test/rules/assertions/checkTypes.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,42 @@ export default {
158158
*/
159159
function quux (foo, bar, baz) {
160160
161+
}
162+
`
163+
},
164+
{
165+
code: `
166+
/**
167+
* @param {typeof bar} foo
168+
*/
169+
function qux(foo) {
170+
}
171+
`
172+
},
173+
{
174+
code: `
175+
/**
176+
* @param {import('./foo').bar.baz} foo
177+
*/
178+
function qux(foo) {
179+
}
180+
`
181+
},
182+
{
183+
code: `
184+
/**
185+
* @param {(x: number, y: string) => string} foo
186+
*/
187+
function qux(foo) {
188+
}
189+
`
190+
},
191+
{
192+
code: `
193+
/**
194+
* @param {() => string} foo
195+
*/
196+
function qux(foo) {
161197
}
162198
`
163199
}

0 commit comments

Comments
 (0)