Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename avoid_using_debug_print -> avoid_debug_print #138

Merged
merged 2 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion example/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion lib/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/solid_lints.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,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/avoid_using_debug_print/avoid_using_debug_print_rule.dart';
import 'package:solid_lints/src/lints/avoid_debug_print/avoid_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';
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
import 'package:analyzer/dart/ast/ast.dart';

/// A class used to parse function expression
class AvoidUsingDebugPrintFuncModel {
class AvoidDebugPrintFuncModel {
/// Function name
final String name;

/// Function's source path
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: '',
);
Expand Down
2 changes: 1 addition & 1 deletion lint_test/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading