diff --git a/lib/src/validator/dependency.dart b/lib/src/validator/dependency.dart index 66d2ae22f53cddb804d42096f8d7c2cb46674fc3..46cde9acc690c2094cd8286bf2dd5fc8833a8a33 100644 --- a/lib/src/validator/dependency.dart +++ b/lib/src/validator/dependency.dart @@ -23,6 +23,14 @@ class DependencyValidator extends Validator { return _warnAboutSource(dependency); } + if (dependency.name == entrypoint.root.name) { + warnings.add('You don\'t need to explicitly depend on your own ' + 'package.\n' + 'Pub enables "package:${entrypoint.root.name}" imports ' + 'implicitly.'); + return new Future.immediate(null); + } + if (dependency.constraint.isAny && // TODO(nweiz): once we have development dependencies (issue 5358), we // should warn about unittest. Until then, it's reasonable not to put diff --git a/test/validator_test.dart b/test/validator_test.dart index 6f5764a95a4beabf134f6f640d83c019a743f784..1c064bed10dc132682bed064e5de13170051c0e4 100644 --- a/test/validator_test.dart +++ b/test/validator_test.dart @@ -531,5 +531,17 @@ main() { }); }); }); + + test('has a hosted dependency on itself', () { + dir(appPath, [ + libPubspec("test_pkg", "1.0.0", [ + {'hosted': {'name': 'test_pkg', 'version': '>=1.0.0'}} + ]) + ]).scheduleCreate(); + + expectValidationWarning(dependency); + + run(); + }); }); }