这是indexloc提供的服务,不要输入任何密码
Skip to content
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
4 changes: 2 additions & 2 deletions .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
strategy:
fail-fast: false
matrix:
sdk: [3.7.0, dev]
sdk: [3.9.0, dev]
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
- uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c
Expand Down Expand Up @@ -50,7 +50,7 @@ jobs:
matrix:
# Add macos-latest and/or windows-latest if relevant for this package.
os: [ubuntu-latest]
sdk: [3.7.0, dev]
sdk: [3.9.0, dev]
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
- uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c
Expand Down
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 3.1.3-wip
## 3.1.3

* No longer format imports with configurations and a prefix in the wrong order.
The parser used to accept this without error even though it violated the
Expand All @@ -12,6 +12,9 @@
* Don't force a space between `?` and `.` if a null-aware element contains a
dot shorthand.

* Require `analyzer: '>=8.2.0 <10.0.0'`.
* Require `sdk: ^3.9.0`

### Bug fixes

* Respect `@dart=` version comments when determining which >3.7 style to apply.
Expand Down
7 changes: 3 additions & 4 deletions benchmark/directory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,9 @@ void main(List<String> arguments) async {
void _runFormatter(String source) {
try {
var formatter = DartFormatter(
languageVersion:
_isShort
? DartFormatter.latestShortStyleLanguageVersion
: DartFormatter.latestLanguageVersion,
languageVersion: _isShort
? DartFormatter.latestShortStyleLanguageVersion
: DartFormatter.latestLanguageVersion,
);

var result = formatter.format(source);
Expand Down
7 changes: 3 additions & 4 deletions benchmark/run.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,9 @@ List<double> _runTrials(String verb, Benchmark benchmark, int trials) {
);

var formatter = DartFormatter(
languageVersion:
_isShort
? DartFormatter.latestShortStyleLanguageVersion
: DartFormatter.latestLanguageVersion,
languageVersion: _isShort
? DartFormatter.latestShortStyleLanguageVersion
: DartFormatter.latestLanguageVersion,
pageWidth: benchmark.pageWidth,
lineEnding: '\n',
);
Expand Down
9 changes: 4 additions & 5 deletions lib/src/back_end/code_writer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,10 @@ final class CodeWriter {
// indication into account which may vary based on the surrounding pieces
// when we get here.
Profile.begin('CodeWriter try to bind by page width');
isUnsolved =
!_solution.tryBindByPageWidth(
piece,
_pageWidth - _indentStack.first.spaces,
);
isUnsolved = !_solution.tryBindByPageWidth(
piece,
_pageWidth - _indentStack.first.spaces,
);
Profile.end('CodeWriter try to bind by page width');
}

Expand Down
26 changes: 12 additions & 14 deletions lib/src/cli/format_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,20 +183,18 @@ final class FormatCommand extends Command<int> {
return 0;
}

var show =
const {
'all': Show.all,
'changed': Show.changed,
'none': Show.none,
}[argResults['show']]!;

var output =
const {
'write': Output.write,
'show': Output.show,
'none': Output.none,
'json': Output.json,
}[argResults['output']]!;
var show = const {
'all': Show.all,
'changed': Show.changed,
'none': Show.none,
}[argResults['show']]!;

var output = const {
'write': Output.write,
'show': Output.show,
'none': Output.none,
'json': Output.json,
}[argResults['output']]!;

var summary = Summary.none;
switch (argResults['summary'] as String) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/cli/formatter_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'show.dart';
import 'summary.dart';

// Note: The following line of code is modified by tool/grind.dart.
const dartStyleVersion = '3.1.3-wip';
const dartStyleVersion = '3.1.3';

/// Global options parsed from the command line that affect how the formatter
/// produces and uses its outputs.
Expand Down
16 changes: 7 additions & 9 deletions lib/src/dart_formatter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,9 @@ final class DartFormatter {
text,
uri: source.uri,
isCompilationUnit: false,
selectionStart:
source.selectionStart != null
? source.selectionStart! + inputOffset
: null,
selectionStart: source.selectionStart != null
? source.selectionStart! + inputOffset
: null,
selectionLength: source.selectionLength,
);
}
Expand Down Expand Up @@ -176,10 +175,9 @@ final class DartFormatter {
}

// Throw if there are syntactic errors.
var syntacticErrors =
parseResult.errors.where((error) {
return error.diagnosticCode.type == DiagnosticType.SYNTACTIC_ERROR;
}).toList();
var syntacticErrors = parseResult.errors.where((error) {
return error.diagnosticCode.type == DiagnosticType.SYNTACTIC_ERROR;
}).toList();
if (syntacticErrors.isNotEmpty) {
throw FormatterException(syntacticErrors);
}
Expand All @@ -200,7 +198,7 @@ final class DartFormatter {
source: stringSource,
offset: token.offset - inputOffset,
length: math.max(token.length, 1),
diagnosticCode: ParserErrorCode.UNEXPECTED_TOKEN,
diagnosticCode: ParserErrorCode.unexpectedToken,
arguments: [token.lexeme],
);
throw FormatterException([error]);
Expand Down
14 changes: 6 additions & 8 deletions lib/src/front_end/ast_node_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1794,10 +1794,9 @@ final class AstNodeVisitor extends ThrowingAstVisitor<void> with PieceFactory {
var isSinglePositional =
positionalFields.length == 1 && namedFields == null;

var listStyle =
isSinglePositional
? const ListStyle(commas: Commas.alwaysTrailing)
: const ListStyle(commas: Commas.trailing);
var listStyle = isSinglePositional
? const ListStyle(commas: Commas.alwaysTrailing)
: const ListStyle(commas: Commas.trailing);
var builder = DelimitedListBuilder(this, listStyle);

// If all parameters are optional, put the `{` right after `(`.
Expand Down Expand Up @@ -1963,10 +1962,9 @@ final class AstNodeVisitor extends ThrowingAstVisitor<void> with PieceFactory {
for (var element in node.elements) {
pieces.visit(
element,
context:
node.isMultiline
? NodeContext.multilineStringInterpolation
: NodeContext.none,
context: node.isMultiline
? NodeContext.multilineStringInterpolation
: NodeContext.none,
);
}
}
Expand Down
11 changes: 6 additions & 5 deletions lib/src/front_end/delimited_list_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,10 @@ final class DelimitedListBuilder {
hanging: hangingComments,
separate: separateComments,
leading: leadingComments,
) = _splitCommaComments(comments, hasElementAfter: hasElementAfter);
) = _splitCommaComments(
comments,
hasElementAfter: hasElementAfter,
);

// Add any hanging inline block comments to the previous element before the
// subsequent ",".
Expand Down Expand Up @@ -401,10 +404,8 @@ final class DelimitedListBuilder {
}
}

var (
hangingComments,
separateCommentsBeforeComma,
) = remainingCommentsBeforeComma.splitAt(hangingCommentCount);
var (hangingComments, separateCommentsBeforeComma) =
remainingCommentsBeforeComma.splitAt(hangingCommentCount);

// Inline block comments on the same line as the next element lead at the
// beginning of that line, as in:
Expand Down
7 changes: 3 additions & 4 deletions lib/src/front_end/piece_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -856,10 +856,9 @@ mixin PieceFactory {
pieces.token(question);
}

var returnTypeModifiers =
parameter != null
? [parameter.requiredKeyword, parameter.covariantKeyword]
: const <Token?>[];
var returnTypeModifiers = parameter != null
? [parameter.requiredKeyword, parameter.covariantKeyword]
: const <Token?>[];

// If the type is a function-typed parameter with a default value, then
// grab the default value from the parent node and attach it to the
Expand Down
7 changes: 3 additions & 4 deletions lib/src/front_end/piece_writer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,9 @@ final class PieceWriter {
var builtPieces = _pieces.removeLast();
assert(builtPieces.isNotEmpty);

var builtPiece =
builtPieces.length == 1
? builtPieces.first
: AdjacentPiece(builtPieces);
var builtPiece = builtPieces.length == 1
? builtPieces.first
: AdjacentPiece(builtPieces);

if (leadingPieces.isEmpty) {
// No metadata, so return the content piece directly.
Expand Down
5 changes: 3 additions & 2 deletions lib/src/short/line_splitting/solve_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,9 @@ final class SolveState {
if (chunk is BlockChunk) {
if (_splits.shouldSplitAt(i)) {
// Include the cost of the nested block.
cost +=
_splitter.writer.formatBlock(chunk, _splits.getColumn(i)).cost;
cost += _splitter.writer
.formatBlock(chunk, _splits.getColumn(i))
.cost;
} else {
// Include the nested block inline, if any.
length += chunk.unsplitBlockLength;
Expand Down
12 changes: 6 additions & 6 deletions lib/src/short/source_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1251,12 +1251,12 @@ final class SourceVisitor extends ThrowingAstVisitor {
return;
}

var requiredParams =
node.parameters
.where((param) => param is! DefaultFormalParameter)
.toList();
var optionalParams =
node.parameters.whereType<DefaultFormalParameter>().toList();
var requiredParams = node.parameters
.where((param) => param is! DefaultFormalParameter)
.toList();
var optionalParams = node.parameters
.whereType<DefaultFormalParameter>()
.toList();

if (nestExpression) builder.nestExpression();
token(node.leftParenthesis);
Expand Down
5 changes: 3 additions & 2 deletions lib/src/testing/benchmark.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ final class Benchmark {

var input = inputLines.join('\n');

var shortOutput =
File(p.setExtension(path, '.expect_short')).readAsStringSync();
var shortOutput = File(
p.setExtension(path, '.expect_short'),
).readAsStringSync();
var tallOutput = File(p.setExtension(path, '.expect')).readAsStringSync();

return Benchmark(
Expand Down
14 changes: 6 additions & 8 deletions lib/src/testing/test_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ final _outputPattern = RegExp(r'<<<( (\d+)\.(\d+))?(.*)');

/// Get the absolute local file path to the dart_style package's root directory.
Future<String> findPackageDirectory() async {
var libraryPath =
(await Isolate.resolvePackageUri(
Uri.parse('package:dart_style/src/testing/test_file.dart'),
))?.toFilePath();
var libraryPath = (await Isolate.resolvePackageUri(
Uri.parse('package:dart_style/src/testing/test_file.dart'),
))?.toFilePath();

// Fallback, if we can't resolve the package URI because we're running in an
// AOT snapshot, just assume we're running from the root directory of the
Expand Down Expand Up @@ -299,10 +298,9 @@ final class TestFile {
/// If [version] is given, then it specifies the language version to run the
/// test at. Otherwise, the test's default version is used.
DartFormatter formatterForTest(FormatTest test, [Version? version]) {
var defaultLanguageVersion =
isTall
? DartFormatter.latestLanguageVersion
: DartFormatter.latestShortStyleLanguageVersion;
var defaultLanguageVersion = isTall
? DartFormatter.latestLanguageVersion
: DartFormatter.latestShortStyleLanguageVersion;

return DartFormatter(
languageVersion: version ?? defaultLanguageVersion,
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
name: dart_style
# Note: See tool/grind.dart for how to bump the version.
version: 3.1.3-wip
version: 3.1.3
description: >-
Opinionated, automatic Dart source code formatter.
Provides an API and a CLI tool.
repository: https://github.com/dart-lang/dart_style
environment:
sdk: ^3.7.0
sdk: ^3.9.0

dependencies:
analyzer: ^8.1.0
analyzer: '>=8.2.0 <10.0.0'
args: ^2.0.0
collection: ^1.19.0
package_config: ^2.1.0
Expand Down
7 changes: 3 additions & 4 deletions test/dart_formatter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ void _runTests({required bool isTall}) {
int? indent,
String? lineEnding,
}) {
languageVersion ??=
isTall
? DartFormatter.latestLanguageVersion
: DartFormatter.latestShortStyleLanguageVersion;
languageVersion ??= isTall
? DartFormatter.latestLanguageVersion
: DartFormatter.latestShortStyleLanguageVersion;

return DartFormatter(
languageVersion: languageVersion,
Expand Down
12 changes: 6 additions & 6 deletions test/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,9 @@ Future<void> testBenchmarks({required bool useTallStyle}) async {
for (var benchmark in benchmarks) {
test(benchmark.name, () {
var formatter = DartFormatter(
languageVersion:
useTallStyle
? DartFormatter.latestLanguageVersion
: DartFormatter.latestShortStyleLanguageVersion,
languageVersion: useTallStyle
? DartFormatter.latestLanguageVersion
: DartFormatter.latestShortStyleLanguageVersion,
pageWidth: benchmark.pageWidth,
);

Expand All @@ -127,8 +126,9 @@ Future<void> testBenchmarks({required bool useTallStyle}) async {
var actualText = actual.text;
if (!benchmark.isCompilationUnit) actualText += '\n';

var expected =
useTallStyle ? benchmark.tallOutput : benchmark.shortOutput;
var expected = useTallStyle
? benchmark.tallOutput
: benchmark.shortOutput;

// Fail with an explicit message because it's easier to read than
// the matcher output.
Expand Down
7 changes: 3 additions & 4 deletions tool/update_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,9 @@ bool _writeOutput(
buffer.writeln('<<< $outputDescription'.trim());
_writeComments(buffer, output.comments);

var defaultVersion =
testFile.isTall
? DartFormatter.latestLanguageVersion
: DartFormatter.latestShortStyleLanguageVersion;
var defaultVersion = testFile.isTall
? DartFormatter.latestLanguageVersion
: DartFormatter.latestShortStyleLanguageVersion;

var formatter = testFile.formatterForTest(
formatTest,
Expand Down