[linter] Move some stray LintCode constants to code generation.

Moving these diagnostic constants to code generation will make it
easier to make further improvements to the analyzer diagnostic
representation, because I'll be able to make a single adjustment to
the code generator and then re-generate all the diagnostics.

Change-Id: I6a6a6964228cb6df26798411f16524d15c6f8098
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/445283
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
diff --git a/pkg/linter/lib/src/lint_codes.g.dart b/pkg/linter/lib/src/lint_codes.g.dart
index 1295f7e..6c4fc6d 100644
--- a/pkg/linter/lib/src/lint_codes.g.dart
+++ b/pkg/linter/lib/src/lint_codes.g.dart
@@ -103,6 +103,85 @@
     hasPublishedDocs: true,
   );
 
+  /// Lint issued if a file in the analyzer public API contains a `part`
+  /// directive that points to a file that's not in the analyzer public API.
+  ///
+  /// The rationale for this lint is that if such a `part` directive were to
+  /// exist, it would cause all the members of the part file to become part of
+  /// the analyzer's public API, even though they don't appear to be public API.
+  ///
+  /// Note that the analyzer doesn't make very much use of `part` directives,
+  /// but it may do so in the future once augmentations and enhanced parts are
+  /// supported.
+  ///
+  /// No parameters.
+  static const LintCode analyzerPublicApiBadPartDirective = LinterLintCode(
+    LintNames.analyzer_public_api_bad_part_directive,
+    "Part directives in the analyzer public API should point to files in the "
+    "analyzer public API.",
+  );
+
+  /// Lint issued if a method, function, getter, or setter in the analyzer
+  /// public API makes use of a type that's not part of the analyzer public API,
+  /// or if a non-public type appears in an `extends`, `implements`, `with`, or
+  /// `on` clause.
+  ///
+  /// The reason this is a problem is that it makes it possible for analyzer
+  /// clients to implicitly reference analyzer internal types. This can happen
+  /// in many ways; here are some examples:
+  ///
+  /// - If `C` is a public API class that implements `B`, and `B` is a private
+  ///   class with a getter called `x`, then a client can access `B.x` via `C`.
+  ///
+  /// - If `f` has return type `T`, and `T` is a private class with a getter
+  ///   called `x`, then a client can access `T.x` via `f().x`.
+  ///
+  /// - If `f` has type `void Function(T)`, and `T` is a private class with a
+  ///   getter called `x`, then a client can access `T.x` via
+  ///   `var g = f; g = (t) { print(t.x); }`.
+  ///
+  /// This lint can be suppressed either with an `ignore` comment, or by marking
+  /// the referenced type with `@AnalyzerPublicApi(...)`. The advantage of
+  /// marking the referenced type with `@AnalyzerPublicApi(...)` is that it
+  /// causes the members of referenced type to be checked by this lint.
+  ///
+  /// Parameters:
+  /// String types: list of types, separated by `, `
+  static const LintCode analyzerPublicApiBadType = LinterLintCode(
+    LintNames.analyzer_public_api_bad_type,
+    "Element makes use of type(s) which is not part of the analyzer public "
+    "API: {0}.",
+  );
+
+  /// Lint issued if a file in the analyzer public API contains an `export`
+  /// directive that exports a name that's not part of the analyzer public API.
+  ///
+  /// This lint can be suppressed either with an `ignore` comment, or by marking
+  /// the exported declaration with `@AnalyzerPublicApi(...)`. The advantage of
+  /// marking the exported declaration with `@AnalyzerPublicApi(...)` is that it
+  /// causes the members of the exported declaration to be checked by this lint.
+  ///
+  /// Parameters:
+  /// String elements: List of elements, separated by `, `
+  static const LintCode analyzerPublicApiExportsNonPublicName = LinterLintCode(
+    LintNames.analyzer_public_api_exports_non_public_name,
+    "Export directive exports element(s) that are not part of the analyzer "
+    "public API: {0}.",
+  );
+
+  /// Lint issued if a top level declaration in the analyzer public API has a
+  /// name ending in `Impl`.
+  ///
+  /// Such declarations are not meant to be members of the analyzer public API,
+  /// so if they are either declared outside of `package:analyzer/src`, or
+  /// marked with `@AnalyzerPublicApi(...)`, that is almost certainly a mistake.
+  ///
+  /// No parameters.
+  static const LintCode analyzerPublicApiImplInPublicApi = LinterLintCode(
+    LintNames.analyzer_public_api_impl_in_public_api,
+    "Declarations in the analyzer public API should not end in \"Impl\".",
+  );
+
   /// Parameters:
   /// Object p0: undocumented
   static const LintCode annotateOverrides = LinterLintCode(
@@ -1130,6 +1209,23 @@
   );
 
   /// No parameters.
