@@ -407,19 +407,20 @@ void main() {
407407 });
408408 });
409409
410- group ('dart_code_linter ' , () {
411- test ('runs dart_code_linter if present in dev_dependencies' , () async {
410+ group ('cognitive_complexity ' , () {
411+ test ('runs cognitive_complexity if present in dev_dependencies' , () async {
412412 final RepositoryPackage package = createFakePackage (
413413 'a_package' ,
414414 packagesDir,
415415 isFlutter: true ,
416416 );
417417 _writeFakePubspecWithLinter (package, inDevDependencies: true );
418+ package.libDirectory.childFile ('lib.dart' ).createSync ();
418419
419420 _mockCallsForFlutterAnalyze (
420421 processRunner,
421422 extraDartCalls: [
422- FakeProcessInfo (MockProcess (), < String > ['run' , 'dart_code_linter:metrics ' ]),
423+ FakeProcessInfo (MockProcess (), < String > ['run' , 'cognitive_complexity ' ]),
423424 ],
424425 );
425426
@@ -432,23 +433,22 @@ void main() {
432433 ProcessCall ('dart' , const < String > ['analyze' , '--fatal-infos' ], package.path),
433434 ProcessCall ('dart' , const < String > [
434435 'run' ,
435- 'dart_code_linter:metrics' ,
436- 'analyze' ,
437- 'lib' ,
438- '--set-exit-on-violation-level=warning' ,
436+ 'cognitive_complexity' ,
437+ 'lib/lib.dart' ,
439438 ], package.path),
440439 ]),
441440 );
442- expect (output, contains ('Running dart_code_linter:metrics analysis...' ));
441+ expect (output, contains ('Running cognitive_complexity analysis...' ));
443442 });
444443
445- test ('does not run dart_code_linter when --downgrade is specified' , () async {
444+ test ('does not run cognitive_complexity when --downgrade is specified' , () async {
446445 final RepositoryPackage package = createFakePackage (
447446 'a_package' ,
448447 packagesDir,
449448 isFlutter: true ,
450449 );
451450 _writeFakePubspecWithLinter (package, inDevDependencies: true );
451+ package.libDirectory.childFile ('lib.dart' ).createSync ();
452452
453453 processRunner.mockProcessesForExecutable['flutter' ] = < FakeProcessInfo > [
454454 FakeProcessInfo (MockProcess (), < String > ['pub' , 'downgrade' ]),
@@ -472,17 +472,17 @@ void main() {
472472 ]),
473473 );
474474 final String combinedOutput = output.join ('\n ' ).toLowerCase ();
475- expect (combinedOutput, isNot (contains ('dart_code_linter' )));
476- expect (combinedOutput, isNot (contains ('metrics' )));
475+ expect (combinedOutput, isNot (contains ('cognitive_complexity' )));
477476 });
478477
479- test ('does not run dart_code_linter if present in dependencies' , () async {
478+ test ('does not run cognitive_complexity if present in dependencies' , () async {
480479 final RepositoryPackage package = createFakePackage (
481480 'a_package' ,
482481 packagesDir,
483482 isFlutter: true ,
484483 );
485484 _writeFakePubspecWithLinter (package, inDependencies: true );
485+ package.libDirectory.childFile ('lib.dart' ).createSync ();
486486
487487 _mockCallsForFlutterAnalyze (processRunner);
488488
@@ -496,16 +496,16 @@ void main() {
496496 ]),
497497 );
498498 final String combinedOutput = output.join ('\n ' ).toLowerCase ();
499- expect (combinedOutput, isNot (contains ('dart_code_linter' )));
500- expect (combinedOutput, isNot (contains ('metrics' )));
499+ expect (combinedOutput, isNot (contains ('cognitive_complexity' )));
501500 });
502501
503- test ('does not run dart_code_linter if not present' , () async {
502+ test ('does not run cognitive_complexity if not present' , () async {
504503 final RepositoryPackage package = createFakePackage (
505504 'a_package' ,
506505 packagesDir,
507506 isFlutter: true ,
508507 );
508+ package.libDirectory.childFile ('lib.dart' ).createSync ();
509509
510510 _mockCallsForFlutterAnalyze (processRunner);
511511
@@ -519,18 +519,18 @@ void main() {
519519 ]),
520520 );
521521 final String combinedOutput = output.join ('\n ' ).toLowerCase ();
522- expect (combinedOutput, isNot (contains ('dart_code_linter' )));
523- expect (combinedOutput, isNot (contains ('metrics' )));
522+ expect (combinedOutput, isNot (contains ('cognitive_complexity' )));
524523 });
525524
526- test ('runs dart_code_linter using dart for pure Dart packages' , () async {
525+ test ('runs cognitive_complexity using dart for pure Dart packages' , () async {
527526 final RepositoryPackage package = createFakePackage ('a_package' , packagesDir);
528527 _writeFakePubspecWithLinter (package, inDevDependencies: true , includeFlutter: false );
528+ package.libDirectory.childFile ('lib.dart' ).createSync ();
529529
530530 processRunner.mockProcessesForExecutable['dart' ] = < FakeProcessInfo > [
531531 FakeProcessInfo (MockProcess (), < String > ['pub' , 'get' ]),
532532 FakeProcessInfo (MockProcess (), < String > ['analyze' ]),
533- FakeProcessInfo (MockProcess (), < String > ['run' , 'dart_code_linter:metrics ' ]),
533+ FakeProcessInfo (MockProcess (), < String > ['run' , 'cognitive_complexity ' ]),
534534 ];
535535
536536 final List <String > output = await runCapturingPrint (runner, < String > ['analyze' ]);
@@ -542,17 +542,15 @@ void main() {
542542 ProcessCall ('dart' , const < String > ['analyze' , '--fatal-infos' ], package.path),
543543 ProcessCall ('dart' , const < String > [
544544 'run' ,
545- 'dart_code_linter:metrics' ,
546- 'analyze' ,
547- 'lib' ,
548- '--set-exit-on-violation-level=warning' ,
545+ 'cognitive_complexity' ,
546+ 'lib/lib.dart' ,
549547 ], package.path),
550548 ]),
551549 );
552- expect (output, contains ('Running dart_code_linter:metrics analysis...' ));
550+ expect (output, contains ('Running cognitive_complexity analysis...' ));
553551 });
554552
555- test ('skips dart_code_linter if lib/ does not exist' , () async {
553+ test ('skips cognitive_complexity if lib/ does not exist' , () async {
556554 final RepositoryPackage package = createFakePackage (
557555 'a_package' ,
558556 packagesDir,
@@ -573,22 +571,48 @@ void main() {
573571 ]),
574572 );
575573 final String combinedOutput = output.join ('\n ' ).toLowerCase ();
576- expect (combinedOutput, isNot (contains ('dart_code_linter' )));
577- expect (combinedOutput, isNot (contains ('metrics' )));
574+ expect (combinedOutput, isNot (contains ('cognitive_complexity' )));
578575 });
579576
580- test ('fails if dart_code_linter analysis fails ' , () async {
577+ test ('skips cognitive_complexity if lib/ only contains generated files ' , () async {
581578 final RepositoryPackage package = createFakePackage (
582579 'a_package' ,
583580 packagesDir,
584581 isFlutter: true ,
585582 );
586583 _writeFakePubspecWithLinter (package, inDevDependencies: true );
584+ package.libDirectory.childFile ('foo.g.dart' ).createSync ();
585+ package.libDirectory.childFile ('bar.mocks.dart' ).createSync ();
586+ package.libDirectory.childFile ('baz.gen.dart' ).createSync ();
587+
588+ _mockCallsForFlutterAnalyze (processRunner);
589+
590+ final List <String > output = await runCapturingPrint (runner, < String > ['analyze' ]);
591+
592+ expect (
593+ processRunner.recordedCalls,
594+ orderedEquals (< ProcessCall > [
595+ ProcessCall ('flutter' , const < String > ['pub' , 'get' ], package.path),
596+ ProcessCall ('dart' , const < String > ['analyze' , '--fatal-infos' ], package.path),
597+ ]),
598+ );
599+ final String combinedOutput = output.join ('\n ' ).toLowerCase ();
600+ expect (combinedOutput, isNot (contains ('cognitive_complexity' )));
601+ });
602+
603+ test ('fails if cognitive_complexity analysis fails' , () async {
604+ final RepositoryPackage package = createFakePackage (
605+ 'a_package' ,
606+ packagesDir,
607+ isFlutter: true ,
608+ );
609+ _writeFakePubspecWithLinter (package, inDevDependencies: true );
610+ package.libDirectory.childFile ('lib.dart' ).createSync ();
587611
588612 _mockCallsForFlutterAnalyze (
589613 processRunner,
590614 extraDartCalls: [
591- FakeProcessInfo (MockProcess (exitCode: 1 ), < String > ['run' , 'dart_code_linter:metrics ' ]),
615+ FakeProcessInfo (MockProcess (exitCode: 1 ), < String > ['run' , 'cognitive_complexity ' ]),
592616 ],
593617 );
594618
@@ -619,17 +643,17 @@ void main() {
619643 isFlutter: true ,
620644 );
621645 _writeFakePubspecWithLinter (package, inDevDependencies: true );
646+ package.libDirectory.childFile ('lib.dart' ).createSync ();
622647 package.ciConfigFile.writeAsStringSync ('allow_custom_analysis_options: true' );
623648 package.directory.childFile ('analysis_options.yaml' ).writeAsStringSync ('''
624- dart_code_linter:
625- metrics:
626- cyclomatic-complexity: 15
649+ cognitive_complexity:
650+ fail-threshold: 15
627651''' );
628652
629653 _mockCallsForFlutterAnalyze (
630654 processRunner,
631655 extraDartCalls: [
632- FakeProcessInfo (MockProcess (exitCode: 1 ), < String > ['run' , 'dart_code_linter:metrics ' ]),
656+ FakeProcessInfo (MockProcess (exitCode: 1 ), < String > ['run' , 'cognitive_complexity ' ]),
633657 ],
634658 );
635659
@@ -642,6 +666,22 @@ dart_code_linter:
642666 },
643667 );
644668
669+ expect (
670+ processRunner.recordedCalls,
671+ orderedEquals (< ProcessCall > [
672+ ProcessCall ('flutter' , const < String > ['pub' , 'get' ], package.path),
673+ ProcessCall ('dart' , const < String > ['analyze' , '--fatal-infos' ], package.path),
674+ ProcessCall ('dart' , const < String > [
675+ 'run' ,
676+ 'cognitive_complexity' ,
677+ '--threshold' ,
678+ '15' ,
679+ '--fail-threshold' ,
680+ '15' ,
681+ 'lib/lib.dart' ,
682+ ], package.path),
683+ ]),
684+ );
645685 expect (commandError, isA <ToolExit >());
646686 expect (
647687 output,
@@ -773,6 +813,7 @@ dart_code_linter:
773813 isFlutter: true ,
774814 );
775815 _writeFakePubspecWithLinter (package, inDevDependencies: true );
816+ package.libDirectory.childFile ('lib.dart' ).createSync ();
776817 package.ciConfigFile.writeAsStringSync ('analyze_skills: true' );
777818
778819 package.directory
@@ -789,7 +830,7 @@ dart_code_linter:
789830 FakeProcessInfo (MockProcess (exitCode: 1 ), < String > ['analyze' ]), // skills package
790831 FakeProcessInfo (MockProcess (exitCode: 1 ), < String > [
791832 'run' ,
792- 'dart_code_linter:metrics ' ,
833+ 'cognitive_complexity ' ,
793834 ]), // custom linter
794835 ];
795836
@@ -1914,8 +1955,8 @@ environment:
19141955 ${includeFlutter ? 'flutter: ">=2.5.0"' : '' }
19151956dependencies:
19161957 ${includeFlutter ? 'flutter:\n sdk: flutter' : '' }
1917- ${inDependencies ? ' dart_code_linter: 4.1.5 ' : '' }
1918- ${inDevDependencies ? 'dev_dependencies:\n dart_code_linter: 4.1.5 ' : '' }
1958+ ${inDependencies ? ' cognitive_complexity: 0.2.0 ' : '' }
1959+ ${inDevDependencies ? 'dev_dependencies:\n cognitive_complexity: 0.2.0 ' : '' }
19191960''' );
19201961}
19211962
0 commit comments