Revert "Remove preview-dart-2 option in analysis options"
This reverts commit f30e5de558da46d582f32c4058d972b251070bec.
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 https://github.com/dart-lang/sdk/issues/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 <brianwilkerson@google.com>
> Commit-Queue: Samuel Rawlins <srawlins@google.com>
> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
# 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 <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
diff --git a/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml b/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml
index a51282c..b98d952 100644
--- a/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml
+++ b/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml
@@ -40,6 +40,9 @@
notes: |-
Because of the way the YAML parser works, there isn't enough information to
be able to provide a fix.
+AnalysisOptionsHintCode.PREVIEW_DART_2_SETTING_DEPRECATED:
+ status: needsFix
+ notes: Fixed.
AnalysisOptionsWarningCode.INCLUDE_FILE_NOT_FOUND:
status: noFix
notes: |-
diff --git a/pkg/analysis_server/lib/src/services/correction/fix/analysis_options/fix_generator.dart b/pkg/analysis_server/lib/src/services/correction/fix/analysis_options/fix_generator.dart
index 4fae1c0..3620fe8 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix/analysis_options/fix_generator.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix/analysis_options/fix_generator.dart
@@ -62,7 +62,10 @@
// if (errorCode == AnalysisOptionsErrorCode.INCLUDED_FILE_PARSE_ERROR) {
// } else if (errorCode == AnalysisOptionsErrorCode.PARSE_ERROR) {
// } else
- if (errorCode == DEPRECATED_LINT_HINT) {
+ if (errorCode ==
+ AnalysisOptionsHintCode.PREVIEW_DART_2_SETTING_DEPRECATED) {
+ await _addFix_removeSetting(coveringNodePath);
+ } else if (errorCode == DEPRECATED_LINT_HINT) {
await _addFix_removeLint(coveringNodePath);
// } else if (errorCode == AnalysisOptionsWarningCode.INCLUDED_FILE_WARNING) {
// } else if (errorCode == AnalysisOptionsWarningCode.INCLUDE_FILE_NOT_FOUND) {
diff --git a/pkg/analysis_server/test/src/services/correction/fix/analysis_options/remove_setting_test.dart b/pkg/analysis_server/test/src/services/correction/fix/analysis_options/remove_setting_test.dart
index f7b02e5..13450a2 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/analysis_options/remove_setting_test.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/analysis_options/remove_setting_test.dart
@@ -14,6 +14,20 @@
@reflectiveTest
class RemoveSettingTest extends AnalysisOptionsFixTest {
+ Future<void> test_enablePreviewDart2() async {
+ await assertHasFix('''
+analyzer:
+ enable-experiment:
+ - test-experiment
+ language:
+ enablePreviewDart2: true
+''', '''
+analyzer:
+ enable-experiment:
+ - test-experiment
+''');
+ }
+
Future<void> test_invalidExperiment_first() async {
await assertHasFix('''
analyzer:
diff --git a/pkg/analyzer/lib/src/analysis_options/error/option_codes.dart b/pkg/analyzer/lib/src/analysis_options/error/option_codes.dart
index b0f7634..56ca27b 100644
--- a/pkg/analyzer/lib/src/analysis_options/error/option_codes.dart
+++ b/pkg/analyzer/lib/src/analysis_options/error/option_codes.dart
@@ -2,28 +2,4 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-import 'package:analyzer/error/error.dart';
-
export 'package:analyzer/src/analysis_options/error/option_codes.g.dart';
-
-class AnalysisOptionsHintCode extends ErrorCode {
- /// Initialize a newly created error code to have the given [name].
- const AnalysisOptionsHintCode(
- String name,
- String problemMessage, {
- super.correctionMessage,
- super.hasPublishedDocs = false,
- super.isUnresolvedIdentifier = false,
- String? uniqueName,
- }) : super(
- name: name,
- problemMessage: problemMessage,
- uniqueName: 'AnalysisOptionsHintCode.${uniqueName ?? name}',
- );
-
- @override
- ErrorSeverity get errorSeverity => ErrorSeverity.INFO;
-
- @override
- ErrorType get type => ErrorType.HINT;
-}
diff --git a/pkg/analyzer/lib/src/analysis_options/error/option_codes.g.dart b/pkg/analyzer/lib/src/analysis_options/error/option_codes.g.dart
index fba9d58..46e25fa 100644
--- a/pkg/analyzer/lib/src/analysis_options/error/option_codes.g.dart
+++ b/pkg/analyzer/lib/src/analysis_options/error/option_codes.g.dart
@@ -58,6 +58,37 @@
ErrorType get type => ErrorType.COMPILE_TIME_ERROR;
}
+class AnalysisOptionsHintCode extends ErrorCode {
+ /// An error code indicating that the enablePreviewDart2 setting is
+ /// deprecated.
+ static const AnalysisOptionsHintCode PREVIEW_DART_2_SETTING_DEPRECATED =
+ AnalysisOptionsHintCode(
+ 'PREVIEW_DART_2_SETTING_DEPRECATED',
+ "The 'enablePreviewDart2' setting is deprecated.",
+ correctionMessage: "It is no longer necessary to explicitly enable Dart 2.",
+ );
+
+ /// Initialize a newly created error code to have the given [name].
+ const AnalysisOptionsHintCode(
+ String name,
+ String problemMessage, {
+ super.correctionMessage,
+ super.hasPublishedDocs = false,
+ super.isUnresolvedIdentifier = false,
+ String? uniqueName,
+ }) : super(
+ name: name,
+ problemMessage: problemMessage,
+ uniqueName: 'AnalysisOptionsHintCode.${uniqueName ?? name}',
+ );
+
+ @override
+ ErrorSeverity get errorSeverity => ErrorSeverity.INFO;
+
+ @override
+ ErrorType get type => ErrorType.HINT;
+}
+
class AnalysisOptionsWarningCode extends ErrorCode {
/// An error code indicating a specified include file has a warning.
///
diff --git a/pkg/analyzer/lib/src/error/error_code_values.g.dart b/pkg/analyzer/lib/src/error/error_code_values.g.dart
index 76d527c..87ec09f 100644
--- a/pkg/analyzer/lib/src/error/error_code_values.g.dart
+++ b/pkg/analyzer/lib/src/error/error_code_values.g.dart
@@ -22,6 +22,7 @@
const List<ErrorCode> errorCodeValues = [
AnalysisOptionsErrorCode.INCLUDED_FILE_PARSE_ERROR,
AnalysisOptionsErrorCode.PARSE_ERROR,
+ AnalysisOptionsHintCode.PREVIEW_DART_2_SETTING_DEPRECATED,
AnalysisOptionsWarningCode.INCLUDED_FILE_WARNING,
AnalysisOptionsWarningCode.INCLUDE_FILE_NOT_FOUND,
AnalysisOptionsWarningCode.INVALID_OPTION,
diff --git a/pkg/analyzer/lib/src/lint/analysis.dart b/pkg/analyzer/lib/src/lint/analysis.dart
index 5e5e85a..2827708 100644
--- a/pkg/analyzer/lib/src/lint/analysis.dart
+++ b/pkg/analyzer/lib/src/lint/analysis.dart
@@ -82,6 +82,13 @@
set enableAssertInitializer(bool enable) {
// Ignored because the option is now always enabled.
}
+
+ /// Whether to use Dart 2.0 features.
+ @deprecated
+ bool get previewDart2 => true;
+
+ @deprecated
+ set previewDart2(bool value) {}
}
class LintDriver {
diff --git a/pkg/analyzer/lib/src/task/options.dart b/pkg/analyzer/lib/src/task/options.dart
index 8a65019..0e080f1 100644
--- a/pkg/analyzer/lib/src/task/options.dart
+++ b/pkg/analyzer/lib/src/task/options.dart
@@ -118,6 +118,7 @@
/// `analyzer` analysis options constants.
class AnalyzerOptions {
static const String analyzer = 'analyzer';
+ static const String enablePreviewDart2 = 'enablePreviewDart2';
static const String cannotIgnore = 'cannot-ignore';
static const String codeStyle = 'code-style';
@@ -489,7 +490,11 @@
bool validKey = false;
if (k is YamlScalar) {
key = k.value?.toString();
- if (!AnalyzerOptions.languageOptions.contains(key)) {
+ if (AnalyzerOptions.enablePreviewDart2 == key) {
+ reporter.reportErrorForSpan(
+ AnalysisOptionsHintCode.PREVIEW_DART_2_SETTING_DEPRECATED,
+ k.span);
+ } else if (!AnalyzerOptions.languageOptions.contains(key)) {
_builder.reportError(reporter, AnalyzerOptions.language, k);
} else {
// If we have a valid key, go on and check the value.
diff --git a/pkg/analyzer/messages.yaml b/pkg/analyzer/messages.yaml
index 93e9cfe..1fe45cc 100644
--- a/pkg/analyzer/messages.yaml
+++ b/pkg/analyzer/messages.yaml
@@ -53,6 +53,13 @@
Parameters:
0: the error message from the parse error
+AnalysisOptionsHintCode:
+ PREVIEW_DART_2_SETTING_DEPRECATED:
+ problemMessage: "The 'enablePreviewDart2' setting is deprecated."
+ correctionMessage: It is no longer necessary to explicitly enable Dart 2.
+ comment: |-
+ An error code indicating that the enablePreviewDart2 setting is
+ deprecated.
AnalysisOptionsWarningCode:
INCLUDED_FILE_WARNING:
problemMessage: "Warning in the included options file {0}({1}..{2}): {3}"
diff --git a/pkg/analyzer/tool/messages/error_code_info.dart b/pkg/analyzer/tool/messages/error_code_info.dart
index e60d203..f0bb4f5 100644
--- a/pkg/analyzer/tool/messages/error_code_info.dart
+++ b/pkg/analyzer/tool/messages/error_code_info.dart
@@ -20,6 +20,11 @@
severity: 'ERROR'),
ErrorClassInfo(
filePath: 'lib/src/analysis_options/error/option_codes.g.dart',
+ name: 'AnalysisOptionsHintCode',
+ type: 'HINT',
+ severity: 'INFO'),
+ ErrorClassInfo(
+ filePath: 'lib/src/analysis_options/error/option_codes.g.dart',
name: 'AnalysisOptionsWarningCode',
type: 'STATIC_WARNING',
severity: 'WARNING'),