Skip to content

Commit

Permalink
migrate from pedantic -> flutter_lints
Browse files Browse the repository at this point in the history
  • Loading branch information
coreysprague committed Oct 15, 2021
1 parent 905cd94 commit 29a36d6
Show file tree
Hide file tree
Showing 22 changed files with 82 additions and 160 deletions.
122 changes: 1 addition & 121 deletions packages/golden_toolkit/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,121 +1 @@
# pedantic has a strong foundation, but right now they only enable a small set of lints
# we'll use them as a base, and add on the additional ones that our team has agreed upon.
include: package:pedantic/analysis_options.yaml

analyzer:
strong-mode:
implicit-dynamic: false
errors:
missing_required_param: warning
missing_return: warning
implementation_imports: warning
todo: ignore
exclude:

linter:
rules:
# These are specified by effective dart guidelines, but are not yet in pedantic
- avoid_classes_with_only_static_members
# - avoid_catches_without_on_clauses -- pedeantic dart disagrees for valid reasons
# - avoid_function_literals_in_foreach_calls
- avoid_null_checks_in_equality_operators
# - avoid_positional_boolean_parameters -- too many false positives, not enough of an issue
- avoid_private_typedef_functions
- avoid_returning_null
- avoid_returning_this
- avoid_setters_without_getters
- camel_case_types
- constant_identifier_names
- directives_ordering
- file_names
- hash_and_equals
- non_constant_identifier_names
# - omit_local_variable_types
- one_member_abstracts
- package_api_docs
- prefer_adjacent_string_concatenation
- prefer_collection_literals
- prefer_final_fields
- prefer_function_declarations_over_variables
- prefer_generic_function_type_aliases
- prefer_initializing_formals
- prefer_interpolation_to_compose_strings
- public_member_api_docs
- type_annotate_public_apis
- unnecessary_brace_in_string_interps
- unnecessary_getters_setters
- unnecessary_lambdas
- unnecessary_this
# - use_setters_to_change_properties -- too many false positives... pedantic chose to not enforce it as well
- use_to_and_as_if_applicable

# These are not specified by pedantic dart
- always_declare_return_types
- always_put_control_body_on_new_line
- always_require_non_null_named_parameters
- annotate_overrides
- avoid_field_initializers_in_const_classes
- avoid_renaming_method_parameters
- avoid_returning_null_for_void
- avoid_slow_async_io
- avoid_unused_constructor_parameters
- avoid_void_async
- cancel_subscriptions
- control_flow_in_finally
- empty_statements
- flutter_style_todos
- implementation_imports
- iterable_contains_unrelated_type
- list_remove_unrelated_type
- no_adjacent_strings_in_list
- overridden_fields
- package_names
- package_prefixed_library_names
- prefer_asserts_in_initializer_lists
- prefer_conditional_assignment
- prefer_const_constructors
- prefer_const_constructors_in_immutables
- prefer_const_declarations
- prefer_const_literals_to_create_immutables
- prefer_final_locals
- prefer_foreach
- prefer_single_quotes
- prefer_typing_uninitialized_variables
- prefer_void_to_null
- sort_constructors_first
- sort_pub_dependencies
- sort_unnamed_constructors_first
- test_types_in_equals
- throw_in_finally
- unnecessary_null_aware_assignments
- unnecessary_overrides
- unnecessary_parenthesis
- unnecessary_statements

#Possible new rules to add
- avoid_returning_null_for_future
- literal_only_boolean_expressions
# - always_put_required_named_parameters_first -- seems like a good idea, but requires adjusting a lot of code
- avoid_bool_literals_in_conditional_expressions
- avoid_catching_errors
# - avoid_types_on_closure_parameters -- is great most of the time, but is necessary often in tests... we should review
# - cascade_invocations -- is great for production code... causes a lot of noise with GWT in tests -- puts multiple thens in a single line
- join_return_with_assignment
- only_throw_errors
- parameter_assignments
- prefer_constructors_over_static_methods
# - prefer_expression_function_bodies -- LINTs on widget build methods...
- prefer_final_in_for_each
- prefer_for_elements_to_map_fromIterable
- prefer_if_elements_to_conditional_expressions
- prefer_if_null_operators
- prefer_inlined_adds
- prefer_null_aware_operators
- prefer_spread_collections
- provide_deprecation_message
- sort_child_properties_last
- unnecessary_await_in_return
- prefer_relative_imports
- avoid_equals_and_hash_code_on_mutable_classes
- avoid_unnecessary_containers
- prefer_is_not_operator
include: package:flutter_lints/flutter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'package:flutter/material.dart';

