[flutter_plugin_tools] Validate pubspec description (#4396)

pub.dev deducts points for having a pubspec.yaml `description` that is too short or too long; several of our plugins are losing points on this. To ensure that we are following—and modeling—best practices, this adds a check that our `description` fields meet pub.dev expectations.

Fixes our existing violations. Two are not published even though this only takes effect once published:
- camera: We change this plugin pretty frequently, so this should go out soon without adding a release just for this trivial issue.
- wifi_info_flutter: This is deprecated, so we don't plan to release it. It has to be fixed to allow the tool change to land though.
This commit is contained in:
stuartmorgan
2021-09-30 13:30:26 -04:00
committed by GitHub
parent 769043d35a
commit a731d6e131
5 changed files with 172 additions and 0 deletions

View File

@ -126,6 +126,18 @@ class PubspecCheckCommand extends PackageLoopingCommand {
'${indentation * 2}$_expectedIssueLinkFormat<package label>');
passing = false;
}
// Don't check descriptions for federated package components other than
// the app-facing package, since they are unlisted, and are expected to
// have short descriptions.
if (!package.isPlatformInterface && !package.isPlatformImplementation) {
final String? descriptionError =
_checkDescription(pubspec, package: package);
if (descriptionError != null) {
printError('$indentation$descriptionError');
passing = false;
}
}
}
return passing;
@ -180,6 +192,27 @@ class PubspecCheckCommand extends PackageLoopingCommand {
return errorMessages;
}
// Validates the "description" field for a package, returning an error
// string if there are any issues.
String? _checkDescription(
Pubspec pubspec, {
required RepositoryPackage package,
}) {
final String? description = pubspec.description;
if (description == null) {
return 'Missing "description"';
}
if (description.length < 60) {
return '"description" is too short. pub.dev recommends package '
'descriptions of 60-180 characters.';
}
if (description.length > 180) {
return '"description" is too long. pub.dev recommends package '
'descriptions of 60-180 characters.';
}
}
bool _checkIssueLink(Pubspec pubspec) {
return pubspec.issueTracker
?.toString()