Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move prefer_typing_uninitialized_variables tests #4551

Merged
merged 1 commit into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions test/rules/all.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ import 'prefer_mixin_test.dart' as prefer_mixin;
import 'prefer_relative_imports_test.dart' as prefer_relative_imports;
import 'prefer_single_quotes_test.dart' as prefer_single_quotes;
import 'prefer_spread_collections_test.dart' as prefer_spread_collections;
import 'prefer_typing_uninitialized_variables_test.dart'
as prefer_typing_uninitialized_variables;
import 'prefer_void_to_null_test.dart' as prefer_void_to_null;
import 'provide_deprecation_message_test.dart' as provide_deprecation_message;
import 'public_member_api_docs_test.dart' as public_member_api_docs;
Expand Down Expand Up @@ -263,6 +265,7 @@ void main() {
prefer_relative_imports.main();
prefer_single_quotes.main();
prefer_spread_collections.main();
prefer_typing_uninitialized_variables.main();
prefer_void_to_null.main();
provide_deprecation_message.main();
public_member_api_docs.main();
Expand Down
121 changes: 121 additions & 0 deletions test/rules/prefer_typing_uninitialized_variables_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// Copyright (c) 2023, 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:test_reflective_loader/test_reflective_loader.dart';

import '../rule_test_support.dart';

main() {
defineReflectiveSuite(() {
defineReflectiveTests(PreferTypingUninitializedVariablesTest);
});
}

@reflectiveTest
class PreferTypingUninitializedVariablesTest extends LintRuleTest {
@override
String get lintRule => 'prefer_typing_uninitialized_variables';

test_field_final_noInitializer() async {
await assertDiagnostics(r'''
class C {
final x;
C(this.x);
}
''', [
lint(18, 1),
]);
}

test_field_typed() async {
await assertNoDiagnostics(r'''
class C {
String? x;
}
''');
}

test_field_var_noInitializer() async {
await assertDiagnostics(r'''
class C {
var x;
}
''', [
lint(16, 1),
]);
}

test_field_var_noInitializer_notFirst() async {
await assertDiagnostics(r'''
class C {
var a = 5,
b;
}
''', [
lint(29, 1),
]);
}

test_field_var_noInitializer_static() async {
await assertDiagnostics(r'''
class C {
static var x;
}
''', [
lint(23, 1),
]);
}

test_forEachLoopVariable_final() async {
await assertNoDiagnostics(r'''
void f() {
for (final e in <String>[]) {}
}
''');
}

test_forLoopVariable_var_noInitializer() async {
await assertDiagnostics(r'''
void f() {
for (var i, j = 0; j < 5; i = j, j++) {}
}
''', [
lint(22, 1),
]);
}

test_localVariable_var_initializer() async {
await assertNoDiagnostics(r'''
void f() {
// ignore: unused_local_variable
var x = 1;
}
''');
}

test_localVariable_var_noInitializer() async {
await assertDiagnostics(r'''
void f() {
// ignore: unused_local_variable
var x;
}
''', [
lint(52, 1),
]);
}

test_topLevelVariable_var_initializer() async {
await assertNoDiagnostics(r'''
var x = 4;
''');
}

test_topLevelVariable_var_noInitializer() async {
await assertDiagnostics(r'''
var x;
''', [
lint(4, 1),
]);
}
}
45 changes: 0 additions & 45 deletions test_data/rules/prefer_typing_uninitialized_variables.dart

This file was deleted.