Skip to content

Commit dd0ac56

Browse files
stereotype441Commit Queue
authored andcommitted
[analyzer] Code generate TodoCode constants.
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: I6a6a6964154fb3d61bf2b11cc6fa871b47a1ce1f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/445282 Commit-Queue: Paul Berry <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent 44e36ba commit dd0ac56

File tree

5 files changed

+123
-50
lines changed

5 files changed

+123
-50
lines changed

pkg/analyzer/lib/src/dart/error/todo_codes.dart

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
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';
5+
// ignore: deprecated_member_use_from_same_package
6+
import 'package:analyzer/src/dart/error/todo_codes.g.dart';
67

7-
// It is hard to visually separate each code's _doc comment_ from its published
8-
// _documentation comment_ when each is written as an end-of-line comment.
9-
// ignore_for_file: slash_for_doc_comments
8+
// ignore: deprecated_member_use_from_same_package
9+
export 'package:analyzer/src/dart/error/todo_codes.g.dart' show TodoCode;
1010

1111
/// Static helper methods and properties for working with [TodoCode]s.
1212
class Todo {
@@ -53,41 +53,3 @@ class Todo {
5353
/// Returns the TodoCode for [kind], falling back to [TodoCode.todo].
5454
static TodoCode forKind(String kind) => _codes[kind] ?? TodoCode.todo;
5555
}
56-
57-
/**
58-
* The error code indicating a marker in code for work that needs to be finished
59-
* or revisited.
60-
*/
61-
class TodoCode extends DiagnosticCode {
62-
/**
63-
* A standard TODO comment marked as TODO.
64-
*/
65-
static const TodoCode todo = TodoCode('TODO');
66-
67-
/**
68-
* A TODO comment marked as FIXME.
69-
*/
70-
static const TodoCode fixme = TodoCode('FIXME');
71-
72-
/**
73-
* A TODO comment marked as HACK.
74-
*/
75-
static const TodoCode hack = TodoCode('HACK');
76-
77-
/**
78-
* A TODO comment marked as UNDONE.
79-
*/
80-
static const TodoCode undone = TodoCode('UNDONE');
81-
82-
/**
83-
* Initialize a newly created error code to have the given [name].
84-
*/
85-
const TodoCode(String name)
86-
: super(problemMessage: "{0}", name: name, uniqueName: 'TodoCode.$name');
87-
88-
@override
89-
DiagnosticSeverity get severity => DiagnosticSeverity.INFO;
90-
91-
@override
92-
DiagnosticType get type => DiagnosticType.TODO;
93-
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// THIS FILE IS GENERATED. DO NOT EDIT.
6+
//
7+
// Instead modify 'pkg/analyzer/messages.yaml' and run
8+
// 'dart run pkg/analyzer/tool/messages/generate.dart' to update.
9+
10+
// While transitioning `HintCodes` to `WarningCodes`, we refer to deprecated
11+
// codes here.
12+
// ignore_for_file: deprecated_member_use_from_same_package
13+
//
14+
// Generated comments don't quite align with flutter style.
15+
// ignore_for_file: flutter_style_todos
16+
17+
/// @docImport 'package:analyzer/src/dart/error/syntactic_errors.g.dart';
18+
/// @docImport 'package:analyzer/src/error/inference_error.dart';
19+
@Deprecated(
20+
// This library is deprecated to prevent it from being accidentally imported
21+
// It should only be imported by the corresponding non-code-generated library
22+
// (which suppresses the deprecation warning using an "ignore" comment).
23+
'Use package:analyzer/src/dart/error/todo_codes.dart instead',
24+
)
25+
library;
26+
27+
import "package:_fe_analyzer_shared/src/base/errors.dart";
28+
29+
/// The error code indicating a marker in code for work that needs to be finished
30+
/// or revisited.
31+
class TodoCode extends DiagnosticCode {
32+
/// A TODO comment marked as FIXME.
33+
///
34+
/// Parameters:
35+
/// String message: the user-supplied problem message
36+
static const TodoCode fixme = TodoCode('FIXME', "{0}");
37+
38+
/// A TODO comment marked as HACK.
39+
///
40+
/// Parameters:
41+
/// String message: the user-supplied problem message
42+
static const TodoCode hack = TodoCode('HACK', "{0}");
43+
44+
/// A standard TODO comment marked as TODO.
45+
///
46+
/// Parameters:
47+
/// String message: the user-supplied problem message
48+
static const TodoCode todo = TodoCode('TODO', "{0}");
49+
50+
/// A TODO comment marked as UNDONE.
51+
///
52+
/// Parameters:
53+
/// String message: the user-supplied problem message
54+
static const TodoCode undone = TodoCode('UNDONE', "{0}");
55+
56+
/// Initialize a newly created error code to have the given [name].
57+
const TodoCode(
58+
String name,
59+
String problemMessage, {
60+
super.correctionMessage,
61+
super.hasPublishedDocs = false,
62+
super.isUnresolvedIdentifier = false,
63+
String? uniqueName,
64+
}) : super(
65+
name: name,
66+
problemMessage: problemMessage,
67+
uniqueName: 'TodoCode.${uniqueName ?? name}',
68+
);
69+
70+
@override
71+
DiagnosticSeverity get severity => DiagnosticSeverity.INFO;
72+
73+
@override
74+
DiagnosticType get type => DiagnosticType.TODO;
75+
}

pkg/analyzer/messages.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23220,6 +23220,35 @@ StaticWarningCode:
2322023220
if (x case var a when a > 0) {}
2322123221
}
2322223222
```
23223+
TodoCode:
23224+
FIXME:
23225+
parameters:
23226+
String message: the user-supplied problem message
23227+
problemMessage: "#message"
23228+
hasPublishedDocs: false
23229+
comment: |-
23230+
A TODO comment marked as FIXME.
23231+
HACK:
23232+
parameters:
23233+
String message: the user-supplied problem message
23234+
problemMessage: "#message"
23235+
hasPublishedDocs: false
23236+
comment: |-
23237+
A TODO comment marked as HACK.
23238+
TODO:
23239+
parameters:
23240+
String message: the user-supplied problem message
23241+
problemMessage: "#message"
23242+
hasPublishedDocs: false
23243+
comment: |-
23244+
A standard TODO comment marked as TODO.
23245+
UNDONE:
23246+
parameters:
23247+
String message: the user-supplied problem message
23248+
problemMessage: "#message"
23249+
hasPublishedDocs: false
23250+
comment: |-
23251+
A TODO comment marked as UNDONE.
2322323252
TransformSetErrorCode:
2322423253
conflicting_key:
2322523254
parameters:

pkg/analyzer/tool/messages/error_code_info.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@ const List<ErrorClassInfo> errorClasses = [
8787
type: 'STATIC_WARNING',
8888
severity: 'WARNING',
8989
),
90+
ErrorClassInfo(
91+
file: todoCodesFile,
92+
name: 'TodoCode',
93+
type: 'TODO',
94+
severity: 'INFO',
95+
comment: '''
96+
The error code indicating a marker in code for work that needs to be finished
97+
or revisited.
98+
''',
99+
),
90100
ErrorClassInfo(
91101
file: transformSetErrorCodeFile,
92102
name: 'TransformSetErrorCode',
@@ -138,6 +148,11 @@ const syntacticErrorsFile = GeneratedErrorCodeFile(
138148
preferredImportUri: 'package:analyzer/src/dart/error/syntactic_errors.dart',
139149
);
140150

151+
const todoCodesFile = GeneratedErrorCodeFile(
152+
path: 'analyzer/lib/src/dart/error/todo_codes.g.dart',
153+
preferredImportUri: 'package:analyzer/src/dart/error/todo_codes.dart',
154+
);
155+
141156
const transformSetErrorCodeFile = GeneratedErrorCodeFile(
142157
path:
143158
'analysis_server/lib/src/services/correction/fix/data_driven/'

pkg/analyzer/tool/messages/generate.dart

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,6 @@ class _DiagnosticCodeValuesGenerator {
259259
_DiagnosticCodeValuesGenerator(this.generatedCodes);
260260

261261
void generate() {
262-
// The scanner error codes are not yet being generated, so we need to add
263-
// them to the list explicitly.
264-
generatedCodes.addAll([
265-
('TodoCode', 'TODO'),
266-
('TodoCode', 'FIXME'),
267-
('TodoCode', 'HACK'),
268-
('TodoCode', 'UNDONE'),
269-
]);
270262
generatedCodes.sortBy((x) => '${x.$1}.${x.$2}');
271263

272264
out.writeln();

0 commit comments

Comments
 (0)