From e6030f0141081324d91ea5a48b4322ddfdc00e0a Mon Sep 17 00:00:00 2001 From: Dmitry Krutskikh Date: Sat, 11 Dec 2021 07:26:23 +0300 Subject: [PATCH] chore: activate language strict rules --- CHANGELOG.md | 1 + analysis_options.yaml | 3 +++ lib/src/analyzers/lint_analyzer/lint_analyzer.dart | 5 +++-- .../metrics_list/maintainability_index_metric.dart | 2 +- .../metrics_list/number_of_parameters_metric.dart | 2 +- .../metrics/metrics_list/weight_of_class_metric.dart | 2 +- .../lint_analyzer/metrics/models/file_metric.dart | 2 +- .../analyzers/lint_analyzer/metrics/models/metric.dart | 2 +- .../lint_analyzer/reporters/reporter_factory.dart | 7 ++++--- .../code_climate/lint_code_climate_reporter.dart | 6 +++--- .../reporters_list/console/lint_console_reporter.dart | 6 +++--- .../reporters_list/github/lint_github_reporter.dart | 4 ++-- .../reporters_list/html/lint_html_reporter.dart | 4 ++-- .../reporters_list/json/lint_json_reporter.dart | 10 +++------- .../reporters/reporter_factory.dart | 6 ++++-- .../unused_files_analyzer/unused_files_analyzer.dart | 2 +- .../reporters/reporter_factory.dart | 9 ++++----- .../unused_l10n_analyzer/unused_l10n_analyzer.dart | 2 +- lib/src/cli/commands/analyze_command.dart | 2 +- lib/src/cli/commands/base_command.dart | 3 --- lib/src/cli/commands/check_unused_files_command.dart | 2 +- lib/src/cli/commands/check_unused_l10n_command.dart | 2 +- .../reporters/reporters_list/report_example.dart | 2 +- 23 files changed, 43 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2682913286..480da8d375 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * fix: fixed issue with type check in prefer-match-file-name * doc: add flutter favorite badge * chore: disable github_checks annotations from codecov +* chore: activate language strict rules ## 4.8.1 diff --git a/analysis_options.yaml b/analysis_options.yaml index f92b11e219..7960e22384 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -5,6 +5,9 @@ analyzer: - test/resources/* - test/resources/unused_files_analyzer/** - test/**/examples/** + language: + strict-inference: true + strict-raw-types: true plugins: - dart_code_metrics strong-mode: diff --git a/lib/src/analyzers/lint_analyzer/lint_analyzer.dart b/lib/src/analyzers/lint_analyzer/lint_analyzer.dart index 82d58d14b3..994b7cd77a 100644 --- a/lib/src/analyzers/lint_analyzer/lint_analyzer.dart +++ b/lib/src/analyzers/lint_analyzer/lint_analyzer.dart @@ -5,6 +5,7 @@ import 'package:path/path.dart'; import '../../config_builder/config_builder.dart'; import '../../config_builder/models/analysis_options.dart'; +import '../../reporters/models/file_report.dart'; import '../../reporters/models/reporter.dart'; import '../../utils/analyzer_utils.dart'; import '../../utils/exclude_utils.dart'; @@ -33,7 +34,7 @@ class LintAnalyzer { /// Returns a reporter for the given [name]. Use the reporter /// to convert analysis reports to console, JSON or other supported format. - Reporter? getReporter({ + Reporter? getReporter({ required String name, required IOSink output, required String reportFolder, @@ -125,7 +126,7 @@ class LintAnalyzer { return analyzerResult; } - Iterable getSummary( + Iterable> getSummary( Iterable records, ) => [ diff --git a/lib/src/analyzers/lint_analyzer/metrics/metrics_list/maintainability_index_metric.dart b/lib/src/analyzers/lint_analyzer/metrics/metrics_list/maintainability_index_metric.dart index e936fc70e8..033586b4e4 100644 --- a/lib/src/analyzers/lint_analyzer/metrics/metrics_list/maintainability_index_metric.dart +++ b/lib/src/analyzers/lint_analyzer/metrics/metrics_list/maintainability_index_metric.dart @@ -43,7 +43,7 @@ class MaintainabilityIndexMetric extends FunctionMetric { Iterable classDeclarations, Iterable functionDeclarations, InternalResolvedUnitResult source, - Iterable otherMetricsValues, + Iterable> otherMetricsValues, ) => super.supports( node, diff --git a/lib/src/analyzers/lint_analyzer/metrics/metrics_list/number_of_parameters_metric.dart b/lib/src/analyzers/lint_analyzer/metrics/metrics_list/number_of_parameters_metric.dart index 6b6c6752f7..bdea0f8426 100644 --- a/lib/src/analyzers/lint_analyzer/metrics/metrics_list/number_of_parameters_metric.dart +++ b/lib/src/analyzers/lint_analyzer/metrics/metrics_list/number_of_parameters_metric.dart @@ -39,7 +39,7 @@ class NumberOfParametersMetric extends FunctionMetric { Iterable classDeclarations, Iterable functionDeclarations, InternalResolvedUnitResult source, - Iterable otherMetricsValues, + Iterable> otherMetricsValues, ) { if (node is FunctionDeclaration) { return true; diff --git a/lib/src/analyzers/lint_analyzer/metrics/metrics_list/weight_of_class_metric.dart b/lib/src/analyzers/lint_analyzer/metrics/metrics_list/weight_of_class_metric.dart index 71303f9fcb..e0906c3e53 100644 --- a/lib/src/analyzers/lint_analyzer/metrics/metrics_list/weight_of_class_metric.dart +++ b/lib/src/analyzers/lint_analyzer/metrics/metrics_list/weight_of_class_metric.dart @@ -42,7 +42,7 @@ class WeightOfClassMetric extends ClassMetric { Iterable classDeclarations, Iterable functionDeclarations, InternalResolvedUnitResult source, - Iterable otherMetricsValues, + Iterable> otherMetricsValues, ) => super.supports( node, diff --git a/lib/src/analyzers/lint_analyzer/metrics/models/file_metric.dart b/lib/src/analyzers/lint_analyzer/metrics/models/file_metric.dart index 891a293522..32f3889cfa 100644 --- a/lib/src/analyzers/lint_analyzer/metrics/models/file_metric.dart +++ b/lib/src/analyzers/lint_analyzer/metrics/models/file_metric.dart @@ -29,7 +29,7 @@ abstract class FileMetric extends Metric { Iterable classDeclarations, Iterable functionDeclarations, InternalResolvedUnitResult source, - Iterable otherMetricsValues, + Iterable> otherMetricsValues, ) => node is CompilationUnit; diff --git a/lib/src/analyzers/lint_analyzer/metrics/models/metric.dart b/lib/src/analyzers/lint_analyzer/metrics/models/metric.dart index b7a3c7808b..1722d6b44f 100644 --- a/lib/src/analyzers/lint_analyzer/metrics/models/metric.dart +++ b/lib/src/analyzers/lint_analyzer/metrics/models/metric.dart @@ -39,7 +39,7 @@ abstract class Metric { Iterable classDeclarations, Iterable functionDeclarations, InternalResolvedUnitResult source, - Iterable otherMetricsValues, + Iterable> otherMetricsValues, ) => true; diff --git a/lib/src/analyzers/lint_analyzer/reporters/reporter_factory.dart b/lib/src/analyzers/lint_analyzer/reporters/reporter_factory.dart index 037747d9fb..43ca6aa52d 100644 --- a/lib/src/analyzers/lint_analyzer/reporters/reporter_factory.dart +++ b/lib/src/analyzers/lint_analyzer/reporters/reporter_factory.dart @@ -2,6 +2,7 @@ import 'dart:io'; import '../../../reporters/models/code_climate_reporter.dart'; import '../../../reporters/models/console_reporter.dart'; +import '../../../reporters/models/file_report.dart'; import '../../../reporters/models/github_reporter.dart'; import '../../../reporters/models/html_reporter.dart'; import '../../../reporters/models/json_reporter.dart'; @@ -12,8 +13,8 @@ import 'reporters_list/github/lint_github_reporter.dart'; import 'reporters_list/html/lint_html_reporter.dart'; import 'reporters_list/json/lint_json_reporter.dart'; -final _implementedReports = - { +final _implementedReports = Function(IOSink output, String reportFolder)>{ ConsoleReporter.id: (output, _) => LintConsoleReporter(output), ConsoleReporter.verboseId: (output, _) => LintConsoleReporter(output, reportAll: true), @@ -25,7 +26,7 @@ final _implementedReports = LintCodeClimateReporter(output, gitlabCompatible: true), }; -Reporter? reporter({ +Reporter? reporter({ required String name, required IOSink output, required String reportFolder, diff --git a/lib/src/analyzers/lint_analyzer/reporters/reporters_list/code_climate/lint_code_climate_reporter.dart b/lib/src/analyzers/lint_analyzer/reporters/reporters_list/code_climate/lint_code_climate_reporter.dart index 39942cc0d7..cc90330d0c 100644 --- a/lib/src/analyzers/lint_analyzer/reporters/reporters_list/code_climate/lint_code_climate_reporter.dart +++ b/lib/src/analyzers/lint_analyzer/reporters/reporters_list/code_climate/lint_code_climate_reporter.dart @@ -18,8 +18,8 @@ import 'models/code_climate_issue_severity.dart'; /// Lint Code Climate reporter. /// /// Use it to create reports in Code Climate format. -class LintCodeClimateReporter - extends CodeClimateReporter { +class LintCodeClimateReporter extends CodeClimateReporter> { LintCodeClimateReporter(IOSink output, {bool gitlabCompatible = false}) : super( output, @@ -29,7 +29,7 @@ class LintCodeClimateReporter @override Future report( Iterable records, { - Iterable summary = const [], + Iterable> summary = const [], }) async { if (records.isEmpty) { return; diff --git a/lib/src/analyzers/lint_analyzer/reporters/reporters_list/console/lint_console_reporter.dart b/lib/src/analyzers/lint_analyzer/reporters/reporters_list/console/lint_console_reporter.dart index e9a910818e..b3069470bf 100644 --- a/lib/src/analyzers/lint_analyzer/reporters/reporters_list/console/lint_console_reporter.dart +++ b/lib/src/analyzers/lint_analyzer/reporters/reporters_list/console/lint_console_reporter.dart @@ -14,7 +14,7 @@ import 'lint_console_reporter_helper.dart'; /// /// Use it to create reports in console format. class LintConsoleReporter - extends ConsoleReporter { + extends ConsoleReporter> { /// If true will report info about all files even if they're not above warning threshold final bool reportAll; @@ -25,7 +25,7 @@ class LintConsoleReporter @override Future report( Iterable records, { - Iterable summary = const [], + Iterable> summary = const [], }) async { if (records.isEmpty) { return; @@ -74,6 +74,6 @@ class LintConsoleReporter return []; } - bool _isNeedToReport(MetricValue metric) => + bool _isNeedToReport(MetricValue metric) => metric.level > MetricValueLevel.none; } diff --git a/lib/src/analyzers/lint_analyzer/reporters/reporters_list/github/lint_github_reporter.dart b/lib/src/analyzers/lint_analyzer/reporters/reporters_list/github/lint_github_reporter.dart index 4c8bf77406..89367de047 100644 --- a/lib/src/analyzers/lint_analyzer/reporters/reporters_list/github/lint_github_reporter.dart +++ b/lib/src/analyzers/lint_analyzer/reporters/reporters_list/github/lint_github_reporter.dart @@ -15,13 +15,13 @@ const _deprecationMessage = /// **Note:** this reporter is deprecated and should not be used. /// Consider using Dart Code Metrics GitHub Action instead. class LintGitHubReporter - extends GitHubReporter { + extends GitHubReporter> { const LintGitHubReporter(IOSink output) : super(output); @override Future report( Iterable records, { - Iterable summary = const [], + Iterable> summary = const [], }) async { if (records.isEmpty) { return; diff --git a/lib/src/analyzers/lint_analyzer/reporters/reporters_list/html/lint_html_reporter.dart b/lib/src/analyzers/lint_analyzer/reporters/reporters_list/html/lint_html_reporter.dart index 9dbabe7107..8ddb36f0c5 100644 --- a/lib/src/analyzers/lint_analyzer/reporters/reporters_list/html/lint_html_reporter.dart +++ b/lib/src/analyzers/lint_analyzer/reporters/reporters_list/html/lint_html_reporter.dart @@ -53,13 +53,13 @@ const _designIssues = 'Design issues'; /// /// Use it to create reports in HTML format. class LintHtmlReporter - extends HtmlReporter { + extends HtmlReporter> { LintHtmlReporter(String reportFolder) : super(reportFolder); @override Future report( Iterable records, { - Iterable summary = const [], + Iterable> summary = const [], }) async { await super.report(records); diff --git a/lib/src/analyzers/lint_analyzer/reporters/reporters_list/json/lint_json_reporter.dart b/lib/src/analyzers/lint_analyzer/reporters/reporters_list/json/lint_json_reporter.dart index d3f823b44f..5071ce3564 100644 --- a/lib/src/analyzers/lint_analyzer/reporters/reporters_list/json/lint_json_reporter.dart +++ b/lib/src/analyzers/lint_analyzer/reporters/reporters_list/json/lint_json_reporter.dart @@ -18,13 +18,13 @@ import '../../../models/summary_lint_report_record.dart'; /// Use it to create reports in JSON format. @immutable class LintJsonReporter - extends JsonReporter { + extends JsonReporter> { const LintJsonReporter(IOSink output) : super(output, 2); @override Future report( Iterable records, { - Iterable summary = const [], + Iterable> summary = const [], }) async { if (records.isEmpty) { return; @@ -35,11 +35,7 @@ class LintJsonReporter 'timestamp': getTimestamp(), 'records': records.map(_lintFileReportToJson).toList(), if (summary.isNotEmpty) - 'summary': summary - .map((record) => _summaryLintReportRecordToJson( - record as SummaryLintReportRecord, - )) - .toList(), + 'summary': summary.map(_summaryLintReportRecordToJson).toList(), }); output.write(encodedReport); diff --git a/lib/src/analyzers/unused_files_analyzer/reporters/reporter_factory.dart b/lib/src/analyzers/unused_files_analyzer/reporters/reporter_factory.dart index de595e5ca4..a1b242ee7f 100644 --- a/lib/src/analyzers/unused_files_analyzer/reporters/reporter_factory.dart +++ b/lib/src/analyzers/unused_files_analyzer/reporters/reporter_factory.dart @@ -3,15 +3,17 @@ import 'dart:io'; import '../../../reporters/models/console_reporter.dart'; import '../../../reporters/models/json_reporter.dart'; import '../../../reporters/models/reporter.dart'; +import '../models/unused_files_file_report.dart'; import 'reporters_list/console/unused_files_console_reporter.dart'; import 'reporters_list/json/unused_files_json_reporter.dart'; -final _implementedReports = { +final _implementedReports = + Function(IOSink output)>{ ConsoleReporter.id: (output) => UnusedFilesConsoleReporter(output), JsonReporter.id: (output) => UnusedFilesJsonReporter(output), }; -Reporter? reporter({ +Reporter? reporter({ required String name, required IOSink output, }) { diff --git a/lib/src/analyzers/unused_files_analyzer/unused_files_analyzer.dart b/lib/src/analyzers/unused_files_analyzer/unused_files_analyzer.dart index 7a11c3e267..9fb0f2d5df 100644 --- a/lib/src/analyzers/unused_files_analyzer/unused_files_analyzer.dart +++ b/lib/src/analyzers/unused_files_analyzer/unused_files_analyzer.dart @@ -20,7 +20,7 @@ class UnusedFilesAnalyzer { /// Returns a reporter for the given [name]. Use the reporter /// to convert analysis reports to console, JSON or other supported format. - Reporter? getReporter({ + Reporter? getReporter({ required String name, required IOSink output, }) => diff --git a/lib/src/analyzers/unused_l10n_analyzer/reporters/reporter_factory.dart b/lib/src/analyzers/unused_l10n_analyzer/reporters/reporter_factory.dart index 2baa6c8dfb..946a9bf653 100644 --- a/lib/src/analyzers/unused_l10n_analyzer/reporters/reporter_factory.dart +++ b/lib/src/analyzers/unused_l10n_analyzer/reporters/reporter_factory.dart @@ -3,18 +3,17 @@ import 'dart:io'; import '../../../reporters/models/console_reporter.dart'; import '../../../reporters/models/json_reporter.dart'; import '../../../reporters/models/reporter.dart'; +import '../models/unused_l10n_file_report.dart'; import 'reporters_list/console/unused_l10n_console_reporter.dart'; import 'reporters_list/json/unused_l10n_json_reporter.dart'; -// ignore: avoid_private_typedef_functions -typedef _ReportersFactory = Reporter Function(IOSink output); - -final _implementedReports = { +final _implementedReports = + Function(IOSink output)>{ ConsoleReporter.id: (output) => UnusedL10nConsoleReporter(output), JsonReporter.id: (output) => UnusedL10nJsonReporter(output), }; -Reporter? reporter({ +Reporter? reporter({ required String name, required IOSink output, }) { diff --git a/lib/src/analyzers/unused_l10n_analyzer/unused_l10n_analyzer.dart b/lib/src/analyzers/unused_l10n_analyzer/unused_l10n_analyzer.dart index 6baede7879..d4ef5c7de6 100644 --- a/lib/src/analyzers/unused_l10n_analyzer/unused_l10n_analyzer.dart +++ b/lib/src/analyzers/unused_l10n_analyzer/unused_l10n_analyzer.dart @@ -25,7 +25,7 @@ class UnusedL10nAnalyzer { /// Returns a reporter for the given [name]. Use the reporter /// to convert analysis reports to console, JSON or other supported format. - Reporter? getReporter({ + Reporter? getReporter({ required String name, required IOSink output, }) => diff --git a/lib/src/cli/commands/analyze_command.dart b/lib/src/cli/commands/analyze_command.dart index 0141436fe4..42523c8012 100644 --- a/lib/src/cli/commands/analyze_command.dart +++ b/lib/src/cli/commands/analyze_command.dart @@ -27,7 +27,7 @@ class AnalyzeCommand extends BaseCommand { @override String get invocation => - '${runner.executableName} $name [arguments] '; + '${runner?.executableName} $name [arguments] '; AnalyzeCommand() { _addFlags(); diff --git a/lib/src/cli/commands/base_command.dart b/lib/src/cli/commands/base_command.dart index 0b763673f9..f66e7ba926 100644 --- a/lib/src/cli/commands/base_command.dart +++ b/lib/src/cli/commands/base_command.dart @@ -21,9 +21,6 @@ abstract class BaseCommand extends Command { return super.argResults!; } - @override - CommandRunner get runner => super.runner as CommandRunner; - @override Future run() => _verifyThenRunCommand(); diff --git a/lib/src/cli/commands/check_unused_files_command.dart b/lib/src/cli/commands/check_unused_files_command.dart index ca8745fa3b..1168b82f4f 100644 --- a/lib/src/cli/commands/check_unused_files_command.dart +++ b/lib/src/cli/commands/check_unused_files_command.dart @@ -18,7 +18,7 @@ class CheckUnusedFilesCommand extends BaseCommand { @override String get invocation => - '${runner.executableName} $name [arguments] '; + '${runner?.executableName} $name [arguments] '; CheckUnusedFilesCommand() { _addFlags(); diff --git a/lib/src/cli/commands/check_unused_l10n_command.dart b/lib/src/cli/commands/check_unused_l10n_command.dart index f8a17f5223..fdd8c14480 100644 --- a/lib/src/cli/commands/check_unused_l10n_command.dart +++ b/lib/src/cli/commands/check_unused_l10n_command.dart @@ -18,7 +18,7 @@ class CheckUnusedL10nCommand extends BaseCommand { @override String get invocation => - '${runner.executableName} $name [arguments] '; + '${runner?.executableName} $name [arguments] '; CheckUnusedL10nCommand() { _addFlags(); diff --git a/test/src/analyzers/lint_analyzer/reporters/reporters_list/report_example.dart b/test/src/analyzers/lint_analyzer/reporters/reporters_list/report_example.dart index 8099563efa..d8206685d3 100644 --- a/test/src/analyzers/lint_analyzer/reporters/reporters_list/report_example.dart +++ b/test/src/analyzers/lint_analyzer/reporters/reporters_list/report_example.dart @@ -175,7 +175,7 @@ final Iterable testReport = [ ), ]; -const Iterable testSummary = [ +const Iterable> testSummary = [ SummaryLintReportRecord>( status: SummaryLintReportRecordStatus.none, title: 'Scanned package folders',