Skip to content

Commit f977229

Browse files
stereotype441Commit Queue
authored andcommitted
[messages] Stop generating lint_codes.g.dart.
All the code that remained in this file was hand-authored and inserted into the generated file using triple-quoted strings in the code generator. Moving the code into a handwritten file will make it easier to maintain in the future. Change-Id: I6a6a696404276223981416db38785a50a2cbde09 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/464625 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent 2110e90 commit f977229

File tree

5 files changed

+48
-169
lines changed

5 files changed

+48
-169
lines changed

pkg/analyzer_utilities/lib/analyzer_messages.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ transform set.
9393
),
9494
];
9595

96-
const String generatedLintCodesPath = 'linter/lib/src/lint_codes.g.dart';
97-
9896
/// Base diagnostic classes used for lint messages.
9997
const linterBaseClasses = DiagnosticBaseClasses(
10098
requiresTypeArgument: false,

pkg/linter/lib/src/lint_codes.dart

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,51 @@
44

55
import 'analyzer.dart';
66

7-
part 'lint_codes.g.dart';
7+
class LinterLintCode extends LintCodeWithExpectedTypes {
8+
const LinterLintCode({
9+
required super.name,
10+
required super.problemMessage,
11+
required super.uniqueName,
12+
super.expectedTypes,
13+
super.correctionMessage,
14+
super.hasPublishedDocs,
15+
});
16+
17+
@override
18+
String get url {
19+
if (hasPublishedDocs) {
20+
return 'https://dart.dev/diagnostics/$name';
21+
}
22+
return 'https://dart.dev/lints/$name';
23+
}
24+
}
25+
26+
final class LinterLintTemplate<T extends Function> extends LinterLintCode
27+
implements DiagnosticWithArguments<T> {
28+
@override
29+
final T withArguments;
30+
31+
/// Initialize a newly created error code to have the given [name].
32+
const LinterLintTemplate({
33+
required super.name,
34+
required super.problemMessage,
35+
required this.withArguments,
36+
required super.expectedTypes,
37+
required super.uniqueName,
38+
super.correctionMessage,
39+
super.hasPublishedDocs = false,
40+
});
41+
}
42+
43+
final class LinterLintWithoutArguments extends LinterLintCode
44+
with DiagnosticWithoutArguments {
45+
/// Initialize a newly created error code to have the given [name].
46+
const LinterLintWithoutArguments({
47+
required super.name,
48+
required super.problemMessage,
49+
required super.expectedTypes,
50+
required super.uniqueName,
51+
super.correctionMessage,
52+
super.hasPublishedDocs = false,
53+
});
54+
}

pkg/linter/lib/src/lint_codes.g.dart

Lines changed: 0 additions & 68 deletions
This file was deleted.

pkg/linter/test/verify_generated_files_test.dart

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,5 @@ void main() {
2020
"Run 'dart run pkg/linter/tool/generate_lints.dart' to update.",
2121
);
2222
});
23-
24-
test('ensure lint codes are up to date', () async {
25-
expect(
26-
await generatedCodesFile.check(pkg_root.packageRoot),
27-
isTrue,
28-
reason:
29-
"The generated lint codes at 'lib/src/lint_codes.g.dart' need "
30-
'to be regenerated. '
31-
"Run 'dart run pkg/linter/tool/generate_lints.dart' to update.",
32-
);
33-
});
3423
});
3524
}

pkg/linter/tool/generate_lints.dart

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -7,105 +7,18 @@
77
library;
88

99
import 'package:analyzer_testing/package_root.dart' as pkg_root;
10-
import 'package:analyzer_utilities/analyzer_messages.dart';
1110
import 'package:analyzer_utilities/tools.dart';
1211

1312
import 'messages_info.dart';
1413

1514
void main() async {
1615
await GeneratedContent.generateAll(pkg_root.packageRoot, [
1716
generatedNamesFile,
18-
generatedCodesFile,
1917
]);
2018
}
2119

2220
const String generatedNamesPath = 'linter/lib/src/lint_names.g.dart';
2321

24-
GeneratedFile get generatedCodesFile =>
25-
GeneratedFile(generatedLintCodesPath, (pkgRoot) async {
26-
var out = StringBuffer('''
27-
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
28-
// for details. All rights reserved. Use of this source code is governed by a
29-
// BSD-style license that can be found in the LICENSE file.
30-
31-
// THIS FILE IS GENERATED. DO NOT EDIT.
32-
//
33-
// Instead modify 'pkg/linter/messages.yaml' and run
34-
// 'dart run pkg/linter/tool/generate_lints.dart' to update.
35-
36-
// Generated comments don't quite align with flutter style.
37-
// ignore_for_file: flutter_style_todos
38-
39-
// Generator currently outputs double quotes for simplicity.
40-
// ignore_for_file: prefer_single_quotes
41-
42-
// Generated `withArguments` methods always use block bodies for simplicity.
43-
// ignore_for_file: prefer_expression_function_bodies
44-
45-
part of 'lint_codes.dart';
46-
47-
class LinterLintCode extends LintCodeWithExpectedTypes {
48-
''');
49-
var memberAccumulator = MemberAccumulator();
50-
51-
memberAccumulator.constructors[''] = '''
52-
const LinterLintCode({
53-
required super.name,
54-
required super.problemMessage,
55-
required super.uniqueName,
56-
super.expectedTypes,
57-
super.correctionMessage,
58-
super.hasPublishedDocs,
59-
});
60-
''';
61-
62-
memberAccumulator.accessors['url'] = '''
63-
@override
64-
String get url {
65-
if (hasPublishedDocs) {
66-
return 'https://dart.dev/diagnostics/\$name';
67-
}
68-
return 'https://dart.dev/lints/\$name';
69-
}
70-
''';
71-
memberAccumulator.writeTo(out);
72-
out.writeln('}');
73-
74-
out.write('''
75-
76-
final class LinterLintTemplate<T extends Function> extends LinterLintCode
77-
implements DiagnosticWithArguments<T> {
78-
@override
79-
final T withArguments;
80-
81-
/// Initialize a newly created error code to have the given [name].
82-
const LinterLintTemplate({
83-
required super.name,
84-
required super.problemMessage,
85-
required this.withArguments,
86-
required super.expectedTypes,
87-
required super.uniqueName,
88-
super.correctionMessage,
89-
super.hasPublishedDocs = false,
90-
});
91-
}
92-
93-
final class LinterLintWithoutArguments extends LinterLintCode
94-
with DiagnosticWithoutArguments {
95-
/// Initialize a newly created error code to have the given [name].
96-
const LinterLintWithoutArguments({
97-
required super.name,
98-
required super.problemMessage,
99-
required super.expectedTypes,
100-
required super.uniqueName,
101-
super.correctionMessage,
102-
super.hasPublishedDocs = false,
103-
});
104-
}
105-
''');
106-
return out.toString();
107-
});
108-
10922
GeneratedFile get generatedNamesFile =>
11023
GeneratedFile(generatedNamesPath, (pkgRoot) async {
11124
var out = StringBuffer('''

0 commit comments

Comments
 (0)