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>
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 0305cbb..b360ea9 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,9 +40,6 @@
   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 3620fe8..4fae1c0 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,10 +62,7 @@
 //    if (errorCode == AnalysisOptionsErrorCode.INCLUDED_FILE_PARSE_ERROR) {
 //    } else if (errorCode == AnalysisOptionsErrorCode.PARSE_ERROR) {
 //    } else
-    if (errorCode ==
-        AnalysisOptionsHintCode.PREVIEW_DART_2_SETTING_DEPRECATED) {
-      await _addFix_removeSetting(coveringNodePath);
-    } else if (errorCode == DEPRECATED_LINT_HINT) {
+    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 13450a2..f7b02e5 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,20 +14,6 @@
 
 @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 56ca27b..b0f7634 100644
--- a/pkg/analyzer/lib/src/analysis_options/error/option_codes.dart
+++ b/pkg/analyzer/lib/src/analysis_options/error/option_codes.dart
@@ -2,4 +2,28 @@
 // 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 46e25fa..fba9d58 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,37 +58,6 @@
   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 87ec09f..76d527c 100644
--- a/pkg/analyzer/lib/src/error/error_code_values.g.dart
+++ b/pkg/analyzer/lib/src/error/error_code_values.g.dart
@@ -22,7 +22,6 @@
 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 2827708..5e5e85a 100644
--- a/pkg/analyzer/lib/src/lint/analysis.dart
+++ b/pkg/analyzer/lib/src/lint/analysis.dart
@@ -82,13 +82,6 @@
   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 0e080f1..8a65019 100644
--- a/pkg/analyzer/lib/src/task/options.dart
+++ b/pkg/analyzer/lib/src/task/options.dart
@@ -118,7 +118,6 @@
 /// `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';
@@ -490,11 +489,7 @@
           bool validKey = false;
           if (k is YamlScalar) {
             key = k.value?.toString();
-            if (AnalyzerOptions.enablePreviewDart2 == key) {
-              reporter.reportErrorForSpan(
-                  AnalysisOptionsHintCode.PREVIEW_DART_2_SETTING_DEPRECATED,
-                  k.span);
-            } else if (!AnalyzerOptions.languageOptions.contains(key)) {
+            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 1fe45cc..93e9cfe 100644
--- a/pkg/analyzer/messages.yaml
+++ b/pkg/analyzer/messages.yaml
@@ -53,13 +53,6 @@
 
       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 f0bb4f5..e60d203 100644
--- a/pkg/analyzer/tool/messages/error_code_info.dart
+++ b/pkg/analyzer/tool/messages/error_code_info.dart
@@ -20,11 +20,6 @@
       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'),