Skip to content

Commit 6d98fb7

Browse files
committed
fix: add support for arrays
1 parent b702ebf commit 6d98fb7

File tree

3 files changed

+7
-21
lines changed

3 files changed

+7
-21
lines changed

src/__snapshots__/valid-message-syntax.test.js.snap

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,25 @@ exports[`Snapshot Tests for Invalid Code nested translations - icu syntax check
3030
}"
3131
`;
3232

33-
exports[`Snapshot Tests for Invalid Code no arrays or numbers 1`] = `
33+
exports[`Snapshot Tests for Invalid Code no empty objects 1`] = `
3434
"
3535
- Expected
3636
+ Received
3737
3838
Object {
3939
- \\"levelOne\\": \\"ObjectContaining<ValidMessages> | ValidMessage<String>\\",
40-
- \\"levelTwo\\": \\"ValidMessage<String>\\",
41-
+ \\"levelOne\\": \\"Array [] ===> TypeError: An Array cannot be a translation value.\\",
42-
+ \\"levelTwo\\": \\"Number(5) ===> Message must be a String.\\",
40+
+ \\"levelOne\\": \\"Object {} ===> SyntaxError: Empty object.\\",
4341
}"
4442
`;
4543

46-
exports[`Snapshot Tests for Invalid Code no empty objects 1`] = `
44+
exports[`Snapshot Tests for Invalid Code no numbers 1`] = `
4745
"
4846
- Expected
4947
+ Received
5048
5149
Object {
52-
- \\"levelOne\\": \\"ObjectContaining<ValidMessages> | ValidMessage<String>\\",
53-
+ \\"levelOne\\": \\"Object {} ===> SyntaxError: Empty object.\\",
50+
- \\"levelOne\\": \\"ValidMessage<String>\\",
51+
+ \\"levelOne\\": \\"Number(5) ===> Message must be a String.\\",
5452
}"
5553
`;
5654

src/valid-message-syntax.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const getTranslationFileSource = require('./util/get-translation-file-source');
1111

1212
/* Error tokens */
1313
const EMPTY_OBJECT = Symbol.for('EMPTY_OBJECT');
14-
const ARRAY = Symbol.for('ARRAY');
1514

1615
/* Formatting */
1716
const ALL_BACKSLASHES = /[\\]/g;
@@ -31,7 +30,6 @@ const prettyFormatTypePlugin = {
3130
const formatExpectedValue = ({ value }) => {
3231
switch (value) {
3332
case EMPTY_OBJECT:
34-
case ARRAY:
3533
return 'ObjectContaining<ValidMessages> | ValidMessage<String>';
3634
default:
3735
return 'ValidMessage<String>';
@@ -45,8 +43,6 @@ const formatReceivedValue = ({ value, error }) => {
4543
switch (value) {
4644
case EMPTY_OBJECT:
4745
return `${prettyFormat({})} ===> ${error}`;
48-
case ARRAY:
49-
return `${prettyFormat([])} ===> ${error}`;
5046
default:
5147
return `${prettyFormat(value, {
5248
plugins: [prettyFormatTypePlugin]
@@ -140,13 +136,6 @@ const validMessageSyntax = (context, source) => {
140136
error: new SyntaxError('Empty object.')
141137
});
142138
}
143-
} else if (Array.isArray(value)) {
144-
invalidMessages.push({
145-
value: ARRAY,
146-
key,
147-
path,
148-
error: new TypeError('An Array cannot be a translation value.')
149-
});
150139
} else {
151140
try {
152141
validate(value, key);

src/valid-message-syntax.test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,11 @@ describe('Snapshot Tests for Invalid Code', () => {
261261
});
262262
expect(strip(errors[0].message)).toMatchSnapshot();
263263
});
264-
test('no arrays or numbers', () => {
264+
test('no numbers', () => {
265265
const errors = run({
266266
code: `
267267
/*{
268-
"levelOne": [ "data" ],
269-
"levelTwo": 5
268+
"levelOne": 5
270269
}*//*path/to/file.json*/
271270
`,
272271
options: [

0 commit comments

Comments
 (0)