+  static const LintCode noSoloTests = LinterLintCode(
+    LintNames.no_solo_tests,
+    "Don't commit soloed tests.",
+    correctionMessage:
+        "Try removing the 'soloTest' annotation or 'solo_' prefix.",
+    hasPublishedDocs: true,
+  );
+
+  /// No parameters.
+  static const LintCode noTrailingSpaces = LinterLintCode(
+    LintNames.no_trailing_spaces,
+    "Don't create string literals with trailing spaces in tests.",
+    correctionMessage: "Try removing the trailing spaces.",
+    hasPublishedDocs: true,
+  );
+
+  /// No parameters.
   static const LintCode noWildcardVariableUses = LinterLintCode(
     LintNames.no_wildcard_variable_uses,
     "The referenced identifier is a wildcard.",
@@ -2413,6 +2509,15 @@
   );
 
   /// No parameters.
+  static const LintCode visitRegisteredNodes = LinterLintCode(
+    LintNames.visit_registered_nodes,
+    "Declare 'visit' methods for all registered node types.",
+    correctionMessage:
+        "Try declaring a 'visit' method for all registered node types.",
+    hasPublishedDocs: true,
+  );
+
+  /// No parameters.
   static const LintCode voidChecks = LinterLintCode(
     LintNames.void_checks,
     "Assignment to a variable of type 'void'.",
diff --git a/pkg/linter/lib/src/lint_names.g.dart b/pkg/linter/lib/src/lint_names.g.dart
index 8c3b14e..27cb05b 100644
--- a/pkg/linter/lib/src/lint_names.g.dart
+++ b/pkg/linter/lib/src/lint_names.g.dart
@@ -29,6 +29,18 @@
 
   static const String always_use_package_imports = 'always_use_package_imports';
 
+  static const String analyzer_public_api_bad_part_directive =
+      'analyzer_public_api_bad_part_directive';
+
+  static const String analyzer_public_api_bad_type =
+      'analyzer_public_api_bad_type';
+
+  static const String analyzer_public_api_exports_non_public_name =
+      'analyzer_public_api_exports_non_public_name';
+
+  static const String analyzer_public_api_impl_in_public_api =
+      'analyzer_public_api_impl_in_public_api';
+
   static const String annotate_overrides = 'annotate_overrides';
 
   static const String annotate_redeclares = 'annotate_redeclares';
@@ -290,6 +302,10 @@
 
   static const String no_self_assignments = 'no_self_assignments';
 
+  static const String no_solo_tests = 'no_solo_tests';
+
+  static const String no_trailing_spaces = 'no_trailing_spaces';
+
   static const String no_wildcard_variable_uses = 'no_wildcard_variable_uses';
 
   static const String non_constant_identifier_names =
@@ -614,5 +630,7 @@
 
   static const String valid_regexps = 'valid_regexps';
 
+  static const String visit_registered_nodes = 'visit_registered_nodes';
+
   static const String void_checks = 'void_checks';
 }
diff --git a/pkg/linter/lib/src/rules/analyzer_public_api.dart b/pkg/linter/lib/src/rules/analyzer_public_api.dart
index 51d661d..e1f3fe5 100644
--- a/pkg/linter/lib/src/rules/analyzer_public_api.dart
+++ b/pkg/linter/lib/src/rules/analyzer_public_api.dart
@@ -13,81 +13,14 @@
 import 'package:analyzer/dart/element/type.dart';
 import 'package:analyzer/error/error.dart';
 
