diff --git a/CHANGELOG.md b/CHANGELOG.md index a21c1cd..e9c8b8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## 0.1.5 -- Added `avoid_using_debug_print` rule +- Added `avoid_debug_print` rule - Fixed an issue with no_magic_number lint ## 0.1.4 diff --git a/example/analysis_options.yaml b/example/analysis_options.yaml index ef2ab4e..1e39170 100644 --- a/example/analysis_options.yaml +++ b/example/analysis_options.yaml @@ -19,7 +19,7 @@ custom_lint: - avoid_unnecessary_setstate - double_literal_format - avoid_unnecessary_type_assertions - - avoid_using_debug_print + - avoid_debug_print - avoid_using_api: severity: info entries: diff --git a/lib/analysis_options.yaml b/lib/analysis_options.yaml index fc1f7ad..6d1ce56 100644 --- a/lib/analysis_options.yaml +++ b/lib/analysis_options.yaml @@ -50,7 +50,7 @@ custom_lint: - avoid_unnecessary_type_casts - avoid_unrelated_type_assertions - avoid_unused_parameters - - avoid_using_debug_print + - avoid_debug_print - cyclomatic_complexity: max_complexity: 10 diff --git a/lib/solid_lints.dart b/lib/solid_lints.dart index b35e3d8..f6524d0 100644 --- a/lib/solid_lints.dart +++ b/lib/solid_lints.dart @@ -1,6 +1,7 @@ library solid_metrics; import 'package:custom_lint_builder/custom_lint_builder.dart'; +import 'package:solid_lints/src/lints/avoid_debug_print/avoid_debug_print_rule.dart'; import 'package:solid_lints/src/lints/avoid_global_state/avoid_global_state_rule.dart'; import 'package:solid_lints/src/lints/avoid_late_keyword/avoid_late_keyword_rule.dart'; import 'package:solid_lints/src/lints/avoid_non_null_assertion/avoid_non_null_assertion_rule.dart'; @@ -11,7 +12,6 @@ import 'package:solid_lints/src/lints/avoid_unnecessary_type_casts/avoid_unneces import 'package:solid_lints/src/lints/avoid_unrelated_type_assertions/avoid_unrelated_type_assertions_rule.dart'; import 'package:solid_lints/src/lints/avoid_unused_parameters/avoid_unused_parameters_rule.dart'; import 'package:solid_lints/src/lints/avoid_using_api/avoid_using_api_rule.dart'; -import 'package:solid_lints/src/lints/avoid_using_debug_print/avoid_using_debug_print_rule.dart'; import 'package:solid_lints/src/lints/cyclomatic_complexity/cyclomatic_complexity_metric.dart'; import 'package:solid_lints/src/lints/double_literal_format/double_literal_format_rule.dart'; import 'package:solid_lints/src/lints/function_lines_of_code/function_lines_of_code_metric.dart'; @@ -60,7 +60,7 @@ class _SolidLints extends PluginBase { PreferLastRule.createRule(configs), PreferMatchFileNameRule.createRule(configs), ProperSuperCallsRule.createRule(configs), - AvoidUsingDebugPrint.createRule(configs), + AvoidDebugPrint.createRule(configs), ]; // Return only enabled rules diff --git a/lib/src/lints/avoid_using_debug_print/avoid_using_debug_print_rule.dart b/lib/src/lints/avoid_debug_print/avoid_debug_print_rule.dart similarity index 82% rename from lib/src/lints/avoid_using_debug_print/avoid_using_debug_print_rule.dart rename to lib/src/lints/avoid_debug_print/avoid_debug_print_rule.dart index a898b1a..73d60c4 100644 --- a/lib/src/lints/avoid_using_debug_print/avoid_using_debug_print_rule.dart +++ b/lib/src/lints/avoid_debug_print/avoid_debug_print_rule.dart @@ -2,11 +2,11 @@ import 'package:analyzer/dart/ast/ast.dart'; import 'package:analyzer/dart/ast/syntactic_entity.dart'; import 'package:analyzer/error/listener.dart'; import 'package:custom_lint_builder/custom_lint_builder.dart'; -import 'package:solid_lints/src/lints/avoid_using_debug_print/models/avoid_using_debug_print_func_model.dart'; +import 'package:solid_lints/src/lints/avoid_debug_print/models/avoid_debug_print_func_model.dart'; import 'package:solid_lints/src/models/rule_config.dart'; import 'package:solid_lints/src/models/solid_lint_rule.dart'; -/// A `avoid_using_debug_print` rule which forbids calling or referencing +/// A `avoid_debug_print` rule which forbids calling or referencing /// debugPrint function from flutter/foundation. /// /// ### Example @@ -25,23 +25,23 @@ import 'package:solid_lints/src/models/solid_lint_rule.dart'; /// ```dart /// log(''); /// ``` -class AvoidUsingDebugPrint extends SolidLintRule { +class AvoidDebugPrint extends SolidLintRule { /// The [LintCode] of this lint rule that represents /// the error when debugPrint is called - static const lintName = 'avoid_using_debug_print'; + static const lintName = 'avoid_debug_print'; - AvoidUsingDebugPrint._(super.config); + AvoidDebugPrint._(super.config); - /// Creates a new instance of [AvoidUsingDebugPrint] + /// Creates a new instance of [AvoidDebugPrint] /// based on the lint configuration. - factory AvoidUsingDebugPrint.createRule(CustomLintConfigs configs) { + factory AvoidDebugPrint.createRule(CustomLintConfigs configs) { final rule = RuleConfig( configs: configs, name: lintName, problemMessage: (_) => "Avoid using 'debugPrint'", ); - return AvoidUsingDebugPrint._(rule); + return AvoidDebugPrint._(rule); } @override @@ -89,7 +89,7 @@ class AvoidUsingDebugPrint extends SolidLintRule { required AstNode node, required ErrorReporter reporter, }) { - final funcModel = AvoidUsingDebugPrintFuncModel.parseExpression(identifier); + final funcModel = AvoidDebugPrintFuncModel.parseExpression(identifier); if (funcModel.hasSameName && funcModel.hasTheSameSource) { reporter.reportErrorForNode(code, node); diff --git a/lib/src/lints/avoid_using_debug_print/models/avoid_using_debug_print_func_model.dart b/lib/src/lints/avoid_debug_print/models/avoid_debug_print_func_model.dart similarity index 78% rename from lib/src/lints/avoid_using_debug_print/models/avoid_using_debug_print_func_model.dart rename to lib/src/lints/avoid_debug_print/models/avoid_debug_print_func_model.dart index 8bcea5a..c0fb542 100644 --- a/lib/src/lints/avoid_using_debug_print/models/avoid_using_debug_print_func_model.dart +++ b/lib/src/lints/avoid_debug_print/models/avoid_debug_print_func_model.dart @@ -1,7 +1,7 @@ import 'package:analyzer/dart/ast/ast.dart'; /// A class used to parse function expression -class AvoidUsingDebugPrintFuncModel { +class AvoidDebugPrintFuncModel { /// Function name final String name; @@ -9,36 +9,36 @@ class AvoidUsingDebugPrintFuncModel { final String sourcePath; /// A class used to parse function expression - const AvoidUsingDebugPrintFuncModel({ + const AvoidDebugPrintFuncModel({ required this.name, required this.sourcePath, }); /// A constructor that parses identifier into [name] and [sourcePath] - factory AvoidUsingDebugPrintFuncModel.parseExpression( + factory AvoidDebugPrintFuncModel.parseExpression( Identifier identifier, ) { switch (identifier) { case PrefixedIdentifier(): final prefix = identifier.prefix.name; - return AvoidUsingDebugPrintFuncModel( + return AvoidDebugPrintFuncModel( name: identifier.name.replaceAll('$prefix.', ''), sourcePath: identifier.staticElement?.librarySource?.uri.toString() ?? '', ); case SimpleIdentifier(): - return AvoidUsingDebugPrintFuncModel( + return AvoidDebugPrintFuncModel( name: identifier.name, sourcePath: identifier.staticElement?.librarySource?.uri.toString() ?? '', ); default: - return AvoidUsingDebugPrintFuncModel._empty(); + return AvoidDebugPrintFuncModel._empty(); } } - factory AvoidUsingDebugPrintFuncModel._empty() { - return const AvoidUsingDebugPrintFuncModel( + factory AvoidDebugPrintFuncModel._empty() { + return const AvoidDebugPrintFuncModel( name: '', sourcePath: '', ); diff --git a/lint_test/analysis_options.yaml b/lint_test/analysis_options.yaml index f81fe40..ea43510 100644 --- a/lint_test/analysis_options.yaml +++ b/lint_test/analysis_options.yaml @@ -27,7 +27,7 @@ custom_lint: - newline_before_return - no_empty_block - no_equal_then_else - - avoid_using_debug_print + - avoid_debug_print - member_ordering: alphabetize: true order: diff --git a/lint_test/avoid_using_debug_print_test.dart/avoid_using_debug_print_prefix_test.dart b/lint_test/avoid_debug_print_test.dart/avoid_debug_print_prefix_test.dart similarity index 63% rename from lint_test/avoid_using_debug_print_test.dart/avoid_using_debug_print_prefix_test.dart rename to lint_test/avoid_debug_print_test.dart/avoid_debug_print_prefix_test.dart index 4d6ab9b..1767f8f 100644 --- a/lint_test/avoid_using_debug_print_test.dart/avoid_using_debug_print_prefix_test.dart +++ b/lint_test/avoid_debug_print_test.dart/avoid_debug_print_prefix_test.dart @@ -2,17 +2,17 @@ import 'package:flutter/foundation.dart' as f; -/// Test the avoid_using_debug_print +/// Test the avoid_debug_print void avoidDebugPrintTest() { - // expect_lint: avoid_using_debug_print + // expect_lint: avoid_debug_print f.debugPrint(''); - // expect_lint: avoid_using_debug_print + // expect_lint: avoid_debug_print final test = f.debugPrint; test('test'); - // expect_lint: avoid_using_debug_print + // expect_lint: avoid_debug_print final test2 = f.debugPrint(''); debugPrint(); diff --git a/lint_test/avoid_using_debug_print_test.dart/avoid_using_debug_print_test.dart b/lint_test/avoid_debug_print_test.dart/avoid_debug_print_test.dart similarity index 61% rename from lint_test/avoid_using_debug_print_test.dart/avoid_using_debug_print_test.dart rename to lint_test/avoid_debug_print_test.dart/avoid_debug_print_test.dart index f075bd7..32cdc59 100644 --- a/lint_test/avoid_using_debug_print_test.dart/avoid_using_debug_print_test.dart +++ b/lint_test/avoid_debug_print_test.dart/avoid_debug_print_test.dart @@ -2,22 +2,22 @@ import 'package:flutter/foundation.dart'; -/// Test the avoid_using_debug_print +/// Test the avoid_debug_print void avoidDebugPrintTest() { - // expect_lint: avoid_using_debug_print + // expect_lint: avoid_debug_print debugPrint(''); - // expect_lint: avoid_using_debug_print + // expect_lint: avoid_debug_print final test = debugPrint; var test2; - // expect_lint: avoid_using_debug_print + // expect_lint: avoid_debug_print test2 = debugPrint; test.call('test'); - // expect_lint: avoid_using_debug_print + // expect_lint: avoid_debug_print final test3 = debugPrint(''); someOtherFunction();