File tree Expand file tree Collapse file tree 3 files changed +127
-0
lines changed
src/services/correction/fix Expand file tree Collapse file tree 3 files changed +127
-0
lines changed Original file line number Diff line number Diff line change @@ -36,4 +36,43 @@ class B extends A {
3636 var result = await sendEditBulkFixes ([sourceDirectory.path]);
3737 expect (result.edits, hasLength (1 ));
3838 }
39+
40+ @FailingTest (issue: 'https://github.com/dart-lang/sdk/issues/59572' )
41+ Future <void > test_bulk_fix_with_parts () async {
42+ writeFile (sourcePath (file_paths.analysisOptionsYaml), '''
43+ linter:
44+ rules:
45+ - empty_statements
46+ - prefer_const_constructors
47+ ''' );
48+ writeFile (sourcePath ('part.dart' ), '''
49+ part of 'test.dart';
50+
51+ class C {
52+ const C();
53+ }
54+
55+ C b() {
56+ // dart fix should only add a single const
57+ return C();
58+ }
59+ ''' );
60+ writeFile (sourcePath ('test.dart' ), '''
61+ part 'part.dart';
62+
63+ void a() {
64+ // need to trigger a lint in main.dart for the bug to happen
65+ ;
66+ b();
67+ }
68+ ''' );
69+ await standardAnalysisSetup ();
70+ await analysisFinished;
71+
72+ var result = await sendEditBulkFixes ([sourceDirectory.path]);
73+ var edits = result.edits;
74+ expect (edits, hasLength (2 ));
75+ expect (edits[0 ].edits, hasLength (1 ));
76+ expect (edits[1 ].edits, hasLength (1 ));
77+ }
3978}
Original file line number Diff line number Diff line change @@ -146,6 +146,41 @@ var c = new C();
146146 expect (processor.changeMap.libraryMap.length, 3 );
147147 }
148148
149+ /// https://github.com/dart-lang/sdk/issues/59572
150+ Future <void > test_hasFixes_in_part_and_library2 () async {
151+ createAnalysisOptionsFile (
152+ experiments: experiments,
153+ lints: [LintNames .empty_statements, LintNames .prefer_const_constructors],
154+ );
155+
156+ newFile ('$testPackageLibPath /part.dart' , '''
157+ part of 'test.dart';
158+
159+ class C {
160+ const C();
161+ }
162+
163+ C b() {
164+ // dart fix should only add a single const
165+ return C();
166+ }
167+ ''' );
168+
169+ await resolveTestCode ('''
170+ part 'part.dart';
171+
172+ void a() {
173+ // need to trigger a lint in main.dart for the bug to happen
174+ ;
175+ b();
176+ }
177+ ''' );
178+
179+ expect (await computeHasFixes (), isTrue);
180+ expect (processor.changeMap.libraryMap.length, 2 );
181+ expect (processor.fixDetails.length, 2 );
182+ }
183+
149184 Future <void > test_hasFixes_stoppedAfterFirst () async {
150185 createAnalysisOptionsFile (
151186 experiments: experiments,
Original file line number Diff line number Diff line change @@ -403,6 +403,59 @@ linter:
403403 ]));
404404 });
405405
406+ test (
407+ '--apply --code=(multiple) [part file]' ,
408+ () async {
409+ p = project (
410+ mainSrc: '''
411+ part 'part.dart';
412+
413+ void a() {
414+ // need to trigger a lint in main.dart for the bug to happen
415+ ;
416+ b();
417+ }
418+ ''' ,
419+ analysisOptions: '''
420+ linter:
421+ rules:
422+ - empty_statements
423+ - prefer_const_constructors
424+ ''' ,
425+ );
426+ p! .file ('lib/part.dart' , '''
427+ part of 'main.dart';
428+
429+ Stream<String> b() {
430+ // dart fix should only add a single const
431+ return Stream.empty();
432+ }
433+ ''' );
434+ var result = await p! .runFix ([
435+ '--apply' ,
436+ '--code' ,
437+ 'empty_statements' ,
438+ '--code' ,
439+ 'prefer_const_constructors' ,
440+ '.'
441+ ], workingDir: p! .dirPath);
442+
443+ expect (result.exitCode, 0 );
444+ expect (result.stderr, isEmpty);
445+ expect (
446+ result.stdout,
447+ stringContainsInOrderWithVariableBullets ([
448+ 'Applying fixes...' ,
449+ 'lib${Platform .pathSeparator }main.dart' ,
450+ ' empty_statements $bullet 1 fix' ,
451+ 'lib${Platform .pathSeparator }part.dart' ,
452+ ' prefer_const_constructors $bullet 1 fix' ,
453+ '2 fixes made in 2 files.' ,
454+ ]));
455+ },
456+ skip: 'Failing: https://github.com/dart-lang/sdk/issues/59572' ,
457+ );
458+
406459 test ('--apply --code=(multiple: comma-delimited)' , () async {
407460 p = project (
408461 mainSrc: '''
You can’t perform that action at this time.
0 commit comments