diff --git a/CHANGELOG.md b/CHANGELOG.md index 226206a..5392d67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/src/common/parameters/excluded_identifier_parameter.dart b/lib/src/common/parameters/excluded_identifier_parameter.dart index 8fb0535..c886a7f 100644 --- a/lib/src/common/parameters/excluded_identifier_parameter.dart +++ b/lib/src/common/parameters/excluded_identifier_parameter.dart @@ -9,7 +9,7 @@ class ExcludedIdentifierParameter { /// Constructor for [ExcludedIdentifierParameter] model const ExcludedIdentifierParameter({ required this.methodName, - required this.className, + this.className, }); /// diff --git a/lib/src/common/parameters/excluded_identifiers_list_parameter.dart b/lib/src/common/parameters/excluded_identifiers_list_parameter.dart index fcde7ac..48a45d4 100644 --- a/lib/src/common/parameters/excluded_identifiers_list_parameter.dart +++ b/lib/src/common/parameters/excluded_identifiers_list_parameter.dart @@ -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( @@ -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( @@ -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; diff --git a/lib/src/lints/no_empty_block/models/no_empty_block_parameters.dart b/lib/src/lints/no_empty_block/models/no_empty_block_parameters.dart index 1ed023b..42f1eb4 100644 --- a/lib/src/lints/no_empty_block/models/no_empty_block_parameters.dart +++ b/lib/src/lints/no_empty_block/models/no_empty_block_parameters.dart @@ -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. diff --git a/lint_test/analysis_options.yaml b/lint_test/analysis_options.yaml index 2989d61..ffabfbe 100644 --- a/lint_test/analysis_options.yaml +++ b/lint_test/analysis_options.yaml @@ -37,6 +37,8 @@ custom_lint: - class_name: Exclude method_name: excludeMethod - method_name: excludeMethod + - simpleMethodName + - SimpleClassName - newline_before_return - no_empty_block: exclude: diff --git a/lint_test/avoid_unused_parameters_test.dart b/lint_test/avoid_unused_parameters_test.dart index 4511de7..b4eb7bd 100644 --- a/lint_test/avoid_unused_parameters_test.dart +++ b/lint_test/avoid_unused_parameters_test.dart @@ -213,6 +213,11 @@ void excludeMethod(String s) { return; } +// no lint +void simpleMethodName(String s) { + return; +} + class Exclude { // no lint void excludeMethod(String s) { @@ -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; + } +}