mirror of
https://github.com/flutter/flutter.git
synced 2026-01-09 07:51:35 +08:00
WIP Commits separated as follows: - Update lints in analysis_options files - Run `dart fix --apply` - Clean up leftover analysis issues - Run `dart format .` in the right places. Local analysis and testing passes. Checking CI now. Part of https://github.com/flutter/flutter/issues/178827 - Adoption of flutter_lints in examples/api coming in a separate change (cc @loic-sharma) ## Pre-launch Checklist - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [ ] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [ ] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
120 lines
3.4 KiB
Dart
120 lines
3.4 KiB
Dart
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'dart:io' as io;
|
|
|
|
import 'package:path/path.dart' as path;
|
|
import 'package:test/test.dart';
|
|
|
|
class FileContentPair {
|
|
FileContentPair({required this.name, required this.original, required this.formatted});
|
|
|
|
final String name;
|
|
final String original;
|
|
final String formatted;
|
|
}
|
|
|
|
final FileContentPair dartContentPair = FileContentPair(
|
|
name: 'format_test.dart',
|
|
original: 'enum \n\nfoo {\n entry1,\n entry2,\n}',
|
|
formatted: 'enum foo { entry1, entry2 }\n',
|
|
);
|
|
|
|
class TestFileFixture {
|
|
TestFileFixture(this.filePairs, this.baseDir) {
|
|
for (final FileContentPair filePair in filePairs) {
|
|
final file = io.File(path.join(baseDir.path, filePair.name));
|
|
file.writeAsStringSync(filePair.original);
|
|
files.add(file);
|
|
}
|
|
}
|
|
|
|
final List<io.File> files = <io.File>[];
|
|
final io.Directory baseDir;
|
|
final List<FileContentPair> filePairs;
|
|
|
|
void gitAdd() {
|
|
final args = <String>['add'];
|
|
for (final io.File file in files) {
|
|
args.add(file.path);
|
|
}
|
|
|
|
io.Process.runSync('git', args);
|
|
}
|
|
|
|
void gitRemove() {
|
|
final args = <String>['rm', '-f'];
|
|
for (final io.File file in files) {
|
|
args.add(file.path);
|
|
}
|
|
io.Process.runSync('git', args);
|
|
}
|
|
|
|
Iterable<FileContentPair> getFileContents() {
|
|
final results = <FileContentPair>[];
|
|
for (var i = 0; i < files.length; i++) {
|
|
final io.File file = files[i];
|
|
final FileContentPair filePair = filePairs[i];
|
|
final String content = file.readAsStringSync().replaceAll('\r\n', '\n');
|
|
results.add(
|
|
FileContentPair(name: filePair.name, original: content, formatted: filePair.formatted),
|
|
);
|
|
}
|
|
return results;
|
|
}
|
|
}
|
|
|
|
void main() {
|
|
final io.File script = io.File(path.current).absolute;
|
|
final io.Directory flutterRoot = script.parent.parent;
|
|
final String formatterPath = path.join(
|
|
flutterRoot.path,
|
|
'dev',
|
|
'tools',
|
|
'format.${io.Platform.isWindows ? 'bat' : 'sh'}',
|
|
);
|
|
|
|
test(
|
|
'Can fix Dart formatting errors',
|
|
() {
|
|
final fixture = TestFileFixture(<FileContentPair>[dartContentPair], flutterRoot);
|
|
try {
|
|
fixture.gitAdd();
|
|
io.Process.runSync(formatterPath, <String>['--fix'], workingDirectory: flutterRoot.path);
|
|
|
|
final Iterable<FileContentPair> files = fixture.getFileContents();
|
|
for (final pair in files) {
|
|
expect(pair.original, equals(pair.formatted));
|
|
}
|
|
} finally {
|
|
fixture.gitRemove();
|
|
}
|
|
},
|
|
// TODO(goderbauer): Re-enable after the formatting changes have landed.
|
|
skip: true,
|
|
);
|
|
|
|
test(
|
|
'Prints error if dart formatter fails',
|
|
() {
|
|
final fixture = TestFileFixture(<FileContentPair>[], flutterRoot);
|
|
final dartFile = io.File('${flutterRoot.path}/format_test2.dart');
|
|
dartFile.writeAsStringSync('P\n');
|
|
fixture.files.add(dartFile);
|
|
|
|
try {
|
|
fixture.gitAdd();
|
|
final io.ProcessResult result = io.Process.runSync(formatterPath, <String>[
|
|
'--fix',
|
|
], workingDirectory: flutterRoot.path);
|
|
expect(result.stdout, contains('format_test2.dart produced the following error'));
|
|
expect(result.exitCode, isNot(0));
|
|
} finally {
|
|
fixture.gitRemove();
|
|
}
|
|
}, // TODO(goderbauer): Re-enable after the formatting changes have landed.
|
|
skip: true,
|
|
);
|
|
}
|