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 use_setters_to_change_properties tests #4544

Merged
merged 1 commit into from
Jul 10, 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 @@ -174,6 +174,8 @@ import 'use_key_in_widget_constructors_test.dart'
import 'use_late_for_private_fields_and_variables_test.dart'
as use_late_for_private_fields_and_variables;
import 'use_named_constants_test.dart' as use_named_constants;
import 'use_setters_to_change_properties_test.dart'
as use_setters_to_change_properties;
import 'use_super_parameters_test.dart' as use_super_parameters;
import 'use_test_throws_matchers_test.dart' as use_test_throws_matchers;
import 'void_checks_test.dart' as void_checks;
Expand Down Expand Up @@ -305,6 +307,7 @@ void main() {
use_key_in_widget_constructors.main();
use_late_for_private_fields_and_variables.main();
use_named_constants.main();
use_setters_to_change_properties.main();
use_super_parameters.main();
use_test_throws_matchers.main();
void_checks.main();
Expand Down
110 changes: 110 additions & 0 deletions test/rules/use_setters_to_change_properties_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// 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(() {
// TODO(srawlins): Add test with setter-like with multiple statements; add
// test with non-trivial right side (`this.x = x + 1`).
defineReflectiveTests(UseSettersToChangePropertiesTest);
});
}

@reflectiveTest
class UseSettersToChangePropertiesTest extends LintRuleTest {
@override
String get lintRule => 'use_setters_to_change_properties';

test_setterLike_expressionBody() async {
await assertDiagnostics(r'''
abstract class A {
int x = 0;
void setX(int x) => this.x = x;
}
''', [
lint(39, 4),
]);
}

test_setterLike_blockBody() async {
await assertDiagnostics(r'''
abstract class A {
int x = 0;
void setX(int x) {
this.x = x;
}
}
''', [
lint(39, 4),
]);
}

test_combo() async {
await assertNoDiagnostics(r'''
abstract class A {
int x = 0;
void setX(int x) => this.x += x;
}
''');
}

test_inheritedFromSuperclass() async {
await assertNoDiagnostics(r'''
abstract class A {
void setX(int x);
}

class B extends A {
int x = 0;

void setX(int x) {
this.x = x;
}
}
''');
}

test_abstract() async {
await assertNoDiagnostics(r'''
abstract class A {
void setX(int x);
}
''');
}

test_inheritedFromSuperInterface() async {
await assertNoDiagnostics(r'''
abstract class A {
void setX(int x);
}

class B implements A {
int x = 0;

void setX(int x) {
this.x = x;
}
}
''');
}

test_extension() async {
await assertDiagnostics(r'''
class A {
int x = 0;
}

extension E on A {
void setX(int x) {
this.x = x;
}
}
''', [
lint(52, 4),
]);
}
}
55 changes: 0 additions & 55 deletions test_data/rules/use_setters_to_change_properties.dart

This file was deleted.