021b6438c5
Pub is still all kinds of broken with this, but it's slightly less broken. Some tests pass, and at least the code *parses* after this. Review URL: https://codereview.chromium.org//11785028 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@16763 260f80e4-7a28-3924-810f-c04153c831b5
62 lines
2.0 KiB
Dart
62 lines
2.0 KiB
Dart
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
library pubspec_field_validator;
|
|
|
|
import 'dart:async';
|
|
|
|
import '../entrypoint.dart';
|
|
import '../system_cache.dart';
|
|
import '../validator.dart';
|
|
import '../version.dart';
|
|
|
|
/// A validator that checks that the pubspec has valid "author" and "homepage"
|
|
/// fields.
|
|
class PubspecFieldValidator extends Validator {
|
|
PubspecFieldValidator(Entrypoint entrypoint)
|
|
: super(entrypoint);
|
|
|
|
Future validate() {
|
|
// The types of all fields are validated when the pubspec is parsed.
|
|
var pubspec = entrypoint.root.pubspec;
|
|
var author = pubspec.fields['author'];
|
|
var authors = pubspec.fields['authors'];
|
|
if (author == null && authors == null) {
|
|
errors.add('Your pubspec.yaml must have an "author" or "authors" field.');
|
|
} else {
|
|
if (authors == null) authors = [author];
|
|
|
|
var hasName = new RegExp(r"^ *[^< ]");
|
|
var hasEmail = new RegExp(r"<[^>]+> *$");
|
|
for (var authorName in authors) {
|
|
if (!hasName.hasMatch(authorName)) {
|
|
warnings.add('Author "$authorName" in pubspec.yaml should have a '
|
|
'name.');
|
|
}
|
|
if (!hasEmail.hasMatch(authorName)) {
|
|
warnings.add('Author "$authorName" in pubspec.yaml should have an '
|
|
'email address\n(e.g. "name <email>").');
|
|
}
|
|
}
|
|
}
|
|
|
|
var homepage = pubspec.fields['homepage'];
|
|
if (homepage == null) {
|
|
errors.add('Your pubspec.yaml is missing a "homepage" field.');
|
|
}
|
|
|
|
var description = pubspec.fields['description'];
|
|
if (description == null) {
|
|
errors.add('Your pubspec.yaml is missing a "description" field.');
|
|
}
|
|
|
|
var version = pubspec.fields['version'];
|
|
if (version == null) {
|
|
errors.add('Your pubspec.yaml is missing a "version" field.');
|
|
}
|
|
|
|
return new Future.immediate(null);
|
|
}
|
|
}
|