Skip to content

Commit 6d05f24

Browse files
srawlinsCommit Queue
authored and
Commit Queue
committed
Revert "Remove preview-dart-2 option in analysis options"
This reverts commit f30e5de. Reason for revert: https://dart-review.googlesource.com/c/sdk/+/274921 broke customer test, and this CL sits right on top of it. Original change's description: > Remove preview-dart-2 option in analysis options > > Fixes #50680 > > AnalysisOptionsHintCode is moved from generated `option_codes.g.dart` to `option_codes.dart`, for non-generated diagnostics: > > * AnalysisOptionsHintCode.DEPRECATED_LINT_HINT and > * AnalysisOptionsHintCode.DUPLICATE_RULE_HINT > > Change-Id: I131fb2901fca26ff971b6c9c519ab2f0b983a65c > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/275500 > Reviewed-by: Brian Wilkerson <[email protected]> > Commit-Queue: Samuel Rawlins <[email protected]> > Reviewed-by: Konstantin Shcheglov <[email protected]> # Not skipping CQ checks because original CL landed > 1 day ago. Change-Id: Ia417aa5edc5b279a5fced43154de4cd5c9d3be2c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/276023 Reviewed-by: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Siva Annamalai <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent ea1473e commit 6d05f24

File tree

10 files changed

+78
-26
lines changed

10 files changed

+78
-26
lines changed

pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ AnalysisOptionsErrorCode.PARSE_ERROR:
4040
notes: |-
4141
Because of the way the YAML parser works, there isn't enough information to
4242
be able to provide a fix.
43+
AnalysisOptionsHintCode.PREVIEW_DART_2_SETTING_DEPRECATED:
44+
status: needsFix
45+
notes: Fixed.
4346
AnalysisOptionsWarningCode.INCLUDE_FILE_NOT_FOUND:
4447
status: noFix
4548
notes: |-

