Skip to content
This repository was archived by the owner on Jul 16, 2023. It is now read-only.

feat: cleanup public API #1053

Merged
merged 2 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* feat: support dynamic method names for [`member-ordering`](https://dartcodemetrics.dev/docs/rules/common/member-ordering).
* fix: check `of` constructor exist for [`prefer-iterable-of`](https://dartcodemetrics.dev/docs/rules/common/prefer-iterable-of)
* feat: **Breaking change** change severity for avoid-banned-imports, prefer-trailing-comma, ban-name rules.
* feat: **Breaking change** cleanup public API.

## 4.21.2

Expand Down
2 changes: 2 additions & 0 deletions lib/cli_runner.dart
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export 'package:dart_code_metrics/src/cli/cli_runner.dart';
export 'package:dart_code_metrics/src/logger/logger.dart';
export 'package:dart_code_metrics/src/logger/progress.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import '../../../../utils/node_utils.dart';
import '../../lint_utils.dart';
import '../../metrics/metric_utils.dart';
import '../../metrics/metrics_list/source_lines_of_code/source_lines_of_code_metric.dart';
import '../../metrics/models/metric_value_level.dart';
import '../../models/entity_type.dart';
import '../../models/internal_resolved_unit_result.dart';
import '../../models/issue.dart';
Expand Down Expand Up @@ -74,9 +73,6 @@ class LongMethod extends Pattern {
),
),
),
if (_sourceLinesOfCodeMetricThreshold == null)
// ignore: deprecated_member_use_from_same_package
..._legacyBehaviour(source, entry),
])
.toList();

Expand Down Expand Up @@ -109,30 +105,4 @@ class LongMethod extends Pattern {
maximumLines != null
? "Based on configuration of this package, we don't recommend write a $functionType longer than $maximumLines lines with code."
: null;

@Deprecated('Fallback for current behaviour, will be removed in 5.0.0')
Iterable<Issue> _legacyBehaviour(
InternalResolvedUnitResult source,
MapEntry<ScopedFunctionDeclaration, Report> entry,
) =>
entry.value.metrics
.where((metricValue) =>
metricValue.metricsId == SourceLinesOfCodeMetric.metricId &&
metricValue.level == MetricValueLevel.none &&
metricValue.value > 50)
.map(
(metricValue) => createIssue(
pattern: this,
location: nodeLocation(
node: entry.key.declaration,
source: source,
),
message: _compileMessage(
lines: metricValue.value,
functionType: entry.key.type,
),
verboseMessage:
'Anti pattern works in deprecated mode. Please configure ${SourceLinesOfCodeMetric.metricId} metric. For detailed information please read documentation.',
),
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import '../../../../utils/node_utils.dart';
import '../../lint_utils.dart';
import '../../metrics/metric_utils.dart';
import '../../metrics/metrics_list/number_of_parameters_metric.dart';
import '../../metrics/models/metric_value_level.dart';
import '../../models/entity_type.dart';
import '../../models/function_type.dart';
import '../../models/internal_resolved_unit_result.dart';
Expand Down Expand Up @@ -72,9 +71,6 @@ class LongParameterList extends Pattern {
),
),
),
if (_numberOfParametersMetricThreshold == null)
// ignore: deprecated_member_use_from_same_package
..._legacyBehaviour(source, entry),
])
.toList();