/// Counter page from flutters default generated app
class FlutterDemoPage extends StatelessWidget {
const FlutterDemoPage({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return MaterialApp(
Expand Down
2 changes: 2 additions & 0 deletions packages/golden_toolkit/example/lib/src/shadow_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import 'package:flutter/widgets.dart';
/// refactor and clean it up!
class ShadowWidget extends StatelessWidget {
const ShadowWidget({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Padding(
Expand Down
6 changes: 3 additions & 3 deletions packages/golden_toolkit/example/lib/src/weather_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@ class WeeklyForecastCompact extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Container(
return SizedBox(
height: 175,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: forecasts
.map((f) => Container(
.map((f) => SizedBox(
width: MediaQuery.of(context).size.width * .3,
child: WeatherCard.forecast(f),
))
Expand Down Expand Up @@ -211,7 +211,7 @@ class WeatherCard extends StatelessWidget {
//if screen is small, we want this card to be vertical as Column
Widget _verticalCard(BuildContext context) {
final cardTheme = CardTheme.of(context);
return Container(
return SizedBox(
width: 180,
child: Card(
shape: cardTheme.shape ?? _cardShape,
Expand Down
21 changes: 14 additions & 7 deletions packages/golden_toolkit/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_lints:
dependency: "direct dev"
description:
name: flutter_lints
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
flutter_test:
dependency: "direct dev"
description: flutter
Expand All @@ -67,6 +74,13 @@ packages:
relative: true
source: path
version: "0.10.0"
lints:
dependency: transitive
description:
name: lints
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
matcher:
dependency: transitive
description:
Expand All @@ -88,13 +102,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
pedantic:
dependency: "direct dev"
description:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.10.0-nullsafety.3"
sky_engine:
dependency: transitive
description: flutter
Expand Down
2 changes: 1 addition & 1 deletion packages/golden_toolkit/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ dependencies:
sdk: flutter

dev_dependencies:
flutter_lints: ^1.0.4
flutter_test:
sdk: flutter
golden_toolkit:
path: ../
pedantic: ^1.10.0-nullsafety.3

flutter:
uses-material-design: true
Expand Down
10 changes: 5 additions & 5 deletions packages/golden_toolkit/example/test/flutter_demo_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void main() {
testGoldens('DeviceBuilder - one scenario - default devices', (tester) async {
final builder = DeviceBuilder()
..addScenario(
widget: FlutterDemoPage(),
widget: const FlutterDemoPage(),
name: 'default page',
);

Expand All @@ -28,7 +28,7 @@ void main() {
Device.tabletLandscape,
])
..addScenario(
widget: FlutterDemoPage(),
widget: const FlutterDemoPage(),
name: 'default page',
);

Expand All @@ -48,11 +48,11 @@ void main() {
Device.tabletLandscape,
])
..addScenario(
widget: FlutterDemoPage(),
widget: const FlutterDemoPage(),
name: 'default page',
)
..addScenario(
widget: FlutterDemoPage(),
widget: const FlutterDemoPage(),
name: 'tap once',
onCreate: (scenarioWidgetKey) async {
final finder = find.descendant(
Expand All @@ -64,7 +64,7 @@ void main() {
},
)
..addScenario(
widget: FlutterDemoPage(),
widget: const FlutterDemoPage(),
name: 'tap five times',
onCreate: (scenarioWidgetKey) async {
final finder = find.descendant(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import '../../lib/src/shadow_widget.dart';

void main() {
testGoldens('Shadows are globally enabled by default', (tester) async {
await tester.pumpWidgetBuilder(ShadowWidget());
await tester.pumpWidgetBuilder(const ShadowWidget());

await screenMatchesGolden(tester, 'shadow_widget_globally_enabled_shadows');
});
Expand All @@ -15,7 +15,7 @@ void main() {
testGoldens(
'Shadows can be disabled locally by wrapping in GoldenToolkit.runWithConfiguration',
(tester) async {
await tester.pumpWidgetBuilder(ShadowWidget());
await tester.pumpWidgetBuilder(const ShadowWidget());

await screenMatchesGolden(
tester, 'shadow_widget_locally_disabled_shadows');
Expand Down
4 changes: 2 additions & 2 deletions packages/golden_toolkit/example/test/shadow_widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import '../lib/src/shadow_widget.dart';

void main() {
testGoldens('Shadows are disabled by default', (tester) async {
await tester.pumpWidgetBuilder(ShadowWidget());
await tester.pumpWidgetBuilder(const ShadowWidget());

await screenMatchesGolden(tester, 'shadow_widget_disabled_shadows');
});
Expand All @@ -15,7 +15,7 @@ void main() {
testGoldens(
'Shadows can be enabled locally by wrapping in GoldenToolkit.runWithConfiguration',
(tester) async {
await tester.pumpWidgetBuilder(ShadowWidget());
await tester.pumpWidgetBuilder(const ShadowWidget());

await screenMatchesGolden(
tester, 'shadow_widget_locally_enabled_shadows');
Expand Down
1 change: 1 addition & 0 deletions packages/golden_toolkit/lib/src/device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class Device {
textScale: textScale,
brightness: Brightness.dark,
safeArea: safeArea,
// ignore: unnecessary_string_escapes
name: '$name\_dark',
);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/golden_toolkit/lib/src/device_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class _DeviceScenarioWidget extends StatelessWidget {

return MediaQuery(
data: mergedMediaQuery,
child: Container(
child: SizedBox(
width: device.size.width,
height: device.size.height,
child: widget,
Expand All @@ -216,7 +216,7 @@ class _DeviceScenarioWidget extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Container(
SizedBox(
height: 20,
width: device.size.width,
child: Text(
Expand Down
21 changes: 14 additions & 7 deletions packages/golden_toolkit/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,25 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_lints:
dependency: "direct dev"
description:
name: flutter_lints
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
flutter_test:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
lints:
dependency: transitive
description:
name: lints
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
matcher:
dependency: transitive
description:
Expand All @@ -81,13 +95,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
pedantic:
dependency: "direct dev"
description:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.11.1"
sample_dependency:
dependency: "direct dev"
description:
Expand Down
2 changes: 1 addition & 1 deletion packages/golden_toolkit/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dependencies:
meta: ^1.1.8

dev_dependencies:
pedantic: ^1.11.1
flutter_lints: ^1.0.4
sample_dependency:
path: test/sample_dependency
test_api: ^0.4.2
Expand Down
Loading

0 comments on commit 29a36d6

Please sign in to comment.