diff --git a/test/integration/use_build_context_synchronously.dart b/test/integration/use_build_context_synchronously.dart deleted file mode 100644 index 327a57e50f9d..000000000000 --- a/test/integration/use_build_context_synchronously.dart +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'package:analyzer/src/lint/io.dart'; -import 'package:analyzer/src/lint/linter.dart'; -import 'package:analyzer/src/utilities/legacy.dart'; -import 'package:linter/src/analyzer.dart'; -import 'package:linter/src/cli.dart' as cli; -import 'package:test/test.dart'; - -import '../mocks.dart'; -import '../test_constants.dart'; - -void main() { - group('use_build_context_synchronously', () { - var currentOut = outSink; - var collectingOut = CollectingSink(); - setUp(() { - noSoundNullSafety = false; - return outSink = collectingOut; - }); - tearDown(() { - noSoundNullSafety = true; - collectingOut.buffer.clear(); - outSink = currentOut; - }); - //https://github.com/dart-lang/linter/issues/2572 - test('mixed_mode', () async { - await cli.runLinter([ - '$integrationTestDir/use_build_context_synchronously/lib/unmigrated.dart', - '--rules=use_build_context_synchronously', - ], LinterOptions()); - var out = collectingOut.trim(); - expect(out, contains('1 file analyzed, 1 issue found')); - expect(out, contains('22:3')); - }); - }); -} diff --git a/test/integration_test.dart b/test/integration_test.dart index baee4023a63b..5973c114133e 100644 --- a/test/integration_test.dart +++ b/test/integration_test.dart @@ -18,8 +18,6 @@ import 'integration/avoid_web_libraries_in_flutter.dart' as avoid_web_libraries_in_flutter; import 'integration/close_sinks.dart' as close_sinks; import 'integration/public_member_api_docs.dart' as public_member_api_docs; -import 'integration/use_build_context_synchronously.dart' - as use_build_context_synchronously; import 'mocks.dart'; import 'test_constants.dart'; @@ -128,7 +126,6 @@ void ruleTests() { avoid_web_libraries_in_flutter.main(); close_sinks.main(); public_member_api_docs.main(); - use_build_context_synchronously.main(); }); } diff --git a/test/rules/use_build_context_synchronously_test.dart b/test/rules/use_build_context_synchronously_test.dart index 977169fbf64b..fc3abb1fc86f 100644 --- a/test/rules/use_build_context_synchronously_test.dart +++ b/test/rules/use_build_context_synchronously_test.dart @@ -4,6 +4,7 @@ import 'package:analyzer/dart/ast/ast.dart'; import 'package:analyzer/src/test_utilities/find_node.dart'; +import 'package:analyzer/src/utilities/legacy.dart'; import 'package:linter/src/rules/use_build_context_synchronously.dart'; import 'package:test/test.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; @@ -14,6 +15,7 @@ main() { defineReflectiveSuite(() { defineReflectiveTests(AsyncStateTest); defineReflectiveTests(UseBuildContextSynchronouslyTest); + defineReflectiveTests(UseBuildContextSynchronouslyMixedModeTest); }); } @@ -1630,6 +1632,52 @@ void foo(BuildContext context) async { } } +@reflectiveTest +class UseBuildContextSynchronouslyMixedModeTest extends LintRuleTest { + @override + bool get addFlutterPackageDep => true; + + @override + String get lintRule => 'use_build_context_synchronously'; + + /// Ensure we're not run in the test dir. + @override + String get testPackageRootPath => '$workspaceRootPath/lib'; + + @override + setUp() { + super.setUp(); + noSoundNullSafety = false; + } + + tearDown() { + noSoundNullSafety = true; + } + + /// https://github.com/dart-lang/linter/issues/2572 + test_mixedMode() async { + newFile('$testPackageLibPath/migrated.dart', ''' +import 'package:flutter/widgets.dart'; + +BuildContext? get contextOrNull => null; + +void f(BuildContext? contextOrNull) {} +'''); + + await assertNoDiagnostics(r''' +// @dart=2.9 + +import 'migrated.dart'; + +void nullableContext() async { + f(contextOrNull); + await Future.delayed(Duration()); + f(contextOrNull); +} +'''); + } +} + @reflectiveTest class UseBuildContextSynchronouslyTest extends LintRuleTest { @override diff --git a/test_data/integration/use_build_context_synchronously/.dart_tool/package_config.json b/test_data/integration/use_build_context_synchronously/.dart_tool/package_config.json deleted file mode 100644 index 6a297fb9340f..000000000000 --- a/test_data/integration/use_build_context_synchronously/.dart_tool/package_config.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "configVersion": 2, - "packages": [ - { - "name": "flutter", - "rootUri": "../../../mock_packages/flutter/", - "packageUri": "lib/", - "languageVersion": "2.17" - } - ], - "generated": "2022-06-30T01:27:31.576781Z", - "generator": "pub", - "generatorVersion": "2.17.0" -} diff --git a/test_data/integration/use_build_context_synchronously/analysis_options.yaml b/test_data/integration/use_build_context_synchronously/analysis_options.yaml deleted file mode 100644 index c82119aee997..000000000000 --- a/test_data/integration/use_build_context_synchronously/analysis_options.yaml +++ /dev/null @@ -1,3 +0,0 @@ -linter: - rules: - - use_build_context_synchronously diff --git a/test_data/integration/use_build_context_synchronously/lib/migrated.dart b/test_data/integration/use_build_context_synchronously/lib/migrated.dart deleted file mode 100644 index 4ad51cc51216..000000000000 --- a/test_data/integration/use_build_context_synchronously/lib/migrated.dart +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'package:flutter/widgets.dart'; - -BuildContext? get contextOrNull => null; - -void f(BuildContext? contextOrNull) {} diff --git a/test_data/integration/use_build_context_synchronously/lib/unmigrated.dart b/test_data/integration/use_build_context_synchronously/lib/unmigrated.dart deleted file mode 100644 index 7c83ad1adfb7..000000000000 --- a/test_data/integration/use_build_context_synchronously/lib/unmigrated.dart +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// @dart=2.9 - -import 'package:flutter/foundation.dart'; -import 'package:flutter/widgets.dart'; - -import 'migrated.dart'; - -void nullableContext() async { - f(contextOrNull); - await Future.delayed(Duration()); - f(contextOrNull); // OK -} - -void topLevel(BuildContext context) async { - Navigator.of(context).pushNamed('routeName'); // OK - - await Future.delayed(Duration()); - Navigator.of(context).pushNamed('routeName'); // LINT -} - -void anonymousFunction(BuildContext context) async { - final anon = () async { - await Future.delayed(Duration(seconds: 1)); - }; - await Navigator.of(context).pushNamed('routeName'); // OK -} - -void anonymousExpressionFunction(BuildContext context) async { - final anon = () async => await Future.delayed(Duration()); - await Navigator.of(context).pushNamed('routeName'); // OK -} - -void widgetCallbacks(BuildContext context) async { - final widget = _Button( - onTap: () async { - await Future.delayed(Duration()); - }, - ); - // Build complex widget piece by piece... - f(context); // OK -} - -class _Button extends StatelessWidget { - const _Button({Key key, this.onTap}) : super(key: key); - - final VoidCallback onTap; - - @override - Widget build(BuildContext context) { - return Container(); - } -} \ No newline at end of file diff --git a/test_data/integration/use_build_context_synchronously/pubspec.yaml b/test_data/integration/use_build_context_synchronously/pubspec.yaml deleted file mode 100644 index 24725f38276c..000000000000 --- a/test_data/integration/use_build_context_synchronously/pubspec.yaml +++ /dev/null @@ -1,8 +0,0 @@ -name: use_build_context_synchronously - -environment: - sdk: '>=2.13.0-0 <3.0.0' - -dependency_overrides: - flutter: - path: ../../../test/mock_packages/flutter