Migrate analyzer_utilities package to new constructor decl syntax.
This change migrates the analyzer_utilities package to use the new constructor declaration syntax, described in https://github.com/dart-lang/language/blob/main/accepted/future-releases/primary-constructors/feature-specification.md#abbreviations-of-in-body-constructor-declarations. This change was performed in an automated fashion, by (a) bumping the packages' SDK constraints to `3.13.0-0`, (b) enabling the lints `unnecessary_type_name_in_constructor` and `unnecessary_const_in_enum_constructor`, (c) fixing the resulting lint failures using `dart fix`, and then (d) reformatting the affected files. To ease code review, I've reverted unrelated formatting changes. Since this change requires bumping SDK constaints to `3.13.0-0`, it was only performed on packages that are *not* published on pub. (Packages that *are* published on pub should remain on lower language versions until at least after the stable version of 3.13 is released, so that we don't block users on the stable channel from receiving updates to those packages.) Change-Id: Ib9564fe588b1118f7e810bd39ff9c6576a6a6964 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505066 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Samuel Rawlins <srawlins@google.com> Commit-Queue: Paul Berry <paulberry@google.com>
This commit is contained in:
committed by
dart-scoped@luci-project-accounts.iam.gserviceaccount.com
parent
514be1781f
commit
f4ff72aadd
@@ -18,8 +18,10 @@ linter:
|
||||
- prefer_single_quotes
|
||||
- unawaited_futures
|
||||
- unnecessary_breaks
|
||||
- unnecessary_const_in_enum_constructor
|
||||
- unnecessary_ignore
|
||||
- unnecessary_library_directive
|
||||
- unnecessary_parenthesis
|
||||
- unnecessary_type_name_in_constructor
|
||||
- unreachable_from_main
|
||||
- use_null_aware_elements
|
||||
|
||||
@@ -13,7 +13,7 @@ sealed class ConstantStyle {
|
||||
/// The static type of the constant that should be generated.
|
||||
final String staticType;
|
||||
|
||||
ConstantStyle({required this.concreteClassName, required this.staticType});
|
||||
new({required this.concreteClassName, required this.staticType});
|
||||
}
|
||||
|
||||
/// [ConstantStyle] object indicating that an "old style" constant should be
|
||||
@@ -22,10 +22,7 @@ sealed class ConstantStyle {
|
||||
// TODO(paulberry): finish supporting the literate API in all analyzer messages
|
||||
// and eliminate this.
|
||||
class OldConstantStyle extends ConstantStyle {
|
||||
OldConstantStyle({
|
||||
required super.concreteClassName,
|
||||
required super.staticType,
|
||||
});
|
||||
new({required super.concreteClassName, required super.staticType});
|
||||
}
|
||||
|
||||
/// [ConstantStyle] object indicating that a constant should be generated that
|
||||
@@ -34,7 +31,7 @@ class WithArgumentsConstantStyle extends ConstantStyle {
|
||||
/// The parameters that should be accepted by the `.withArguments` getter.
|
||||
final String withArgumentsParams;
|
||||
|
||||
WithArgumentsConstantStyle({
|
||||
new({
|
||||
required super.concreteClassName,
|
||||
required super.staticType,
|
||||
required this.withArgumentsParams,
|
||||
@@ -44,8 +41,5 @@ class WithArgumentsConstantStyle extends ConstantStyle {
|
||||
/// [ConstantStyle] object indicating that a constant should be generated that
|
||||
/// doesn't require any arguments.
|
||||
class WithoutArgumentsConstantStyle extends ConstantStyle {
|
||||
WithoutArgumentsConstantStyle({
|
||||
required super.concreteClassName,
|
||||
required super.staticType,
|
||||
});
|
||||
new({required super.concreteClassName, required super.staticType});
|
||||
}
|
||||
|
||||
@@ -282,7 +282,7 @@ List<String> _splitText(
|
||||
class AliasMessage extends AnalyzerMessage {
|
||||
String aliasFor;
|
||||
|
||||
AliasMessage(
|
||||
new(
|
||||
super.messageYaml, {
|
||||
required this.aliasFor,
|
||||
required super.analyzerCode,
|
||||
@@ -351,7 +351,7 @@ enum AnalyzerDiagnosticPackage {
|
||||
/// the `prefer_single_quotes` lint.
|
||||
final bool shouldIgnorePreferSingleQuotes;
|
||||
|
||||
const AnalyzerDiagnosticPackage({
|
||||
new({
|
||||
required this.diagnosticPathPart,
|
||||
required this.dirName,
|
||||
required this.permittedTypes,
|
||||
@@ -403,7 +403,7 @@ enum AnalyzerDiagnosticType {
|
||||
/// Base classes used for messages of this type.
|
||||
final DiagnosticBaseClasses baseClasses;
|
||||
|
||||
const AnalyzerDiagnosticType({this.baseClasses = analyzerBaseClasses});
|
||||
new({this.baseClasses = analyzerBaseClasses});
|
||||
|
||||
/// The representation of this type in analyzer source code.
|
||||
String get code => 'DiagnosticType.${name.toSnakeCase().toUpperCase()}';
|
||||
@@ -426,7 +426,7 @@ class AnalyzerMessage extends Message with MessageWithAnalyzerCode {
|
||||
@override
|
||||
final AnalyzerDiagnosticType type;
|
||||
|
||||
factory AnalyzerMessage(
|
||||
factory(
|
||||
MessageYaml messageYaml, {
|
||||
required DiagnosticCodeName analyzerCode,
|
||||
required AnalyzerDiagnosticPackage package,
|
||||
@@ -447,7 +447,7 @@ class AnalyzerMessage extends Message with MessageWithAnalyzerCode {
|
||||
}
|
||||
}
|
||||
|
||||
AnalyzerMessage.internal(
|
||||
new internal(
|
||||
MessageYaml messageYaml, {
|
||||
required this.analyzerCode,
|
||||
required this.package,
|
||||
@@ -487,7 +487,7 @@ class DiagnosticBaseClasses {
|
||||
/// require arguments.
|
||||
final String withoutArgumentsImplClass;
|
||||
|
||||
const DiagnosticBaseClasses({
|
||||
const new({
|
||||
required this.requiresTypeArgument,
|
||||
required this.withArgumentsClass,
|
||||
required this.withExpectedTypesClass,
|
||||
@@ -525,11 +525,7 @@ class DiagnosticClassInfo {
|
||||
/// If no documentation comment is needed, this should be the empty string.
|
||||
final String comment;
|
||||
|
||||
const DiagnosticClassInfo({
|
||||
required this.name,
|
||||
required this.type,
|
||||
this.comment = '',
|
||||
});
|
||||
const new({required this.name, required this.type, this.comment = ''});
|
||||
|
||||
static DiagnosticClassInfo byName(String name) =>
|
||||
_diagnosticClassesByName[name] ??
|
||||
|
||||
@@ -12,7 +12,7 @@ const _htmlEscape = HtmlEscape(HtmlEscapeMode.element);
|
||||
class Document extends Element {
|
||||
static const Set<String> selfClosing = {'br', 'link', 'meta'};
|
||||
|
||||
Document() : super.tag('');
|
||||
new() : super.tag('');
|
||||
|
||||
/// Return the full HTML text for the document.
|
||||
String get outerHtml {
|
||||
@@ -64,7 +64,7 @@ class Element extends Node {
|
||||
|
||||
Map<String, String> attributes = {};
|
||||
|
||||
Element.tag(this.name);
|
||||
new tag(this.name);
|
||||
|
||||
List<Element> get children => nodes.whereType<Element>().toList();
|
||||
|
||||
@@ -94,7 +94,7 @@ class Text extends Node {
|
||||
|
||||
final String text;
|
||||
|
||||
Text(this.text);
|
||||
new(this.text);
|
||||
|
||||
@override
|
||||
List<Node> get nodes => const [];
|
||||
|
||||
@@ -45,22 +45,19 @@ class LintMessage extends AnalyzerMessage {
|
||||
|
||||
final Map<LintStateName, Version>? state;
|
||||
|
||||
LintMessage(
|
||||
super.messageYaml, {
|
||||
required super.analyzerCode,
|
||||
required super.package,
|
||||
}) : categories = messageYaml.get(
|
||||
'categories',
|
||||
decode: decodeCategories,
|
||||
ifAbsent: () => null,
|
||||
),
|
||||
deprecatedDetails = messageYaml.getOptionalString('deprecatedDetails'),
|
||||
state = messageYaml.get(
|
||||
'state',
|
||||
decode: decodeState,
|
||||
ifAbsent: () => null,
|
||||
),
|
||||
super.internal();
|
||||
new(super.messageYaml, {required super.analyzerCode, required super.package})
|
||||
: categories = messageYaml.get(
|
||||
'categories',
|
||||
decode: decodeCategories,
|
||||
ifAbsent: () => null,
|
||||
),
|
||||
deprecatedDetails = messageYaml.getOptionalString('deprecatedDetails'),
|
||||
state = messageYaml.get(
|
||||
'state',
|
||||
decode: decodeState,
|
||||
ifAbsent: () => null,
|
||||
),
|
||||
super.internal();
|
||||
|
||||
static Set<LintCategory> decodeCategories(YamlNode node) {
|
||||
if (node is! YamlList) throw 'Must be a list';
|
||||
|
||||
@@ -9,7 +9,7 @@ class LocatedError {
|
||||
final SourceSpan span;
|
||||
final String message;
|
||||
|
||||
LocatedError(this.message, {required this.span});
|
||||
new(this.message, {required this.span});
|
||||
|
||||
@override
|
||||
String toString() => '${span.location}: $message';
|
||||
|
||||
@@ -155,7 +155,7 @@ abstract class CfeStyleMessage extends Message {
|
||||
/// `messages.yaml`.
|
||||
final DiagnosticCodeName frontEndCode;
|
||||
|
||||
CfeStyleMessage(MessageYaml messageYaml)
|
||||
new(MessageYaml messageYaml)
|
||||
: cfeSeverity = messageYaml.get(
|
||||
'severity',
|
||||
decode: (node) {
|
||||
@@ -244,7 +244,7 @@ class DiagnosticCodeName implements Comparable<DiagnosticCodeName> {
|
||||
/// capitalized words, with no separation between words).
|
||||
final String camelCaseName;
|
||||
|
||||
DiagnosticCodeName.fromCamelCase(this.camelCaseName)
|
||||
new fromCamelCase(this.camelCaseName)
|
||||
: snakeCaseName =
|
||||
_snakeCaseExceptions[camelCaseName] ?? camelCaseName.toSnakeCase() {
|
||||
if (snakeCaseName.toLowerCase() != snakeCaseName) {
|
||||
@@ -288,7 +288,7 @@ class DiagnosticParameter {
|
||||
final String comment;
|
||||
final int index;
|
||||
|
||||
DiagnosticParameter({
|
||||
new({
|
||||
required this.name,
|
||||
required this.type,
|
||||
required this.comment,
|
||||
@@ -399,7 +399,7 @@ enum DiagnosticParameterType {
|
||||
/// sufficient.
|
||||
final Conversion? cfeConversion;
|
||||
|
||||
const DiagnosticParameterType({
|
||||
new({
|
||||
required this.messagesYamlName,
|
||||
this._analyzerName,
|
||||
this.cfeName,
|
||||
@@ -407,7 +407,7 @@ enum DiagnosticParameterType {
|
||||
});
|
||||
|
||||
/// Decodes a type name from `messages.yaml` into a [DiagnosticParameterType].
|
||||
factory DiagnosticParameterType.fromMessagesYamlName(String name) =>
|
||||
factory fromMessagesYamlName(String name) =>
|
||||
_messagesYamlNameToValue[name] ?? (throw 'Unknown type name: $name');
|
||||
|
||||
String get analyzerName =>
|
||||
@@ -444,7 +444,7 @@ class DiagnosticTables {
|
||||
/// Map from [DiagnosticCodeName.pascalCaseName] to front end diagnostic.
|
||||
final Map<String, CfeStyleMessage> frontEndDiagnosticsByPascalCaseName = {};
|
||||
|
||||
DiagnosticTables._(List<Message> messages) {
|
||||
new _(List<Message> messages) {
|
||||
var frontEndCodeDuplicateChecker = _DuplicateChecker<DiagnosticCodeName>(
|
||||
kind: 'Front end code',
|
||||
);
|
||||
@@ -538,7 +538,7 @@ class FrontEndMessage extends CfeStyleMessage {
|
||||
// codes.
|
||||
final String? pseudoSharedCode;
|
||||
|
||||
FrontEndMessage(super.messageYaml)
|
||||
new(super.messageYaml)
|
||||
: pseudoSharedCode = messageYaml.getOptionalString('pseudoSharedCode');
|
||||
}
|
||||
|
||||
@@ -547,7 +547,7 @@ class LabelerConversion implements Conversion {
|
||||
/// The name of the [TypeLabeler] method to call.
|
||||
final String methodName;
|
||||
|
||||
const LabelerConversion(this.methodName);
|
||||
const new(this.methodName);
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType, methodName.hashCode);
|
||||
@@ -623,7 +623,7 @@ abstract class Message {
|
||||
final String keyString;
|
||||
|
||||
/// Decodes a [Message] object from its YAML representation.
|
||||
Message(MessageYaml messageYaml, {bool requireProblemMessage = false})
|
||||
new(MessageYaml messageYaml, {bool requireProblemMessage = false})
|
||||
: comment = messageYaml.getOptionalString('comment'),
|
||||
correctionMessage = messageYaml.getMessageTemplate(
|
||||
'correctionMessage',
|
||||
@@ -691,7 +691,7 @@ class MessageYaml {
|
||||
/// this set, an exception will be thrown to report them as unexpected keys.
|
||||
final Set<String> _permittedKeys = {};
|
||||
|
||||
MessageYaml._(this._key, this._map);
|
||||
new _(this._key, this._map);
|
||||
|
||||
/// The span of the YAML key node from the key/value pair that defines the
|
||||
/// message.
|
||||
@@ -894,7 +894,7 @@ class NumericConversion implements Conversion {
|
||||
/// used.
|
||||
final bool padWithZeros;
|
||||
|
||||
NumericConversion({
|
||||
new({
|
||||
required this.fractionDigits,
|
||||
required this.padWidth,
|
||||
required this.padWithZeros,
|
||||
@@ -974,7 +974,7 @@ class SharedMessage extends CfeStyleMessage with MessageWithAnalyzerCode {
|
||||
@override
|
||||
final AnalyzerDiagnosticType type;
|
||||
|
||||
SharedMessage(super.messageYaml)
|
||||
new(super.messageYaml)
|
||||
: analyzerCode = messageYaml.get(
|
||||
'analyzerCode',
|
||||
decode: _decodeAnalyzerCode,
|
||||
@@ -1006,7 +1006,7 @@ class SimpleConversion implements Conversion {
|
||||
/// The name of the function to be invoked.
|
||||
final String functionName;
|
||||
|
||||
const SimpleConversion(this.functionName);
|
||||
const new(this.functionName);
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType, functionName.hashCode);
|
||||
@@ -1028,7 +1028,7 @@ class TemplateLiteralPart implements TemplatePart {
|
||||
/// The literal text.
|
||||
final String text;
|
||||
|
||||
TemplateLiteralPart(this.text);
|
||||
new(this.text);
|
||||
}
|
||||
|
||||
/// [TemplatePart] representing a parameter to be substituted into the
|
||||
@@ -1044,7 +1044,7 @@ class TemplateParameterPart implements TemplatePart {
|
||||
|
||||
/// Builds a [TemplateParameterPart] from the given [match] of
|
||||
/// [placeholderPattern].
|
||||
factory TemplateParameterPart.fromMatch(
|
||||
factory fromMatch(
|
||||
Match match, {
|
||||
required Map<String, DiagnosticParameter> parameters,
|
||||
}) {
|
||||
@@ -1060,10 +1060,7 @@ class TemplateParameterPart implements TemplatePart {
|
||||
);
|
||||
}
|
||||
|
||||
TemplateParameterPart._({
|
||||
required this.parameter,
|
||||
required this.conversionOverride,
|
||||
});
|
||||
new _({required this.parameter, required this.conversionOverride});
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(parameter, conversionOverride);
|
||||
@@ -1085,7 +1082,7 @@ class _DuplicateChecker<Code> {
|
||||
final Map<Code, List<Message>> _codeToMessages = {};
|
||||
final String kind;
|
||||
|
||||
_DuplicateChecker({required this.kind});
|
||||
new({required this.kind});
|
||||
|
||||
void operator []=(Code code, Message message) {
|
||||
(_codeToMessages[code] ??= []).add(message);
|
||||
|
||||
@@ -12,7 +12,7 @@ class MapEntryMatcher extends Matcher {
|
||||
final Matcher keyMatcher;
|
||||
final Matcher valueMatcher;
|
||||
|
||||
MapEntryMatcher(Object? key, Object? value)
|
||||
new(Object? key, Object? value)
|
||||
: keyMatcher = wrapMatcher(key),
|
||||
valueMatcher = wrapMatcher(value);
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ class TreeStringSink {
|
||||
final StringSink _sink;
|
||||
String _indent = '';
|
||||
|
||||
TreeStringSink({required this._sink, required this._indent});
|
||||
new({required this._sink, required this._indent});
|
||||
|
||||
void withIndent(void Function() f) {
|
||||
var indent = _indent;
|
||||
|
||||
@@ -53,7 +53,7 @@ class _TextFormatter with CodeGenerator {
|
||||
/// True if the output should be Javadoc compatible.
|
||||
final bool javadocStyle;
|
||||
|
||||
_TextFormatter(this.width, this.javadocStyle);
|
||||
new(this.width, this.javadocStyle);
|
||||
|
||||
/// Process an HTML node.
|
||||
void add(dom.Node node) {
|
||||
|
||||
@@ -232,7 +232,7 @@ class CodeGeneratorSettings {
|
||||
/// String used for indenting code.
|
||||
String indent;
|
||||
|
||||
CodeGeneratorSettings({
|
||||
new({
|
||||
this.languageName = 'java',
|
||||
this.lineCommentLineLeader = '// ',
|
||||
this.docCommentStartMarker = '/**',
|
||||
@@ -322,7 +322,7 @@ class GeneratedDirectory extends GeneratedContent {
|
||||
/// Callback function that computes the directory contents.
|
||||
final DirectoryContentsComputer directoryContentsComputer;
|
||||
|
||||
GeneratedDirectory(this.outputDirPath, this.directoryContentsComputer);
|
||||
new(this.outputDirPath, this.directoryContentsComputer);
|
||||
|
||||
@override
|
||||
Future<void> generate(String pkgRoot) async {
|
||||
@@ -366,7 +366,7 @@ class GeneratedFile extends GeneratedContent {
|
||||
/// Callback function which computes the file.
|
||||
final FileContentsComputer computeContents;
|
||||
|
||||
GeneratedFile(this.outputPath, this.computeContents);
|
||||
new(this.outputPath, this.computeContents);
|
||||
|
||||
bool get isDartFile => outputPath.endsWith('.dart');
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ class VerifyTests {
|
||||
/// Paths to exclude from analysis completely.
|
||||
final List<String>? excludedPaths;
|
||||
|
||||
VerifyTests(this.testDirPath, {this.excludedPaths});
|
||||
new(this.testDirPath, {this.excludedPaths});
|
||||
|
||||
/// Build tests.
|
||||
void build({bool Function(AnalysisContext)? analysisContextPredicate}) {
|
||||
|
||||
@@ -3,7 +3,7 @@ name: analyzer_utilities
|
||||
publish_to: none
|
||||
|
||||
environment:
|
||||
sdk: '^3.12.0-0'
|
||||
sdk: '^3.13.0-0'
|
||||
|
||||
resolution: workspace
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ class _Visitor extends RecursiveAstVisitor<void> {
|
||||
|
||||
final List<void Function(DartFileEditBuilder)> changes = [];
|
||||
|
||||
_Visitor({
|
||||
new({
|
||||
required this.rejectStats,
|
||||
required this.fileContents,
|
||||
required this.path,
|
||||
|
||||
@@ -113,7 +113,7 @@ class _Visitor extends RecursiveAstVisitor<void> {
|
||||
|
||||
final List<void Function(DartFileEditBuilder)> changes = [];
|
||||
|
||||
_Visitor({
|
||||
new({
|
||||
required this.rejectStats,
|
||||
required this.fileContents,
|
||||
required this.path,
|
||||
|
||||
Reference in New Issue
Block a user