blob: 9564ab727759b1546fcb3a6a63c46cd36b2c4b6d [file] [log] [blame]
// Copyright (c) 2017, 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 'package:analyzer/error/listener.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:analyzer/src/pubspec/pubspec_validator.dart';
import 'package:analyzer/src/pubspec/pubspec_warning_code.dart';
import 'package:yaml/yaml.dart';
class NameValidator extends BasePubspecValidator {
NameValidator(ResourceProvider provider, Source source)
: super(provider, source);
/// Validate the value of the required `name` field.
void validate(ErrorReporter reporter, Map<dynamic, YamlNode> contents) {
var nameField = contents[PubspecField.NAME_FIELD];
if (nameField == null) {
reporter.reportErrorForOffset(PubspecWarningCode.MISSING_NAME, 0, 0);
} else if (nameField is! YamlScalar || nameField.value is! String) {
reportErrorForNode(
reporter, nameField, PubspecWarningCode.NAME_NOT_STRING);
}
}
}