Skip to content

Commit

Permalink
issue-167. fixed after comments
Browse files Browse the repository at this point in the history
  • Loading branch information
shaark committed Dec 5, 2024
1 parent 71c28c0 commit 2cc9b19
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 10 deletions.
15 changes: 9 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
## 0.3.4
- Added exclude classes, methods, functions into avoid_returning_widgets,avoid_unused_parameters, cyclomatic_complexity, function_lines_of_code, no_empty_bloc, number_of_parameters
- Changed exclude parameter name into unction lines of code from excludeNames to exclude

## 0.2.4

## 0.3.0
- Added `exclude` parameter for the following lints:
- `avoid_returning_widgets`
- `avoid_unused_parameters`
- `cyclomatic_complexity`
- `function_lines_of_code`
- `no_empty_bloc`
- `number_of_parameters`
- BREAKING CHANGE: Renamed `excludeNames` parameter to `exclude` for `function_lines_of_code` lint.
- Fixed an issue with `prefer_early_retrun` for throw expression

## 0.2.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ExcludedIdentifierParameter {
/// Constructor for [ExcludedIdentifierParameter] model
const ExcludedIdentifierParameter({
required this.methodName,
required this.className,
this.className,
});

///
Expand Down
16 changes: 14 additions & 2 deletions lib/src/common/parameters/excluded_identifiers_list_parameter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ class ExcludedIdentifiersListParameter {
for (final item in excludeList) {
if (item is Map) {
exclude.add(ExcludedIdentifierParameter.fromJson(item));
} else if (item is String) {
exclude.add(
ExcludedIdentifierParameter(
methodName: item,
),
);
}
}
return ExcludedIdentifiersListParameter(
Expand All @@ -47,6 +53,12 @@ class ExcludedIdentifiersListParameter {
for (final item in excludeList) {
if (item is Map) {
exclude.add(ExcludedIdentifierParameter.fromJson(item));
} else if (item is String) {
exclude.add(
ExcludedIdentifierParameter(
methodName: item,
),
);
}
}
return ExcludedIdentifiersListParameter(
Expand All @@ -56,10 +68,10 @@ class ExcludedIdentifiersListParameter {

/// Returns whether the target node should be ignored during analysis.
bool shouldIgnore(Declaration node) {
final methodName = node.declaredElement?.name;
final declaredName = node.declaredElement?.name;

final excludedItem = exclude.firstWhereOrNull(
(e) => e.methodName == methodName || e.className == methodName,
(e) => e.methodName == declaredName || e.className == declaredName,
);

if (excludedItem == null) return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:solid_lints/src/common/parameters/excluded_identifiers_list_parameter.dart';

/// A data model class that represents the "no empty block" input
/// A data model class that represents the "no empty block" lint input
/// parameters.
class NoEmptyBlockParameters {
/// A list of methods that should be excluded from the lint.
Expand Down
2 changes: 2 additions & 0 deletions lint_test/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ custom_lint:
- class_name: Exclude
method_name: excludeMethod
- method_name: excludeMethod
- simpleMethodName
- SimpleClassName
- newline_before_return
- no_empty_block:
exclude:
Expand Down
17 changes: 17 additions & 0 deletions lint_test/avoid_unused_parameters_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ void excludeMethod(String s) {
return;
}

// no lint
void simpleMethodName(String s) {
return;
}

class Exclude {
// no lint
void excludeMethod(String s) {
Expand All @@ -224,3 +229,15 @@ class Exclude {
return;
}
}

class SimpleClassName {
// no lint
void simpleMethodName(String s) {
return;
}

// expect_lint: avoid_unused_parameters
void simpleMethodName2(String s) {
return;
}
}

0 comments on commit 2cc9b19

Please sign in to comment.