+import '../lint_codes.dart';
+
 const _desc =
     'Do not expose implementation details through the analyzer public API.';
 
 class AnalyzerPublicApi extends MultiAnalysisRule {
   static const ruleName = 'analyzer_public_api';
 
-  /// Lint issued if a file in the analyzer public API contains a `part`
-  /// directive that points to a file that's not in the analyzer public API.
-  ///
-  /// The rationale for this lint is that if such a `part` directive were to
-  /// exist, it would cause all the members of the part file to become part of
-  /// the analyzer's public API, even though they don't appear to be public API.
-  ///
-  /// Note that the analyzer doesn't make very much use of `part` directives,
-  /// but it may do so in the future once augmentations and enhanced parts are
-  /// supported.
-  static const LintCode badPartDirective = LintCode(
-    'analyzer_public_api_bad_part_directive',
-    'Part directives in the analyzer public API should point to files in the '
-        'analyzer public API.',
-  );
-
-  /// Lint issued if a method, function, getter, or setter in the analyzer
-  /// public API makes use of a type that's not part of the analyzer public API,
-  /// or if a non-public type appears in an `extends`, `implements`, `with`, or
-  /// `on` clause.
-  ///
-  /// The reason this is a problem is that it makes it possible for analyzer
-  /// clients to implicitly reference analyzer internal types. This can happen
-  /// in many ways; here are some examples:
-  ///
-  /// - If `C` is a public API class that implements `B`, and `B` is a private
-  ///   class with a getter called `x`, then a client can access `B.x` via `C`.
-  ///
-  /// - If `f` has return type `T`, and `T` is a private class with a getter
-  ///   called `x`, then a client can access `T.x` via `f().x`.
-  ///
-  /// - If `f` has type `void Function(T)`, and `T` is a private class with a
-  ///   getter called `x`, then a client can access `T.x` via
-  ///   `var g = f; g = (t) { print(t.x); }`.
-  ///
-  /// This lint can be suppressed either with an `ignore` comment, or by marking
-  /// the referenced type with `@AnalyzerPublicApi(...)`. The advantage of
-  /// marking the referenced type with `@AnalyzerPublicApi(...)` is that it
-  /// causes the members of referenced type to be checked by this lint.
-  static const LintCode badType = LintCode(
-    'analyzer_public_api_bad_type',
-    'Element makes use of type(s) which is not part of the analyzer public '
-        'API: {0}.',
-  );
-
-  /// Lint issued if a file in the analyzer public API contains an `export`
-  /// directive that exports a name that's not part of the analyzer public API.
-  ///
-  /// This lint can be suppressed either with an `ignore` comment, or by marking
-  /// the exported declaration with `@AnalyzerPublicApi(...)`. The advantage of
-  /// marking the exported declaration with `@AnalyzerPublicApi(...)` is that it
-  /// causes the members of the exported declaration to be checked by this lint.
-  static const LintCode exportsNonPublicName = LintCode(
-    'analyzer_public_api_exports_non_public_name',
-    'Export directive exports element(s) that are not part of the analyzer '
-        'public API: {0}.',
-  );
-
-  /// Lint issued if a top level declaration in the analyzer public API has a
-  /// name ending in `Impl`.
-  ///
-  /// Such declarations are not meant to be members of the analyzer public API,
-  /// so if they are either declared outside of `package:analyzer/src`, or
-  /// marked with `@AnalyzerPublicApi(...)`, that is almost certainly a mistake.
-  static const LintCode implInPublicApi = LintCode(
-    'analyzer_public_api_impl_in_public_api',
-    'Declarations in the analyzer public API should not end in "Impl".',
-  );
-
   AnalyzerPublicApi()
     : super(
         name: ruleName,
@@ -97,10 +30,10 @@
 
   @override
   List<DiagnosticCode> get diagnosticCodes => [
-    badPartDirective,
-    badType,
-    exportsNonPublicName,
-    implInPublicApi,
+    LinterLintCode.analyzerPublicApiBadPartDirective,
+    LinterLintCode.analyzerPublicApiBadType,
+    LinterLintCode.analyzerPublicApiExportsNonPublicName,
+    LinterLintCode.analyzerPublicApiImplInPublicApi,
   ];
 
   @override
@@ -170,7 +103,7 @@
     if (badNames != null) {
       rule.reportAtNode(
         node,
-        diagnosticCode: AnalyzerPublicApi.exportsNonPublicName,
+        diagnosticCode: LinterLintCode.analyzerPublicApiExportsNonPublicName,
         arguments: [badNames.join(', ')],
       );
     }
@@ -187,7 +120,7 @@
     if (!partElement.includedFragment!.source.uri.isInAnalyzerPublicLib) {
       rule.reportAtNode(
         node,
-        diagnosticCode: AnalyzerPublicApi.badPartDirective,
+        diagnosticCode: LinterLintCode.analyzerPublicApiBadPartDirective,
       );
     }
   }
@@ -217,7 +150,7 @@
       rule.reportAtOffset(
         fragment.nameOffset!,
         name.length,
-        diagnosticCode: AnalyzerPublicApi.implInPublicApi,
+        diagnosticCode: LinterLintCode.analyzerPublicApiImplInPublicApi,
       );
     }
     switch (fragment) {
@@ -302,7 +235,7 @@
     rule.reportAtOffset(
       offset,
       length,
-      diagnosticCode: AnalyzerPublicApi.badType,
+      diagnosticCode: LinterLintCode.analyzerPublicApiBadType,
       arguments: [problems.join(', ')],
     );
   }
