Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support for arrays #58

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
12 changes: 5 additions & 7 deletions src/__snapshots__/valid-message-syntax.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,25 @@ exports[`Snapshot Tests for Invalid Code nested translations - icu syntax check
}"
`;

exports[`Snapshot Tests for Invalid Code no arrays or numbers 1`] = `
exports[`Snapshot Tests for Invalid Code no empty objects 1`] = `
"
- Expected
+ Received

Object {
- \\"levelOne\\": \\"ObjectContaining<ValidMessages> | ValidMessage<String>\\",
- \\"levelTwo\\": \\"ValidMessage<String>\\",
+ \\"levelOne\\": \\"Array [] ===> TypeError: An Array cannot be a translation value.\\",
+ \\"levelTwo\\": \\"Number(5) ===> Message must be a String.\\",
+ \\"levelOne\\": \\"Object {} ===> SyntaxError: Empty object.\\",
}"
`;

exports[`Snapshot Tests for Invalid Code no empty objects 1`] = `
exports[`Snapshot Tests for Invalid Code no numbers 1`] = `
"
- Expected
+ Received

Object {
- \\"levelOne\\": \\"ObjectContaining<ValidMessages> | ValidMessage<String>\\",
+ \\"levelOne\\": \\"Object {} ===> SyntaxError: Empty object.\\",
- \\"levelOne\\": \\"ValidMessage<String>\\",
+ \\"levelOne\\": \\"Number(5) ===> Message must be a String.\\",
}"
`;

Expand Down
11 changes: 0 additions & 11 deletions src/valid-message-syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const getTranslationFileSource = require('./util/get-translation-file-source');

/* Error tokens */
const EMPTY_OBJECT = Symbol.for('EMPTY_OBJECT');
const ARRAY = Symbol.for('ARRAY');

/* Formatting */
const ALL_BACKSLASHES = /[\\]/g;
Expand All @@ -31,7 +30,6 @@ const prettyFormatTypePlugin = {
const formatExpectedValue = ({ value }) => {
switch (value) {
case EMPTY_OBJECT:
case ARRAY:
return 'ObjectContaining<ValidMessages> | ValidMessage<String>';
default:
return 'ValidMessage<String>';
Expand All @@ -45,8 +43,6 @@ const formatReceivedValue = ({ value, error }) => {
switch (value) {
case EMPTY_OBJECT:
return `${prettyFormat({})} ===> ${error}`;
case ARRAY:
return `${prettyFormat([])} ===> ${error}`;
default:
return `${prettyFormat(value, {
plugins: [prettyFormatTypePlugin]
Expand Down Expand Up @@ -140,13 +136,6 @@ const validMessageSyntax = (context, source) => {
error: new SyntaxError('Empty object.')
});
}
} else if (Array.isArray(value)) {
invalidMessages.push({
value: ARRAY,
key,
path,
error: new TypeError('An Array cannot be a translation value.')
});
} else {
try {
validate(value, key);
Expand Down
5 changes: 2 additions & 3 deletions src/valid-message-syntax.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,11 @@ describe('Snapshot Tests for Invalid Code', () => {
});
expect(strip(errors[0].message)).toMatchSnapshot();
});
test('no arrays or numbers', () => {
test('no numbers', () => {
const errors = run({
code: `
/*{
"levelOne": [ "data" ],
"levelTwo": 5
"levelOne": 5
}*//*path/to/file.json*/
`,
options: [
Expand Down