From bcafc1677fd44893249a2d2e7049df39e0424cad Mon Sep 17 00:00:00 2001 From: Sigurd Meldgaard Date: Thu, 3 Oct 2024 10:51:32 +0200 Subject: [PATCH] Hint about sdk constraint update for workspace and resolution (#4384) --- lib/src/pubspec.dart | 16 ++++++++++++++-- test/pubspec_test.dart | 26 +++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/lib/src/pubspec.dart b/lib/src/pubspec.dart index fcd9259e1..15427683b 100644 --- a/lib/src/pubspec.dart +++ b/lib/src/pubspec.dart @@ -72,6 +72,12 @@ class Pubspec extends PubspecBase { '`workspace` and `resolution` requires at least language version ' '${LanguageVersion.firstVersionWithWorkspaces}', r.span, + hint: ''' +Consider updating the SDK constraint to: + +environment: + sdk: '^${sdk.version}' +''', ); } if (r == null || r.value == null) return []; @@ -103,6 +109,12 @@ class Pubspec extends PubspecBase { '`workspace` and `resolution` requires at least language version ' '${LanguageVersion.firstVersionWithWorkspaces}', r.span, + hint: ''' +Consider updating the SDK constraint to: + +environment: + sdk: '^${sdk.version}' +''', ); } return switch (r?.value) { @@ -720,8 +732,8 @@ T _wrapFormatException( } /// Throws a [SourceSpanApplicationException] with the given message. -Never _error(String message, SourceSpan? span) { - throw SourceSpanApplicationException(message, span); +Never _error(String message, SourceSpan? span, {String? hint}) { + throw SourceSpanApplicationException(message, span, hint: hint); } enum _FileType { diff --git a/test/pubspec_test.dart b/test/pubspec_test.dart index 5db5bf3a9..8dbff1876 100644 --- a/test/pubspec_test.dart +++ b/test/pubspec_test.dart @@ -24,6 +24,7 @@ void main() { String contents, void Function(Pubspec) fn, { String? expectedContains, + String? hintContains, Description? containingDescription, }) { var expectation = const TypeMatcher(); @@ -34,6 +35,13 @@ void main() { contains(expectedContains), ); } + if (hintContains != null) { + expectation = expectation.having( + (error) => error.hint, + 'hint', + contains(hintContains), + ); + } final pubspec = Pubspec.parse( contents, @@ -384,6 +392,14 @@ environment: workspace: ['a', 'b', 'c'] ''', (p) => p.workspace, + expectedContains: '`workspace` and `resolution` ' + 'requires at least language version 3.5', + hintContains: ''' +Consider updating the SDK constraint to: + +environment: + sdk: '^${Platform.version.split(' ').first}' +''', ); // but no error if you don't look at it. expect( @@ -406,9 +422,17 @@ resolution: workspace ''' environment: sdk: ^1.2.3 -resolution: local +resolution: workspace ''', (p) => p.resolution, + expectedContains: '`workspace` and `resolution` ' + 'requires at least language version 3.5', + hintContains: ''' +Consider updating the SDK constraint to: + +environment: + sdk: '^${Platform.version.split(' ').first}' +''', ); });