Skip to content

Commit c52383f

Browse files
authored
Update Dart formatter message (#937)
1 parent bb8946c commit c52383f

7 files changed

+20
-36
lines changed

CONTRIBUTING.md

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ new tests, use the existing tests as a guideline for what they should look like.
3838
Before you send your pull request, make sure all the tests pass! Just run
3939
`dart test`.
4040

41+
When updating UI messages, the golden test files in `test/goldens` -- which
42+
contain the expected UI output -- need to be updated. To do that, simply delete the outdated golden test file, and it will be regenerated when `dart test` is run.
43+
4144
### File headers
4245

4346
All files in the project must start with the following header.

lib/src/messages.dart

+3-25
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,9 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
class _MsgDict {
6-
final String dartanalyzerShortName;
7-
final String dartanalyzerShortCmd;
8-
final String dartfmtShortName;
9-
final String dartfmtShortCmd;
10-
11-
_MsgDict._({
12-
this.dartanalyzerShortName = 'dart analyze',
13-
this.dartanalyzerShortCmd = 'dart analyze .',
14-
this.dartfmtShortName = 'dartfmt',
15-
this.dartfmtShortCmd = 'dartfmt -n .',
16-
});
17-
18-
static _MsgDict defaultDict = _MsgDict._();
19-
20-
static _MsgDict flutterDict = _MsgDict._(
21-
dartanalyzerShortName: 'flutter analyze',
22-
dartanalyzerShortCmd: 'flutter analyze',
23-
dartfmtShortName: 'flutter format',
24-
dartfmtShortCmd: 'flutter format',
25-
);
26-
}
27-
285
String runningDartanalyzerFailed(bool usesFlutter, errorMsg) {
29-
final dict = usesFlutter ? _MsgDict.flutterDict : _MsgDict.defaultDict;
30-
return 'Running `${dict.dartanalyzerShortCmd}` failed with the following output:\n\n'
6+
final message = usesFlutter ? 'flutter analyze' : 'dart analyze .';
7+
8+
return 'Running `$message` failed with the following output:\n\n'
319
'```\n$errorMsg\n```\n';
3210
}

lib/src/report/static_analysis.dart

+6-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import '../model.dart';
1414
import '../package_context.dart';
1515
import '../sdk_env.dart';
1616
import '../utils.dart';
17-
1817
import '_common.dart';
1918

2019
Future<ReportSection> staticAnalysis(PackageContext context) async {
@@ -153,8 +152,12 @@ Future<List<Issue>> _formatPackage(
153152
lineLength: lineLength,
154153
);
155154
return unformattedFiles
156-
.map((f) => Issue('$f is not formatted according to dartfmt',
157-
suggestion: 'To format your files run: `dartfmt -w .`'))
155+
.map((f) => Issue(
156+
'$f doesn\'t match the Dart formatter.',
157+
suggestion: usesFlutter
158+
? 'To format your files run: `flutter format .`'
159+
: 'To format your files run: `dart format .`',
160+
))
158161
.toList();
159162
} on ToolException catch (e) {
160163
return [

test/goldens/end2end/sdp_transform-0.2.0.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
"grantedPoints": 20,
7777
"maxPoints": 30,
7878
"status": "partial",
79-
"summary": "### [~] 20/30 points: code has no errors, warnings, lints, or formatting issues\n\n<details>\n<summary>\nlib/src/grammar.dart is not formatted according to dartfmt\n</summary>\n\nTo format your files run: `dartfmt -w .`\n</details>\n<details>\n<summary>\nlib/src/parser.dart is not formatted according to dartfmt\n</summary>\n\nTo format your files run: `dartfmt -w .`\n</details>"
79+
"summary": "### [~] 20/30 points: code has no errors, warnings, lints, or formatting issues\n\n<details>\n<summary>\nlib/src/grammar.dart doesn't match the Dart formatter.\n</summary>\n\nTo format your files run: `dart format .`\n</details>\n<details>\n<summary>\nlib/src/parser.dart doesn't match the Dart formatter.\n</summary>\n\nTo format your files run: `dart format .`\n</details>"
8080
},
8181
{
8282
"id": "dependency",

test/goldens/end2end/sdp_transform-0.2.0.json_report.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ See [package layout](https://dart.dev/tools/pub/package-layout#examples) guideli
3939

4040
<details>
4141
<summary>
42-
lib/src/grammar.dart is not formatted according to dartfmt
42+
lib/src/grammar.dart doesn't match the Dart formatter.
4343
</summary>
4444

45-
To format your files run: `dartfmt -w .`
45+
To format your files run: `dart format .`
4646
</details>
4747
<details>
4848
<summary>
49-
lib/src/parser.dart is not formatted according to dartfmt
49+
lib/src/parser.dart doesn't match the Dart formatter.
5050
</summary>
5151

52-
To format your files run: `dartfmt -w .`
52+
To format your files run: `dart format .`
5353
</details>
5454

5555
## 10/20 Support up-to-date dependencies

test/goldens/end2end/skiplist-0.1.0.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"grantedPoints": 20,
5858
"maxPoints": 30,
5959
"status": "partial",
60-
"summary": "### [~] 20/30 points: code has no errors, warnings, lints, or formatting issues\n\n<details>\n<summary>\nlib/skiplist.dart is not formatted according to dartfmt\n</summary>\n\nTo format your files run: `dartfmt -w .`\n</details>"
60+
"summary": "### [~] 20/30 points: code has no errors, warnings, lints, or formatting issues\n\n<details>\n<summary>\nlib/skiplist.dart doesn't match the Dart formatter.\n</summary>\n\nTo format your files run: `dart format .`\n</details>"
6161
},
6262
{
6363
"id": "dependency",

test/goldens/end2end/skiplist-0.1.0.json_report.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ Run `dart pub get` for more information.
4747

4848
<details>
4949
<summary>
50-
lib/skiplist.dart is not formatted according to dartfmt
50+
lib/skiplist.dart doesn't match the Dart formatter.
5151
</summary>
5252

53-
To format your files run: `dartfmt -w .`
53+
To format your files run: `dart format .`
5454
</details>
5555

5656
## 0/20 Support up-to-date dependencies

0 commit comments

Comments
 (0)