File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed
apps/oxlint/test/fixtures/sourceCode_token_methods Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change 33
44# stdout
55```
6+ x token-plugin(token): Tokens for VariableDeclaration, including comments:
7+ | Keyword loc=1:6-1:9 range=6-9 "var"
8+ | Identifier loc=1:10-1:16 range=10-16 "answer"
9+ | Block loc=1:17-1:22 range=17-22 "B"
10+ | Punctuator loc=1:23-1:24 range=23-24 "="
11+ | Block loc=1:25-1:30 range=25-30 "C"
12+ | Identifier loc=1:31-1:32 range=31-32 "a"
13+ | Block loc=1:33-1:38 range=33-38 "D"
14+ | Punctuator loc=1:39-1:40 range=39-40 "*"
15+ | Identifier loc=1:41-1:42 range=41-42 "b"
16+ | Punctuator loc=1:42-1:43 range=42-43 ";"
17+ ,-[files/eslint-test-case.js:1:7]
18+ 1 | /*A*/ var answer /*B*/ = /*C*/ a /*D*/ * b; /*E*/ //F\n call();\n/*Z*/
19+ : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20+ `----
21+
622 x token-plugin(token): Tokens for VariableDeclaration:
723 | Keyword loc=1:6-1:9 range=6-9 "var"
824 | Identifier loc=1:10-1:16 range=10-16 "answer"
348364 61 | `-> }
349365 `----
350366
351- Found 0 warnings and 20 errors.
367+ Found 0 warnings and 21 errors.
352368Finished in Xms on 2 files using X threads.
353369```
354370
Original file line number Diff line number Diff line change @@ -22,6 +22,23 @@ const rule: Rule = {
2222 . join ( '\n' ) ,
2323 node,
2424 } ) ;
25+ const tokensWithComments = sourceCode . getTokens ( node , { includeComments : true } ) ;
26+ if ( tokensWithComments . length > tokens . length ) {
27+ context . report ( {
28+ message :
29+ `Tokens for ${ node . type } , including comments:\n` +
30+ tokensWithComments
31+ . map (
32+ ( { type, loc, range, value } ) =>
33+ `${ type . padEnd ( 17 ) } ` +
34+ `loc=${ loc . start . line } :${ loc . start . column } -${ loc . end . line } :${ loc . end . column } ` . padEnd ( 16 ) +
35+ `range=${ range [ 0 ] } -${ range [ 1 ] } ` . padEnd ( 10 ) +
36+ `"${ value } "` ,
37+ )
38+ . join ( '\n' ) ,
39+ node,
40+ } ) ;
41+ }
2542 }
2643 } ,
2744 } ;
You can’t perform that action at this time.
0 commit comments