Skip to content

Commit 63bf3c2

Browse files
lilnasycamc314
authored andcommitted
chore(linter): snapshot test start, end, range, and loc for comments
1 parent 1e93ceb commit 63bf3c2

File tree

2 files changed

+136
-83
lines changed

2 files changed

+136
-83
lines changed

apps/oxlint/test/fixtures/unicode-comments/output.snap.md

Lines changed: 122 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -3,86 +3,132 @@
33

44
# stdout
55
```
6-
x unicode-comments(unicode-comments): getAllComments: [
7-
| {
8-
| "type": "Line",
9-
| "value": " Unicode test with emojis and multi-byte characters"
10-
| },
11-
| {
12-
| "type": "Line",
13-
| "value": " Line comment with emoji"
14-
| },
15-
| {
16-
| "type": "Block",
17-
| "value": "*\n * Function with emoji in JSDoc\n * @param {string} name - User's name 👤\n * @returns {string} Greeting message\n "
18-
| },
19-
| {
20-
| "type": "Line",
21-
| "value": " Comment with multiple emojis 🚀⭐💫"
22-
| },
23-
| {
24-
| "type": "Block",
25-
| "value": " Block comment with unicode: ñáéíóú "
26-
| },
27-
| {
28-
| "type": "Block",
29-
| "value": " Multi-byte comment: 你好世界 "
30-
| },
31-
| {
32-
| "type": "Line",
33-
| "value": " Line comment: ñáéíóú"
34-
| },
35-
| {
36-
| "type": "Block",
37-
| "value": "*\n * JSDoc with emojis and unicode: 你好 👋\n * @param {number} count - Number of items 🔢\n "
38-
| },
39-
| {
40-
| "type": "Line",
41-
| "value": " Comment with mixed unicode: αβγδε русский עברית"
42-
| },
43-
| {
44-
| "type": "Block",
45-
| "value": " Block: ñáéíóú 🚀 "
46-
| },
47-
| {
48-
| "type": "Line",
49-
| "value": " Final comment with emoji: 🎉✨🎊"
50-
| }
51-
| ]
52-
,-[files/unicode-comments.js:2:1]
53-
1 | // Unicode test with emojis and multi-byte characters
54-
2 | ,-> const greeting = 'Hello 🌍'; // Line comment with emoji
55-
3 | |
56-
4 | | /**
57-
5 | | * Function with emoji in JSDoc
58-
6 | | * @param {string} name - User's name 👤
59-
7 | | * @returns {string} Greeting message
60-
8 | | */
61-
9 | | function greetUser(name) {
62-
10 | | // Comment with multiple emojis 🚀⭐💫
63-
11 | | const message = `Hello ${name}! 🌟`;
64-
12 | | /* Block comment with unicode: ñáéíóú */
65-
13 | | return message;
66-
14 | | }
67-
15 | |
68-
16 | | /* Multi-byte comment: 你好世界 */
69-
17 | | const 你好世界 = 'Testing üöä'; // Line comment: ñáéíóú
70-
18 | |
71-
19 | | /**
6+
x unicode-comments(unicode-comments): {
7+
| "lines": "1,0-1,53",
8+
| "value": " Unicode test with emojis and multi-byte characters"
9+
| }
10+
,-[files/unicode-comments.js:1:1]
11+
1 | // Unicode test with emojis and multi-byte characters
12+
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13+
2 | const greeting = 'Hello 🌍'; // Line comment with emoji
14+
`----
15+
16+
x unicode-comments(unicode-comments): {
17+
| "lines": "2,29-2,55",
18+
| "value": " Line comment with emoji"
19+
| }
20+
,-[files/unicode-comments.js:2:32]
21+
1 | // Unicode test with emojis and multi-byte characters
22+
2 | const greeting = 'Hello 🌍'; // Line comment with emoji
23+
: ^^^^^^^^^^^^^^^^^^^^^^^^^^
24+
3 |
25+
`----
26+
27+
x unicode-comments(unicode-comments): {
28+
| "lines": "4,0-8,3",
29+
| "value": "*\n * Function with emoji in JSDoc\n * @param {string} name - User's name 👤\n * @returns {string} Greeting message\n "
30+
| }
31+
,-[files/unicode-comments.js:4:1]
32+
3 |
33+
4 | ,-> /**
34+
5 | | * Function with emoji in JSDoc
35+
6 | | * @param {string} name - User's name 👤
36+
7 | | * @returns {string} Greeting message
37+
8 | `-> */
38+
9 | function greetUser(name) {
39+
`----
40+
41+
x unicode-comments(unicode-comments): {
42+
| "lines": "10,2-10,39",
43+
| "value": " Comment with multiple emojis 🚀⭐💫"
44+
| }
45+
,-[files/unicode-comments.js:10:3]
46+
9 | function greetUser(name) {
47+
10 | // Comment with multiple emojis 🚀⭐💫
48+
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
49+
11 | const message = `Hello ${name}! 🌟`;
50+
`----
51+
52+
x unicode-comments(unicode-comments): {
53+
| "lines": "12,2-12,42",
54+
| "value": " Block comment with unicode: ñáéíóú "
55+
| }
56+
,-[files/unicode-comments.js:12:3]
57+
11 | const message = `Hello ${name}! 🌟`;
58+
12 | /* Block comment with unicode: ñáéíóú */
59+
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
60+
13 | return message;
61+
`----
62+
63+
x unicode-comments(unicode-comments): {
64+
| "lines": "16,0-16,30",
65+
| "value": " Multi-byte comment: 你好世界 "
66+
| }
67+
,-[files/unicode-comments.js:16:1]
68+
15 |
69+
16 | /* Multi-byte comment: 你好世界 */
70+
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
71+
17 | const 你好世界 = 'Testing üöä'; // Line comment: ñáéíóú
72+
`----
73+
74+
x unicode-comments(unicode-comments): {
75+
| "lines": "17,28-17,51",
76+
| "value": " Line comment: ñáéíóú"
77+
| }
78+
,-[files/unicode-comments.js:17:40]
79+
16 | /* Multi-byte comment: 你好世界 */
80+
17 | const 你好世界 = 'Testing üöä'; // Line comment: ñáéíóú
81+
: ^^^^^^^^^^^^^^^^^^^^^^^
82+
18 |
83+
`----
84+
85+
x unicode-comments(unicode-comments): {
86+
| "lines": "19,0-22,3",
87+
| "value": "*\n * JSDoc with emojis and unicode: 你好 👋\n * @param {number} count - Number of items 🔢\n "
88+
| }
89+
,-[files/unicode-comments.js:19:1]
90+
18 |
91+
19 | ,-> /**
7292
20 | | * JSDoc with emojis and unicode: 你好 👋
7393
21 | | * @param {number} count - Number of items 🔢
74-
22 | | */
75-
23 | | function processItems(count) {
76-
24 | | // Comment with mixed unicode: αβγδε русский עברית
77-
25 | | const result = count * 2; /* Block: ñáéíóú 🚀 */
78-
26 | | return result;
79-
27 | | }
80-
28 | |
81-
29 | | // Final comment with emoji: 🎉✨🎊
82-
30 | `-> const finalVar = 'Done ✅';
94+
22 | `-> */
95+
23 | function processItems(count) {
96+
`----
97+
98+
x unicode-comments(unicode-comments): {
99+
| "lines": "24,2-24,52",
100+
| "value": " Comment with mixed unicode: αβγδε русский עברית"
101+
| }
102+
,-[files/unicode-comments.js:24:3]
103+
23 | function processItems(count) {
104+
24 | // Comment with mixed unicode: αβγδε русский עברית
105+
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
106+
25 | const result = count * 2; /* Block: ñáéíóú 🚀 */
107+
`----
108+
109+
x unicode-comments(unicode-comments): {
110+
| "lines": "25,28-25,50",
111+
| "value": " Block: ñáéíóú 🚀 "
112+
| }
113+
,-[files/unicode-comments.js:25:29]
114+
24 | // Comment with mixed unicode: αβγδε русский עברית
115+
25 | const result = count * 2; /* Block: ñáéíóú 🚀 */
116+
: ^^^^^^^^^^^^^^^^^^^^^^
117+
26 | return result;
118+
`----
119+
120+
x unicode-comments(unicode-comments): {
121+
| "lines": "29,0-29,34",
122+
| "value": " Final comment with emoji: 🎉✨🎊"
123+
| }
124+
,-[files/unicode-comments.js:29:1]
125+
28 |
126+
29 | // Final comment with emoji: 🎉✨🎊
127+
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
128+
30 | const finalVar = 'Done ✅';
83129
`----
84130
85-
Found 0 warnings and 1 error.
131+
Found 0 warnings and 11 errors.
86132
Finished in Xms on 1 file using X threads.
87133
```
88134

apps/oxlint/test/fixtures/unicode-comments/plugin.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1+
import assert from 'node:assert';
12
import type { Plugin, Rule } from '../../../dist/index.js';
23

34
const unicodeCommentsRule: Rule = {
45
create(context) {
56
const { sourceCode } = context;
6-
const { ast } = sourceCode;
77

8-
context.report({
9-
message: `getAllComments: ${
10-
JSON.stringify(sourceCode.getAllComments().map(c => ({ type: c.type, value: c.value })), null, 4)
11-
}`,
12-
node: ast,
13-
});
8+
for (const comment of sourceCode.getAllComments()) {
9+
assert(comment.start === comment.range[0]);
10+
assert(comment.end === comment.range[1]);
11+
const { start, end } = comment.loc;
12+
context.report({
13+
message: JSON.stringify(
14+
{ lines: `${start.line},${start.column}-${end.line},${end.column}`, value: comment.value },
15+
null,
16+
4,
17+
),
18+
node: comment,
19+
});
20+
}
1421

1522
return {};
1623
},

0 commit comments

Comments
 (0)