-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ignore magic numbers in widget parameters (#74)
* Ignore magic numbers in widget parameters * Add lint parameter to ignore magic numbers in widget params * Improve the allowed_in_widget_params parameter to exclude magic numbers in nested objects of Widget parameters * Add tests for disabled allowed_in_widget_params lint parameter * Remove unnecessary dependency --------- Co-authored-by: vladimir-beloded <[email protected]>
- Loading branch information
1 parent
414a14e
commit b45d2be
Showing
6 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
lint_test/no_magic_number_allowed_in_widget_params_test/analysis_options.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
27 changes: 27 additions & 0 deletions
27
...c_number_allowed_in_widget_params_test/no_magic_number_allowed_in_widget_params_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); | ||
} |
11 changes: 11 additions & 0 deletions
11
lint_test/no_magic_number_allowed_in_widget_params_test/pubspec.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
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' | ||
|
||
dev_dependencies: | ||
solid_lints: | ||
path: ../../ | ||
test: ^1.20.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters