Skip to content

Commit 4188824

Browse files
committed
Output validation errors on stdout, slightly prettier formatted
1 parent 8c2e621 commit 4188824

17 files changed

+162
-75
lines changed

lib/src/command/lish.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ the \$PUB_HOSTED_URL environment variable.''',
466466
? _publicationFromEntrypoint()
467467
: _publicationFromArchive(_fromArchive));
468468
if (dryRun) {
469-
log.warning(publication.warningsCountMessage);
469+
log.message(publication.warningsCountMessage);
470470
if (publication.warningCount != 0) {
471471
overrideExitCode(DATA);
472472
}

lib/src/validator.dart

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -185,36 +185,26 @@ abstract class Validator {
185185
.addAll([for (final validator in validators) ...validator.warnings]);
186186
errors.addAll([for (final validator in validators) ...validator.errors]);
187187

188-
if (errors.isNotEmpty) {
189-
final s = errors.length > 1 ? 's' : '';
190-
log.error('Package validation found the following error$s:');
191-
for (var error in errors) {
192-
log.error("* ${error.split('\n').join('\n ')}");
188+
String presentDiagnostics(List<String> diagnostics) => diagnostics
189+
.map((diagnostic) => "* ${diagnostic.split('\n').join('\n ')}\n")
190+
.join('\n');
191+
final sections = <String>[];
192+
193+
for (final (kind, diagnostics) in [
194+
('error', errors),
195+
('potential issue', warnings),
196+
('hint', hints),
197+
]) {
198+
if (diagnostics.isNotEmpty) {
199+
final s = diagnostics.length > 1 ? 's' : '';
200+
final count = diagnostics.length > 1 ? '${diagnostics.length} ' : '';
201+
sections.add(
202+
'Package validation found the following $count$kind$s:\n'
203+
'${presentDiagnostics(diagnostics)}',
204+
);
193205
}
194-
log.error('');
195-
}
196-
197-
if (warnings.isNotEmpty) {
198-
final s = warnings.length > 1 ? 's' : '';
199-
log.warning(
200-
'Package validation found the following potential issue$s:',
201-
);
202-
for (var warning in warnings) {
203-
log.warning("* ${warning.split('\n').join('\n ')}");
204-
}
205-
log.warning('');
206-
}
207-
208-
if (hints.isNotEmpty) {
209-
final s = hints.length > 1 ? 's' : '';
210-
log.warning(
211-
'Package validation found the following hint$s:',
212-
);
213-
for (var hint in hints) {
214-
log.warning("* ${hint.split('\n').join('\n ')}");
215-
}
216-
log.warning('');
217206
}
207+
log.message(sections.join('\n'));
218208
});
219209
}
220210

lib/src/validator/dependency_override.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import '../validator.dart';
1212
/// absence thereof).
1313
class DependencyOverrideValidator extends Validator {
1414
@override
15-
Future validate() {
15+
Future<void> validate() async {
1616
final overridden =
1717
MapKeySet(context.entrypoint.workspaceRoot.allOverridesInWorkspace);
1818
final dev = MapKeySet(package.devDependencies);
@@ -31,6 +31,5 @@ This might be necessary for packages with cyclic dependencies.
3131
3232
Please be extra careful when publishing.''');
3333
}
34-
return Future.value();
3534
}
3635
}

pubspec.lock

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@ packages:
55
dependency: transitive
66
description:
77
name: _fe_analyzer_shared
8-
sha256: c57b02f47e021c9d7ced6d2e28824b315e0fd585578274bc4c2a5db0626f154a
8+
sha256: "45cfa8471b89fb6643fe9bf51bd7931a76b8f5ec2d65de4fb176dba8d4f22c77"
99
url: "https://pub.dev"
1010
source: hosted
11-
version: "75.0.0"
11+
version: "73.0.0"
1212
_macros:
1313
dependency: transitive
1414
description: dart
1515
source: sdk
16-
version: "0.3.3"
16+
version: "0.3.2"
1717
analyzer:
1818
dependency: "direct main"
1919
description:
2020
name: analyzer
21-
sha256: ef226c581b7cd875f734125b1b9928df3db08cc85ff87ce7d9be89a677aaee23
21+
sha256: "4959fec185fe70cce007c57e9ab6983101dbe593d2bf8bbfb4453aaec0cf470a"
2222
url: "https://pub.dev"
2323
source: hosted
24-
version: "6.10.0"
24+
version: "6.8.0"
2525
args:
2626
dependency: "direct main"
2727
description:
@@ -178,10 +178,10 @@ packages:
178178
dependency: transitive
179179
description:
180180
name: lints
181-
sha256: "4a16b3f03741e1252fda5de3ce712666d010ba2122f8e912c94f9f7b90e1a4c3"
181+
sha256: "3315600f3fb3b135be672bf4a178c55f274bebe368325ae18462c89ac1e3b413"
182182
url: "https://pub.dev"
183183
source: hosted
184-
version: "5.1.0"
184+
version: "5.0.0"
185185
logging:
186186
dependency: transitive
187187
description:
@@ -194,10 +194,10 @@ packages:
194194
dependency: transitive
195195
description:
196196
name: macros
197-
sha256: "1d9e801cd66f7ea3663c45fc708450db1fa57f988142c64289142c9b7ee80656"
197+
sha256: "0acaed5d6b7eab89f63350bccd82119e6c602df0f391260d0e32b5e23db79536"
198198
url: "https://pub.dev"
199199
source: hosted
200-
version: "0.1.3-main.0"
200+
version: "0.1.2-main.4"
201201
matcher:
202202
dependency: transitive
203203
description:
@@ -479,4 +479,4 @@ packages:
479479
source: hosted
480480
version: "2.2.1"
481481
sdks:
482-
dart: ">=3.6.0-0 <4.0.0"
482+
dart: ">=3.5.0 <4.0.0"

