Skip to content

Commit f257b5c

Browse files
committed
docs(linter/plugins): clarify JSDoc comments for tokens methods (#16062)
These doc comments were copied from ESLint. But it's not so helpful saying "params same as this other method" - better to specify them explicitly for each method. It also makes it easier to review the code.
1 parent df0b948 commit f257b5c

File tree

1 file changed

+34
-15
lines changed

1 file changed

+34
-15
lines changed

apps/oxlint/src-js/plugins/tokens.ts

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ export function resetTokens() {
195195
/**
196196
* Get all tokens that are related to the given node.
197197
* @param node - The AST node.
198-
* @param countOptions? - Options object. If this is a function then it's `countOptions.filter`.
198+
* @param countOptions? - Options object. If is a function, equivalent to `{ filter: fn }`.
199199
* @returns Array of `Token`s.
200200
*/
201201
/**
@@ -293,8 +293,9 @@ export function getTokens(
293293
/**
294294
* Get the first token of the given node.
295295
* @param node - The AST node.
296-
* @param skipOptions? - Options object. If this is a number then it's `options.skip`.
297-
* If this is a function then it's `options.filter`.
296+
* @param skipOptions? - Options object.
297+
* If is a number, equivalent to `{ skip: n }`.
298+
* If is a function, equivalent to `{ filter: fn }`.
298299
* @returns `Token`, or `null` if all were skipped.
299300
*/
300301
export function getFirstToken(node: Node, skipOptions?: SkipOptions | number | FilterFn | null): Token | null {
@@ -399,8 +400,9 @@ export function getFirstToken(node: Node, skipOptions?: SkipOptions | number | F
399400
/**
400401
* Get the first tokens of the given node.
401402
* @param node - The AST node.
402-
* @param countOptions? - Options object. If this is a number then it's `options.count`.
403-
* If this is a function then it's `options.filter`.
403+
* @param countOptions? - Options object.
404+
* If is a number, equivalent to `{ count: n }`.
405+
* If is a function, equivalent to `{ filter: fn }`.
404406
* @returns Array of `Token`s.
405407
*/
406408
export function getFirstTokens(node: Node, countOptions?: CountOptions | number | FilterFn | null): Token[] {
@@ -500,7 +502,9 @@ export function getFirstTokens(node: Node, countOptions?: CountOptions | number
500502
/**
501503
* Get the last token of the given node.
502504
* @param node - The AST node.
503-
* @param skipOptions? - Options object. Same options as `getFirstToken()`.
505+
* @param skipOptions? - Options object.
506+
* If is a number, equivalent to `{ skip: n }`.
507+
* If is a function, equivalent to `{ filter: fn }`.
504508
* @returns `Token`, or `null` if all were skipped.
505509
*/
506510
export function getLastToken(node: Node, skipOptions?: SkipOptions | number | FilterFn | null): Token | null {
@@ -596,7 +600,9 @@ export function getLastToken(node: Node, skipOptions?: SkipOptions | number | Fi
596600
/**
597601
* Get the last tokens of the given node.
598602
* @param node - The AST node.
599-
* @param countOptions? - Options object. Same options as `getFirstTokens()`.
603+
* @param countOptions? - Options object.
604+
* If is a number, equivalent to `{ count: n }`.
605+
* If is a function, equivalent to `{ filter: fn }`.
600606
* @returns Array of `Token`s.
601607
*/
602608
export function getLastTokens(node: Node, countOptions?: CountOptions | number | FilterFn | null): Token[] {
@@ -701,7 +707,9 @@ export function getLastTokens(node: Node, countOptions?: CountOptions | number |
701707
/**
702708
* Get the token that precedes a given node or token.
703709
* @param nodeOrToken - The AST node or token.
704-
* @param skipOptions? - Options object. Same options as `getFirstToken()`.
710+
* @param skipOptions? - Options object.
711+
* If is a number, equivalent to `{ skip: n }`.
712+
* If is a function, equivalent to `{ filter: fn }`.
705713
* @returns `Token`, or `null` if all were skipped.
706714
*/
707715
export function getTokenBefore(
@@ -812,7 +820,9 @@ export function getTokenOrCommentBefore(nodeOrToken: NodeOrToken | Comment, skip
812820
/**
813821
* Get the tokens that precede a given node or token.
814822
* @param nodeOrToken - The AST node or token.
815-
* @param countOptions? - Options object. Same options as `getFirstTokens()`.
823+
* @param countOptions? - Options object.
824+
* If is a number, equivalent to `{ count: n }`.
825+
* If is a function, equivalent to `{ filter: fn }`.
816826
* @returns Array of `Token`s.
817827
*/
818828
export function getTokensBefore(
@@ -907,7 +917,8 @@ export function getTokensBefore(
907917
/**
908918
* Get the token that follows a given node or token.
909919
* @param nodeOrToken - The AST node or token.
910-
* @param skipOptions? - Options object. Same options as `getFirstToken()`.
920+
* If is a number, equivalent to `{ skip: n }`.
921+
* If is a function, equivalent to `{ filter: fn }`.
911922
* @returns `Token`, or `null` if all were skipped.
912923
*/
913924
export function getTokenAfter(
@@ -1015,7 +1026,9 @@ export function getTokenOrCommentAfter(nodeOrToken: NodeOrToken | Comment, skip?
10151026
/**
10161027
* Get the tokens that follow a given node or token.
10171028
* @param nodeOrToken - The AST node or token.
1018-
* @param countOptions? - Options object. Same options as `getFirstTokens()`.
1029+
* @param countOptions? - Options object.
1030+
* If is a number, equivalent to `{ count: n }`.
1031+
* If is a function, equivalent to `{ filter: fn }`.
10191032
* @returns Array of `Token`s.
10201033
*/
10211034
export function getTokensAfter(
@@ -1129,7 +1142,8 @@ export function getTokensBetween(
11291142
* Get the first token between two non-overlapping nodes.
11301143
* @param nodeOrToken1 - Node before the desired token range.
11311144
* @param nodeOrToken2 - Node after the desired token range.
1132-
* @param skipOptions? - Options object. Same options as `getFirstToken()`.
1145+
* If is a number, equivalent to `{ skip: n }`.
1146+
* If is a function, equivalent to `{ filter: fn }`.
11331147
* @returns `Token`, or `null` if all were skipped.
11341148
*/
11351149
/* oxlint-disable no-unused-vars */
@@ -1146,7 +1160,9 @@ export function getFirstTokenBetween(
11461160
* Get the first tokens between two non-overlapping nodes.
11471161
* @param nodeOrToken1 - Node before the desired token range.
11481162
* @param nodeOrToken2 - Node after the desired token range.
1149-
* @param countOptions? - Options object. Same options as `getFirstTokens()`.
1163+
* @param countOptions? - Options object.
1164+
* If is a number, equivalent to `{ count: n }`.
1165+
* If is a function, equivalent to `{ filter: fn }`.
11501166
* @returns Array of `Token`s between `nodeOrToken1` and `nodeOrToken2`.
11511167
*/
11521168
/* oxlint-disable no-unused-vars */
@@ -1163,7 +1179,8 @@ export function getFirstTokensBetween(
11631179
* Get the last token between two non-overlapping nodes.
11641180
* @param nodeOrToken1 - Node before the desired token range.
11651181
* @param nodeOrToken2 - Node after the desired token range.
1166-
* @param skipOptions? - Options object. Same options as `getFirstToken()`.
1182+
* If is a number, equivalent to `{ skip: n }`.
1183+
* If is a function, equivalent to `{ filter: fn }`.
11671184
* @returns `Token`, or `null` if all were skipped.
11681185
*/
11691186
/* oxlint-disable no-unused-vars */
@@ -1180,7 +1197,9 @@ export function getLastTokenBetween(
11801197
* Get the last tokens between two non-overlapping nodes.
11811198
* @param nodeOrToken1 - Node before the desired token range.
11821199
* @param nodeOrToken2 - Node after the desired token range.
1183-
* @param countOptions? - Options object. Same options as `getFirstTokens()`.
1200+
* @param countOptions? - Options object.
1201+
* If is a number, equivalent to `{ count: n }`.
1202+
* If is a function, equivalent to `{ filter: fn }`.
11841203
* @returns Array of `Token`s between `nodeOrToken1` and `nodeOrToken2`.
11851204
*/
11861205
/* oxlint-disable no-unused-vars */

0 commit comments

Comments
 (0)