File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -22,6 +22,12 @@ cd vrchat_dart_generated
2222dart pub get
2323cd ..
2424
25+ # openapi-generator can emit invalid Dart like r'you\'re' (escapes in raw
26+ # strings). Fix that before formatting, which fails on unparseable files.
27+ cd vrchat_dart
28+ dart run tool/fix_raw_string_escapes.dart
29+ cd ..
30+
2531# Format before patching since extra line breaks can break the patches
2632dart format .
2733cd vrchat_dart
Original file line number Diff line number Diff line change 1+ import 'dart:io' ;
2+
3+ import 'package:path/path.dart' as path;
4+
5+ /// openapi-generator's dart-dio templates emit raw strings with `\'` , which is
6+ /// invalid Dart. Rewrite those as double-quoted raw strings before formatting.
7+ void main () {
8+ final root = Directory (path.join ('..' , 'vrchat_dart_generated' ));
9+ for (final entity in root.listSync (recursive: true )) {
10+ if (entity is ! File || ! entity.path.endsWith ('.dart' )) continue ;
11+
12+ final content = entity.readAsStringSync ();
13+ final fixed = fixRawStringEscapes (content);
14+ if (fixed != content) {
15+ entity.writeAsStringSync (fixed);
16+ }
17+ }
18+ }
19+
20+ String fixRawStringEscapes (String source) {
21+ return source.replaceAllMapped (RegExp (r"r'((?:[^'\\]|\\.)*)'" ), (match) {
22+ final inner = match[1 ]! ;
23+ if (! inner.contains (r"\'" )) return match[0 ]! ;
24+
25+ final unescaped = inner.replaceAll (r"\'" , "'" );
26+ if (! unescaped.contains ('"' )) {
27+ return 'r"$unescaped "' ;
28+ }
29+
30+ final escaped = unescaped
31+ .replaceAll (r'\' , r'\\' )
32+ .replaceAll ('"' , r'\"' )
33+ .replaceAll (r'$' , r'\$' );
34+ return '"$escaped "' ;
35+ });
36+ }
You can’t perform that action at this time.
0 commit comments