-
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.
add exclude params support to avoid_returning_widgets rule
- Loading branch information
Showing
5 changed files
with
95 additions
and
2 deletions.
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
24 changes: 24 additions & 0 deletions
24
lib/src/lints/avoid_returning_widgets/models/avoid_returning_widgets_exclude.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,24 @@ | ||
/// Model class for AvoidReturningWidgetsExclude parameters | ||
class AvoidReturningWidgetsExclude { | ||
/// The name of the method that should be excluded from the lint. | ||
final String methodName; | ||
|
||
/// The name of the class that should be excluded from the lint. | ||
final String? className; | ||
|
||
/// Constructor for [AvoidReturningWidgetsExclude] model | ||
const AvoidReturningWidgetsExclude({ | ||
required this.methodName, | ||
required this.className, | ||
}); | ||
|
||
/// | ||
factory AvoidReturningWidgetsExclude.fromJson( | ||
Map<dynamic, dynamic> json, | ||
) { | ||
return AvoidReturningWidgetsExclude( | ||
methodName: json['method_name'] as String, | ||
className: json['class_name'] as String?, | ||
); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
lib/src/lints/avoid_returning_widgets/models/avoid_returning_widgets_parameters.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 @@ | ||
import 'package:solid_lints/src/lints/avoid_returning_widgets/models/avoid_returning_widgets_exclude.dart'; | ||
|
||
/// A data model class that represents the "avoid returning widgets" input | ||
/// parameters. | ||
class AvoidReturningWidgetsParameters { | ||
/// A list of methods that should be excluded from the lint. | ||
final List<AvoidReturningWidgetsExclude> exclude; | ||
|
||
/// Constructor for [AvoidReturningWidgetsParameters] model | ||
AvoidReturningWidgetsParameters({ | ||
required this.exclude, | ||
}); | ||
|
||
/// Method for creating from json data | ||
factory AvoidReturningWidgetsParameters.fromJson(Map<String, dynamic> json) { | ||
final exclude = <AvoidReturningWidgetsExclude>[]; | ||
|
||
for (final item in (json['exclude'] as Iterable?) ?? []) { | ||
if (item is Map && item['method_name'] is String) { | ||
exclude.add(AvoidReturningWidgetsExclude.fromJson(item)); | ||
} | ||
} | ||
return AvoidReturningWidgetsParameters( | ||
exclude: exclude, | ||
); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
lint_test/avoid_returning_widget_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,11 @@ | ||
analyzer: | ||
plugins: | ||
- ../custom_lint | ||
|
||
custom_lint: | ||
rules: | ||
- avoid_returning_widgets: | ||
exclude: | ||
- method_name: excludeWidget | ||
class_name: SizedBox | ||
- method_name: excludeWidget2 |
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