test/lish/dry_run_package_validation_has_a_warning_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void main() {
2828

2929
await pub.shouldExit(exit_codes.DATA);
3030
expect(
31-
pub.stderr,
31+
pub.stdout,
3232
emitsThrough('Package has 1 warning.'),
3333
);
3434
});

test/lish/dry_run_package_validation_has_no_warnings_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ void main() {
1818
final pub = await startPublish(globalServer, args: ['--dry-run']);
1919

2020
await pub.shouldExit(exit_codes.SUCCESS);
21-
expect(pub.stderr, emitsThrough('Package has 0 warnings.'));
21+
expect(pub.stdout, emitsThrough('Package has 0 warnings.'));
2222
});
2323
}

test/lish/force_publishes_if_there_are_warnings_test.dart

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,17 @@ void main() {
4242
});
4343

4444
await pub.shouldExit(exit_codes.SUCCESS);
45-
final stderrLines = await pub.stderr.rest.toList();
45+
final stdoutLines = await pub.stdout.rest.toList();
4646
expect(
47-
stderrLines,
47+
stdoutLines,
4848
allOf([
4949
contains('Package validation found the following potential issue:'),
5050
contains(
5151
'* Your dependency on "foo" should have a version constraint. '
5252
'For example:',
5353
),
54+
contains('Message from server: Package test_pkg 1.0.0 uploaded!'),
5455
]),
5556
);
56-
expect(
57-
pub.stdout,
58-
emitsThrough('Message from server: Package test_pkg 1.0.0 uploaded!'),
59-
);
6057
});
6158
}

test/testdata/goldens/directory_option_test/commands taking a --directory~-C parameter work.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ Publishing test_pkg 1.0.0 to http://localhost:$PORT:
138138
Total compressed archive size: <1 KB.
139139
Validating package...
140140
The server may enforce additional checks.
141-
[STDERR]
142-
[STDERR] Package has 0 warnings.
141+
142+
Package has 0 warnings.
143143

144144
-------------------------------- END OF OUTPUT ---------------------------------
145145

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# GENERATED BY: test/validator/validations_output_test.dart
2+
3+
## Section 0
4+
$ pub publish --dry-run
5+
Resolving dependencies...
6+
Downloading packages...
7+
! bar 1.0.0 (overridden)
8+
+ foo 1.0.0
9+
Changed 1 dependency!
10+
Publishing myapp 0.0.0 to http://localhost:$PORT:
11+
├── bin
12+
│ └── main.dart (<1 KB)
13+
└── pubspec.yaml (<1 KB)
14+
15+
Total compressed archive size: <1 KB.
16+
Validating package...
17+
Package validation found the following 4 errors:
18+
* You must have a LICENSE file in the root directory.
19+
An open-source license helps ensure people can legally use your code.
20+
21+
* Your pubspec.yaml is missing a "description" field.
22+
23+
* Your pubspec.yaml is missing a "version" field.
24+
25+
* line 1, column 1 of bin/main.dart: foo is in the `dev_dependencies` section of `pubspec.yaml`. Packages used in bin/ must be declared in the `dependencies` section.
26+
27+
1 │ import 'package:foo/foo.dart';
28+
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
29+
30+
31+
Package validation found the following 5 potential issues:
32+
* `dart analyze` found the following issue(s):
33+
Analyzing bin, pubspec.yaml...
34+
35+
warning - bin/main.dart:1:8 - Unused import: 'package:foo/foo.dart'. Try removing the import directive. - unused_import
36+
37+
1 issue found.
38+
39+
40+
* It's strongly recommended to include a "homepage" or "repository" field in your pubspec.yaml
41+
42+
* Your dependency on "bar" should have a version constraint. For example:
43+
44+
dependencies:
45+
bar: ^1.0.0
46+
47+
Without a constraint, you're promising to support all future versions of "bar".
48+
49+
* Please add a README.md file that describes your package.
50+
51+
* Please add a `CHANGELOG.md` to your package. See https://dart.dev/tools/pub/publishing#important-files.
52+
53+
Package validation found the following hint:
54+
* Non-dev dependencies are overridden in pubspec.yaml.
55+
56+
This indicates you are not testing your package against the same versions of its
57+
dependencies that users will have when they use it.
58+
59+
This might be necessary for packages with cyclic dependencies.
60+
61+
Please be extra careful when publishing.
62+
[STDERR] Sorry, your package is missing some requirements and can't be published yet.
63+
[STDERR] For more information, see: https://dart.dev/tools/pub/cmd/pub-lish.
64+
[EXIT CODE] 65
65+

test/validator/analyze_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ analyzer:
8080
]).create();
8181

8282
await expectValidation(
83-
error: allOf([
83+
message: allOf([
8484
contains(
8585
"The 'http' protocol shouldn't be used because it isn't secure. "
8686
"Try using a secure protocol, such as 'https'.",
@@ -132,7 +132,7 @@ void main() {
132132
]).create();
133133

134134
await expectValidation(
135-
error: allOf([
135+
message: allOf([
136136
contains('`dart analyze` found the following issue(s):'),
137137
contains('Analyzing bin, lib, build.dart, link.dart, pubspec.yaml...'),
138138
contains('error -'),

0 commit comments

Comments
 (0)