Skip to content

Commit

Permalink
Add new lint rule: consider_making_a_member_private_rule.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
4akloon committed Apr 18, 2024
1 parent c626a30 commit 455e17c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/solid_lints.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -61,6 +62,7 @@ class _SolidLints extends PluginBase {
PreferMatchFileNameRule.createRule(configs),
ProperSuperCallsRule.createRule(configs),
AvoidDebugPrint.createRule(configs),
ConsiderMakingAMemberPrivateRule.createRule(configs),
];

// Return only enabled rules
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
}
});
}
}
1 change: 1 addition & 0 deletions lint_test/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 455e17c

Please sign in to comment.