Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
198 changes: 122 additions & 76 deletions apps/oxlint/test/fixtures/unicode-comments/output.snap.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,86 +3,132 @@

# stdout
```
x unicode-comments(unicode-comments): getAllComments: [
| {
| "type": "Line",
| "value": " Unicode test with emojis and multi-byte characters"
| },
| {
| "type": "Line",
| "value": " Line comment with emoji"
| },
| {
| "type": "Block",
| "value": "*\n * Function with emoji in JSDoc\n * @param {string} name - User's name 👤\n * @returns {string} Greeting message\n "
| },
| {
| "type": "Line",
| "value": " Comment with multiple emojis 🚀⭐💫"
| },
| {
| "type": "Block",
| "value": " Block comment with unicode: ñáéíóú "
| },
| {
| "type": "Block",
| "value": " Multi-byte comment: 你好世界 "
| },
| {
| "type": "Line",
| "value": " Line comment: ñáéíóú"
| },
| {
| "type": "Block",
| "value": "*\n * JSDoc with emojis and unicode: 你好 👋\n * @param {number} count - Number of items 🔢\n "
| },
| {
| "type": "Line",
| "value": " Comment with mixed unicode: αβγδε русский עברית"
| },
| {
| "type": "Block",
| "value": " Block: ñáéíóú 🚀 "
| },
| {
| "type": "Line",
| "value": " Final comment with emoji: 🎉✨🎊"
| }
| ]
,-[files/unicode-comments.js:2:1]
1 | // Unicode test with emojis and multi-byte characters
2 | ,-> const greeting = 'Hello 🌍'; // Line comment with emoji
3 | |
4 | | /**
5 | | * Function with emoji in JSDoc
6 | | * @param {string} name - User's name 👤
7 | | * @returns {string} Greeting message
8 | | */
9 | | function greetUser(name) {
10 | | // Comment with multiple emojis 🚀⭐💫
11 | | const message = `Hello ${name}! 🌟`;
12 | | /* Block comment with unicode: ñáéíóú */
13 | | return message;
14 | | }
15 | |
16 | | /* Multi-byte comment: 你好世界 */
17 | | const 你好世界 = 'Testing üöä'; // Line comment: ñáéíóú
18 | |
19 | | /**
x unicode-comments(unicode-comments): {
| "lines": "1,0-1,53",
| "value": " Unicode test with emojis and multi-byte characters"
| }
,-[files/unicode-comments.js:1:1]
1 | // Unicode test with emojis and multi-byte characters
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 | const greeting = 'Hello 🌍'; // Line comment with emoji
`----

