More lints (#70500)

This commit is contained in:
Ian Hickson 2020-11-16 11:07:37 -08:00 committed by GitHub
parent 9a2bf0e70f
commit 6cff33832e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 54 additions and 50 deletions

View file

@ -83,7 +83,7 @@ linter:
- avoid_returning_null_for_void
# - avoid_returning_this # there are plenty of valid reasons to return this
# - avoid_setters_without_getters # not yet tested
# - avoid_shadowing_type_parameters # not yet tested
- avoid_shadowing_type_parameters
- avoid_single_cascade_in_expression_statements
- avoid_slow_async_io
# - avoid_type_to_string # we do this commonly
@ -103,7 +103,7 @@ linter:
# - comment_references # blocked on https://github.com/flutter/flutter/issues/20765
# - constant_identifier_names # needs an opt-out https://github.com/dart-lang/linter/issues/204
- control_flow_in_finally
# - curly_braces_in_flow_control_structures # not yet tested
# - curly_braces_in_flow_control_structures # not required by flutter style
# - diagnostic_describe_all_properties # not yet tested
- directives_ordering
# - do_not_use_environment # we do this commonly
@ -117,22 +117,22 @@ linter:
- implementation_imports
# - invariant_booleans # too many false positives: https://github.com/dart-lang/linter/issues/811
- iterable_contains_unrelated_type
# - join_return_with_assignment # not yet tested
# - join_return_with_assignment # not required by flutter style
- leading_newlines_in_multiline_strings
- library_names
- library_prefixes
# - lines_longer_than_80_chars # not yet tested
# - lines_longer_than_80_chars # not required by flutter style
- list_remove_unrelated_type
# - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/sdk/issues/34181
# - missing_whitespace_between_adjacent_strings # not yet tested
- no_adjacent_strings_in_list
# - no_default_cases # too many false positives
- no_duplicate_case_values
# - no_logic_in_create_state # not yet tested
# - no_runtimeType_toString # not yet tested
- no_logic_in_create_state
# - no_runtimeType_toString # ok in tests; we enable this only in packages/
- non_constant_identifier_names
- null_check_on_nullable_type_parameter
# - null_closures # not yet tested
# - null_closures # not required by flutter style
# - omit_local_variable_types # opposite of always_specify_types
# - one_member_abstracts # too many false positives
# - only_throw_errors # https://github.com/flutter/flutter/issues/5792
@ -143,14 +143,14 @@ linter:
# - parameter_assignments # we do this commonly
- prefer_adjacent_string_concatenation
- prefer_asserts_in_initializer_lists
# - prefer_asserts_with_message # not yet tested
# - prefer_asserts_with_message # not required by flutter style
- prefer_collection_literals
- prefer_conditional_assignment
- prefer_const_constructors
- prefer_const_constructors_in_immutables
- prefer_const_declarations
- prefer_const_literals_to_create_immutables
# - prefer_constructors_over_static_methods # not yet tested
# - prefer_constructors_over_static_methods # far too many false positives
- prefer_contains
# - prefer_double_quotes # opposite of prefer_single_quotes
- prefer_equal_for_default_values

View file

@ -12,34 +12,34 @@ enum FilterType {
}
class FilteredChildAnimationPage extends StatefulWidget {
const FilteredChildAnimationPage(
this._filterType,
[
this._complexChild = true,
this._useRepaintBoundary = true,
]);
const FilteredChildAnimationPage(this.initialFilterType, [
this.initialComplexChild = true,
this.initialUseRepaintBoundary = true,
]);
final FilterType _filterType;
final bool _complexChild;
final bool _useRepaintBoundary;
final FilterType initialFilterType;
final bool initialComplexChild;
final bool initialUseRepaintBoundary;
@override
_FilteredChildAnimationPageState createState() => _FilteredChildAnimationPageState(_filterType, _complexChild, _useRepaintBoundary);
_FilteredChildAnimationPageState createState() => _FilteredChildAnimationPageState();
}
class _FilteredChildAnimationPageState extends State<FilteredChildAnimationPage> with SingleTickerProviderStateMixin {
_FilteredChildAnimationPageState(this._filterType, this._complexChild, this._useRepaintBoundary);
AnimationController _controller;
bool _useRepaintBoundary;
bool _complexChild;
FilterType _filterType;
final GlobalKey _childKey = GlobalKey(debugLabel: 'child to animate');
Offset _childCenter = Offset.zero;
FilterType _filterType;
bool _complexChild;
bool _useRepaintBoundary;
@override
void initState() {
super.initState();
_filterType = widget.initialFilterType;
_complexChild = widget.initialComplexChild;
_useRepaintBoundary = widget.initialUseRepaintBoundary;
WidgetsBinding.instance.addPostFrameCallback((_) {
final RenderBox childBox = _childKey.currentContext.findRenderObject() as RenderBox;
_childCenter = childBox.paintBounds.center;

View file

@ -528,11 +528,16 @@ class _WidgetBuildRecorderHost extends StatefulWidget {
final WidgetBuildRecorder recorder;
@override
State<StatefulWidget> createState() =>
recorder._hostState = _WidgetBuildRecorderHostState();
State<StatefulWidget> createState() => _WidgetBuildRecorderHostState();
}
class _WidgetBuildRecorderHostState extends State<_WidgetBuildRecorderHost> {
@override
void initState() {
super.initState();
widget.recorder._hostState = this;
}
// This is just to bypass the @protected on setState.
void _setStateTrampoline() {
setState(() {});

View file

@ -1,8 +1,9 @@
# Take our settings from the repo's main analysis_options.yaml file, but include
# an additional rule to validate that public members are documented.
# Take our settings from the repo's main analysis_options.yaml file, and include
# additional rules that are specific to production code.
include: ../analysis_options.yaml
linter:
rules:
- public_member_api_docs
- public_member_api_docs # see https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#documentation-dartdocs-javadocs-etc
- no_runtimeType_toString # use objectRuntimeType from package:foundation

View file

@ -5,7 +5,4 @@ include: ../analysis_options.yaml
analyzer:
errors:
always_require_non_null_named_parameters: false # not needed with nnbd
type_init_formals: false # https://github.com/dart-lang/linter/issues/2192
unrelated_type_equality_checks: false # https://github.com/dart-lang/linter/issues/2196
void_checks: false # https://github.com/dart-lang/linter/issues/2185
unnecessary_null_comparison: false # Turned off until null-safe rollout is complete.

View file

@ -369,7 +369,7 @@ class CupertinoDatePicker extends StatefulWidget {
final Color? backgroundColor;
@override
State<StatefulWidget> createState() {
State<StatefulWidget> createState() { // ignore: no_logic_in_create_state, https://github.com/flutter/flutter/issues/70499
// The `time` mode and `dateAndTime` mode of the picker share the time
// columns, so they are placed together to one state.
// The `date` mode has different children and is implemented in a different

View file

@ -136,7 +136,7 @@ class CupertinoSearchTextField extends StatefulWidget {
this.backgroundColor,
this.borderRadius,
this.padding = const EdgeInsetsDirectional.fromSTEB(3.8, 8, 5, 8),
Color this.itemColor = CupertinoColors.secondaryLabel,
this.itemColor = CupertinoColors.secondaryLabel,
this.itemSize = 20.0,
this.prefixInsets = const EdgeInsetsDirectional.fromSTEB(6, 0, 0, 4),
this.suffixInsets = const EdgeInsetsDirectional.fromSTEB(0, 0, 5, 2),

View file

@ -375,7 +375,7 @@ class SystemMouseCursor extends MouseCursor {
final String kind;
@override
String get debugDescription => '$runtimeType($kind)';
String get debugDescription => '${objectRuntimeType(this, 'SystemMouseCursor')}($kind)';
@override
@protected

View file

@ -936,7 +936,7 @@ abstract class StatefulWidget extends Widget {
/// [State] objects.
@protected
@factory
State createState();
State createState(); // ignore: no_logic_in_create_state, this is the original sin
}
/// Tracks the lifecycle of [State] objects when asserts are enabled.

View file

@ -297,7 +297,7 @@ abstract class ImplicitlyAnimatedWidget extends StatefulWidget {
final VoidCallback? onEnd;
@override
ImplicitlyAnimatedWidgetState<ImplicitlyAnimatedWidget> createState();
ImplicitlyAnimatedWidgetState<ImplicitlyAnimatedWidget> createState(); // ignore: no_logic_in_create_state, https://github.com/dart-lang/linter/issues/2345
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {

View file

@ -28,7 +28,7 @@ abstract class UniqueWidget<T extends State<StatefulWidget>> extends StatefulWid
super(key: key);
@override
T createState();
T createState(); // ignore: no_logic_in_create_state, https://github.com/dart-lang/linter/issues/2345
/// The state for the unique inflated instance of this widget.
///

View file

@ -27,8 +27,9 @@ void main() {
expect(await stream.single, equals(42));
bool ranAction = false;
final Future<int> completeResult = future.whenComplete(() {
final Future<int> completeResult = future.whenComplete(() { // ignore: void_checks, https://github.com/dart-lang/linter/issues/1675
ranAction = true;
// verify that whenComplete does NOT propagate its return value:
return Future<int>.value(31);
});
@ -39,7 +40,7 @@ void main() {
Object? exception;
try {
await future.whenComplete(() {
await future.whenComplete(() { // ignore: void_checks, https://github.com/dart-lang/linter/issues/1675
throw ArgumentError();
});
// Unreached.

View file

@ -24,7 +24,7 @@ class TestImageInfo implements ImageInfo {
final int value;
@override
String toString() => '$runtimeType($value)';
String toString() => '${objectRuntimeType(this, 'TestImageInfo')}($value)';
@override
TestImageInfo clone() {
@ -81,7 +81,7 @@ class TestImageProvider extends ImageProvider<int> {
}
@override
String toString() => '$runtimeType($key, $imageValue)';
String toString() => '${objectRuntimeType(this, 'TestImageProvider')}($key, $imageValue)';
}
class FailingTestImageProvider extends TestImageProvider {

View file

@ -374,7 +374,7 @@ class TestAnimatedWidget extends StatefulWidget {
final State<StatefulWidget> state;
@override
State<StatefulWidget> createState() => state;
State<StatefulWidget> createState() => state; // ignore: no_logic_in_create_state, this test predates the lint
}
abstract class _TestAnimatedWidgetState extends State<TestAnimatedWidget> {

View file

@ -29,8 +29,8 @@ class TestScrollPhysics extends ScrollPhysics {
@override
String toString() {
if (parent == null)
return '$runtimeType($name)';
return '$runtimeType($name) -> $parent';
return '${objectRuntimeType(this, 'TestScrollPhysics')}($name)';
return '${objectRuntimeType(this, 'TestScrollPhysics')}($name) -> $parent';
}
}

View file

@ -349,7 +349,7 @@ class TestSemantics {
String toString([ int indentAmount = 0 ]) {
final String indent = ' ' * indentAmount;
final StringBuffer buf = StringBuffer();
buf.writeln('$indent$runtimeType(');
buf.writeln('$indent${objectRuntimeType(this, 'TestSemantics')}(');
if (id != null)
buf.writeln('$indent id: $id,');
if (flags is int && flags != 0 || flags is List<SemanticsFlag> && (flags as List<SemanticsFlag>).isNotEmpty)

View file

@ -114,7 +114,7 @@ class CyclicDiagnostic extends DiagnosticableTree {
final String name;
@override
String toStringShort() => '$runtimeType-$name';
String toStringShort() => '${objectRuntimeType(this, 'CyclicDiagnistic')}-$name';
// We have to override toString to avoid the toString call itself triggering a
// stack overflow.

View file

@ -777,7 +777,7 @@ class DriverOffset {
final double dy;
@override
String toString() => '$runtimeType($dx, $dy)';
String toString() => '$runtimeType($dx, $dy)'; // ignore: no_runtimetype_tostring, can't access package:flutter here to use objectRuntimeType
@override
bool operator ==(Object other) {

View file

@ -52,7 +52,7 @@ class SyncTestLocalizationsDelegate extends LocalizationsDelegate<TestLocalizati
}
@override
String toString() => '$runtimeType($prefix)';
String toString() => '${objectRuntimeType(this, 'SyncTestLocalizationsDelegate')}($prefix)';
}
class AsyncTestLocalizationsDelegate extends LocalizationsDelegate<TestLocalizations> {
@ -74,7 +74,7 @@ class AsyncTestLocalizationsDelegate extends LocalizationsDelegate<TestLocalizat
}
@override
String toString() => '$runtimeType($prefix)';
String toString() => '${objectRuntimeType(this, 'AsyncTestLocalizationsDelegate')}($prefix)';
}
class MoreLocalizations {