Skip to content

Commit

Permalink
Add tests for disabled allowed_in_widget_params lint parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
vova-beloded-solid committed Nov 20, 2023
1 parent 9c00eba commit e40e846
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 3 deletions.
3 changes: 1 addition & 2 deletions lint_test/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ custom_lint:
- did_change_dependencies_method
- did_update_widget_method
- dispose_method
- no_magic_number:
allowed_in_widget_params: true
- no_magic_number
- prefer_conditional_expressions
- prefer_first
- prefer_last
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
analyzer:
plugins:
- ../custom_lint

custom_lint:
rules:
- no_magic_number:
allowed_in_widget_params: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Allowed for numbers in a Widget subtype parameters.
abstract interface class Widget {}

class StatelessWidget implements Widget {}

class MyWidget extends StatelessWidget {
final MyWidgetDecoration decoration;
final int value;

MyWidget({
required this.decoration,
required this.value,
});
}

class MyWidgetDecoration {
final int size;

MyWidgetDecoration({required this.size});
}

Widget build() {
return MyWidget(
decoration: MyWidgetDecoration(size: 12),
value: 23,
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: no_magic_number_allowed_in_widget_params_test
description: A starting point for Dart libraries or applications.
publish_to: none

environment:
sdk: '>=3.0.0 <4.0.0'

dependencies:
flutter:
sdk: flutter

dev_dependencies:
solid_lints:
path: ../../
test: ^1.20.1
3 changes: 2 additions & 1 deletion lint_test/no_magic_number_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ class ConstructorInitializer {
ConstructorInitializer() : value = 10;
}

// Allowed for numbers in a Widget subtype parameters.
abstract interface class Widget {}

class StatelessWidget implements Widget {}
Expand All @@ -110,7 +109,9 @@ class MyWidgetDecoration {

Widget build() {
return MyWidget(
// expect_lint: no_magic_number
decoration: MyWidgetDecoration(size: 12),
// expect_lint: no_magic_number
value: 23,
);
}

0 comments on commit e40e846

Please sign in to comment.