Expand All @@ -91,30 +87,4 @@ class LongParameterList extends Pattern {
maximumArguments != null
? "Based on configuration of this package, we don't recommend writing a $functionType with argument count more than $maximumArguments."
: null;

@Deprecated('Fallback for current behaviour, will be removed in 5.0.0')
Iterable<Issue> _legacyBehaviour(
InternalResolvedUnitResult source,
MapEntry<ScopedFunctionDeclaration, Report> entry,
) =>
entry.value.metrics
.where((metricValue) =>
metricValue.metricsId == NumberOfParametersMetric.metricId &&
metricValue.level == MetricValueLevel.none &&
metricValue.value > 4)
.map(
(metricValue) => createIssue(
pattern: this,
location: nodeLocation(
node: entry.key.declaration,
source: source,
),
message: _compileMessage(
args: metricValue.value,
functionType: entry.key.type,
),
verboseMessage:
'Anti pattern works in deprecated mode. Please configure ${NumberOfParametersMetric.metricId} metric. For detailed information please read documentation.',
),
);
}
4 changes: 1 addition & 3 deletions lib/src/analyzers/lint_analyzer/lint_analyzer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@ class LintAnalyzer {

/// Returns a reporter for the given [name]. Use the reporter
/// to convert analysis reports to console, JSON or other supported format.
Reporter<FileReport, Object, LintReportParams>? getReporter({
Reporter<FileReport, LintReportParams>? getReporter({
required String name,
required IOSink output,
required String reportFolder,
@Deprecated('Unused argument. Will be removed in 5.0.0.') // ignore: avoid-unused-parameters
LintConfig? config,
}) =>
reporter(
name: name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ class SummaryLintReportRecordStatus {
/// Error.
///
/// Status indicates that a record contains error information.
/// Commonly represend by ❌ emoji
/// Commonly represented by ❌ emoji
static const error = SummaryLintReportRecordStatus._('error');

/// Warning.
///
/// Status indicates that a record requires user attention.
/// Commonly represend by ⚠️ emoji.
/// Commonly represented by ⚠️ emoji.
static const warning = SummaryLintReportRecordStatus._('warning');

/// OK.
///
/// Standard status for successful record.
/// Commonly represend by ✅ emoji.
/// Commonly represented by ✅ emoji.
static const ok = SummaryLintReportRecordStatus._('ok');

/// None.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import '../models/summary_lint_report_record.dart';

/// Represents additional lint reporter params.
class LintReportParams {
final bool congratulate;
final Iterable<SummaryLintReportRecord<Object>> summary;

const LintReportParams({required this.congratulate});
const LintReportParams({required this.congratulate, required this.summary});
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import 'reporters_list/json/lint_json_reporter.dart';

final _implementedReports = <
String,
Reporter<FileReport, Object, LintReportParams> Function(
Reporter<FileReport, LintReportParams> Function(
IOSink output,
String reportFolder,
)>{
Expand All @@ -34,7 +34,7 @@ final _implementedReports = <
LintCodeClimateReporter(output, gitlabCompatible: true),
};

Reporter<FileReport, Object, LintReportParams>? reporter({
Reporter<FileReport, LintReportParams>? reporter({
required String name,
required IOSink output,
required String reportFolder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@ import '../../../../../reporters/models/checkstyle_reporter.dart';
import '../../../metrics/models/metric_value_level.dart';
import '../../../models/lint_file_report.dart';
import '../../../models/severity.dart';
import '../../../models/summary_lint_report_record.dart';
import '../../lint_report_params.dart';

/// Lint Checkstyle reporter.
///
/// Use it to create reports in Checkstyle format.
class LintCheckstyleReporter extends CheckstyleReporter<LintFileReport,
SummaryLintReportRecord<Object>, LintReportParams> {
class LintCheckstyleReporter
extends CheckstyleReporter<LintFileReport, LintReportParams> {
LintCheckstyleReporter(super.output);

@override
Future<void> report(
Iterable<LintFileReport> records, {
Iterable<SummaryLintReportRecord<Object>> summary = const [],
LintReportParams? additionalParams,
}) async {
if (records.isEmpty) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import '../../../models/issue.dart';
import '../../../models/lint_file_report.dart';
import '../../../models/report.dart';
import '../../../models/severity.dart';
import '../../../models/summary_lint_report_record.dart';
import '../../lint_report_params.dart';
import 'models/code_climate_issue.dart';
import 'models/code_climate_issue_category.dart';
Expand All @@ -18,14 +17,13 @@ import 'models/code_climate_issue_severity.dart';
/// Lint Code Climate reporter.
///
/// Use it to create reports in Code Climate format.
class LintCodeClimateReporter extends CodeClimateReporter<LintFileReport,
SummaryLintReportRecord<Object>, LintReportParams> {
class LintCodeClimateReporter
extends CodeClimateReporter<LintFileReport, LintReportParams> {
LintCodeClimateReporter(super.output, {super.gitlabCompatible});

@override
Future<void> report(
Iterable<LintFileReport> records, {
Iterable<SummaryLintReportRecord<Object>> summary = const [],
LintReportParams? additionalParams,
}) async {
if (records.isEmpty) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import '../../../metrics/models/metric_value_level.dart';
import '../../../models/issue.dart';
import '../../../models/lint_file_report.dart';
import '../../../models/report.dart';
import '../../../models/summary_lint_report_record.dart';
import '../../lint_report_params.dart';
import 'lint_console_reporter_helper.dart';

/// Lint console reporter.
///
/// Use it to create reports in console format.
class LintConsoleReporter extends ConsoleReporter<LintFileReport,
SummaryLintReportRecord<Object>, LintReportParams> {
class LintConsoleReporter
extends ConsoleReporter<LintFileReport, LintReportParams> {
/// If true will report info about all files even if they're not above warning threshold.
final bool reportAll;

Expand All @@ -24,7 +23,6 @@ class LintConsoleReporter extends ConsoleReporter<LintFileReport,
@override
Future<void> report(
Iterable<LintFileReport> records, {
Iterable<SummaryLintReportRecord<Object>> summary = const [],
LintReportParams? additionalParams,
}) async {
var hasReportData = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
import '../../../../../reporters/models/github_reporter.dart';
import '../../../models/lint_file_report.dart';
import '../../../models/severity.dart';
import '../../../models/summary_lint_report_record.dart';
import '../../lint_report_params.dart';

const _deprecationMessage =
'DEPRECATED! This reporter is deprecated and will be removed in 5.0.0. You can migrate on our GitHub Action.';

/// Lint GitHub reporter.
///
/// Use it to create reports in GitHub format.
///
/// **Note:** this reporter is deprecated and should not be used.
/// Consider using Dart Code Metrics GitHub Action instead.
class LintGitHubReporter extends GitHubReporter<LintFileReport,
SummaryLintReportRecord<Object>, LintReportParams> {
class LintGitHubReporter
extends GitHubReporter<LintFileReport, LintReportParams> {
const LintGitHubReporter(super.output);

@override
Future<void> report(
Iterable<LintFileReport> records, {
Iterable<SummaryLintReportRecord<Object>> summary = const [],
LintReportParams? additionalParams,
}) async {
if (records.isEmpty) {
Expand All @@ -30,7 +22,7 @@ class LintGitHubReporter extends GitHubReporter<LintFileReport,
for (final analysisRecord in records) {
for (final antiPattern in analysisRecord.antiPatternCases) {
output.writeln(GitHubReporter.commands.warning(
'$_deprecationMessage ${antiPattern.message}',
antiPattern.message,
absolutePath: analysisRecord.path,
sourceSpan: antiPattern.location,
));
Expand All @@ -40,12 +32,12 @@ class LintGitHubReporter extends GitHubReporter<LintFileReport,
output.writeln(
issue.severity == Severity.error
? GitHubReporter.commands.error(
'$_deprecationMessage ${issue.message}',
issue.message,
absolutePath: analysisRecord.path,
sourceSpan: issue.location,
)
: GitHubReporter.commands.warning(
'$_deprecationMessage ${issue.message}',
issue.message,
absolutePath: analysisRecord.path,
sourceSpan: issue.location,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import '../../../metrics/metrics_list/cyclomatic_complexity/cyclomatic_complexit
import '../../../metrics/metrics_list/technical_debt/technical_debt_metric.dart';
import '../../../metrics/models/metric_value_level.dart';
import '../../../models/lint_file_report.dart';
import '../../../models/summary_lint_report_record.dart';
import '../../lint_report_params.dart';
import '../../utility_selector.dart';
import 'components/icon.dart';
Expand Down Expand Up @@ -53,14 +52,12 @@ const _designIssues = 'Design issues';
/// Lint HTML reporter.
///
/// Use it to create reports in HTML format.
class LintHtmlReporter extends HtmlReporter<LintFileReport,
SummaryLintReportRecord<Object>, LintReportParams> {
class LintHtmlReporter extends HtmlReporter<LintFileReport, LintReportParams> {
LintHtmlReporter(super.reportFolder);

@override
Future<void> report(
Iterable<LintFileReport> records, {
Iterable<SummaryLintReportRecord<Object>> summary = const [],
LintReportParams? additionalParams,
}) async {
await super.report(records);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import '../../lint_report_params.dart';
/// Lint JSON reporter.
///
/// Use it to create reports in JSON format.
class LintJsonReporter extends JsonReporter<LintFileReport,
SummaryLintReportRecord<Object>, LintReportParams> {
class LintJsonReporter extends JsonReporter<LintFileReport, LintReportParams> {
const LintJsonReporter(IOSink output) : super(output, 2);

factory LintJsonReporter.toFile(String path, String rootFolder) {
Expand All @@ -33,18 +32,19 @@ class LintJsonReporter extends JsonReporter<LintFileReport,
@override
Future<void> report(
Iterable<LintFileReport> records, {
Iterable<SummaryLintReportRecord<Object>> summary = const [],
LintReportParams? additionalParams,
}) async {
if (records.isEmpty) {
return;
}

final summary = additionalParams?.summary;

final encodedReport = json.encode({
'formatVersion': formatVersion,
'timestamp': getTimestamp(),
'records': records.map(_lintFileReportToJson).toList(),
if (summary.isNotEmpty)
if (summary != null && summary.isNotEmpty)
'summary': summary.map(_summaryLintReportRecordToJson).toList(),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ import 'unnecessary_nullable_report_params.dart';

final _implementedReports = <
String,
Reporter<UnnecessaryNullableFileReport, void,
UnnecessaryNullableReportParams>
Reporter<UnnecessaryNullableFileReport, UnnecessaryNullableReportParams>
Function(
IOSink output,
)>{
ConsoleReporter.id: UnnecessaryNullableConsoleReporter.new,
JsonReporter.id: UnnecessaryNullableJsonReporter.new,
};

Reporter<UnnecessaryNullableFileReport, void, UnnecessaryNullableReportParams>?
Reporter<UnnecessaryNullableFileReport, UnnecessaryNullableReportParams>?
reporter({
required String name,
required IOSink output,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import '../../unnecessary_nullable_report_params.dart';
///
/// Use it to create reports in console format.
class UnnecessaryNullableConsoleReporter extends ConsoleReporter<
UnnecessaryNullableFileReport, void, UnnecessaryNullableReportParams> {
UnnecessaryNullableFileReport, UnnecessaryNullableReportParams> {
UnnecessaryNullableConsoleReporter(super.output);

@override
Future<void> report(
Iterable<UnnecessaryNullableFileReport> records, {
Iterable<void> summary = const [],
UnnecessaryNullableReportParams? additionalParams,
}) async {
if (records.isEmpty) {
Expand Down
Loading