blob: 614eba2ddd604d36620340ea0e0562cfe3db0e75 [file] [log] [blame]
// Copyright (c) 2018, 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.
import 'dart:async';
import 'dart:convert';
import 'package:path/path.dart' as p;
import '../entrypoint.dart';
import '../io.dart';
import '../validator.dart';
/// A validator that validates a package's changelog file.
class ChangelogValidator extends Validator {
ChangelogValidator(Entrypoint entrypoint) : super(entrypoint);
Future validate() {
return Future.sync(() {
final changelog = entrypoint.root.changelogPath;
if (changelog == null) {
warnings.add('Please add a `` to your package. '
if (p.basename(changelog) != '') {
warnings.add('Please consider renaming $changelog to ``. '
var bytes = readBinaryFile(changelog);
String contents;
try {
// utf8.decode doesn't allow invalid UTF-8.
contents = utf8.decode(bytes);
} on FormatException catch (_) {
warnings.add('$changelog contains invalid UTF-8.\n'
'This will cause it to be displayed incorrectly on '
'the Pub site (');
// Failed to decode contents, so there's nothing else to check.
final version = entrypoint.root.pubspec.version.toString();
if (!contents.contains(version)) {
warnings.add("$changelog doesn't mention current version ($version).\n"
'Consider updating it with notes on this version prior to '