x unicode-comments(unicode-comments): {
| "lines": "2,29-2,55",
| "value": " Line comment with emoji"
| }
,-[files/unicode-comments.js:2:32]
1 | // Unicode test with emojis and multi-byte characters
2 | const greeting = 'Hello 🌍'; // Line comment with emoji
: ^^^^^^^^^^^^^^^^^^^^^^^^^^
3 |
`----

x unicode-comments(unicode-comments): {
| "lines": "4,0-8,3",
| "value": "*\n * Function with emoji in JSDoc\n * @param {string} name - User's name 👤\n * @returns {string} Greeting message\n "
| }
,-[files/unicode-comments.js:4:1]
3 |
4 | ,-> /**
5 | | * Function with emoji in JSDoc
6 | | * @param {string} name - User's name 👤
7 | | * @returns {string} Greeting message
8 | `-> */
9 | function greetUser(name) {
`----

x unicode-comments(unicode-comments): {
| "lines": "10,2-10,39",
| "value": " Comment with multiple emojis 🚀⭐💫"
| }
,-[files/unicode-comments.js:10:3]
9 | function greetUser(name) {
10 | // Comment with multiple emojis 🚀⭐💫
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11 | const message = `Hello ${name}! 🌟`;
`----

x unicode-comments(unicode-comments): {
| "lines": "12,2-12,42",
| "value": " Block comment with unicode: ñáéíóú "
| }
,-[files/unicode-comments.js:12:3]
11 | const message = `Hello ${name}! 🌟`;
12 | /* Block comment with unicode: ñáéíóú */
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13 | return message;
`----

x unicode-comments(unicode-comments): {
| "lines": "16,0-16,30",
| "value": " Multi-byte comment: 你好世界 "
| }
,-[files/unicode-comments.js:16:1]
15 |
16 | /* Multi-byte comment: 你好世界 */
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17 | const 你好世界 = 'Testing üöä'; // Line comment: ñáéíóú
`----

x unicode-comments(unicode-comments): {
| "lines": "17,28-17,51",
| "value": " Line comment: ñáéíóú"
| }
,-[files/unicode-comments.js:17:40]
16 | /* Multi-byte comment: 你好世界 */
17 | const 你好世界 = 'Testing üöä'; // Line comment: ñáéíóú
: ^^^^^^^^^^^^^^^^^^^^^^^
18 |
`----

x unicode-comments(unicode-comments): {
| "lines": "19,0-22,3",
| "value": "*\n * JSDoc with emojis and unicode: 你好 👋\n * @param {number} count - Number of items 🔢\n "
| }
,-[files/unicode-comments.js:19:1]
18 |
19 | ,-> /**
20 | | * JSDoc with emojis and unicode: 你好 👋
21 | | * @param {number} count - Number of items 🔢
22 | | */
23 | | function processItems(count) {
24 | | // Comment with mixed unicode: αβγδε русский עברית
25 | | const result = count * 2; /* Block: ñáéíóú 🚀 */
26 | | return result;
27 | | }
28 | |
29 | | // Final comment with emoji: 🎉✨🎊
30 | `-> const finalVar = 'Done ✅';
22 | `-> */
23 | function processItems(count) {
`----

x unicode-comments(unicode-comments): {
| "lines": "24,2-24,52",
| "value": " Comment with mixed unicode: αβγδε русский עברית"
| }
,-[files/unicode-comments.js:24:3]
23 | function processItems(count) {
24 | // Comment with mixed unicode: αβγδε русский עברית
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25 | const result = count * 2; /* Block: ñáéíóú 🚀 */
`----

x unicode-comments(unicode-comments): {
| "lines": "25,28-25,50",
| "value": " Block: ñáéíóú 🚀 "
| }
,-[files/unicode-comments.js:25:29]
24 | // Comment with mixed unicode: αβγδε русский עברית
25 | const result = count * 2; /* Block: ñáéíóú 🚀 */
: ^^^^^^^^^^^^^^^^^^^^^^
26 | return result;
`----

x unicode-comments(unicode-comments): {
| "lines": "29,0-29,34",
| "value": " Final comment with emoji: 🎉✨🎊"
| }
,-[files/unicode-comments.js:29:1]
28 |
29 | // Final comment with emoji: 🎉✨🎊
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30 | const finalVar = 'Done ✅';
`----

Found 0 warnings and 1 error.
Found 0 warnings and 11 errors.
Finished in Xms on 1 file using X threads.
```

Expand Down
21 changes: 14 additions & 7 deletions apps/oxlint/test/fixtures/unicode-comments/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import assert from 'node:assert';
import type { Plugin, Rule } from '../../../dist/index.js';

const unicodeCommentsRule: Rule = {
create(context) {
const { sourceCode } = context;
const { ast } = sourceCode;

context.report({
message: `getAllComments: ${
JSON.stringify(sourceCode.getAllComments().map(c => ({ type: c.type, value: c.value })), null, 4)
}`,
node: ast,
});
for (const comment of sourceCode.getAllComments()) {
assert(comment.start === comment.range[0]);
assert(comment.end === comment.range[1]);
const { start, end } = comment.loc;
context.report({
message: JSON.stringify(
{ lines: `${start.line},${start.column}-${end.line},${end.column}`, value: comment.value },
null,
4,
),
node: comment,
});
}

return {};
},
Expand Down
Loading