Skip to content

Commit 90e083f

Browse files
author
shaark
committed
issue-167. fixed after comments
1 parent 5175b01 commit 90e083f

File tree

4 files changed

+65
-65
lines changed

4 files changed

+65
-65
lines changed

lib/src/lints/avoid_returning_widgets/models/avoid_returning_widgets_parameters.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import 'package:solid_lints/src/models/exclude_params.dart';
1+
import 'package:solid_lints/src/models/excluded_identifiers_list_parameter.dart';
22

33
/// A data model class that represents the "avoid returning widgets" input
44
/// parameters.
55
class AvoidReturningWidgetsParameters {
66
/// A list of methods that should be excluded from the lint.
7-
final ExcludeParameters exclude;
7+
final ExcludedIdentifiersListParameter exclude;
88

99
/// Constructor for [AvoidReturningWidgetsParameters] model
1010
AvoidReturningWidgetsParameters({
@@ -14,9 +14,9 @@ class AvoidReturningWidgetsParameters {
1414
/// Method for creating from json data
1515
factory AvoidReturningWidgetsParameters.fromJson(Map<String, dynamic> json) {
1616
return AvoidReturningWidgetsParameters(
17-
exclude: ExcludeParameters.fromJson(
17+
exclude: ExcludedIdentifiersListParameter.fromJson(
1818
excludeList:
19-
json[ExcludeParameters.excludeParameterName] as Iterable? ?? [],
19+
json[ExcludedIdentifiersListParameter.excludeParameterName] as Iterable? ?? [],
2020
),
2121
);
2222
}

lib/src/models/exclude_params.dart

Lines changed: 0 additions & 56 deletions
This file was deleted.

lib/src/models/excluded_identifiers_parameter.dart renamed to lib/src/models/excluded_identifier_parameter.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
/// Model class for ExcludeRule parameters
2-
class ExcludedIdentifiersParameter {
2+
class ExcludedIdentifierParameter {
33
/// The name of the method that should be excluded from the lint.
44
final String methodName;
55

66
/// The name of the class that should be excluded from the lint.
77
final String? className;
88

9-
/// Constructor for [ExcludedIdentifiersParameter] model
10-
const ExcludedIdentifiersParameter({
9+
/// Constructor for [ExcludedIdentifierParameter] model
10+
const ExcludedIdentifierParameter({
1111
required this.methodName,
1212
required this.className,
1313
});
1414

1515
///
16-
factory ExcludedIdentifiersParameter.fromJson(
16+
factory ExcludedIdentifierParameter.fromJson(
1717
Map<dynamic, dynamic> json,
1818
) {
19-
return ExcludedIdentifiersParameter(
19+
return ExcludedIdentifierParameter(
2020
methodName: json['method_name'] as String,
2121
className: json['class_name'] as String?,
2222
);
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import 'package:analyzer/dart/ast/ast.dart';
2+
import 'package:collection/collection.dart';
3+
import 'package:solid_lints/src/models/excluded_identifier_parameter.dart';
4+
5+
/// A data model class that represents the exclude input
6+
/// parameters.
7+
class ExcludedIdentifiersListParameter {
8+
/// A list of identifiers (classes, methods, functions) that should be
9+
/// excluded from the lint.
10+
final List<ExcludedIdentifierParameter> exclude;
11+
12+
/// A common parameter key for analysis_options.yaml
13+
static const String excludeParameterName = 'exclude';
14+
15+
/// Constructor for [ExcludedIdentifiersListParameter] model
16+
ExcludedIdentifiersListParameter({
17+
required this.exclude,
18+
});
19+
20+
/// Method for creating from json data
21+
factory ExcludedIdentifiersListParameter.fromJson({
22+
required Iterable<dynamic> excludeList,
23+
}) {
24+
final exclude = <ExcludedIdentifierParameter>[];
25+
26+
for (final item in excludeList) {
27+
if (item is Map) {
28+
exclude.add(ExcludedIdentifierParameter.fromJson(item));
29+
}
30+
}
31+
return ExcludedIdentifiersListParameter(
32+
exclude: exclude,
33+
);
34+
}
35+
36+
/// Returns whether the target node should be ignored during analysis.
37+
bool shouldIgnore(Declaration node) {
38+
final methodName = node.declaredElement?.name;
39+
40+
final excludedItem =
41+
exclude.firstWhereOrNull((e) => e.methodName == methodName);
42+
43+
if (excludedItem == null) return false;
44+
45+
final className = excludedItem.className;
46+
47+
if (className == null || node is! MethodDeclaration) {
48+
return true;
49+
} else {
50+
final classDeclaration = node.thisOrAncestorOfType<ClassDeclaration>();
51+
52+
return classDeclaration != null &&
53+
classDeclaration.name.toString() == className;
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)