diff --git a/lib/src/lints/avoid_returning_widgets/models/avoid_returning_widgets_exclude.dart b/lib/src/common/parameters/excluded_identifier_parameter.dart similarity index 59% rename from lib/src/lints/avoid_returning_widgets/models/avoid_returning_widgets_exclude.dart rename to lib/src/common/parameters/excluded_identifier_parameter.dart index f2cd81be..8fb05354 100644 --- a/lib/src/lints/avoid_returning_widgets/models/avoid_returning_widgets_exclude.dart +++ b/lib/src/common/parameters/excluded_identifier_parameter.dart @@ -1,22 +1,22 @@ -/// Model class for AvoidReturningWidgetsExclude parameters -class AvoidReturningWidgetsExclude { +/// Model class for ExcludeRule parameters +class ExcludedIdentifierParameter { /// 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({ + /// Constructor for [ExcludedIdentifierParameter] model + const ExcludedIdentifierParameter({ required this.methodName, required this.className, }); /// - factory AvoidReturningWidgetsExclude.fromJson( + factory ExcludedIdentifierParameter.fromJson( Map json, ) { - return AvoidReturningWidgetsExclude( + return ExcludedIdentifierParameter( methodName: json['method_name'] as String, className: json['class_name'] as String?, ); diff --git a/lib/src/common/parameters/excluded_identifiers_list_parameter.dart b/lib/src/common/parameters/excluded_identifiers_list_parameter.dart new file mode 100644 index 00000000..fcde7acd --- /dev/null +++ b/lib/src/common/parameters/excluded_identifiers_list_parameter.dart @@ -0,0 +1,78 @@ +import 'package:analyzer/dart/ast/ast.dart'; +import 'package:collection/collection.dart'; +import 'package:solid_lints/src/common/parameters/excluded_identifier_parameter.dart'; + +/// A model representing "exclude" parameters for linting, defining +/// identifiers (classes, methods, functions) to be ignored during analysis. +class ExcludedIdentifiersListParameter { + /// A list of identifiers (classes, methods, functions) that should be + /// excluded from the lint. + final List exclude; + + /// A common parameter key for analysis_options.yaml + static const String excludeParameterName = 'exclude'; + + /// Constructor for [ExcludedIdentifiersListParameter] model + ExcludedIdentifiersListParameter({ + required this.exclude, + }); + + /// Method for creating from json data + factory ExcludedIdentifiersListParameter.fromJson({ + required Iterable excludeList, + }) { + final exclude = []; + + for (final item in excludeList) { + if (item is Map) { + exclude.add(ExcludedIdentifierParameter.fromJson(item)); + } + } + return ExcludedIdentifiersListParameter( + exclude: exclude, + ); + } + + /// Method for creating from json data with default params + factory ExcludedIdentifiersListParameter.defaultFromJson( + Map json, + ) { + final exclude = []; + + final excludeList = + json[ExcludedIdentifiersListParameter.excludeParameterName] + as Iterable? ?? + []; + + for (final item in excludeList) { + if (item is Map) { + exclude.add(ExcludedIdentifierParameter.fromJson(item)); + } + } + return ExcludedIdentifiersListParameter( + exclude: exclude, + ); + } + + /// Returns whether the target node should be ignored during analysis. + bool shouldIgnore(Declaration node) { + final methodName = node.declaredElement?.name; + + final excludedItem = exclude.firstWhereOrNull( + (e) => e.methodName == methodName || e.className == methodName, + ); + + if (excludedItem == null) return false; + + final className = excludedItem.className; + + if (className == null || node is! MethodDeclaration) { + return true; + } else { + final classDeclaration = node.thisOrAncestorOfType(); + + return classDeclaration != null && + classDeclaration.name.toString() == className; + } + } +} diff --git a/lib/src/lints/avoid_returning_widgets/avoid_returning_widgets_rule.dart b/lib/src/lints/avoid_returning_widgets/avoid_returning_widgets_rule.dart index d1a7195a..3c113552 100644 --- a/lib/src/lints/avoid_returning_widgets/avoid_returning_widgets_rule.dart +++ b/lib/src/lints/avoid_returning_widgets/avoid_returning_widgets_rule.dart @@ -1,7 +1,6 @@ import 'package:analyzer/dart/ast/ast.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:analyzer/error/listener.dart'; -import 'package:collection/collection.dart'; import 'package:custom_lint_builder/custom_lint_builder.dart'; import 'package:solid_lints/src/lints/avoid_returning_widgets/models/avoid_returning_widgets_parameters.dart'; import 'package:solid_lints/src/models/rule_config.dart'; @@ -96,7 +95,7 @@ class AvoidReturningWidgetsRule final isWidgetReturned = hasWidgetType(returnType); - final isIgnored = _shouldIgnore(node); + final isIgnored = config.parameters.exclude.shouldIgnore(node); final isOverriden = node.declaredElement?.hasOverride ?? false; @@ -105,25 +104,4 @@ class AvoidReturningWidgetsRule } }); } - - bool _shouldIgnore(Declaration node) { - final methodName = node.declaredElement?.name; - - final excludedItem = config.parameters.exclude - .firstWhereOrNull((e) => e.methodName == methodName); - - if (excludedItem == null) return false; - - final className = excludedItem.className; - - if (className == null || node is! MethodDeclaration) { - return true; - } else { - final classDeclaration = node.thisOrAncestorOfType(); - - if (classDeclaration == null) return false; - - return classDeclaration.name.toString() == className; - } - } } diff --git a/lib/src/lints/avoid_returning_widgets/models/avoid_returning_widgets_parameters.dart b/lib/src/lints/avoid_returning_widgets/models/avoid_returning_widgets_parameters.dart index 75012f5d..7947ea64 100644 --- a/lib/src/lints/avoid_returning_widgets/models/avoid_returning_widgets_parameters.dart +++ b/lib/src/lints/avoid_returning_widgets/models/avoid_returning_widgets_parameters.dart @@ -1,10 +1,10 @@ -import 'package:solid_lints/src/lints/avoid_returning_widgets/models/avoid_returning_widgets_exclude.dart'; +import 'package:solid_lints/src/common/parameters/excluded_identifiers_list_parameter.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 exclude; + final ExcludedIdentifiersListParameter exclude; /// Constructor for [AvoidReturningWidgetsParameters] model AvoidReturningWidgetsParameters({ @@ -13,16 +13,8 @@ class AvoidReturningWidgetsParameters { /// Method for creating from json data factory AvoidReturningWidgetsParameters.fromJson(Map json) { - final exclude = []; - - final excludeList = json['exclude'] as Iterable? ?? []; - for (final item in excludeList) { - if (item is Map) { - exclude.add(AvoidReturningWidgetsExclude.fromJson(item)); - } - } return AvoidReturningWidgetsParameters( - exclude: exclude, + exclude: ExcludedIdentifiersListParameter.defaultFromJson(json), ); } } diff --git a/lib/src/lints/avoid_unused_parameters/avoid_unused_parameters_rule.dart b/lib/src/lints/avoid_unused_parameters/avoid_unused_parameters_rule.dart index aaf8a095..3496e1e2 100644 --- a/lib/src/lints/avoid_unused_parameters/avoid_unused_parameters_rule.dart +++ b/lib/src/lints/avoid_unused_parameters/avoid_unused_parameters_rule.dart @@ -1,5 +1,7 @@ + import 'package:analyzer/error/listener.dart'; import 'package:custom_lint_builder/custom_lint_builder.dart'; +import 'package:solid_lints/src/lints/avoid_unused_parameters/models/avoid_unused_parameters.dart'; import 'package:solid_lints/src/lints/avoid_unused_parameters/visitors/avoid_unused_parameters_visitor.dart'; import 'package:solid_lints/src/models/rule_config.dart'; import 'package:solid_lints/src/models/solid_lint_rule.dart'; @@ -64,7 +66,7 @@ import 'package:solid_lints/src/models/solid_lint_rule.dart'; /// }; /// /// ``` -class AvoidUnusedParametersRule extends SolidLintRule { +class AvoidUnusedParametersRule extends SolidLintRule { /// This lint rule represents /// the error whether we use bad formatted double literals. static const String lintName = 'avoid_unused_parameters'; @@ -79,6 +81,7 @@ class AvoidUnusedParametersRule extends SolidLintRule { final rule = RuleConfig( configs: configs, name: lintName, + paramsParser: AvoidUnusedParameters.fromJson, problemMessage: (_) => 'Parameter is unused.', ); @@ -91,12 +94,16 @@ class AvoidUnusedParametersRule extends SolidLintRule { ErrorReporter reporter, CustomLintContext context, ) { - context.registry.addCompilationUnit((node) { - final visitor = AvoidUnusedParametersVisitor(); - node.accept(visitor); + context.registry.addDeclaration((node) { + final isIgnored = config.parameters.exclude.shouldIgnore(node); + + if (!isIgnored) { + final visitor = AvoidUnusedParametersVisitor(); + node.accept(visitor); - for (final element in visitor.unusedParameters) { - reporter.atNode(element, code); + for (final element in visitor.unusedParameters) { + reporter.atNode(element, code); + } } }); } diff --git a/lib/src/lints/avoid_unused_parameters/models/avoid_unused_parameters.dart b/lib/src/lints/avoid_unused_parameters/models/avoid_unused_parameters.dart new file mode 100644 index 00000000..f4dac97b --- /dev/null +++ b/lib/src/lints/avoid_unused_parameters/models/avoid_unused_parameters.dart @@ -0,0 +1,20 @@ +import 'package:solid_lints/src/common/parameters/excluded_identifiers_list_parameter.dart'; + +/// A data model class that represents the "avoid returning widgets" input +/// parameters. +class AvoidUnusedParameters { + /// A list of methods that should be excluded from the lint. + final ExcludedIdentifiersListParameter exclude; + + /// Constructor for [AvoidUnusedParameters] model + AvoidUnusedParameters({ + required this.exclude, + }); + + /// Method for creating from json data + factory AvoidUnusedParameters.fromJson(Map json) { + return AvoidUnusedParameters( + exclude: ExcludedIdentifiersListParameter.defaultFromJson(json), + ); + } +} diff --git a/lib/src/lints/cyclomatic_complexity/cyclomatic_complexity_rule.dart b/lib/src/lints/cyclomatic_complexity/cyclomatic_complexity_rule.dart index cc2949fb..3090db10 100644 --- a/lib/src/lints/cyclomatic_complexity/cyclomatic_complexity_rule.dart +++ b/lib/src/lints/cyclomatic_complexity/cyclomatic_complexity_rule.dart @@ -52,13 +52,19 @@ class CyclomaticComplexityRule CustomLintContext context, ) { context.registry.addBlockFunctionBody((node) { - final visitor = CyclomaticComplexityFlowVisitor(); - node.visitChildren(visitor); + context.registry.addDeclaration((declarationNode) { + final isIgnored = + config.parameters.exclude.shouldIgnore(declarationNode); + if (!isIgnored) { + final visitor = CyclomaticComplexityFlowVisitor(); + node.visitChildren(visitor); - if (visitor.complexityEntities.length + 1 > - config.parameters.maxComplexity) { - reporter.atNode(node, code); - } + if (visitor.complexityEntities.length + 1 > + config.parameters.maxComplexity) { + reporter.atNode(node, code); + } + } + }); }); } } diff --git a/lib/src/lints/cyclomatic_complexity/models/cyclomatic_complexity_parameters.dart b/lib/src/lints/cyclomatic_complexity/models/cyclomatic_complexity_parameters.dart index 3ffa5ae1..93d3b2cd 100644 --- a/lib/src/lints/cyclomatic_complexity/models/cyclomatic_complexity_parameters.dart +++ b/lib/src/lints/cyclomatic_complexity/models/cyclomatic_complexity_parameters.dart @@ -1,19 +1,26 @@ +import 'package:solid_lints/src/common/parameters/excluded_identifiers_list_parameter.dart'; + /// Cyclomatic complexity metric limits configuration. class CyclomaticComplexityParameters { /// Threshold cyclomatic complexity level, exceeding it triggers a warning. final int maxComplexity; + /// A list of methods that should be excluded from the lint. + final ExcludedIdentifiersListParameter exclude; + /// Reference: NIST 500-235 item 2.5 static const _defaultMaxComplexity = 10; /// Constructor for [CyclomaticComplexityParameters] model const CyclomaticComplexityParameters({ required this.maxComplexity, + required this.exclude, }); /// Method for creating from json data factory CyclomaticComplexityParameters.fromJson(Map json) => CyclomaticComplexityParameters( maxComplexity: json['max_complexity'] as int? ?? _defaultMaxComplexity, + exclude: ExcludedIdentifiersListParameter.defaultFromJson(json), ); } diff --git a/lib/src/lints/function_lines_of_code/function_lines_of_code_rule.dart b/lib/src/lints/function_lines_of_code/function_lines_of_code_rule.dart index c8d2623f..b71b21af 100644 --- a/lib/src/lints/function_lines_of_code/function_lines_of_code_rule.dart +++ b/lib/src/lints/function_lines_of_code/function_lines_of_code_rule.dart @@ -50,9 +50,15 @@ class FunctionLinesOfCodeRule ) { void checkNode(AstNode node) => _checkNode(resolver, reporter, node); - context.registry.addMethodDeclaration(checkNode); - context.registry.addFunctionDeclaration(checkNode); - context.registry.addFunctionExpression(checkNode); + context.registry.addDeclaration((declarationNode) { + final isIgnored = config.parameters.exclude.shouldIgnore(declarationNode); + + if (!isIgnored) { + context.registry.addMethodDeclaration(checkNode); + context.registry.addFunctionDeclaration(checkNode); + context.registry.addFunctionExpression(checkNode); + } + }); } void _checkNode( @@ -60,12 +66,6 @@ class FunctionLinesOfCodeRule ErrorReporter reporter, AstNode node, ) { - final functionName = _getFunctionName(node); - if (functionName != null && - config.parameters.excludeNames.contains(functionName)) { - return; - } - final visitor = FunctionLinesOfCodeVisitor(resolver.lineInfo); node.visitChildren(visitor); @@ -84,16 +84,4 @@ class FunctionLinesOfCodeRule ); } } - - String? _getFunctionName(AstNode node) { - if (node is FunctionDeclaration) { - return node.name.lexeme; - } else if (node is MethodDeclaration) { - return node.name.lexeme; - } else if (node is FunctionExpression) { - return node.declaredElement?.name; - } else { - return null; - } - } } diff --git a/lib/src/lints/function_lines_of_code/models/function_lines_of_code_parameters.dart b/lib/src/lints/function_lines_of_code/models/function_lines_of_code_parameters.dart index 757f5baf..7df6da2a 100644 --- a/lib/src/lints/function_lines_of_code/models/function_lines_of_code_parameters.dart +++ b/lib/src/lints/function_lines_of_code/models/function_lines_of_code_parameters.dart @@ -1,3 +1,5 @@ +import 'package:solid_lints/src/common/parameters/excluded_identifiers_list_parameter.dart'; + /// A data model class that represents the "function lines of code" input /// parameters. class FunctionLinesOfCodeParameters { @@ -5,22 +7,21 @@ class FunctionLinesOfCodeParameters { /// exceeding this limit triggers a warning. final int maxLines; - /// Function names to be excluded from the rule check - final List excludeNames; + /// A list of methods that should be excluded from the lint. + final ExcludedIdentifiersListParameter exclude; static const _defaultMaxLines = 200; /// Constructor for [FunctionLinesOfCodeParameters] model const FunctionLinesOfCodeParameters({ required this.maxLines, - required this.excludeNames, + required this.exclude, }); /// Method for creating from json data factory FunctionLinesOfCodeParameters.fromJson(Map json) => FunctionLinesOfCodeParameters( maxLines: json['max_lines'] as int? ?? _defaultMaxLines, - excludeNames: - List.from(json['excludeNames'] as Iterable? ?? []), + exclude: ExcludedIdentifiersListParameter.defaultFromJson(json), ); } 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 new file mode 100644 index 00000000..2a5555d8 --- /dev/null +++ b/lib/src/lints/no_empty_block/models/no_empty_block_parameters.dart @@ -0,0 +1,20 @@ +import 'package:solid_lints/src/common/parameters/excluded_identifiers_list_parameter.dart'; + +/// A data model class that represents the "avoid returning widgets" input +/// parameters. +class NoEmptyBlockParameters { + /// A list of methods that should be excluded from the lint. + final ExcludedIdentifiersListParameter exclude; + + /// Constructor for [NoEmptyBlockParameters] model + NoEmptyBlockParameters({ + required this.exclude, + }); + + /// Method for creating from json data + factory NoEmptyBlockParameters.fromJson(Map json) { + return NoEmptyBlockParameters( + exclude: ExcludedIdentifiersListParameter.defaultFromJson(json), + ); + } +} diff --git a/lib/src/lints/no_empty_block/no_empty_block_rule.dart b/lib/src/lints/no_empty_block/no_empty_block_rule.dart index fd469056..ebcefb2b 100644 --- a/lib/src/lints/no_empty_block/no_empty_block_rule.dart +++ b/lib/src/lints/no_empty_block/no_empty_block_rule.dart @@ -1,5 +1,6 @@ import 'package:analyzer/error/listener.dart'; import 'package:custom_lint_builder/custom_lint_builder.dart'; +import 'package:solid_lints/src/lints/no_empty_block/models/no_empty_block_parameters.dart'; import 'package:solid_lints/src/lints/no_empty_block/visitors/no_empty_block_visitor.dart'; import 'package:solid_lints/src/models/rule_config.dart'; import 'package:solid_lints/src/models/solid_lint_rule.dart'; @@ -49,7 +50,7 @@ import 'package:solid_lints/src/models/solid_lint_rule.dart'; /// } catch (_) {} // ignored by this rule /// } /// ``` -class NoEmptyBlockRule extends SolidLintRule { +class NoEmptyBlockRule extends SolidLintRule { /// This lint rule represents /// the error whether left empty block. static const String lintName = 'no_empty_block'; @@ -62,6 +63,7 @@ class NoEmptyBlockRule extends SolidLintRule { final config = RuleConfig( configs: configs, name: lintName, + paramsParser: NoEmptyBlockParameters.fromJson, problemMessage: (_) => 'Block is empty. Empty blocks are often indicators of missing code.', ); @@ -75,12 +77,15 @@ class NoEmptyBlockRule extends SolidLintRule { ErrorReporter reporter, CustomLintContext context, ) { - context.registry.addCompilationUnit((node) { - final visitor = NoEmptyBlockVisitor(); - node.accept(visitor); + context.registry.addDeclaration((node) { + final isIgnored = config.parameters.exclude.shouldIgnore(node); + if (!isIgnored) { + final visitor = NoEmptyBlockVisitor(); + node.accept(visitor); - for (final emptyBlock in visitor.emptyBlocks) { - reporter.atNode(emptyBlock, code); + for (final emptyBlock in visitor.emptyBlocks) { + reporter.atNode(emptyBlock, code); + } } }); } diff --git a/lib/src/lints/number_of_parameters/models/number_of_parameters_parameters.dart b/lib/src/lints/number_of_parameters/models/number_of_parameters_parameters.dart index e17e63d8..0ac631a4 100644 --- a/lib/src/lints/number_of_parameters/models/number_of_parameters_parameters.dart +++ b/lib/src/lints/number_of_parameters/models/number_of_parameters_parameters.dart @@ -1,19 +1,26 @@ +import 'package:solid_lints/src/common/parameters/excluded_identifiers_list_parameter.dart'; + /// A data model class that represents the "number of parameters" input /// parameters. class NumberOfParametersParameters { /// Maximum number of parameters allowed before a warning is triggered. final int maxParameters; + /// A list of methods that should be excluded from the lint. + final ExcludedIdentifiersListParameter exclude; + static const _defaultMaxParameters = 2; /// Constructor for [NumberOfParametersParameters] model const NumberOfParametersParameters({ required this.maxParameters, + required this.exclude, }); /// Method for creating from json data factory NumberOfParametersParameters.fromJson(Map json) => NumberOfParametersParameters( maxParameters: json['max_parameters'] as int? ?? _defaultMaxParameters, + exclude: ExcludedIdentifiersListParameter.defaultFromJson(json), ); } diff --git a/lib/src/lints/number_of_parameters/number_of_parameters_rule.dart b/lib/src/lints/number_of_parameters/number_of_parameters_rule.dart index 8df3eea1..f03a9c7a 100644 --- a/lib/src/lints/number_of_parameters/number_of_parameters_rule.dart +++ b/lib/src/lints/number_of_parameters/number_of_parameters_rule.dart @@ -65,6 +65,7 @@ class NumberOfParametersRule CustomLintContext context, ) { context.registry.addDeclaration((node) { + final isIgnored = config.parameters.exclude.shouldIgnore(node); final parameters = switch (node) { (final MethodDeclaration node) => node.parameters?.parameters.length ?? 0, @@ -73,7 +74,7 @@ class NumberOfParametersRule _ => 0, }; - if (parameters > config.parameters.maxParameters) { + if (!isIgnored && parameters > config.parameters.maxParameters) { reporter.atOffset( offset: node.firstTokenAfterCommentAndMetadata.offset, length: node.end, diff --git a/lint_test/analysis_options.yaml b/lint_test/analysis_options.yaml index 3d8da192..fae7e441 100644 --- a/lint_test/analysis_options.yaml +++ b/lint_test/analysis_options.yaml @@ -6,23 +6,45 @@ custom_lint: rules: - cyclomatic_complexity: max_complexity: 4 + exclude: + - method_name: excludeMethod + class_name: Exclude + - method_name: excludeMethod - number_of_parameters: max_parameters: 2 + exclude: + - method_name: avoidNumberOfParameters + class_name: Exclude + - method_name: avoidNumberOfParameters + - method_name: copyWith + class_name: UserDto - function_lines_of_code: max_lines: 50 - avoid_non_null_assertion - avoid_late_keyword: allow_initialized: true - avoid_global_state - - avoid_returning_widgets + - avoid_returning_widgets: + exclude: + - method_name: excludeWidgetMethod + class_name: ExcludeWidget + - method_name: excludeMethod - avoid_unnecessary_setstate - double_literal_format - avoid_unnecessary_type_assertions - avoid_unnecessary_type_casts - avoid_unrelated_type_assertions - - avoid_unused_parameters + - avoid_unused_parameters: + exclude: + - method_name: excludeMethod + class_name: Exclude + - method_name: excludeMethod - newline_before_return - - no_empty_block + - no_empty_block: + exclude: + - method_name: excludeMethod + class_name: Exclude + - method_name: excludeMethod - no_equal_then_else - avoid_debug_print_in_release - prefer_early_return diff --git a/lint_test/avoid_returning_widget_test/avoid_returning_widget_test.dart b/lint_test/avoid_returning_widget_test/avoid_returning_widget_test.dart index a1f3677f..ad4398ba 100644 --- a/lint_test/avoid_returning_widget_test/avoid_returning_widget_test.dart +++ b/lint_test/avoid_returning_widget_test/avoid_returning_widget_test.dart @@ -65,7 +65,7 @@ Widget build() { return Offstage(); } -// expect_lint: avoid_returning_widgets +// no lint SizedBox excludeMethod() => const SizedBox(); class ExcludeWidget extends StatelessWidget { @@ -76,7 +76,7 @@ class ExcludeWidget extends StatelessWidget { return const Placeholder(); } - // expect_lint: avoid_returning_widgets + // no lint Widget excludeWidgetMethod() => const SizedBox(); // expect_lint: avoid_returning_widgets diff --git a/lint_test/avoid_unused_parameters_test.dart b/lint_test/avoid_unused_parameters_test.dart index b75e120f..4511de75 100644 --- a/lint_test/avoid_unused_parameters_test.dart +++ b/lint_test/avoid_unused_parameters_test.dart @@ -207,3 +207,20 @@ class UsingConstructorParameterInInitializer { print(_value); } } + +// no lint +void excludeMethod(String s) { + return; +} + +class Exclude { + // no lint + void excludeMethod(String s) { + return; + } + +// expect_lint: avoid_unused_parameters + void excludeMethod2(String s) { + return; + } +} diff --git a/lint_test/avoid_unused_parameters_test/analysis_options.yaml b/lint_test/avoid_unused_parameters_test/analysis_options.yaml new file mode 100644 index 00000000..b70780bf --- /dev/null +++ b/lint_test/avoid_unused_parameters_test/analysis_options.yaml @@ -0,0 +1,11 @@ +analyzer: + plugins: + - ../custom_lint + +custom_lint: + rules: + - avoid_unused_parameters: + exclude: + - method_name: excludeMethod + class_name: Exclude + - method_name: excludeMethod diff --git a/lint_test/cyclomatic_complexity_test.dart b/lint_test/cyclomatic_complexity_test.dart index 0fafcdab..116e1fe0 100644 --- a/lint_test/cyclomatic_complexity_test.dart +++ b/lint_test/cyclomatic_complexity_test.dart @@ -31,3 +31,27 @@ class A { if (true) {} } } + +// no lint +void excludeMethod() { + if (true) { + if (true) { + if (true) { + if (true) {} + } + } + } +} + +class Exclude { + // no lint + void excludeMethod() { + if (true) { + if (true) { + if (true) { + if (true) {} + } + } + } + } +} diff --git a/lint_test/function_lines_of_code_test/analysis_options.yaml b/lint_test/function_lines_of_code_test/analysis_options.yaml index 51f88abf..7c277572 100644 --- a/lint_test/function_lines_of_code_test/analysis_options.yaml +++ b/lint_test/function_lines_of_code_test/analysis_options.yaml @@ -6,6 +6,6 @@ custom_lint: rules: - function_lines_of_code: max_lines: 5 - excludeNames: - - "longFunctionExcluded" - - "longMethodExcluded" + exclude: + - method_name: longFunctionExcluded + - method_name: longMethodExcluded diff --git a/lint_test/no_empty_block_test.dart b/lint_test/no_empty_block_test.dart index 385d30cb..96f2ef0d 100644 --- a/lint_test/no_empty_block_test.dart +++ b/lint_test/no_empty_block_test.dart @@ -49,3 +49,11 @@ class A { // TODO: implement toDoMethod } } + +// no lint +void excludeMethod() {} + +class Exclude { + // no lint + void excludeMethod() {} +} diff --git a/lint_test/number_of_parameters_test.dart b/lint_test/number_of_parameters_test.dart index 12fa6e21..b85c200a 100644 --- a/lint_test/number_of_parameters_test.dart +++ b/lint_test/number_of_parameters_test.dart @@ -1,7 +1,56 @@ -/// Check number of parameters fail +// ignore_for_file: prefer_match_file_name +// Check number of parameters fail /// /// `number_of_parameters: max_parameters` /// expect_lint: number_of_parameters String numberOfParameters(String a, String b, String c) { return a + b + c; } + +//no lint +String avoidNumberOfParameters(String a, String b, String c) { + return a + b + c; +} + +class Exclude { + //no lint + String avoidNumberOfParameters(String a, String b, String c) { + return a + b + c; + } +} + +class UserDto { + final String email; + final String firstName; + final String id; + final String imageUrl; + final String lastName; + + final String phone; + const UserDto({ + required this.id, + required this.firstName, + required this.lastName, + required this.imageUrl, + required this.email, + required this.phone, + }); + + UserDto copyWith({ + String? email, + String? firstName, + String? id, + String? imageUrl, + String? lastName, + String? phone, + }) { + return UserDto( + email: email ?? this.email, + firstName: firstName ?? this.firstName, + id: id ?? this.id, + imageUrl: imageUrl ?? this.imageUrl, + lastName: lastName ?? this.lastName, + phone: phone ?? this.phone, + ); + } +}