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
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var testWithNoData = {};
var testWithName = {};
var testWithNameNoData = {};
var testWithMultiple = {};
var testWithMultipleNoData = {};
var testWithMissingData = {};
var testWithSpaces = {};
48 changes: 32 additions & 16 deletions apps/oxlint/test/fixtures/message_id_interpolation/output.snap.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,61 @@

# stdout
```
x interpolation-test(no-var): Variable {{name}} should not use var
x interpolation-test(no-var): Variables should not use var
,-[files/index.js:1:1]
1 | var testWithNoData = {};
: ^^^^^^^^^^^^^^^^^^^^^^^^
2 | var testWithName = {};
`----

x interpolation-test(no-var): Variable testWithName of type string should not use var
x interpolation-test(no-var): Variable `testWithName` should not use var
,-[files/index.js:2:1]
1 | var testWithNoData = {};
2 | var testWithName = {};
: ^^^^^^^^^^^^^^^^^^^^^^
3 | var testWithMultiple = {};
3 | var testWithNameNoData = {};
`----

x interpolation-test(no-var): Variable testWithMultiple of type number should not use var
x interpolation-test(no-var): Variable `{{name}}` should not use var
,-[files/index.js:3:1]
2 | var testWithName = {};
3 | var testWithMultiple = {};
: ^^^^^^^^^^^^^^^^^^^^^^^^^^
4 | var testWithMissingData = {};
3 | var testWithNameNoData = {};
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4 | var testWithMultiple = {};
`----

x interpolation-test(no-var): Value is example and name is {{name}}
x interpolation-test(no-var): Variable `testWithMultiple` of type `string` should not use var
,-[files/index.js:4:1]
3 | var testWithMultiple = {};
4 | var testWithMissingData = {};
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5 | var testWithSpaces = {};
3 | var testWithNameNoData = {};
4 | var testWithMultiple = {};
: ^^^^^^^^^^^^^^^^^^^^^^^^^^
5 | var testWithMultipleNoData = {};
`----

x interpolation-test(no-var): Value with spaces: hello and name: world
x interpolation-test(no-var): Variable `{{name}}` of type `{{type}}` should not use var
,-[files/index.js:5:1]
4 | var testWithMissingData = {};
5 | var testWithSpaces = {};
4 | var testWithMultiple = {};
5 | var testWithMultipleNoData = {};
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6 | var testWithMissingData = {};
`----

x interpolation-test(no-var): Value is `example` and name is `{{name}}`
,-[files/index.js:6:1]
5 | var testWithMultipleNoData = {};
6 | var testWithMissingData = {};
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7 | var testWithSpaces = {};
`----

x interpolation-test(no-var): Value with spaces is `hello` and name is `world`
,-[files/index.js:7:1]
6 | var testWithMissingData = {};
7 | var testWithSpaces = {};
: ^^^^^^^^^^^^^^^^^^^^^^^^
`----

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

Expand Down
35 changes: 22 additions & 13 deletions apps/oxlint/test/fixtures/message_id_interpolation/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ const plugin: Plugin = {
meta: {
messages: {
noData: 'Variables should not use var',
withName: 'Variable {{name}} should not use var',
withMultiple: 'Variable {{name}} of type {{type}} should not use var',
withName: 'Variable `{{name}}` should not use var',
withMultiple: 'Variable `{{name}}` of type `{{type}}` should not use var',
// edge cases
missingData: 'Value is {{value}} and name is {{name}}',
withSpaces: 'Value with spaces: {{ value }} and name: {{ name }}',
missingData: 'Value is `{{value}}` and name is `{{name}}`',
withSpaces: 'Value with spaces is `{{ value }}` and name is `{{ name }}`',
},
},
create(context) {
Expand All @@ -26,14 +26,27 @@ const plugin: Plugin = {
if (firstDeclaration.id.type === 'Identifier') {
const name = firstDeclaration.id.name;

// Test with single placeholder
if (name === 'testWithNoData') {
// Test with no placeholders, no data
context.report({
messageId: 'noData',
node,
});
} else if (name === 'testWithName') {
// Test with single placeholder
context.report({
messageId: 'withName',
node,
data: { name },
});
} else if (name === 'testWithNameNoData') {
// Test with single placeholder, but no data
context.report({
messageId: 'withName',
node,
});
} // Test with multiple placeholders
else if (name === 'testWithName') {
} else if (name === 'testWithMultiple') {
// Test with multiple placeholders
context.report({
messageId: 'withMultiple',
node,
Expand All @@ -42,15 +55,11 @@ const plugin: Plugin = {
type: 'string',
},
});
} // Test without data
else if (name === 'testWithMultiple') {
} else if (name === 'testWithMultipleNoData') {
// Test with multiple placeholders, but no data
context.report({
messageId: 'withMultiple',
node,
data: {
name,
type: 'number',
},
});
} else if (name === 'testWithMissingData') {
// Test missing data - placeholder should remain
Expand Down
Loading