From 455e17c403c0b63606f37eeb858526d9e31d1af9 Mon Sep 17 00:00:00 2001 From: "alexiuk.genius" Date: Thu, 18 Apr 2024 14:44:01 +0200 Subject: [PATCH] Add new lint rule: consider_making_a_member_private_rule.dart --- lib/solid_lints.dart | 2 ++ ...consider_making_a_member_private_rule.dart | 25 ++++++++++++++++++- lint_test/analysis_options.yaml | 1 + 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/solid_lints.dart b/lib/solid_lints.dart index f6524d0..51c5eb9 100644 --- a/lib/solid_lints.dart +++ b/lib/solid_lints.dart @@ -12,6 +12,7 @@ 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/consider_making_a_member_private/consider_making_a_member_private_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'; @@ -61,6 +62,7 @@ class _SolidLints extends PluginBase { PreferMatchFileNameRule.createRule(configs), ProperSuperCallsRule.createRule(configs), AvoidDebugPrint.createRule(configs), + ConsiderMakingAMemberPrivateRule.createRule(configs), ]; // Return only enabled rules diff --git a/lib/src/lints/consider_making_a_member_private/consider_making_a_member_private_rule.dart b/lib/src/lints/consider_making_a_member_private/consider_making_a_member_private_rule.dart index 8122cd1..636fa5b 100644 --- a/lib/src/lints/consider_making_a_member_private/consider_making_a_member_private_rule.dart +++ b/lib/src/lints/consider_making_a_member_private/consider_making_a_member_private_rule.dart @@ -1,3 +1,5 @@ +import 'package:analyzer/dart/ast/ast.dart'; +import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/error/listener.dart'; import 'package:custom_lint_builder/custom_lint_builder.dart'; import 'package:solid_lints/src/models/rule_config.dart'; @@ -26,6 +28,27 @@ class ConsiderMakingAMemberPrivateRule extends SolidLintRule { ErrorReporter reporter, CustomLintContext context, ) { - // TODO: Implement the rule + context.registry.addMethodDeclaration((node) { + if (node + case MethodDeclaration( + declaredElement: ExecutableElement(isPublic: true) + )) { + // print(node); + } + }); + + context.registry.addVariableDeclaration((node) { + if (node + case VariableDeclaration( + declaredElement: VariableElement(isPublic: true) + )) { + print(node); + } + }); + context.registry.addSimpleIdentifier((node) { + if (node case SimpleIdentifier(staticElement: Element(isPublic: true))) { + print(node); + } + }); } } diff --git a/lint_test/analysis_options.yaml b/lint_test/analysis_options.yaml index ea43510..31625e4 100644 --- a/lint_test/analysis_options.yaml +++ b/lint_test/analysis_options.yaml @@ -28,6 +28,7 @@ custom_lint: - no_empty_block - no_equal_then_else - avoid_debug_print + - consider_making_a_member_private - member_ordering: alphabetize: true order: