|
| 1 | +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file |
| 2 | +// for details. All rights reserved. Use of this source code is governed by a |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 6 | + |
| 7 | +import '../rule_test_support.dart'; |
| 8 | + |
| 9 | +main() { |
| 10 | + defineReflectiveSuite(() { |
| 11 | + defineReflectiveTests(DiagnosticDescribeAllPropertiesTest); |
| 12 | + }); |
| 13 | +} |
| 14 | + |
| 15 | +@reflectiveTest |
| 16 | +class DiagnosticDescribeAllPropertiesTest extends LintRuleTest { |
| 17 | + @override |
| 18 | + bool get addFlutterPackageDep => true; |
| 19 | + |
| 20 | + @override |
| 21 | + String get lintRule => 'diagnostic_describe_all_properties'; |
| 22 | + |
| 23 | + test_field() async { |
| 24 | + await assertDiagnostics(r''' |
| 25 | +import 'package:flutter/widgets.dart'; |
| 26 | +class MyWidget with Diagnosticable { |
| 27 | + bool p = false; |
| 28 | +} |
| 29 | +''', [ |
| 30 | + lint(83, 1), |
| 31 | + ]); |
| 32 | + } |
| 33 | + |
| 34 | + test_field_collectionOfWidgets() async { |
| 35 | + await assertNoDiagnostics(r''' |
| 36 | +import 'package:flutter/widgets.dart'; |
| 37 | +class MyWidget with Diagnosticable { |
| 38 | + List<Widget> p = []; |
| 39 | +} |
| 40 | +'''); |
| 41 | + } |
| 42 | + |
| 43 | + test_field_coveredByDebugField() async { |
| 44 | + await assertNoDiagnostics(r''' |
| 45 | +import 'package:flutter/widgets.dart'; |
| 46 | +class MyWidget with Diagnosticable { |
| 47 | + String foo = ''; |
| 48 | + String debugFoo = ''; |
| 49 | +
|
| 50 | + @override |
| 51 | + void debugFillProperties(DiagnosticPropertiesBuilder properties) { |
| 52 | + debugFoo; |
| 53 | + } |
| 54 | +} |
| 55 | +'''); |
| 56 | + } |
| 57 | + |
| 58 | + test_field_inDebugDescribeChildren() async { |
| 59 | + await assertNoDiagnostics(r''' |
| 60 | +import 'package:flutter/widgets.dart'; |
| 61 | +class MyWidget extends DiagnosticableTree { |
| 62 | + String p = ''; |
| 63 | +
|
| 64 | + @override |
| 65 | + List<DiagnosticsNode> debugDescribeChildren() { |
| 66 | + p; |
| 67 | + return []; |
| 68 | + } |
| 69 | +} |
| 70 | +'''); |
| 71 | + } |
| 72 | + |
| 73 | + test_field_inDebugFillProperties() async { |
| 74 | + await assertNoDiagnostics(r''' |
| 75 | +import 'package:flutter/widgets.dart'; |
| 76 | +class MyWidget with Diagnosticable { |
| 77 | + String p = ''; |
| 78 | +
|
| 79 | + @override |
| 80 | + void debugFillProperties(DiagnosticPropertiesBuilder properties) { |
| 81 | + p; |
| 82 | + } |
| 83 | +} |
| 84 | +'''); |
| 85 | + } |
| 86 | + |
| 87 | + test_field_private() async { |
| 88 | + await assertNoDiagnostics(r''' |
| 89 | +import 'package:flutter/widgets.dart'; |
| 90 | +class MyWidget with Diagnosticable { |
| 91 | + // ignore: unused_field |
| 92 | + String _p = ''; |
| 93 | +} |
| 94 | +'''); |
| 95 | + } |
| 96 | + |
| 97 | + test_field_string() async { |
| 98 | + await assertDiagnostics(r''' |
| 99 | +import 'package:flutter/widgets.dart'; |
| 100 | +class MyWidget with Diagnosticable { |
| 101 | + String p = ''; |
| 102 | +} |
| 103 | +''', [ |
| 104 | + lint(85, 1), |
| 105 | + ]); |
| 106 | + } |
| 107 | + |
| 108 | + test_field_widget() async { |
| 109 | + await assertNoDiagnostics(r''' |
| 110 | +import 'package:flutter/widgets.dart'; |
| 111 | +class MyWidget with Diagnosticable { |
| 112 | + Widget? p; |
| 113 | +} |
| 114 | +'''); |
| 115 | + } |
| 116 | + |
| 117 | + test_getter_string() async { |
| 118 | + await assertDiagnostics(r''' |
| 119 | +import 'package:flutter/widgets.dart'; |
| 120 | +class MyWidget with Diagnosticable { |
| 121 | + String get p => ''; |
| 122 | +} |
| 123 | +''', [ |
| 124 | + lint(89, 1), |
| 125 | + ]); |
| 126 | + } |
| 127 | + |
| 128 | + test_getter_widget() async { |
| 129 | + await assertNoDiagnostics(r''' |
| 130 | +import 'package:flutter/widgets.dart'; |
| 131 | +class MyWidget with Diagnosticable { |
| 132 | + Widget? get p => null; |
| 133 | +} |
| 134 | +'''); |
| 135 | + } |
| 136 | + |
| 137 | + test_staticField_string() async { |
| 138 | + await assertNoDiagnostics(r''' |
| 139 | +import 'package:flutter/widgets.dart'; |
| 140 | +class MyWidget with Diagnosticable { |
| 141 | + static String p = ''; |
| 142 | +} |
| 143 | +'''); |
| 144 | + } |
| 145 | +} |
0 commit comments