Skip to content

Commit d8da4a4

Browse files
committed
test(linter/plugins): clarify tests for message placeholders (#14417)
Follow-on after #14416. Clarify the tests for message interpolation. There were some mismatches between names used in the tests and what they did, which made it a little tricky to verify them.
1 parent 382c5be commit d8da4a4

File tree

3 files changed

+56
-29
lines changed

3 files changed

+56
-29
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
var testWithNoData = {};
22
var testWithName = {};
3+
var testWithNameNoData = {};
34
var testWithMultiple = {};
5+
var testWithMultipleNoData = {};
46
var testWithMissingData = {};
57
var testWithSpaces = {};

apps/oxlint/test/fixtures/message_id_interpolation/output.snap.md

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,61 @@
33

44
# stdout
55
```
6-
x interpolation-test(no-var): Variable {{name}} should not use var
6+
x interpolation-test(no-var): Variables should not use var
77
,-[files/index.js:1:1]
88
1 | var testWithNoData = {};
99
: ^^^^^^^^^^^^^^^^^^^^^^^^
1010
2 | var testWithName = {};
1111
`----
1212
13-
x interpolation-test(no-var): Variable testWithName of type string should not use var
13+
x interpolation-test(no-var): Variable `testWithName` should not use var
1414
,-[files/index.js:2:1]
1515
1 | var testWithNoData = {};
1616
2 | var testWithName = {};
1717
: ^^^^^^^^^^^^^^^^^^^^^^
18-
3 | var testWithMultiple = {};
18+
3 | var testWithNameNoData = {};
1919
`----
2020
21-
x interpolation-test(no-var): Variable testWithMultiple of type number should not use var
21+
x interpolation-test(no-var): Variable `{{name}}` should not use var
2222
,-[files/index.js:3:1]
2323
2 | var testWithName = {};
24-
3 | var testWithMultiple = {};
25-
: ^^^^^^^^^^^^^^^^^^^^^^^^^^
26-
4 | var testWithMissingData = {};
24+
3 | var testWithNameNoData = {};
25+
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26+
4 | var testWithMultiple = {};
2727
`----
2828
29-
x interpolation-test(no-var): Value is example and name is {{name}}
29+
x interpolation-test(no-var): Variable `testWithMultiple` of type `string` should not use var
3030
,-[files/index.js:4:1]
31-
3 | var testWithMultiple = {};
32-
4 | var testWithMissingData = {};
33-
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
34-
5 | var testWithSpaces = {};
31+
3 | var testWithNameNoData = {};
32+
4 | var testWithMultiple = {};
33+
: ^^^^^^^^^^^^^^^^^^^^^^^^^^
34+
5 | var testWithMultipleNoData = {};
3535
`----
3636
37-
x interpolation-test(no-var): Value with spaces: hello and name: world
37+
x interpolation-test(no-var): Variable `{{name}}` of type `{{type}}` should not use var
3838
,-[files/index.js:5:1]
39-
4 | var testWithMissingData = {};
40-
5 | var testWithSpaces = {};
39+
4 | var testWithMultiple = {};
40+
5 | var testWithMultipleNoData = {};
41+
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
42+
6 | var testWithMissingData = {};
43+
`----
44+
45+
x interpolation-test(no-var): Value is `example` and name is `{{name}}`
46+
,-[files/index.js:6:1]
47+
5 | var testWithMultipleNoData = {};
48+
6 | var testWithMissingData = {};
49+
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
50+
7 | var testWithSpaces = {};
51+
`----
52+
53+
x interpolation-test(no-var): Value with spaces is `hello` and name is `world`
54+
,-[files/index.js:7:1]
55+
6 | var testWithMissingData = {};
56+
7 | var testWithSpaces = {};
4157
: ^^^^^^^^^^^^^^^^^^^^^^^^
4258
`----
4359
44-
Found 0 warnings and 5 errors.
60+
Found 0 warnings and 7 errors.
4561
Finished in Xms on 1 file using X threads.
4662
```
4763

apps/oxlint/test/fixtures/message_id_interpolation/plugin.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ const plugin: Plugin = {
99
meta: {
1010
messages: {
1111
noData: 'Variables should not use var',
12-
withName: 'Variable {{name}} should not use var',
13-
withMultiple: 'Variable {{name}} of type {{type}} should not use var',
12+
withName: 'Variable `{{name}}` should not use var',
13+
withMultiple: 'Variable `{{name}}` of type `{{type}}` should not use var',
1414
// edge cases
15-
missingData: 'Value is {{value}} and name is {{name}}',
16-
withSpaces: 'Value with spaces: {{ value }} and name: {{ name }}',
15+
missingData: 'Value is `{{value}}` and name is `{{name}}`',
16+
withSpaces: 'Value with spaces is `{{ value }}` and name is `{{ name }}`',
1717
},
1818
},
1919
create(context) {
@@ -26,14 +26,27 @@ const plugin: Plugin = {
2626
if (firstDeclaration.id.type === 'Identifier') {
2727
const name = firstDeclaration.id.name;
2828

29-
// Test with single placeholder
3029
if (name === 'testWithNoData') {
30+
// Test with no placeholders, no data
31+
context.report({
32+
messageId: 'noData',
33+
node,
34+
});
35+
} else if (name === 'testWithName') {
36+
// Test with single placeholder
37+
context.report({
38+
messageId: 'withName',
39+
node,
40+
data: { name },
41+
});
42+
} else if (name === 'testWithNameNoData') {
43+
// Test with single placeholder, but no data
3144
context.report({
3245
messageId: 'withName',
3346
node,
3447
});
35-
} // Test with multiple placeholders
36-
else if (name === 'testWithName') {
48+
} else if (name === 'testWithMultiple') {
49+
// Test with multiple placeholders
3750
context.report({
3851
messageId: 'withMultiple',
3952
node,
@@ -42,15 +55,11 @@ const plugin: Plugin = {
4255
type: 'string',
4356
},
4457
});
45-
} // Test without data
46-
else if (name === 'testWithMultiple') {
58+
} else if (name === 'testWithMultipleNoData') {
59+
// Test with multiple placeholders, but no data
4760
context.report({
4861
messageId: 'withMultiple',
4962
node,
50-
data: {
51-
name,
52-
type: 'number',
53-
},
5463
});
5564
} else if (name === 'testWithMissingData') {
5665
// Test missing data - placeholder should remain

0 commit comments

Comments
 (0)