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';
2
2
import { sync as mkdirp } from 'mkdirp' ;
3
3
4
4
import { readSchemas } from '../src/utils' ;
5
+ import { cleanFor } from '../src/utils/cleanse' ;
5
6
6
7
const FIXTURE_DIR = __dirname + '/../../../__fixtures__' ;
7
8
const OUTPUT_DIR = __dirname + '/../../../__output__' ;
8
9
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
+
9
21
it ( 'sg721' , async ( ) => {
10
22
const out = OUTPUT_DIR + '/sg721' ;
11
23
const schemaDir = FIXTURE_DIR + '/sg721/' ;
Original file line number Diff line number Diff line change 1
1
import { pascal } from 'case' ;
2
2
3
- const cleanFor = ( str : string ) => {
3
+ export const cleanFor = ( str : string ) => {
4
4
/*
5
5
1. look at first char after _for_
6
6
2. ONLY if you find capitals after, modify it
7
7
*/
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 ] ) ) ;
11
18
}
12
19
13
20
return str ;
You can’t perform that action at this time.
0 commit comments