diff --git a/pkg/linter/messages.yaml b/pkg/linter/messages.yaml
index d98eb6f..d09eef1 100644
--- a/pkg/linter/messages.yaml
+++ b/pkg/linter/messages.yaml
@@ -394,6 +394,90 @@
       import 'package:foo/src/baz.dart';
       ...
       ```
+  analyzer_public_api_bad_part_directive:
+    parameters: none
+    problemMessage: "Part directives in the analyzer public API should point to files in the analyzer public API."
+    hasPublishedDocs: false
+    state:
+      internal: "3.10"
+    categories: [publicInterface]
+    deprecatedDetails: "For internal use only."
+    comment: |-
+      Lint issued if a file in the analyzer public API contains a `part`
+      directive that points to a file that's not in the analyzer public API.
+
+      The rationale for this lint is that if such a `part` directive were to
+      exist, it would cause all the members of the part file to become part of
+      the analyzer's public API, even though they don't appear to be public API.
+
+      Note that the analyzer doesn't make very much use of `part` directives,
+      but it may do so in the future once augmentations and enhanced parts are
+      supported.
+  analyzer_public_api_bad_type:
+    parameters:
+      String types: "list of types, separated by `, `"
+    problemMessage: "Element makes use of type(s) which is not part of the analyzer public API: #types."
+    hasPublishedDocs: false
+    state:
+      internal: "3.10"
+    categories: [publicInterface]
+    deprecatedDetails: "For internal use only."
+    comment: |-
+      Lint issued if a method, function, getter, or setter in the analyzer
+      public API makes use of a type that's not part of the analyzer public API,
+      or if a non-public type appears in an `extends`, `implements`, `with`, or
+      `on` clause.
+
+      The reason this is a problem is that it makes it possible for analyzer
+      clients to implicitly reference analyzer internal types. This can happen
+      in many ways; here are some examples:
+
+      - If `C` is a public API class that implements `B`, and `B` is a private
+        class with a getter called `x`, then a client can access `B.x` via `C`.
+
+      - If `f` has return type `T`, and `T` is a private class with a getter
+        called `x`, then a client can access `T.x` via `f().x`.
+
+      - If `f` has type `void Function(T)`, and `T` is a private class with a
+        getter called `x`, then a client can access `T.x` via
+        `var g = f; g = (t) { print(t.x); }`.
+
+      This lint can be suppressed either with an `ignore` comment, or by marking
+      the referenced type with `@AnalyzerPublicApi(...)`. The advantage of
+      marking the referenced type with `@AnalyzerPublicApi(...)` is that it
+      causes the members of referenced type to be checked by this lint.
+  analyzer_public_api_exports_non_public_name:
+    parameters:
+      String elements: "List of elements, separated by `, `"
+    problemMessage: "Export directive exports element(s) that are not part of the analyzer public API: #elements."
+    hasPublishedDocs: false
+    state:
+      internal: "3.10"
+    categories: [publicInterface]
+    deprecatedDetails: "For internal use only."
+    comment: |-
+      Lint issued if a file in the analyzer public API contains an `export`
+      directive that exports a name that's not part of the analyzer public API.
+
+      This lint can be suppressed either with an `ignore` comment, or by marking
+      the exported declaration with `@AnalyzerPublicApi(...)`. The advantage of
+      marking the exported declaration with `@AnalyzerPublicApi(...)` is that it
+      causes the members of the exported declaration to be checked by this lint.
+  analyzer_public_api_impl_in_public_api:
+    parameters: none
+    problemMessage: 'Declarations in the analyzer public API should not end in "Impl".'
+    hasPublishedDocs: false
+    state:
+      internal: "3.10"
+    categories: [publicInterface]
+    deprecatedDetails: "For internal use only."
+    comment: |-
+      Lint issued if a top level declaration in the analyzer public API has a
+      name ending in `Impl`.
+
+      Such declarations are not meant to be members of the analyzer public API,
+      so if they are either declared outside of `package:analyzer/src`, or
+      marked with `@AnalyzerPublicApi(...)`, that is almost certainly a mistake.
   annotate_overrides:
     parameters:
       Object p0: undocumented
@@ -7045,6 +7129,24 @@
         }
       }
       ```
+  no_solo_tests:
+    parameters: none
+    problemMessage: "Don't commit soloed tests."
+    correctionMessage: "Try removing the 'soloTest' annotation or 'solo_' prefix."
+    hasPublishedDocs: true
+    state:
+      internal: "3.10"
+    categories: [errorProne]
+    deprecatedDetails: "For internal use only."
+  no_trailing_spaces:
+    parameters: none
+    problemMessage: "Don't create string literals with trailing spaces in tests."
+    correctionMessage: 'Try removing the trailing spaces.'
+    hasPublishedDocs: true
+    state:
+      internal: "3.10"
+    categories: [errorProne]
+    deprecatedDetails: "For internal use only."
   no_wildcard_variable_uses:
     parameters: none
     problemMessage: "The referenced identifier is a wildcard."
@@ -15861,6 +15963,15 @@
       ```dart
       print(RegExp(r'\(').hasMatch('foo()'));
       ```
+  visit_registered_nodes:
+    parameters: none
+    problemMessage: "Declare 'visit' methods for all registered node types."
+    correctionMessage: "Try declaring a 'visit' method for all registered node types."
+    hasPublishedDocs: true
+    state:
+      internal: "3.10"
+    categories: [errorProne]
+    deprecatedDetails: "For internal use only."
   void_checks:
     parameters: none
     problemMessage: "Assignment to a variable of type 'void'."
diff --git a/pkg/linter/test/rules/analyzer_public_api_test.dart b/pkg/linter/test/rules/analyzer_public_api_test.dart
index 205708a..f313953 100644
--- a/pkg/linter/test/rules/analyzer_public_api_test.dart
+++ b/pkg/linter/test/rules/analyzer_public_api_test.dart
@@ -3,6 +3,7 @@
 // BSD-style license that can be found in the LICENSE file.
 
 import 'package:analyzer/utilities/package_config_file_builder.dart';
