Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(301)

Side by Side Diff: lib/src/validator/dependency.dart

Issue 2184303002: Make pub strong-mode clean. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Code review changes Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/validator.dart ('k') | lib/src/validator/sdk_constraint.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:async'; 5 import 'dart:async';
6 6
7 import 'package:pub_semver/pub_semver.dart'; 7 import 'package:pub_semver/pub_semver.dart';
8 8
9 import '../entrypoint.dart'; 9 import '../entrypoint.dart';
10 import '../log.dart' as log; 10 import '../log.dart' as log;
(...skipping 18 matching lines...) Expand all
29 class DependencyValidator extends Validator { 29 class DependencyValidator extends Validator {
30 /// Whether the SDK constraint guarantees that `^` version constraints are 30 /// Whether the SDK constraint guarantees that `^` version constraints are
31 /// safe. 31 /// safe.
32 bool get _caretAllowed => entrypoint.root.pubspec.dartSdkConstraint 32 bool get _caretAllowed => entrypoint.root.pubspec.dartSdkConstraint
33 .intersect(_preCaretPubVersions).isEmpty; 33 .intersect(_preCaretPubVersions).isEmpty;
34 34
35 DependencyValidator(Entrypoint entrypoint) 35 DependencyValidator(Entrypoint entrypoint)
36 : super(entrypoint); 36 : super(entrypoint);
37 37
38 Future validate() async { 38 Future validate() async {
39 var caretDeps = []; 39 var caretDeps = <PackageDep>[];
40 40
41 for (var dependency in entrypoint.root.pubspec.dependencies) { 41 for (var dependency in entrypoint.root.pubspec.dependencies) {
42 var constraint = dependency.constraint;
42 if (dependency.source is! HostedSource) { 43 if (dependency.source is! HostedSource) {
43 await _warnAboutSource(dependency); 44 await _warnAboutSource(dependency);
44 } else if (dependency.constraint.isAny) { 45 } else if (constraint.isAny) {
45 _warnAboutNoConstraint(dependency); 46 _warnAboutNoConstraint(dependency);
46 } else if (dependency.constraint is Version) { 47 } else if (constraint is Version) {
47 _warnAboutSingleVersionConstraint(dependency); 48 _warnAboutSingleVersionConstraint(dependency);
48 } else if (dependency.constraint is VersionRange) { 49 } else if (constraint is VersionRange) {
49 if (dependency.constraint.min == null) { 50 if (constraint.min == null) {
50 _warnAboutNoConstraintLowerBound(dependency); 51 _warnAboutNoConstraintLowerBound(dependency);
51 } else if (dependency.constraint.max == null) { 52 } else if (constraint.max == null) {
52 _warnAboutNoConstraintUpperBound(dependency); 53 _warnAboutNoConstraintUpperBound(dependency);
53 } 54 }
54 55
55 if (dependency.constraint.toString().startsWith("^")) { 56 if (constraint.toString().startsWith("^")) {
56 caretDeps.add(dependency); 57 caretDeps.add(dependency);
57 } 58 }
58 } 59 }
59 } 60 }
60 61
61 if (caretDeps.isNotEmpty && !_caretAllowed) { 62 if (caretDeps.isNotEmpty && !_caretAllowed) {
62 _errorAboutCaretConstraints(caretDeps); 63 _errorAboutCaretConstraints(caretDeps);
63 } 64 }
64 } 65 }
65 66
66 /// Warn that dependencies should use the hosted source. 67 /// Warn that dependencies should use the hosted source.
67 Future _warnAboutSource(PackageDep dep) async { 68 Future _warnAboutSource(PackageDep dep) async {
68 var versions; 69 List<Version> versions;
69 try { 70 try {
70 var ids = await entrypoint.cache.hosted 71 var ids = await entrypoint.cache.hosted
71 .getVersions(entrypoint.cache.sources.hosted.refFor(dep.name)); 72 .getVersions(entrypoint.cache.sources.hosted.refFor(dep.name));
72 versions = ids.map((id) => id.version).toList(); 73 versions = ids.map((id) => id.version).toList();
73 } catch (error) { 74 } catch (error) {
74 versions = []; 75 versions = [];
75 } 76 }
76 77
77 var constraint; 78 var constraint;
78 var primary = Version.primary(versions); 79 var primary = Version.primary(versions);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 errors.add(buffer.toString().trim()); 206 errors.add(buffer.toString().trim());
206 } 207 }
207 208
208 /// Returns the suggested version constraint for a dependency that was tested 209 /// Returns the suggested version constraint for a dependency that was tested
209 /// against [version]. 210 /// against [version].
210 String _constraintForVersion(Version version) { 211 String _constraintForVersion(Version version) {
211 if (_caretAllowed) return "^$version"; 212 if (_caretAllowed) return "^$version";
212 return '">=$version <${version.nextBreaking}"'; 213 return '">=$version <${version.nextBreaking}"';
213 } 214 }
214 } 215 }
OLDNEW
« no previous file with comments | « lib/src/validator.dart ('k') | lib/src/validator/sdk_constraint.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698