File tree 2 files changed +6
-2
lines changed
2 files changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import { Language } from '../utils/getLanguage'
5
5
import { includeAllKeys , excludeKeys } from './utils'
6
6
7
7
const locales = readdirSync ( resolve ( __dirname , '../locales' ) ) . filter ( ( file ) => {
8
- return file . includes ( '.json' ) // exclude unnecessary files
8
+ return file . includes ( '.json' )
9
9
} )
10
10
11
11
describe ( 'should match name regex' , ( ) => {
@@ -17,6 +17,7 @@ describe('should match name regex', () => {
17
17
* @example reusable locale: zh-Hant
18
18
*/
19
19
const regex = / ^ [ a - z A - Z ] { 2 } ( - [ a - z A - Z ] { 2 } ) * .j s o n $ | ^ [ a - z A - Z ] { 2 } ( - [ a - z A - z ] { 4 } ) * .j s o n $ /
20
+
20
21
locales . forEach ( ( locale ) => {
21
22
it ( `for ${ locale } ` , ( ) => {
22
23
expect ( locale ) . toMatch ( regex )
@@ -33,7 +34,7 @@ describe('should include full keys', () => {
33
34
} )
34
35
} )
35
36
36
- describe ( "should not include unnecessary keys" , ( ) => {
37
+ describe ( "should not include extra keys" , ( ) => {
37
38
const structure = require ( '../schema/locale.json' ) as Language
38
39
locales . forEach ( ( locale ) => {
39
40
it ( `for ${ locale } ` , ( ) => {
Original file line number Diff line number Diff line change 7
7
export function includeAllKeys ( obj : Object , schema : Object ) {
8
8
for ( let key in schema ) {
9
9
if ( ! obj . hasOwnProperty ( key ) ) {
10
+ console . log ( `key '${ key } ' lost` )
10
11
return false
11
12
}
12
13
if ( schema [ key ] !== null ) {
13
14
if ( typeof schema [ key ] === 'string' ) {
14
15
if ( typeof obj [ key ] !== schema [ key ] ) {
16
+ console . error ( `the type of ${ obj . toString ( ) } is incorrect` )
15
17
return false
16
18
}
17
19
} else if ( typeof schema [ key ] === 'object' ) {
@@ -33,6 +35,7 @@ export function includeAllKeys(obj: Object, schema: Object) {
33
35
export function excludeKeys ( obj : Object , schema : Object ) {
34
36
for ( let key in obj ) {
35
37
if ( ! schema . hasOwnProperty ( key ) ) {
38
+ console . error ( `unexpected key: ${ key } ` )
36
39
return false
37
40
}
38
41
if ( schema [ key ] !== null && typeof schema [ key ] === 'object' ) {
You can’t perform that action at this time.
0 commit comments