Skip to content

Commit

Permalink
Hint about sdk constraint update for workspace and resolution (#4384)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigurdm authored Oct 3, 2024
1 parent 7113e53 commit bcafc16
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
16 changes: 14 additions & 2 deletions lib/src/pubspec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 <String>[];
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -720,8 +732,8 @@ T _wrapFormatException<T>(
}

/// 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 {
Expand Down
26 changes: 25 additions & 1 deletion test/pubspec_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ void main() {
String contents,
void Function(Pubspec) fn, {
String? expectedContains,
String? hintContains,
Description? containingDescription,
}) {
var expectation = const TypeMatcher<SourceSpanApplicationException>();
Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -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}'
''',
);
});

Expand Down

0 comments on commit bcafc16

Please sign in to comment.