[flutter_plugin_tools] Improve 'repository' check (#4244)

Ensures that the full relative path in the 'repository' link is correct,
not just the last segment. This ensure that path-level errors (e.g.,
linking to the group directory rather than the package itself for
app-facing packages) are caught.

Also fixes the errors that this improved check catches, including
several cases where a previously unfederated package wasn't fixed when
it was moved to a subdirectory.
This commit is contained in:
stuartmorgan
2021-08-20 11:50:56 -07:00
committed by GitHub
parent 0f6d559f10
commit 5bbc1791cc
3 changed files with 67 additions and 9 deletions

View File

@ -98,7 +98,7 @@ class PubspecCheckCommand extends PackageLoopingCommand {
if (pubspec.publishTo != 'none') {
final List<String> repositoryErrors =
_checkForRepositoryLinkErrors(pubspec, packageName: package.basename);
_checkForRepositoryLinkErrors(pubspec, package: package);
if (repositoryErrors.isNotEmpty) {
for (final String error in repositoryErrors) {
printError('$indentation$error');
@ -154,14 +154,18 @@ class PubspecCheckCommand extends PackageLoopingCommand {
List<String> _checkForRepositoryLinkErrors(
Pubspec pubspec, {
required String packageName,
required Directory package,
}) {
final List<String> errorMessages = <String>[];
if (pubspec.repository == null) {
errorMessages.add('Missing "repository"');
} else if (!pubspec.repository!.path.endsWith(packageName)) {
errorMessages
.add('The "repository" link should end with the package name.');
} else {
final String relativePackagePath =
path.relative(package.path, from: packagesDir.parent.path);
if (!pubspec.repository!.path.endsWith(relativePackagePath)) {
errorMessages
.add('The "repository" link should end with the package path.');
}
}
if (pubspec.homepage != null) {