diff --git a/analysis_options.yaml b/analysis_options.yaml index 2bf5ba1a..694552bd 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,6 +1,5 @@ -include: package:lints/recommended.yaml -linter: - rules: - - avoid_dynamic_calls - - directives_ordering - - unawaited_futures +include: package:dart_flutter_team_lints/analysis_options.yaml + +analyzer: + errors: + comment_references: ignore diff --git a/benchmark/benchmark.dart b/benchmark/benchmark.dart index 6c79038a..d078ad6d 100644 --- a/benchmark/benchmark.dart +++ b/benchmark/benchmark.dart @@ -13,8 +13,8 @@ const _formatsPerTrial = 30; /// Note, these files use ".txt" because while they can be *parsed* correctly, /// they don't resolve without error. That's OK because the formatter doesn't /// care about that. -final source = loadFile('before.dart.txt'); -final expected = loadFile('after.dart.txt'); +final source = _loadFile('before.dart.txt'); +final expected = _loadFile('after.dart.txt'); void main(List args) { var best = 99999999.0; @@ -27,7 +27,7 @@ void main(List args) { // For a single benchmark, format the source multiple times. String? result; for (var j = 0; j < _formatsPerTrial; j++) { - result = formatSource(); + result = _formatSource(); } var elapsed = @@ -47,32 +47,23 @@ void main(List args) { // Don't print the first run. It's always terrible since the VM hasn't // warmed up yet. if (i == 0) continue; - printResult("Run ${padLeft('#$i', 3)}", elapsed); + _printResult("Run ${'#$i'.padLeft(3)}", elapsed); } - printResult('Best ', best); + _printResult('Best ', best); } -String loadFile(String name) { +String _loadFile(String name) { var path = p.join(p.dirname(p.fromUri(Platform.script)), name); return File(path).readAsStringSync(); } -void printResult(String label, double time) { - print('$label: ${padLeft(time.toStringAsFixed(2), 4)}ms ' +void _printResult(String label, double time) { + print('$label: ${time.toStringAsFixed(2).padLeft(4)}ms ' "${'=' * ((time * 5).toInt())}"); } -String padLeft(input, int length) { - var result = input.toString(); - if (result.length < length) { - result = ' ' * (length - result.length) + result; - } - - return result; -} - -String formatSource() { +String _formatSource() { var formatter = DartFormatter(); return formatter.format(source); } diff --git a/bin/format.dart b/bin/format.dart index f91f0c35..c36bd0d2 100644 --- a/bin/format.dart +++ b/bin/format.dart @@ -25,17 +25,17 @@ void main(List args) async { usageError(parser, err.message); } - if (argResults['help']) { + if (argResults['help'] as bool) { printUsage(parser); return; } - if (argResults['version']) { + if (argResults['version'] as bool) { print(dartStyleVersion); return; } - if (argResults['verbose'] && !(argResults['help'] as bool)) { + if (argResults['verbose'] as bool && !(argResults['help'] as bool)) { usageError(parser, 'Can only use --verbose with --help.'); } @@ -46,7 +46,7 @@ void main(List args) async { usageError(parser, exception.message); } - if (argResults['dry-run'] && argResults['overwrite']) { + if (argResults['dry-run'] as bool && argResults['overwrite'] as bool) { usageError( parser, 'Cannot use --dry-run and --overwrite at the same time.'); } @@ -61,13 +61,13 @@ void main(List args) async { var summary = Summary.none; var output = Output.show; var setExitIfChanged = false; - if (argResults['dry-run']) { + if (argResults['dry-run'] as bool) { checkForReporterCollision('dry-run', 'overwrite'); checkForReporterCollision('dry-run', 'machine'); show = Show.dryRun; output = Output.none; - } else if (argResults['overwrite']) { + } else if (argResults['overwrite'] as bool) { checkForReporterCollision('overwrite', 'machine'); if (argResults.rest.isEmpty) { @@ -77,17 +77,17 @@ void main(List args) async { show = Show.overwrite; output = Output.write; - } else if (argResults['machine']) { + } else if (argResults['machine'] as bool) { output = Output.json; } - if (argResults['profile']) summary = Summary.profile(); + if (argResults['profile'] as bool) summary = Summary.profile(); - setExitIfChanged = argResults['set-exit-if-changed']; + setExitIfChanged = argResults['set-exit-if-changed'] as bool; int pageWidth; try { - pageWidth = int.parse(argResults['line-length']); + pageWidth = int.parse(argResults['line-length'] as String); } on FormatException catch (_) { usageError( parser, @@ -97,8 +97,8 @@ void main(List args) async { int indent; try { - indent = int.parse(argResults['indent']); - if (indent < 0 || indent.toInt() != indent) throw FormatException(); + indent = int.parse(argResults['indent'] as String); + if (indent < 0 || indent.toInt() != indent) throw const FormatException(); } on FormatException catch (_) { usageError( parser, @@ -106,13 +106,13 @@ void main(List args) async { '"${argResults['indent']}".'); } - var followLinks = argResults['follow-links']; + var followLinks = argResults['follow-links'] as bool; var fixes = []; - if (argResults['fix']) fixes.addAll(StyleFix.all); + if (argResults['fix'] as bool) fixes.addAll(StyleFix.all); for (var fix in StyleFix.all) { - if (argResults['fix-${fix.name}']) { - if (argResults['fix']) { + if (argResults['fix-${fix.name}'] as bool) { + if (argResults['fix'] as bool) { usageError(parser, '--fix-${fix.name} is redundant with --fix.'); } @@ -133,7 +133,7 @@ void main(List args) async { output: output, summary: summary, setExitIfChanged: setExitIfChanged, - experimentFlags: argResults['enable-experiment']); + experimentFlags: argResults['enable-experiment'] as List); if (argResults.rest.isEmpty) { await formatStdin(options, selection, argResults['stdin-name'] as String); diff --git a/example/format.dart b/example/format.dart index c07541df..249fbf13 100644 --- a/example/format.dart +++ b/example/format.dart @@ -1,6 +1,7 @@ // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file // 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. + import 'package:dart_style/dart_style.dart'; import 'package:dart_style/src/constants.dart'; import 'package:dart_style/src/debug.dart' as debug; @@ -16,48 +17,17 @@ void main(List args) { debug.tracePieceBuilder = true; debug.traceSolver = true; - runTest('selection/selection.stmt', 2); -} - -void formatStmt(String source, {required bool tall, int pageWidth = 80}) { - runFormatter(source, pageWidth, tall: tall, isCompilationUnit: false); -} - -void formatUnit(String source, {required bool tall, int pageWidth = 80}) { - runFormatter(source, pageWidth, tall: tall, isCompilationUnit: true); -} - -void runFormatter(String source, int pageWidth, - {required bool tall, required bool isCompilationUnit}) { - try { - var formatter = DartFormatter( - pageWidth: pageWidth, - experimentFlags: [if (tall) tallStyleExperimentFlag]); - - String result; - if (isCompilationUnit) { - result = formatter.format(source); - } else { - result = formatter.formatStatement(source); - } - - drawRuler('before', pageWidth); - print(source); - drawRuler('after', pageWidth); - print(result); - } on FormatterException catch (error) { - print(error.message()); - } + _runTest('selection/selection.stmt', 2); } -void drawRuler(String label, int width) { +void _drawRuler(String label, int width) { var padding = ' ' * (width - label.length - 1); print('$label:$padding|'); } /// Runs the formatter test starting on [line] at [path] inside the "test" /// directory. -Future runTest(String path, int line, +Future _runTest(String path, int line, {int pageWidth = 40, bool tall = true}) async { var testFile = await TestFile.read(path); var formatTest = testFile.tests.firstWhere((test) => test.line == line); @@ -81,16 +51,16 @@ Future runTest(String path, int line, var expectedText = formatTest.output.textWithSelectionMarkers; print('$path ${formatTest.description}'); - drawRuler('before', pageWidth); + _drawRuler('before', pageWidth); print(formatTest.input.textWithSelectionMarkers); if (actualText == expectedText) { - drawRuler('result', pageWidth); + _drawRuler('result', pageWidth); print(actualText); } else { print('FAIL'); - drawRuler('expected', pageWidth); + _drawRuler('expected', pageWidth); print(expectedText); - drawRuler('actual', pageWidth); + _drawRuler('actual', pageWidth); print(actualText); } } diff --git a/lib/src/argument_list_visitor.dart b/lib/src/argument_list_visitor.dart index 1774faf5..74b16211 100644 --- a/lib/src/argument_list_visitor.dart +++ b/lib/src/argument_list_visitor.dart @@ -96,10 +96,9 @@ class ArgumentListVisitor { this._allArguments, this._arguments, this._functions, - this._argumentsAfterFunctions) { - assert(_functions == null || _argumentsAfterFunctions != null, - 'If _functions is passed, _argumentsAfterFunctions must be too.'); - } + this._argumentsAfterFunctions) + : assert(_functions == null || _argumentsAfterFunctions != null, + 'If _functions is passed, _argumentsAfterFunctions must be too.'); /// Builds chunks for the argument list. void visit() { diff --git a/lib/src/cli/format_command.dart b/lib/src/cli/format_command.dart index 36092c66..4a9a1d46 100644 --- a/lib/src/cli/format_command.dart +++ b/lib/src/cli/format_command.dart @@ -32,7 +32,7 @@ class FormatCommand extends Command { Future run() async { var argResults = this.argResults!; - if (argResults['version']) { + if (argResults['version'] as bool) { print(dartStyleVersion); return 0; } @@ -78,7 +78,7 @@ class FormatCommand extends Command { } // Can't use --verbose with anything but --help. - if (argResults['verbose'] && !(argResults['help'] as bool)) { + if (argResults['verbose'] as bool && !(argResults['help'] as bool)) { usageException('Can only use --verbose with --help.'); } @@ -87,11 +87,11 @@ class FormatCommand extends Command { usageException('Cannot print a summary with JSON output.'); } - var pageWidth = int.tryParse(argResults['line-length']) ?? + var pageWidth = int.tryParse(argResults['line-length'] as String) ?? usageException('--line-length must be an integer, was ' '"${argResults['line-length']}".'); - var indent = int.tryParse(argResults['indent']) ?? + var indent = int.tryParse(argResults['indent'] as String) ?? usageException('--indent must be an integer, was ' '"${argResults['indent']}".'); @@ -101,10 +101,10 @@ class FormatCommand extends Command { } var fixes = []; - if (argResults['fix']) fixes.addAll(StyleFix.all); + if (argResults['fix'] as bool) fixes.addAll(StyleFix.all); for (var fix in StyleFix.all) { - if (argResults['fix-${fix.name}']) { - if (argResults['fix']) { + if (argResults['fix-${fix.name}'] as bool) { + if (argResults['fix'] as bool) { usageException('--fix-${fix.name} is redundant with --fix.'); } @@ -119,7 +119,7 @@ class FormatCommand extends Command { usageException(exception.message); } - var followLinks = argResults['follow-links']; + var followLinks = argResults['follow-links'] as bool; var setExitIfChanged = argResults['set-exit-if-changed'] as bool; var experimentFlags = argResults['enable-experiment'] as List; diff --git a/lib/src/cli/options.dart b/lib/src/cli/options.dart index b59ea9e2..cbc22565 100644 --- a/lib/src/cli/options.dart +++ b/lib/src/cli/options.dart @@ -145,7 +145,7 @@ List? parseSelection(ArgResults argResults, String optionName) { try { var coordinates = option.split(':'); if (coordinates.length != 2) { - throw FormatException( + throw const FormatException( 'Selection should be a colon-separated pair of integers, "123:45".'); } diff --git a/lib/src/cli/output.dart b/lib/src/cli/output.dart index 9851268d..efdd4451 100644 --- a/lib/src/cli/output.dart +++ b/lib/src/cli/output.dart @@ -46,11 +46,11 @@ enum Output { break; case Output.json: - // TODO(rnystrom): Put an empty selection in here to remain compatible with - // the old formatter. Since there's no way to pass a selection on the - // command line, this will never be used, which is why it's hard-coded to - // -1, -1. If we add support for passing in a selection, put the real - // result here. + // TODO(rnystrom): Put an empty selection in here to remain compatible + // with the old formatter. Since there's no way to pass a selection on + // the command line, this will never be used, which is why it's + // hard-coded to -1, -1. If we add support for passing in a selection, + // put the real result here. print(jsonEncode({ 'path': path, 'source': result.text, diff --git a/lib/src/dart_formatter.dart b/lib/src/dart_formatter.dart index ab6bbc50..d6f806ee 100644 --- a/lib/src/dart_formatter.dart +++ b/lib/src/dart_formatter.dart @@ -71,7 +71,7 @@ class DartFormatter { /// /// If [uri] is given, it is a [String] or [Uri] used to identify the file /// being formatted in error messages. - String format(String source, {uri}) { + String format(String source, {Object? uri}) { if (uri == null) { // Do nothing. } else if (uri is Uri) { @@ -82,7 +82,8 @@ class DartFormatter { throw ArgumentError('uri must be `null`, a Uri, or a String.'); } - return formatSource(SourceCode(source, uri: uri, isCompilationUnit: true)) + return formatSource( + SourceCode(source, uri: uri as String?, isCompilationUnit: true)) .text; } diff --git a/lib/src/debug.dart b/lib/src/debug.dart index 7fcfaf2b..664a8fc7 100644 --- a/lib/src/debug.dart +++ b/lib/src/debug.dart @@ -49,7 +49,7 @@ final _none = _color('\u001b[0m'); final _bold = _color('\u001b[1m'); /// Prints [message] to stdout with each line correctly indented. -void log([message]) { +void log([Object? message]) { if (message == null) { print(''); return; @@ -59,13 +59,13 @@ void log([message]) { } /// Wraps [message] in gray ANSI escape codes if enabled. -String gray(message) => '$_gray$message$_none'; +String gray(Object message) => '$_gray$message$_none'; /// Wraps [message] in green ANSI escape codes if enabled. -String green(message) => '$_green$message$_none'; +String green(Object message) => '$_green$message$_none'; /// Wraps [message] in bold ANSI escape codes if enabled. -String bold(message) => '$_bold$message$_none'; +String bold(Object message) => '$_bold$message$_none'; /// Prints [chunks] to stdout, one chunk per line, with detailed information /// about each chunk. @@ -99,7 +99,7 @@ void dumpChunks(int start, List chunks) { var row = []; row.add('$prefix$index:'); - void writeIf(predicate, String Function() callback) { + void writeIf(bool predicate, String Function() callback) { if (predicate) { row.add(callback()); } else { diff --git a/lib/src/front_end/adjacent_builder.dart b/lib/src/front_end/adjacent_builder.dart index 5a9dd4bc..4c70c51b 100644 --- a/lib/src/front_end/adjacent_builder.dart +++ b/lib/src/front_end/adjacent_builder.dart @@ -87,7 +87,7 @@ class AdjacentBuilder { /// Removes redundant [AdjacentPiece] wrappers from [_pieces]. Piece _flattenPieces() { - List flattened = []; + var flattened = []; void traverse(List pieces) { for (var piece in pieces) { diff --git a/lib/src/front_end/ast_node_visitor.dart b/lib/src/front_end/ast_node_visitor.dart index 3414cd42..b39171c4 100644 --- a/lib/src/front_end/ast_node_visitor.dart +++ b/lib/src/front_end/ast_node_visitor.dart @@ -1472,8 +1472,8 @@ class AstNodeVisitor extends ThrowingAstVisitor with PieceFactory { b.modifier(node.keyword); // TODO(tall): Test how splits inside the type annotation (like in a type - // argument list or a function type's parameter list) affect the indentation - // and splitting of the surrounding variable declaration. + // argument list or a function type's parameter list) affect the + // indentation and splitting of the surrounding variable declaration. b.visit(node.type); }); diff --git a/lib/src/front_end/comment_writer.dart b/lib/src/front_end/comment_writer.dart index b7f70a77..1682343b 100644 --- a/lib/src/front_end/comment_writer.dart +++ b/lib/src/front_end/comment_writer.dart @@ -87,6 +87,7 @@ class CommentWriter { // just override the script tag's line. if (token.previous!.type == TokenType.SCRIPT_TAG) previousLine = tokenLine; + // ignore: prefer_const_constructors var comments = CommentSequence._([], []); for (Token? comment = token.precedingComments; comment != null; @@ -283,7 +284,7 @@ class CommentSequence extends ListBase { SourceComment operator [](int index) => _comments[index]; @override - operator []=(int index, SourceComment value) => + void operator []=(int index, SourceComment value) => throw UnsupportedError('Comment sequence can\'t be modified.'); void _add(int linesBefore, SourceComment comment) { diff --git a/lib/src/front_end/piece_factory.dart b/lib/src/front_end/piece_factory.dart index 81229037..ed1b02a5 100644 --- a/lib/src/front_end/piece_factory.dart +++ b/lib/src/front_end/piece_factory.dart @@ -702,7 +702,7 @@ mixin PieceFactory { AstNode target, Token operator, Expression rightHandSide, {bool splitBeforeOperator = false, bool includeComma = false, - spaceBeforeOperator = true}) { + bool spaceBeforeOperator = true}) { if (splitBeforeOperator) { var targetPiece = nodePiece(target); @@ -729,7 +729,7 @@ mixin PieceFactory { /// Invokes [buildCallback] with a new [AdjacentBuilder] and returns the /// built result. - Piece buildPiece(Function(AdjacentBuilder) buildCallback) { + Piece buildPiece(void Function(AdjacentBuilder) buildCallback) { var builder = AdjacentBuilder(this); buildCallback(builder); return builder.build(); diff --git a/lib/src/io.dart b/lib/src/io.dart index f9ef254e..f3e3bb8b 100644 --- a/lib/src/io.dart +++ b/lib/src/io.dart @@ -25,7 +25,7 @@ Future formatStdin( var completer = Completer(); var input = StringBuffer(); - stdin.transform(Utf8Decoder()).listen(input.write, onDone: () { + stdin.transform(const Utf8Decoder()).listen(input.write, onDone: () { var formatter = DartFormatter( indent: options.indent, pageWidth: options.pageWidth, diff --git a/lib/src/line_splitting/solve_state.dart b/lib/src/line_splitting/solve_state.dart index 4aa2efd9..3d971995 100644 --- a/lib/src/line_splitting/solve_state.dart +++ b/lib/src/line_splitting/solve_state.dart @@ -173,7 +173,7 @@ class SolveState { // The way SolveStates are expanded should guarantee that we never generate // the exact same state twice. Getting here implies that that failed. - throw 'unreachable'; + throw StateError('unreachable'); } /// Enqueues more solve states to consider based on this one. diff --git a/lib/src/line_splitting/solve_state_queue.dart b/lib/src/line_splitting/solve_state_queue.dart index 5ce2975f..5bcb2d47 100644 --- a/lib/src/line_splitting/solve_state_queue.dart +++ b/lib/src/line_splitting/solve_state_queue.dart @@ -14,7 +14,8 @@ import 'solve_state.dart'; /// overflow characters. When a new state is added to the heap, it will be /// discarded, or a previously enqueued one will be discarded, if two overlap. class SolveStateQueue { - /// Initial capacity of a queue when created, or when added to after a [clear]. + /// Initial capacity of a queue when created. + /// /// Number can be any positive value. Picking a size that gives a whole /// number of "tree levels" in the heap is only done for aesthetic reasons. static const int _initialCapacity = 7; @@ -111,7 +112,7 @@ class SolveStateQueue { // The way SolveStates are expanded should guarantee that we never generate // the exact same state twice. Getting here implies that that failed. - throw 'unreachable'; + throw StateError('unreachable'); } /// Determines if any already enqueued state overlaps [state]. diff --git a/lib/src/line_writer.dart b/lib/src/line_writer.dart index 8992c431..0d738b1d 100644 --- a/lib/src/line_writer.dart +++ b/lib/src/line_writer.dart @@ -219,7 +219,7 @@ class _BlockKey { _BlockKey(this.chunk, this.column); @override - bool operator ==(other) { + bool operator ==(Object other) { if (other is! _BlockKey) return false; return chunk == other.chunk && column == other.column; } diff --git a/lib/src/source_visitor.dart b/lib/src/source_visitor.dart index 221b57bf..764d2f8b 100644 --- a/lib/src/source_visitor.dart +++ b/lib/src/source_visitor.dart @@ -577,7 +577,7 @@ class SourceVisitor extends ThrowingAstVisitor { } @override - visitCatchClauseParameter(CatchClauseParameter node) { + void visitCatchClauseParameter(CatchClauseParameter node) { token(node.name); } @@ -842,7 +842,7 @@ class SourceVisitor extends ThrowingAstVisitor { token(node.separator); space(); - // Try to line up the initializers with the first one that follows the ":": + // Try to line up the initializers with the first one that follows the ":" // // Foo(notTrailing) // : initializer = value, @@ -853,8 +853,8 @@ class SourceVisitor extends ThrowingAstVisitor { // ) : initializer = value, // super(); // +4 from previous line. // - // This doesn't work if there is a trailing comma in an optional parameter, - // but we don't want to do a weird +5 alignment: + // This doesn't work if there is a trailing comma in an optional + // parameter, but we don't want to do a weird +5 alignment: // // Foo({ // trailing, @@ -1036,7 +1036,7 @@ class SourceVisitor extends ThrowingAstVisitor { } // The ";" after the constants, which may occur after a trailing comma. - Token afterConstants = node.constants.last.endToken.next!; + var afterConstants = node.constants.last.endToken.next!; Token? semicolon; if (afterConstants.type == TokenType.SEMICOLON) { semicolon = node.constants.last.endToken.next!; @@ -1573,9 +1573,7 @@ class SourceVisitor extends ThrowingAstVisitor { modifier(declaration.keyword); visit(declaration.type, after: space); - visitCommaSeparatedNodes(declaration.variables, between: () { - split(); - }); + visitCommaSeparatedNodes(declaration.variables, between: split); builder.endRule(); builder.unnest(); @@ -1828,8 +1826,8 @@ class SourceVisitor extends ThrowingAstVisitor { } else { split(); - // If the then clause is a non-spread collection or lambda, make sure the - // body is indented. + // If the then clause is a non-spread collection or lambda, make sure + // the body is indented. builder.startBlockArgumentNesting(); } @@ -4128,7 +4126,7 @@ class SourceVisitor extends ThrowingAstVisitor { // TODO(rnystrom): Can the analyzer move "semicolon" to some shared base // type? - token((node as dynamic).semicolon); + token((node as dynamic).semicolon as Token); builder.unnest(); } diff --git a/pubspec.yaml b/pubspec.yaml index f380aace..4f36b03f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -17,12 +17,12 @@ dependencies: source_span: ^1.4.0 dev_dependencies: + dart_flutter_team_lints: ^2.0.0 grinder: ^0.9.0-nullsafety.0 js: ^0.6.0 # TODO(rnystrom): Disabled for now because node_preamble is not migrated yet # and publishing to npm hasn't been used in a while. # node_preamble: ^1.0.0 - lints: ^2.0.0 test: ^1.24.6 test_descriptor: ^2.0.0 test_process: ^2.0.0 diff --git a/test/io_test.dart b/test/io_test.dart index 49851a5b..6a9bfe81 100644 --- a/test/io_test.dart +++ b/test/io_test.dart @@ -42,7 +42,7 @@ void main() { var goodBefore = modTime('good.dart'); // Wait a bit so the mod time of a formatted file will be different. - await Future.delayed(Duration(seconds: 1)); + await Future.delayed(const Duration(seconds: 1)); var dir = Directory(p.join(d.sandbox, 'code')); processDirectory(overwriteOptions, dir); diff --git a/test/short_format_test.dart b/test/short_format_test.dart index 6576bd8f..fbc2bb77 100644 --- a/test/short_format_test.dart +++ b/test/short_format_test.dart @@ -19,8 +19,7 @@ void main() async { test('throws a FormatterException on failed parse', () { var formatter = DartFormatter(); - expect(() => formatter.format('wat?!'), - throwsA(TypeMatcher())); + expect(() => formatter.format('wat?!'), throwsA(isA())); }); test('FormatterException.message() does not throw', () { @@ -130,6 +129,6 @@ void main() async { // attempt to make non-whitespace changes. var formatter = DartFormatter(lineEnding: '%'); expect(() => formatter.format('var i = 1;'), - throwsA(TypeMatcher())); + throwsA(isA())); }); } diff --git a/tool/grind.dart b/tool/grind.dart index 95cc0f2e..4f9f1c49 100644 --- a/tool/grind.dart +++ b/tool/grind.dart @@ -2,6 +2,8 @@ // 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: unreachable_from_main + import 'package:grinder/grinder.dart'; import 'package:pub_semver/pub_semver.dart'; import 'package:yaml/yaml.dart' as yaml; @@ -99,14 +101,19 @@ Future bump() async { // Read the version from the pubspec. var pubspecFile = getFile('pubspec.yaml'); var pubspec = pubspecFile.readAsStringSync(); - var version = Version.parse((yaml.loadYaml(pubspec) as Map)['version']); + var version = + Version.parse((yaml.loadYaml(pubspec) as Map)['version'] as String); // Require a "-dev" version since we don't otherwise know what to bump it to. - if (!version.isPreRelease) throw 'Cannot publish non-dev version $version.'; + if (!version.isPreRelease) { + throw StateError('Cannot publish non-dev version $version.'); + } // Don't allow versions like "1.2.3-dev+4" because it's not clear if the // user intended the "+4" to be discarded or not. - if (version.build.isNotEmpty) throw 'Cannot publish build version $version.'; + if (version.build.isNotEmpty) { + throw StateError('Cannot publish build version $version.'); + } var bumped = Version(version.major, version.minor, version.patch); diff --git a/tool/node_format_service.dart b/tool/node_format_service.dart index 7ce38d82..6ef6a4e7 100644 --- a/tool/node_format_service.dart +++ b/tool/node_format_service.dart @@ -2,6 +2,8 @@ // 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: unreachable_from_main + @JS() library node_format_service;