File tree Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -2,10 +2,22 @@ import { writeFileSync } from 'fs';
22import { sync as mkdirp } from 'mkdirp' ;
33
44import { readSchemas } from '../src/utils' ;
5+ import { cleanFor } from '../src/utils/cleanse' ;
56
67const FIXTURE_DIR = __dirname + '/../../../__fixtures__' ;
78const OUTPUT_DIR = __dirname + '/../../../__output__' ;
89
10+ describe ( 'cleanFor' , ( ) => {
11+ it ( 'works' , ( ) => {
12+ expect ( cleanFor ( 'NftInfoResponse_for_Empty' ) ) . toEqual (
13+ 'NftInfoResponseForEmpty'
14+ ) ;
15+ expect ( cleanFor ( 'UpdateCollectionInfoMsg_for_RoyaltyInfoResponse' ) ) . toEqual (
16+ 'UpdateCollectionInfoMsgForRoyaltyInfoResponse'
17+ ) ;
18+ } ) ;
19+ } ) ;
20+
921it ( 'sg721' , async ( ) => {
1022 const out = OUTPUT_DIR + '/sg721' ;
1123 const schemaDir = FIXTURE_DIR + '/sg721/' ;
Original file line number Diff line number Diff line change 11import { pascal } from 'case' ;
22
3- const cleanFor = ( str : string ) => {
3+ export const cleanFor = ( str : string ) => {
44 /*
55 1. look at first char after _for_
66 2. ONLY if you find capitals after, modify it
77 */
8- while ( / _ [ a - z ] + _ [ A - Z ] / . test ( str ) ) {
9- const m = str . match ( / ( _ [ a - z ] + _ ) [ A - Z ] / ) ;
10- str = str . replace ( m [ 1 ] , pascal ( m [ 1 ] ) ) ;
8+
9+ // When we upgrade to eslint v9, we can remove this exception and
10+ // rely on allExceptWhileTrue (https://eslint.org/docs/latest/rules/no-constant-condition)
11+ // eslint-disable-next-line no-constant-condition
12+ while ( true ) {
13+ const match = str . match ( / ( _ [ a - z ] + _ ) [ A - Z ] / ) ;
14+ if ( ! match ) break ;
15+ // this replace is unsafe as it replaces the same text but maybe
16+ // in a different location than the match
17+ str = str . replace ( match [ 1 ] , pascal ( match [ 1 ] ) ) ;
1118 }
1219
1320 return str ;
You can’t perform that action at this time.
0 commit comments