From 8b564e0beae752d5e8ff0deb39acb54cbd34e907 Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Sun, 19 Nov 2023 17:31:18 +0000 Subject: [PATCH] Enable 'unnecessary_breaks' in analyzer/. Change-Id: I46615f08175db25f24abf341376d571f270756cb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/336831 Commit-Queue: Konstantin Shcheglov Reviewed-by: Samuel Rawlins --- pkg/analyzer/analysis_options.yaml | 1 + pkg/analyzer/lib/src/dart/analysis/driver.dart | 3 --- .../src/dart/resolver/shared_type_analyzer.dart | 1 - pkg/analyzer/lib/src/fasta/ast_builder.dart | 4 ---- pkg/analyzer/lib/src/lint/config.dart | 2 -- pkg/analyzer/lib/src/lint/pub.dart | 17 ----------------- .../lib/src/summary2/macro_application.dart | 1 - ..._expression_type_implements_equals_test.dart | 3 --- ...e_is_not_switch_expression_subtype_test.dart | 4 ---- ...e_expression_from_deferred_library_test.dart | 4 ---- pkg/analyzer/tool/summary/generate.dart | 8 -------- 11 files changed, 1 insertion(+), 47 deletions(-) diff --git a/pkg/analyzer/analysis_options.yaml b/pkg/analyzer/analysis_options.yaml index 23e3e0b5301a..6ad5dea097c6 100644 --- a/pkg/analyzer/analysis_options.yaml +++ b/pkg/analyzer/analysis_options.yaml @@ -44,5 +44,6 @@ linter: - flutter_style_todos - library_annotations - unawaited_futures + - unnecessary_breaks - unnecessary_library_directive - unnecessary_parenthesis diff --git a/pkg/analyzer/lib/src/dart/analysis/driver.dart b/pkg/analyzer/lib/src/dart/analysis/driver.dart index 6d1d710b7490..b1028d1a93d4 100644 --- a/pkg/analyzer/lib/src/dart/analysis/driver.dart +++ b/pkg/analyzer/lib/src/dart/analysis/driver.dart @@ -1265,16 +1265,13 @@ class AnalysisDriver implements AnalysisDriverGeneric { switch (fileChange.kind) { case _FileChangeKind.add: _fileTracker.addFile(path); - break; case _FileChangeKind.change: _fileTracker.changeFile(path); - break; case _FileChangeKind.remove: _fileTracker.removeFile(path); // TODO(scheglov): We have to do this because we discard files. // But this is not right, we need to handle removing better. clearLibraryContext(); - break; } } _pendingFileChanges.clear(); diff --git a/pkg/analyzer/lib/src/dart/resolver/shared_type_analyzer.dart b/pkg/analyzer/lib/src/dart/resolver/shared_type_analyzer.dart index 4c8d05c3d2d2..230b0b1969e5 100644 --- a/pkg/analyzer/lib/src/dart/resolver/shared_type_analyzer.dart +++ b/pkg/analyzer/lib/src/dart/resolver/shared_type_analyzer.dart @@ -264,7 +264,6 @@ class SharedTypeAnalyzerErrors WarningCode.UNNECESSARY_WILDCARD_PATTERN, pattern, ); - break; } } } diff --git a/pkg/analyzer/lib/src/fasta/ast_builder.dart b/pkg/analyzer/lib/src/fasta/ast_builder.dart index 3b042ea17a1a..eb8ada717e1d 100644 --- a/pkg/analyzer/lib/src/fasta/ast_builder.dart +++ b/pkg/analyzer/lib/src/fasta/ast_builder.dart @@ -914,7 +914,6 @@ class AstBuilder extends StackListener { ), ), ); - break; case Assert.Initializer: push( AssertInitializerImpl( @@ -926,7 +925,6 @@ class AstBuilder extends StackListener { rightParenthesis: leftParenthesis.endGroup!, ), ); - break; case Assert.Statement: push( AssertStatementImpl( @@ -939,7 +937,6 @@ class AstBuilder extends StackListener { semicolon: semicolon, ), ); - break; } } @@ -2838,7 +2835,6 @@ class AstBuilder extends StackListener { typeArguments: null, question: null, ); - break; } if (firstFormalParameter.keyword case final keyword?) { if (keyword.keyword != Keyword.CONST) { diff --git a/pkg/analyzer/lib/src/lint/config.dart b/pkg/analyzer/lib/src/lint/config.dart index 2153f9fabf41..2d8bfcd82640 100644 --- a/pkg/analyzer/lib/src/lint/config.dart +++ b/pkg/analyzer/lib/src/lint/config.dart @@ -125,7 +125,6 @@ class _LintConfig implements LintConfig { addAsListOrString(v['include'], fileIncludes); addAsListOrString(v['exclude'], fileExcludes); } - break; case 'rules': @@ -165,7 +164,6 @@ class _LintConfig implements LintConfig { } }); } - break; } }); } diff --git a/pkg/analyzer/lib/src/lint/pub.dart b/pkg/analyzer/lib/src/lint/pub.dart index 865ac4a89658..d6846dcbc4d7 100644 --- a/pkg/analyzer/lib/src/lint/pub.dart +++ b/pkg/analyzer/lib/src/lint/pub.dart @@ -378,16 +378,12 @@ class _PSDependency extends PSDependency { switch (key.toString()) { case 'path': dep.path = _processScalar(key, v, resourceProvider); - break; case 'version': dep.version = _processScalar(key, v, resourceProvider); - break; case 'hosted': dep.host = _processHost(key, v, resourceProvider); - break; case 'git': dep.git = _processGitRepo(key, v, resourceProvider); - break; } }); } @@ -648,43 +644,30 @@ class _Pubspec implements Pubspec { switch (key.toString()) { case 'author': author = _processScalar(key, v, resourceProvider); - break; case 'authors': authors = _processScalarList(key, v, resourceProvider); - break; case 'homepage': homepage = _processScalar(key, v, resourceProvider); - break; case 'repository': repository = _processScalar(key, v, resourceProvider); - break; case 'issue_tracker': issueTracker = _processScalar(key, v, resourceProvider); - break; case 'name': name = _processScalar(key, v, resourceProvider); - break; case 'description': description = _processScalar(key, v, resourceProvider); - break; case 'documentation': documentation = _processScalar(key, v, resourceProvider); - break; case 'dependencies': dependencies = _processDependencies(key, v, resourceProvider); - break; case 'dev_dependencies': devDependencies = _processDependencies(key, v, resourceProvider); - break; case 'dependency_overrides': dependencyOverrides = _processDependencies(key, v, resourceProvider); - break; case 'environment': environment = _processEnvironment(key, v, resourceProvider); - break; case 'version': version = _processScalar(key, v, resourceProvider); - break; } }); } diff --git a/pkg/analyzer/lib/src/summary2/macro_application.dart b/pkg/analyzer/lib/src/summary2/macro_application.dart index 7166d79fea7b..8209bc53781f 100644 --- a/pkg/analyzer/lib/src/summary2/macro_application.dart +++ b/pkg/analyzer/lib/src/summary2/macro_application.dart @@ -407,7 +407,6 @@ class LibraryMacroApplier { case macro.DeclarationDiagnosticTarget macroTarget: final element = (macroTarget.declaration as HasElement).element; target = ElementMacroDiagnosticTarget(element: element); - break; default: target = ApplicationMacroDiagnosticTarget( annotationIndex: application.annotationIndex, diff --git a/pkg/analyzer/test/src/diagnostics/case_expression_type_implements_equals_test.dart b/pkg/analyzer/test/src/diagnostics/case_expression_type_implements_equals_test.dart index 3312610cfc0e..70f5ed6e8b45 100644 --- a/pkg/analyzer/test/src/diagnostics/case_expression_type_implements_equals_test.dart +++ b/pkg/analyzer/test/src/diagnostics/case_expression_type_implements_equals_test.dart @@ -81,16 +81,13 @@ void f(e) { error(CompileTimeErrorCode.CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS, 128, 6), ]; - break; case _Variants.nullSafe: expectedErrors = [ error(CompileTimeErrorCode.CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS, 150, 10), ]; - break; case _Variants.patterns: expectedErrors = []; - break; } await assertErrorsInCode(r''' diff --git a/pkg/analyzer/test/src/diagnostics/case_expression_type_is_not_switch_expression_subtype_test.dart b/pkg/analyzer/test/src/diagnostics/case_expression_type_is_not_switch_expression_subtype_test.dart index b20daae3c75b..a7e8a59f2056 100644 --- a/pkg/analyzer/test/src/diagnostics/case_expression_type_is_not_switch_expression_subtype_test.dart +++ b/pkg/analyzer/test/src/diagnostics/case_expression_type_is_not_switch_expression_subtype_test.dart @@ -58,10 +58,8 @@ mixin CaseExpressionTypeIsNotSwitchExpressionSubtypeTestCases error(CompileTimeErrorCode.CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS, 206, 10), ]; - break; case _Variant.patterns: expectedErrors = []; - break; } await assertErrorsInCode(''' @@ -104,13 +102,11 @@ void f(A e) { 171, 10), ]; - break; case _Variant.patterns: expectedErrors = [ error(WarningCode.CONSTANT_PATTERN_NEVER_MATCHES_VALUE_TYPE, 145, 2), error(WarningCode.CONSTANT_PATTERN_NEVER_MATCHES_VALUE_TYPE, 171, 10), ]; - break; } await assertErrorsInCode(''' diff --git a/pkg/analyzer/test/src/diagnostics/non_constant_case_expression_from_deferred_library_test.dart b/pkg/analyzer/test/src/diagnostics/non_constant_case_expression_from_deferred_library_test.dart index 2f0140ef2898..4a5ce331e783 100644 --- a/pkg/analyzer/test/src/diagnostics/non_constant_case_expression_from_deferred_library_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_constant_case_expression_from_deferred_library_test.dart @@ -90,11 +90,9 @@ const int c = 0; case _Variant.nullSafe: expectedErrorCode = CompileTimeErrorCode .NON_CONSTANT_CASE_EXPRESSION_FROM_DEFERRED_LIBRARY; - break; case _Variant.patterns: expectedErrorCode = CompileTimeErrorCode.PATTERN_CONSTANT_FROM_DEFERRED_LIBRARY; - break; } await assertErrorsInCode(''' @@ -121,11 +119,9 @@ class A {} case _Variant.nullSafe: expectedErrorCode = CompileTimeErrorCode .NON_CONSTANT_CASE_EXPRESSION_FROM_DEFERRED_LIBRARY; - break; case _Variant.patterns: expectedErrorCode = CompileTimeErrorCode.PATTERN_CONSTANT_FROM_DEFERRED_LIBRARY; - break; } await assertErrorsInCode(''' diff --git a/pkg/analyzer/tool/summary/generate.dart b/pkg/analyzer/tool/summary/generate.dart index 6247ad6c24ea..8280d137c9f8 100644 --- a/pkg/analyzer/tool/summary/generate.dart +++ b/pkg/analyzer/tool/summary/generate.dart @@ -458,25 +458,21 @@ class _BuilderGenerator extends _BaseGenerator { ref += " ?? ''"; } out("signatureSink.addString($ref);"); - break; case 'int': if (couldBeNull) { ref += ' ?? 0'; } out('signatureSink.addInt($ref);'); - break; case 'bool': if (couldBeNull) { ref += ' == true'; } out('signatureSink.addBool($ref);'); - break; case 'double': if (couldBeNull) { ref += ' ?? 0.0'; } out('signatureSink.addDouble($ref);'); - break; default: throw "Don't know how to generate signature call for $typeName"; } @@ -895,16 +891,12 @@ class _FlatBufferSchemaGenerator extends _BaseGenerator { switch (type.typeName) { case 'bool': typeStr = 'bool'; - break; case 'double': typeStr = 'double'; - break; case 'int': typeStr = 'uint'; - break; case 'String': typeStr = 'string'; - break; default: typeStr = type.typeName; break;