+import 'package:linter/src/lint_codes.dart';
 import 'package:linter/src/rules/analyzer_public_api.dart';
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
@@ -16,14 +17,16 @@
 
 @reflectiveTest
 class AnalyzerPublicApiTest extends LintRuleTest {
-  static String get badPartDirective => AnalyzerPublicApi.badPartDirective.name;
+  static String get badPartDirective =>
+      LinterLintCode.analyzerPublicApiBadPartDirective.name;
 
-  static String get badType => AnalyzerPublicApi.badType.name;
+  static String get badType => LinterLintCode.analyzerPublicApiBadType.name;
 
   static String get exportsNonPublicName =>
-      AnalyzerPublicApi.exportsNonPublicName.name;
+      LinterLintCode.analyzerPublicApiExportsNonPublicName.name;
 
-  static String get implInPublicApi => AnalyzerPublicApi.implInPublicApi.name;
+  static String get implInPublicApi =>
+      LinterLintCode.analyzerPublicApiImplInPublicApi.name;
 
   String get libFile => '$testPackageRootPath/lib/file.dart';
 
diff --git a/pkg/linter/tool/checks/rules/no_solo_tests.dart b/pkg/linter/tool/checks/rules/no_solo_tests.dart
index 4aa2c3d..9081a87 100644
--- a/pkg/linter/tool/checks/rules/no_solo_tests.dart
+++ b/pkg/linter/tool/checks/rules/no_solo_tests.dart
@@ -10,18 +10,11 @@
 import 'package:analyzer/error/error.dart';
 import 'package:linter/src/analyzer.dart';
 
-const _desc = r"Don't commit soloed tests.";
-
 class NoSoloTests extends LintRule {
-  static const LintCode code = LintCode(
-    'no_solo_tests',
-    _desc,
-    correctionMessage:
-        "Try removing the 'soloTest' annotation or 'solo_' prefix.",
-    hasPublishedDocs: true,
-  );
+  static const LintCode code = LinterLintCode.noSoloTests;
 
-  NoSoloTests() : super(name: 'no_solo_tests', description: _desc);
+  NoSoloTests()
+    : super(name: 'no_solo_tests', description: "Don't commit soloed tests.");
 
   @override
   DiagnosticCode get diagnosticCode => code;
diff --git a/pkg/linter/tool/checks/rules/no_trailing_spaces.dart b/pkg/linter/tool/checks/rules/no_trailing_spaces.dart
index 07c2d48..6f39bbd 100644
--- a/pkg/linter/tool/checks/rules/no_trailing_spaces.dart
+++ b/pkg/linter/tool/checks/rules/no_trailing_spaces.dart
@@ -10,17 +10,15 @@
 import 'package:analyzer/src/dart/ast/token.dart';
 import 'package:linter/src/analyzer.dart';
 
-const _desc = r"Don't create string literals with trailing spaces in tests.";
-
 class NoTrailingSpaces extends LintRule {
-  static const LintCode code = LintCode(
-    'no_trailing_spaces',
-    _desc,
-    correctionMessage: 'Try removing the trailing spaces.',
-    hasPublishedDocs: true,
-  );
+  static const LintCode code = LinterLintCode.noTrailingSpaces;
 
-  NoTrailingSpaces() : super(name: 'no_trailing_spaces', description: _desc);
+  NoTrailingSpaces()
+    : super(
+        name: 'no_trailing_spaces',
+        description:
+            "Don't create string literals with trailing spaces in tests.",
+      );
 
   @override
   DiagnosticCode get diagnosticCode => code;
diff --git a/pkg/linter/tool/checks/rules/visit_registered_nodes.dart b/pkg/linter/tool/checks/rules/visit_registered_nodes.dart
index 6b04ea2..191b51b 100644
--- a/pkg/linter/tool/checks/rules/visit_registered_nodes.dart
+++ b/pkg/linter/tool/checks/rules/visit_registered_nodes.dart
@@ -11,19 +11,14 @@
 import 'package:analyzer/error/error.dart';
 import 'package:linter/src/analyzer.dart';
 
-const _desc = r"Declare 'visit' methods for all registered node types.";
-
 class VisitRegisteredNodes extends LintRule {
-  static const LintCode code = LintCode(
-    'visit_registered_nodes',
-    _desc,
-    correctionMessage:
-        "Try declaring a 'visit' method for all registered node types.",
-    hasPublishedDocs: true,
-  );
+  static const LintCode code = LinterLintCode.visitRegisteredNodes;
 
   VisitRegisteredNodes()
-    : super(name: 'visit_registered_nodes', description: _desc);
+    : super(
+        name: 'visit_registered_nodes',
+        description: "Declare 'visit' methods for all registered node types.",
+      );
 
   @override
   DiagnosticCode get diagnosticCode => code;