From 7d00c54b23680326fa70da42e217e88de7dbc3a0 Mon Sep 17 00:00:00 2001 From: Nicholas Shahan Date: Wed, 30 Oct 2024 21:10:38 +0000 Subject: [PATCH] [ddc] Enforce unnecessary_breaks lint Ignore violations in the js_ast sub-directory to avoid unnecessary diffs with the original package. Change-Id: Iac8c942e5e2446b8433e2073b546c28e42a8f5cf Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392700 Reviewed-by: Kevin Moore Commit-Queue: Nicholas Shahan --- pkg/dev_compiler/analysis_options.yaml | 1 + pkg/dev_compiler/lib/src/js_ast/printer.dart | 2 +- pkg/dev_compiler/lib/src/kernel/compiler.dart | 9 --------- pkg/dev_compiler/lib/src/kernel/compiler_new.dart | 9 --------- .../lib/src/kernel/expression_compiler_worker.dart | 5 ----- .../expression_compiler_e2e_suite.dart | 5 ----- pkg/dev_compiler/test/hot_reload_suite.dart | 7 ------- 7 files changed, 2 insertions(+), 36 deletions(-) diff --git a/pkg/dev_compiler/analysis_options.yaml b/pkg/dev_compiler/analysis_options.yaml index f93da08183a5..6c680e028e39 100644 --- a/pkg/dev_compiler/analysis_options.yaml +++ b/pkg/dev_compiler/analysis_options.yaml @@ -27,3 +27,4 @@ linter: - prefer_single_quotes - prefer_relative_imports - unawaited_futures + - unnecessary_breaks diff --git a/pkg/dev_compiler/lib/src/js_ast/printer.dart b/pkg/dev_compiler/lib/src/js_ast/printer.dart index db0f137779ba..aa43c8cdfacb 100644 --- a/pkg/dev_compiler/lib/src/js_ast/printer.dart +++ b/pkg/dev_compiler/lib/src/js_ast/printer.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// ignore_for_file: omit_local_variable_types +// ignore_for_file: omit_local_variable_types, unnecessary_breaks import 'characters.dart' as char_codes; import 'nodes.dart'; diff --git a/pkg/dev_compiler/lib/src/kernel/compiler.dart b/pkg/dev_compiler/lib/src/kernel/compiler.dart index 48203c0bbfb3..263e904eea63 100644 --- a/pkg/dev_compiler/lib/src/kernel/compiler.dart +++ b/pkg/dev_compiler/lib/src/kernel/compiler.dart @@ -763,10 +763,8 @@ class ProgramCompiler extends ComputeOnceConstantVisitor switch (component.mode) { case NonNullableByDefaultCompiledMode.Strong: soundNullSafety = js_ast.LiteralBool(true); - break; case NonNullableByDefaultCompiledMode.Weak: soundNullSafety = js_ast.LiteralBool(false); - break; default: throw StateError('Unsupported Null Safety mode ${component.mode}, ' 'in ${component.location?.file}.'); @@ -2952,7 +2950,6 @@ class ProgramCompiler extends ComputeOnceConstantVisitor // Reserved by JS, not a valid static member name. case 'prototype': name += '_'; - break; default: // All trailing underscores static names are reserved for the compiler // or SDK libraries. @@ -3656,7 +3653,6 @@ class ProgramCompiler extends ComputeOnceConstantVisitor wrapBody: _emitTopLevelNameNoExternalInterop(_asyncWrapJsFunctionMember), bodyName: bodyName); - break; case AsyncMarker.SyncStar: asyncRewriter = SyncStarRewriter( makeSyncStarIterable: @@ -3669,7 +3665,6 @@ class ProgramCompiler extends ComputeOnceConstantVisitor yieldStarSelector: _emitMemberName('_yieldStar', member: _syncStarIteratorYieldStarMember), bodyName: bodyName); - break; case AsyncMarker.AsyncStar: asyncRewriter = AsyncStarRewriter( asyncStarHelper: @@ -3686,7 +3681,6 @@ class ProgramCompiler extends ComputeOnceConstantVisitor wrapBody: _emitTopLevelNameNoExternalInterop(_asyncWrapJsFunctionMember), bodyName: bodyName); - break; } if (asyncRewriter != null) { return asyncRewriter.rewrite(fun, functionBody, functionEnd, @@ -6684,7 +6678,6 @@ class ProgramCompiler extends ComputeOnceConstantVisitor var rti = _emitType(mapType); return js.call('new #.new(#)', [mapClass, rti]); } - break; case 'Set': case 'HashSet': case 'LinkedHashSet': @@ -6699,12 +6692,10 @@ class ProgramCompiler extends ComputeOnceConstantVisitor var rti = _emitType(setType); return js.call('new #.new(#)', [setClass, rti]); } - break; case 'List': if (ctor.name.text == '') { return _emitList(type.typeArguments[0], []); } - break; } } var rti = _requiresRtiForInstantiation(ctorClass) diff --git a/pkg/dev_compiler/lib/src/kernel/compiler_new.dart b/pkg/dev_compiler/lib/src/kernel/compiler_new.dart index 3abe73ab9d59..1d80165c97e8 100644 --- a/pkg/dev_compiler/lib/src/kernel/compiler_new.dart +++ b/pkg/dev_compiler/lib/src/kernel/compiler_new.dart @@ -893,10 +893,8 @@ class LibraryCompiler extends ComputeOnceConstantVisitor switch (_component.mode) { case NonNullableByDefaultCompiledMode.Strong: soundNullSafety = js_ast.LiteralBool(true); - break; case NonNullableByDefaultCompiledMode.Weak: soundNullSafety = js_ast.LiteralBool(false); - break; default: throw StateError('Unsupported Null Safety mode ${_component.mode}, ' 'in ${_component.location?.file}.'); @@ -3125,7 +3123,6 @@ class LibraryCompiler extends ComputeOnceConstantVisitor // Reserved by JS, not a valid static member name. case 'prototype': name += '_'; - break; default: // All trailing underscores static names are reserved for the compiler // or SDK libraries. @@ -3829,7 +3826,6 @@ class LibraryCompiler extends ComputeOnceConstantVisitor wrapBody: _emitTopLevelNameNoExternalInterop(_asyncWrapJsFunctionMember), bodyName: bodyName); - break; case AsyncMarker.SyncStar: asyncRewriter = SyncStarRewriter( makeSyncStarIterable: @@ -3842,7 +3838,6 @@ class LibraryCompiler extends ComputeOnceConstantVisitor yieldStarSelector: _emitMemberName('_yieldStar', member: _syncStarIteratorYieldStarMember), bodyName: bodyName); - break; case AsyncMarker.AsyncStar: asyncRewriter = AsyncStarRewriter( asyncStarHelper: @@ -3859,7 +3854,6 @@ class LibraryCompiler extends ComputeOnceConstantVisitor wrapBody: _emitTopLevelNameNoExternalInterop(_asyncWrapJsFunctionMember), bodyName: bodyName); - break; } if (asyncRewriter != null) { return asyncRewriter.rewrite(fun, functionBody, functionEnd, @@ -6856,7 +6850,6 @@ class LibraryCompiler extends ComputeOnceConstantVisitor var rti = _emitType(mapType); return js.call('new #.new(#)', [mapClass, rti]); } - break; case 'Set': case 'HashSet': case 'LinkedHashSet': @@ -6871,12 +6864,10 @@ class LibraryCompiler extends ComputeOnceConstantVisitor var rti = _emitType(setType); return js.call('new #.new(#)', [setClass, rti]); } - break; case 'List': if (ctor.name.text == '') { return _emitList(type.typeArguments[0], []); } - break; } } var rti = _requiresRtiForInstantiation(ctorClass) diff --git a/pkg/dev_compiler/lib/src/kernel/expression_compiler_worker.dart b/pkg/dev_compiler/lib/src/kernel/expression_compiler_worker.dart index d914a2c32009..f7b847cdab22 100644 --- a/pkg/dev_compiler/lib/src/kernel/expression_compiler_worker.dart +++ b/pkg/dev_compiler/lib/src/kernel/expression_compiler_worker.dart @@ -287,11 +287,9 @@ class ExpressionCompilerWorker { case 'UpdateDeps': sendResponse(await _updateDependencies( UpdateDependenciesRequest.fromJson(request))); - break; case 'CompileExpression': sendResponse(await _compileExpression( CompileExpressionRequest.fromJson(request))); - break; default: throw ArgumentError( 'Unrecognized command `$command`, full request was `$request`'); @@ -787,13 +785,10 @@ void Function(DiagnosticMessage) _onDiagnosticHandler( case Severity.error: case Severity.internalProblem: errors.add(message.plainTextFormatted.join('\n')); - break; case Severity.warning: warnings.add(message.plainTextFormatted.join('\n')); - break; case Severity.info: infos.add(message.plainTextFormatted.join('\n')); - break; case Severity.context: case Severity.ignored: throw 'Unexpected severity: ${message.severity}'; diff --git a/pkg/dev_compiler/test/expression_compiler/expression_compiler_e2e_suite.dart b/pkg/dev_compiler/test/expression_compiler/expression_compiler_e2e_suite.dart index b4828bcc8933..b282e72ff523 100644 --- a/pkg/dev_compiler/test/expression_compiler/expression_compiler_e2e_suite.dart +++ b/pkg/dev_compiler/test/expression_compiler/expression_compiler_e2e_suite.dart @@ -223,7 +223,6 @@ class ExpressionEvaluationTestDriver { }; '''); - break; case ModuleFormat.amd: var dartSdkPathNoExtension = escaped(SetupCompilerOptions.buildRoot .resolve(p.join( @@ -288,7 +287,6 @@ class ExpressionEvaluationTestDriver { '''); - break; default: throw Exception('Unsupported module format for SDK evaluation tests: ' '${setup.moduleFormat}'); @@ -841,7 +839,6 @@ class ExpressionEvaluationTestDriver { switch (type) { case 'function': str = obj.description ?? ''; - break; case 'object': if (obj.subtype == 'null') { return 'null'; @@ -860,10 +857,8 @@ class ExpressionEvaluationTestDriver { } catch (e, s) { throw StateError('Failed to stringify remote object $obj: $e:$s'); } - break; default: str = '${obj.value}'; - break; } return str; } diff --git a/pkg/dev_compiler/test/hot_reload_suite.dart b/pkg/dev_compiler/test/hot_reload_suite.dart index 6f4f02512316..905dad8c8e0a 100644 --- a/pkg/dev_compiler/test/hot_reload_suite.dart +++ b/pkg/dev_compiler/test/hot_reload_suite.dart @@ -195,7 +195,6 @@ Future main(List args) async { '--target=dartdevc', ]; controller = HotReloadFrontendServerController(fesArgs); - break; case RuntimePlatforms.vm: final vmPlatformDillFromSdkRoot = fe_shared.relativizeUri( sdkRoot, vmPlatformDillUri, fe_shared.isWindows); @@ -205,7 +204,6 @@ Future main(List args) async { '--target=vm', ]; controller = HotReloadFrontendServerController(fesArgs); - break; } controller.start(); @@ -424,7 +422,6 @@ Future main(List args) async { } }); }); - break; case DiffMode.write: _print('Generating source file diffs.', label: testName); filesByGeneration.forEach((basename, filesQueue) { @@ -462,7 +459,6 @@ Future main(List args) async { reportDiffOutcome(file, 'diff updated for $file', true); }); }); - break; case DiffMode.ignore: _print('Ignoring source file diffs.', label: testName); filesByGeneration.forEach((basename, filesQueue) { @@ -471,7 +467,6 @@ Future main(List args) async { reportDiffOutcome(file, 'Ignoring diff for $file', true); }); }); - break; } // Skip this test directory if this platform is excluded. @@ -658,7 +653,6 @@ Future main(List args) async { final d8ExitCode = await d8Suite.runTest(testName: testName); testPassed = d8ExitCode == 0; await d8Suite.teardownTest(testName: testName); - break; case RuntimePlatforms.chrome: // Run the compiled JS generations with Chrome. _print('Creating Chrome hot reload test suite.', label: testName); @@ -683,7 +677,6 @@ Future main(List args) async { final exitCode = await suite.runTest(testName: testName); testPassed = exitCode == 0; await suite.teardownTest(testName: testName); - break; case RuntimePlatforms.vm: final firstGenerationDillUri = tempUri.resolve('generation0/$testName.dill');