pkg/analysis_server/lib/src/services/correction/fix/analysis_options/fix_generator.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ class AnalysisOptionsFixGenerator {
6262
// if (errorCode == AnalysisOptionsErrorCode.INCLUDED_FILE_PARSE_ERROR) {
6363
// } else if (errorCode == AnalysisOptionsErrorCode.PARSE_ERROR) {
6464
// } else
65-
if (errorCode == DEPRECATED_LINT_HINT) {
65+
if (errorCode ==
66+
AnalysisOptionsHintCode.PREVIEW_DART_2_SETTING_DEPRECATED) {
67+
await _addFix_removeSetting(coveringNodePath);
68+
} else if (errorCode == DEPRECATED_LINT_HINT) {
6669
await _addFix_removeLint(coveringNodePath);
6770
// } else if (errorCode == AnalysisOptionsWarningCode.INCLUDED_FILE_WARNING) {
6871
// } else if (errorCode == AnalysisOptionsWarningCode.INCLUDE_FILE_NOT_FOUND) {

pkg/analysis_server/test/src/services/correction/fix/analysis_options/remove_setting_test.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ void main() {
1414

1515
@reflectiveTest
1616
class RemoveSettingTest extends AnalysisOptionsFixTest {
17+
Future<void> test_enablePreviewDart2() async {
18+
await assertHasFix('''
19+
analyzer:
20+
enable-experiment:
21+
- test-experiment
22+
language:
23+
enablePreviewDart2: true
24+
''', '''
25+
analyzer:
26+
enable-experiment:
27+
- test-experiment
28+
''');
29+
}
30+
1731
Future<void> test_invalidExperiment_first() async {
1832
await assertHasFix('''
1933
analyzer:

pkg/analyzer/lib/src/analysis_options/error/option_codes.dart

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,4 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'package:analyzer/error/error.dart';
6-
75
export 'package:analyzer/src/analysis_options/error/option_codes.g.dart';
8-
9-
class AnalysisOptionsHintCode extends ErrorCode {
10-
/// Initialize a newly created error code to have the given [name].
11-
const AnalysisOptionsHintCode(
12-
String name,
13-
String problemMessage, {
14-
super.correctionMessage,
15-
super.hasPublishedDocs = false,
16-
super.isUnresolvedIdentifier = false,
17-
String? uniqueName,
18-
}) : super(
19-
name: name,
20-
problemMessage: problemMessage,
21-
uniqueName: 'AnalysisOptionsHintCode.${uniqueName ?? name}',
22-
);
23-
24-
@override
25-
ErrorSeverity get errorSeverity => ErrorSeverity.INFO;
26-
27-
@override
28-
ErrorType get type => ErrorType.HINT;
29-
}

pkg/analyzer/lib/src/analysis_options/error/option_codes.g.dart

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,37 @@ class AnalysisOptionsErrorCode extends ErrorCode {
5858
ErrorType get type => ErrorType.COMPILE_TIME_ERROR;
5959
}
6060

61+
class AnalysisOptionsHintCode extends ErrorCode {
62+
/// An error code indicating that the enablePreviewDart2 setting is
63+
/// deprecated.
64+
static const AnalysisOptionsHintCode PREVIEW_DART_2_SETTING_DEPRECATED =
65+
AnalysisOptionsHintCode(
66+
'PREVIEW_DART_2_SETTING_DEPRECATED',
67+
"The 'enablePreviewDart2' setting is deprecated.",
68+
correctionMessage: "It is no longer necessary to explicitly enable Dart 2.",
69+
);
70+
71+
/// Initialize a newly created error code to have the given [name].
72+
const AnalysisOptionsHintCode(
73+
String name,
74+
String problemMessage, {
75+
super.correctionMessage,
76+
super.hasPublishedDocs = false,
77+
super.isUnresolvedIdentifier = false,
78+
String? uniqueName,
79+
}) : super(
80+
name: name,
81+
problemMessage: problemMessage,
82+
uniqueName: 'AnalysisOptionsHintCode.${uniqueName ?? name}',
83+
);
84+
85+
@override
86+
ErrorSeverity get errorSeverity => ErrorSeverity.INFO;
87+
88+
@override
89+
ErrorType get type => ErrorType.HINT;
90+
}
91+
6192
class AnalysisOptionsWarningCode extends ErrorCode {
6293
/// An error code indicating a specified include file has a warning.
6394
///

pkg/analyzer/lib/src/error/error_code_values.g.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import 'package:analyzer/src/pubspec/pubspec_warning_code.dart';
2222
const List<ErrorCode> errorCodeValues = [
2323
AnalysisOptionsErrorCode.INCLUDED_FILE_PARSE_ERROR,
2424
AnalysisOptionsErrorCode.PARSE_ERROR,
25+
AnalysisOptionsHintCode.PREVIEW_DART_2_SETTING_DEPRECATED,
2526
AnalysisOptionsWarningCode.INCLUDED_FILE_WARNING,
2627
AnalysisOptionsWarningCode.INCLUDE_FILE_NOT_FOUND,
2728
AnalysisOptionsWarningCode.INVALID_OPTION,

pkg/analyzer/lib/src/lint/analysis.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ class DriverOptions {
8282
set enableAssertInitializer(bool enable) {
8383
// Ignored because the option is now always enabled.
8484
}
85+
86+
/// Whether to use Dart 2.0 features.
87+
@deprecated
88+
bool get previewDart2 => true;
89+
90+
@deprecated
91+
set previewDart2(bool value) {}
8592
}
8693

8794
class LintDriver {

pkg/analyzer/lib/src/task/options.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ void applyToAnalysisOptions(AnalysisOptionsImpl options, YamlMap optionMap) {
118118
/// `analyzer` analysis options constants.
119119
class AnalyzerOptions {
120120
static const String analyzer = 'analyzer';
121+
static const String enablePreviewDart2 = 'enablePreviewDart2';
121122

122123
static const String cannotIgnore = 'cannot-ignore';
123124
static const String codeStyle = 'code-style';
@@ -489,7 +490,11 @@ class LanguageOptionValidator extends OptionsValidator {
489490
bool validKey = false;
490491
if (k is YamlScalar) {
491492
key = k.value?.toString();
492-
if (!AnalyzerOptions.languageOptions.contains(key)) {
493+
if (AnalyzerOptions.enablePreviewDart2 == key) {
494+
reporter.reportErrorForSpan(
495+
AnalysisOptionsHintCode.PREVIEW_DART_2_SETTING_DEPRECATED,
496+
k.span);
497+
} else if (!AnalyzerOptions.languageOptions.contains(key)) {
493498
_builder.reportError(reporter, AnalyzerOptions.language, k);
494499
} else {
495500
// If we have a valid key, go on and check the value.

pkg/analyzer/messages.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ AnalysisOptionsErrorCode:
5353

5454
Parameters:
5555
0: the error message from the parse error
56+
AnalysisOptionsHintCode:
57+
PREVIEW_DART_2_SETTING_DEPRECATED:
58+
problemMessage: "The 'enablePreviewDart2' setting is deprecated."
59+
correctionMessage: It is no longer necessary to explicitly enable Dart 2.
60+
comment: |-
61+
An error code indicating that the enablePreviewDart2 setting is
62+
deprecated.
5663
AnalysisOptionsWarningCode:
5764
INCLUDED_FILE_WARNING:
5865
problemMessage: "Warning in the included options file {0}({1}..{2}): {3}"

pkg/analyzer/tool/messages/error_code_info.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ const List<ErrorClassInfo> errorClasses = [
1818
name: 'AnalysisOptionsErrorCode',
1919
type: 'COMPILE_TIME_ERROR',
2020
severity: 'ERROR'),
21+
ErrorClassInfo(
22+
filePath: 'lib/src/analysis_options/error/option_codes.g.dart',
23+
name: 'AnalysisOptionsHintCode',
24+
type: 'HINT',
25+
severity: 'INFO'),
2126
ErrorClassInfo(
2227
filePath: 'lib/src/analysis_options/error/option_codes.g.dart',
2328
name: 'AnalysisOptionsWarningCode',

0 commit comments

Comments
 (0)