[analyzer/linter] Surface links to available lint diagnostic messages

Dependent on https://github.com/dart-lang/site-www/pull/5914 landing first.

Bug: https://github.com/dart-lang/site-www/issues/4498
Change-Id: I378debd5d484e17f18d59c49173a5d010f05b6df
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371785
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Sam Rawlins <srawlins@google.com>
This commit is contained in:
Parker Lougheed 2024-06-17 14:51:31 +00:00 committed by Commit Queue
parent 56416078a0
commit 91254e4064
117 changed files with 276 additions and 164 deletions

View file

@ -10,16 +10,13 @@ import 'package:analyzer/error/error.dart';
/// compiler, lint recommendations focus on matters of style and practices that
/// might aggregated to define a project's style guide.
class LintCode extends ErrorCode {
final String? _url;
const LintCode(
String name,
String problemMessage, {
super.correctionMessage,
super.hasPublishedDocs,
String? uniqueName,
String? url,
}) : _url = url,
super(
}) : super(
problemMessage: problemMessage,
name: name,
uniqueName: uniqueName ?? 'LintCode.$name',
@ -35,7 +32,7 @@ class LintCode extends ErrorCode {
ErrorType get type => ErrorType.LINT;
@override
String get url => _url ?? 'https://dart.dev/lints/$name';
String get url => super.url ?? 'https://dart.dev/lints/$name';
@override
bool operator ==(Object other) =>

View file

@ -211,10 +211,6 @@ abstract class LintRule {
/// `bin`.
final String? documentation;
/// A flag indicating whether this lint has documentation on the Diagnostic
/// messages page.
final bool hasDocumentation;
/// The state of a lint, and optionally since when the state began.
final State state;
@ -225,7 +221,6 @@ abstract class LintRule {
required this.details,
State? state,
this.documentation,
this.hasDocumentation = false,
}) : state = state ?? State.stable();
/// Indicates whether the lint rule can work with just the parsed information

View file

@ -18,6 +18,18 @@ import '../../generated/test_support.dart';
main() {
group('lint rule', () {
group('code creation', () {
test('without published diagnostic docs', () {
expect(customCode.url,
equals('https://dart.dev/lints/${customCode.name}'));
});
test('with published diagnostic docs', () {
expect(customCodeWithDocs.url,
equals('https://dart.dev/diagnostics/${customCodeWithDocs.name}'));
});
});
group('error code reporting', () {
test('reportLintForToken (custom)', () {
var rule = TestRule();
@ -70,6 +82,10 @@ const LintCode customCode = LintCode(
'hash_and_equals', 'Override `==` if overriding `hashCode`.',
correctionMessage: 'Implement `==`.');
const LintCode customCodeWithDocs = LintCode(
'hash_and_equals', 'Override `==` if overriding `hashCode`.',
correctionMessage: 'Implement `==`.', hasPublishedDocs: true);
class CollectingReporter extends ErrorReporter {
ErrorCode? code;

View file

@ -24204,7 +24204,9 @@ Iterable<String> get zero sync* {
### always_declare_return_types
_Missing return type on method._
_The function '{0}' should have a return type but doesn't._
_The method '{0}' should have a return type but doesn't._
#### Description

View file

@ -46,9 +46,15 @@ typedef predicate = bool Function(Object o);
''';
class AlwaysDeclareReturnTypes extends LintRule {
static const LintCode code = LintCode(
'always_declare_return_types', 'Missing return type on method.',
correctionMessage: 'Try adding a return type.');
static const LintCode functionCode = LintCode('always_declare_return_types',
"The function '{0}' should have a return type but doesn't.",
correctionMessage: 'Try adding a return type to the function.',
hasPublishedDocs: true);
static const LintCode methodCode = LintCode('always_declare_return_types',
"The method '{0}' should have a return type but doesn't.",
correctionMessage: 'Try adding a return type to the method.',
hasPublishedDocs: true);
AlwaysDeclareReturnTypes()
: super(
@ -58,7 +64,7 @@ class AlwaysDeclareReturnTypes extends LintRule {
categories: {Category.style});
@override
LintCode get lintCode => code;
List<LintCode> get lintCodes => [functionCode, methodCode];
@override
void registerNodeProcessors(
@ -71,18 +77,6 @@ class AlwaysDeclareReturnTypes extends LintRule {
}
class _Visitor extends SimpleAstVisitor<void> {
static const LintCode functionCode = LintCode(
"always_declare_return_types", // ignore: prefer_single_quotes
"The function '{0}' should have a return type but doesn't.",
correctionMessage:
"Try adding a return type to the function."); // ignore: prefer_single_quotes
static const LintCode methodCode = LintCode(
"always_declare_return_types", // ignore: prefer_single_quotes
"The method '{0}' should have a return type but doesn't.",
correctionMessage:
"Try adding a return type to the method."); // ignore: prefer_single_quotes
final LintRule rule;
_Visitor(this.rule);
@ -91,7 +85,8 @@ class _Visitor extends SimpleAstVisitor<void> {
void visitFunctionDeclaration(FunctionDeclaration node) {
if (!node.isSetter && node.returnType == null && !node.isAugmentation) {
rule.reportLintForToken(node.name,
arguments: [node.name.lexeme], errorCode: functionCode);
arguments: [node.name.lexeme],
errorCode: AlwaysDeclareReturnTypes.functionCode);
}
}
@ -99,7 +94,8 @@ class _Visitor extends SimpleAstVisitor<void> {
void visitFunctionTypeAlias(FunctionTypeAlias node) {
if (node.returnType == null) {
rule.reportLintForToken(node.name,
arguments: [node.name.lexeme], errorCode: functionCode);
arguments: [node.name.lexeme],
errorCode: AlwaysDeclareReturnTypes.functionCode);
}
}
@ -110,7 +106,8 @@ class _Visitor extends SimpleAstVisitor<void> {
node.name.type != TokenType.INDEX_EQ &&
!node.isAugmentation) {
rule.reportLintForToken(node.name,
arguments: [node.name.lexeme], errorCode: methodCode);
arguments: [node.name.lexeme],
errorCode: AlwaysDeclareReturnTypes.methodCode);
}
}
}

View file

@ -52,7 +52,8 @@ when the Dart formatter is used.
class AlwaysPutControlBodyOnNewLine extends LintRule {
static const LintCode code = LintCode('always_put_control_body_on_new_line',
'Statement should be on a separate line.',
correctionMessage: 'Try moving the statement to a new line.');
correctionMessage: 'Try moving the statement to a new line.',
hasPublishedDocs: true);
AlwaysPutControlBodyOnNewLine()
: super(

View file

@ -40,7 +40,8 @@ class AlwaysPutRequiredNamedParametersFirst extends LintRule {
'Required named parameters should be before optional named parameters.',
correctionMessage:
'Try moving the required named parameter to be before any optional '
'named parameters.');
'named parameters.',
hasPublishedDocs: true);
AlwaysPutRequiredNamedParametersFirst()
: super(

View file

@ -48,7 +48,8 @@ import 'package:foo/src/baz.dart';
class AlwaysUsePackageImports extends LintRule {
static const LintCode code = LintCode('always_use_package_imports',
"Use 'package:' imports for files in the 'lib' directory.",
correctionMessage: "Try converting the URI to a 'package:' URI.");
correctionMessage: "Try converting the URI to a 'package:' URI.",
hasPublishedDocs: true);
AlwaysUsePackageImports()
: super(

View file

@ -51,7 +51,8 @@ class AnnotateOverrides extends LintRule {
'annotate_overrides',
"The member '{0}' overrides an inherited member but isn't annotated "
"with '@override'.",
correctionMessage: "Try adding the '@override' annotation.");
correctionMessage: "Try adding the '@override' annotation.",
hasPublishedDocs: true);
AnnotateOverrides()
: super(

View file

@ -56,7 +56,8 @@ class AvoidEmptyElse extends LintRule {
static const LintCode code = LintCode('avoid_empty_else',
"Empty statements are not allowed in an 'else' clause.",
correctionMessage:
'Try removing the empty statement or removing the else clause.');
'Try removing the empty statement or removing the else clause.',
hasPublishedDocs: true);
AvoidEmptyElse()
: super(

View file

@ -62,7 +62,8 @@ class AvoidFunctionLiteralsInForeachCalls extends LintRule {
static const LintCode code = LintCode(
'avoid_function_literals_in_foreach_calls',
"Function literals shouldn't be passed to 'forEach'.",
correctionMessage: "Try using a 'for' loop.");
correctionMessage: "Try using a 'for' loop.",
hasPublishedDocs: true);
AvoidFunctionLiteralsInForeachCalls()
: super(

View file

@ -61,7 +61,8 @@ Item? bestDeal(List<Item> cart) {
class AvoidInitToNull extends LintRule {
static const LintCode code = LintCode(
'avoid_init_to_null', "Redundant initialization to 'null'.",
correctionMessage: 'Try removing the initializer.');
correctionMessage: 'Try removing the initializer.',
hasPublishedDocs: true);
AvoidInitToNull()
: super(

View file

@ -60,7 +60,8 @@ void f(int x) {
class AvoidPrint extends LintRule {
static const LintCode code = LintCode(
'avoid_print', "Don't invoke 'print' in production code.",
correctionMessage: 'Try using a logging framework.');
correctionMessage: 'Try using a logging framework.',
hasPublishedDocs: true);
AvoidPrint()
: super(

View file

@ -45,7 +45,8 @@ class AvoidRelativeLibImports extends LintRule {
"Can't use a relative path to import a library in 'lib'.",
correctionMessage:
"Try fixing the relative path or changing the import to a 'package:' "
'import.');
'import.',
hasPublishedDocs: true);
AvoidRelativeLibImports()
: super(

View file

@ -50,7 +50,8 @@ class AvoidRenamingMethodParameters extends LintRule {
'avoid_renaming_method_parameters',
"The parameter name '{0}' doesn't match the name '{1}' in the overridden "
'method.',
correctionMessage: "Try changing the name to '{1}'.");
correctionMessage: "Try changing the name to '{1}'.",
hasPublishedDocs: true);
AvoidRenamingMethodParameters()
: super(

View file

@ -29,7 +29,8 @@ set speed(int ms);
class AvoidReturnTypesOnSetters extends LintRule {
static const LintCode code = LintCode(
'avoid_return_types_on_setters', 'Unnecessary return type on a setter.',
correctionMessage: 'Try removing the return type.');
correctionMessage: 'Try removing the return type.',
hasPublishedDocs: true);
AvoidReturnTypesOnSetters()
: super(

View file

@ -48,7 +48,7 @@ class AvoidReturningNullForVoid extends LintRule {
static const LintCode fromMethod = LintCode('avoid_returning_null_for_void',
"Don't return 'null' from a method with a return type of 'void'.",
correctionMessage: "Try removing the 'null'.");
correctionMessage: "Try removing the 'null'.", hasPublishedDocs: true);
AvoidReturningNullForVoid()
: super(

View file

@ -31,7 +31,8 @@ class A<T> {
class AvoidShadowingTypeParameters extends LintRule {
static const LintCode code = LintCode('avoid_shadowing_type_parameters',
"The type parameter '{0}' shadows a type parameter from the enclosing {1}.",
correctionMessage: 'Try renaming one of the type parameters.');
correctionMessage: 'Try renaming one of the type parameters.',
hasPublishedDocs: true);
AvoidShadowingTypeParameters()
: super(

View file

@ -29,7 +29,8 @@ class AvoidSingleCascadeInExpressionStatements extends LintRule {
static const LintCode code = LintCode(
'avoid_single_cascade_in_expression_statements',
'Unnecessary cascade expression.',
correctionMessage: "Try using the operator '{0}'.");
correctionMessage: "Try using the operator '{0}'.",
hasPublishedDocs: true);
AvoidSingleCascadeInExpressionStatements()
: super(

View file

@ -71,7 +71,8 @@ const List<String> _fileSystemEntityMethodNames = <String>[
class AvoidSlowAsyncIo extends LintRule {
static const LintCode code = LintCode(
'avoid_slow_async_io', "Use of an async 'dart:io' method.",
correctionMessage: 'Try using the synchronous version of the method.');
correctionMessage: 'Try using the synchronous version of the method.',
hasPublishedDocs: true);
AvoidSlowAsyncIo()
: super(

View file

@ -52,7 +52,8 @@ Object baz(Thing myThing) {
class AvoidTypeToString extends LintRule {
static const LintCode code = LintCode('avoid_type_to_string',
"Using 'toString' on a 'Type' is not safe in production code.");
"Using 'toString' on a 'Type' is not safe in production code.",
hasPublishedDocs: true);
AvoidTypeToString()
: super(

View file

@ -32,7 +32,8 @@ class AvoidTypesAsParameterNames extends LintRule {
"The parameter name '{0}' matches a visible type name.",
correctionMessage:
'Try adding a name for the parameter or changing the parameter name '
'to not match an existing type.');
'to not match an existing type.',
hasPublishedDocs: true);
AvoidTypesAsParameterNames()
: super(

View file

@ -52,7 +52,8 @@ class AvoidUnnecessaryContainers extends LintRule {
'avoid_unnecessary_containers', "Unnecessary instance of 'Container'.",
correctionMessage:
"Try removing the 'Container' (but not its children) from the "
'widget tree.');
'widget tree.',
hasPublishedDocs: true);
AvoidUnnecessaryContainers()
: super(

View file

@ -45,7 +45,8 @@ YamlMap _parseYaml(String content) {
class AvoidWebLibrariesInFlutter extends LintRule {
static const LintCode code = LintCode('avoid_web_libraries_in_flutter',
"Don't use web-only libraries outside Flutter web plugin packages.",
correctionMessage: 'Try finding a different library for your needs.');
correctionMessage: 'Try finding a different library for your needs.',
hasPublishedDocs: true);
/// Cache of most recent analysis root to parsed "hasFlutter" state.
static final Map<String, bool> _rootHasFlutterCache = {};

View file

@ -39,8 +39,8 @@ main() async {
class AwaitOnlyFutures extends LintRule {
static const LintCode code = LintCode('await_only_futures',
"Uses 'await' on an instance of '{0}', which is not a subtype of 'Future'.",
correctionMessage:
"Try removing the 'await' or changing the expression.");
correctionMessage: "Try removing the 'await' or changing the expression.",
hasPublishedDocs: true);
AwaitOnlyFutures()
: super(

View file

@ -34,7 +34,8 @@ class CamelCaseExtensions extends LintRule {
static const LintCode code = LintCode('camel_case_extensions',
"The extension name '{0}' isn't an UpperCamelCase identifier.",
correctionMessage:
'Try changing the name to follow the UpperCamelCase style.');
'Try changing the name to follow the UpperCamelCase style.',
hasPublishedDocs: true);
CamelCaseExtensions()
: super(

View file

@ -39,7 +39,8 @@ class CamelCaseTypes extends LintRule {
static const LintCode code = LintCode('camel_case_types',
"The type name '{0}' isn't an UpperCamelCase identifier.",
correctionMessage:
'Try changing the name to follow the UpperCamelCase style.');
'Try changing the name to follow the UpperCamelCase style.',
hasPublishedDocs: true);
CamelCaseTypes()
: super(

View file

@ -67,7 +67,8 @@ class CancelSubscriptions extends LintRule {
static const LintCode code = LintCode(
'cancel_subscriptions', "Uncancelled instance of 'StreamSubscription'.",
correctionMessage: "Try invoking 'cancel' in the function in which the "
"'StreamSubscription' was created.");
"'StreamSubscription' was created.",
hasPublishedDocs: true);
CancelSubscriptions()
: super(

View file

@ -67,7 +67,8 @@ class CloseSinks extends LintRule {
'close_sinks', "Unclosed instance of 'Sink'.",
correctionMessage:
"Try invoking 'close' in the function in which the 'Sink' was "
'created.');
'created.',
hasPublishedDocs: true);
CloseSinks()
: super(

View file

@ -70,7 +70,8 @@ void someFunction() {
class CollectionMethodsUnrelatedType extends LintRule {
static const LintCode code = LintCode('collection_methods_unrelated_type',
"The argument type '{0}' isn't related to '{1}'.");
"The argument type '{0}' isn't related to '{1}'.",
hasPublishedDocs: true);
CollectionMethodsUnrelatedType()
: super(

View file

@ -48,7 +48,8 @@ class ConstantIdentifierNames extends LintRule {
static const LintCode code = LintCode('constant_identifier_names',
"The constant name '{0}' isn't a lowerCamelCase identifier.",
correctionMessage:
'Try changing the name to follow the lowerCamelCase style.');
'Try changing the name to follow the lowerCamelCase style.',
hasPublishedDocs: true);
ConstantIdentifierNames()
: super(

View file

@ -86,7 +86,7 @@ class Ok {
class ControlFlowInFinally extends LintRule {
static const LintCode code = LintCode(
'control_flow_in_finally', "Use of '{0}' in a 'finally' clause.",
correctionMessage: 'Try restructuring the code.');
correctionMessage: 'Try restructuring the code.', hasPublishedDocs: true);
ControlFlowInFinally()
: super(

View file

@ -54,7 +54,8 @@ class CurlyBracesInFlowControlStructures extends LintRule {
static const LintCode code = LintCode(
'curly_braces_in_flow_control_structures',
'Statements in {0} should be enclosed in a block.',
correctionMessage: 'Try wrapping the statement in a block.');
correctionMessage: 'Try wrapping the statement in a block.',
hasPublishedDocs: true);
CurlyBracesInFlowControlStructures()
: super(

View file

@ -44,8 +44,8 @@ provide a name in the `library` directive.
class DanglingLibraryDocComments extends LintRule {
static const LintCode code = LintCode(
'dangling_library_doc_comments', 'Dangling library doc comment.',
correctionMessage:
"Add a 'library' directive after the library comment.");
correctionMessage: "Add a 'library' directive after the library comment.",
hasPublishedDocs: true);
DanglingLibraryDocComments()
: super(

View file

@ -52,7 +52,8 @@ class EmptyCatches extends LintRule {
static const LintCode code = LintCode('empty_catches', 'Empty catch block.',
correctionMessage:
'Try adding statements to the block, adding a comment to the block, '
"or removing the 'catch' clause.");
"or removing the 'catch' clause.",
hasPublishedDocs: true);
EmptyCatches()
: super(

View file

@ -39,7 +39,8 @@ class Point {
class EmptyConstructorBodies extends LintRule {
static const LintCode code = LintCode('empty_constructor_bodies',
"Empty constructor bodies should be written using a ';' rather than '{}'.",
correctionMessage: "Try replacing the constructor body with ';'.");
correctionMessage: "Try replacing the constructor body with ';'.",
hasPublishedDocs: true);
EmptyConstructorBodies()
: super(

View file

@ -44,7 +44,8 @@ class EmptyStatements extends LintRule {
static const LintCode code = LintCode(
'empty_statements', 'Unnecessary empty statement.',
correctionMessage:
'Try removing the empty statement or restructuring the code.');
'Try removing the empty statement or restructuring the code.',
hasPublishedDocs: true);
EmptyStatements()
: super(

View file

@ -47,7 +47,8 @@ class FileNames extends LintRule {
"The file name '{0}' isn't a lower_case_with_underscores identifier.",
correctionMessage:
'Try changing the name to follow the lower_case_with_underscores '
'style.');
'style.',
hasPublishedDocs: true);
FileNames()
: super(

View file

@ -55,7 +55,8 @@ class Better {
class HashAndEquals extends LintRule {
static const LintCode code = LintCode(
'hash_and_equals', "Missing a corresponding override of '{0}'.",
correctionMessage: "Try overriding '{0}' or removing '{1}'.");
correctionMessage: "Try overriding '{0}' or removing '{1}'.",
hasPublishedDocs: true);
HashAndEquals()
: super(

View file

@ -63,7 +63,8 @@ class ImplementationImports extends LintRule {
"Import of a library in the 'lib/src' directory of another package.",
correctionMessage:
'Try importing a public library that exports this library, or '
'removing the import.');
'removing the import.',
hasPublishedDocs: true);
ImplementationImports()
: super(

View file

@ -45,7 +45,8 @@ callIt(Callable().call);
class ImplicitCallTearoffs extends LintRule {
static const LintCode code = LintCode(
'implicit_call_tearoffs', "Implicit tear-off of the 'call' method.",
correctionMessage: "Try explicitly tearing off the 'call' method.");
correctionMessage: "Try explicitly tearing off the 'call' method.",
hasPublishedDocs: true);
ImplicitCallTearoffs()
: super(

View file

@ -39,7 +39,8 @@ class LibraryNames extends LintRule {
"The library name '{0}' isn't a lower_case_with_underscores identifier.",
correctionMessage:
'Try changing the name to follow the lower_case_with_underscores '
'style.');
'style.',
hasPublishedDocs: true);
LibraryNames()
: super(

View file

@ -33,11 +33,13 @@ import 'package:javascript_utils/javascript_utils.dart' as js_utils;
''';
class LibraryPrefixes extends LintRule {
static const LintCode code = LintCode('library_prefixes',
"The prefix '{0}' isn't a lower_case_with_underscores identifier.",
correctionMessage:
'Try changing the prefix to follow the lower_case_with_underscores '
'style.');
static const LintCode code =
LintCode('library_prefixes',
"The prefix '{0}' isn't a lower_case_with_underscores identifier.",
correctionMessage:
'Try changing the prefix to follow the lower_case_with_underscores '
'style.',
hasPublishedDocs: true);
LibraryPrefixes()
: super(

View file

@ -46,7 +46,8 @@ class LibraryPrivateTypesInPublicApi extends LintRule {
'Invalid use of a private type in a public API.',
correctionMessage:
'Try making the private type public, or making the API that uses the '
'private type also be private.');
'private type also be private.',
hasPublishedDocs: true);
LibraryPrivateTypesInPublicApi()
: super(

View file

@ -112,7 +112,8 @@ bool _onlyLiterals(Expression? rawExpression) {
class LiteralOnlyBooleanExpressions extends LintRule {
static const LintCode code = LintCode('literal_only_boolean_expressions',
'The Boolean expression has a constant value.',
correctionMessage: 'Try changing the expression.');
correctionMessage: 'Try changing the expression.',
hasPublishedDocs: true);
LiteralOnlyBooleanExpressions()
: super(

View file

@ -37,7 +37,8 @@ List<String> list = <String>[
class NoAdjacentStringsInList extends LintRule {
static const LintCode code = LintCode('no_adjacent_strings_in_list',
"Don't use adjacent strings in a list literal.",
correctionMessage: 'Try adding a comma between the strings.');
correctionMessage: 'Try adding a comma between the strings.',
hasPublishedDocs: true);
NoAdjacentStringsInList()
: super(

View file

@ -46,7 +46,8 @@ class NoDuplicateCaseValues extends LintRule {
'no_duplicate_case_values',
"The value of the case clause ('{0}') is equal to the value of an "
"earlier case clause ('{1}').",
correctionMessage: 'Try removing or changing the value.');
correctionMessage: 'Try removing or changing the value.',
hasPublishedDocs: true);
NoDuplicateCaseValues()
: super(

View file

@ -32,7 +32,8 @@ class NoLeadingUnderscoresForLibraryPrefixes extends LintRule {
'no_leading_underscores_for_library_prefixes',
"The library prefix '{0}' starts with an underscore.",
correctionMessage:
'Try renaming the prefix to not start with an underscore.');
'Try renaming the prefix to not start with an underscore.',
hasPublishedDocs: true);
NoLeadingUnderscoresForLibraryPrefixes()
: super(

View file

@ -54,7 +54,8 @@ class NoLeadingUnderscoresForLocalIdentifiers extends LintRule {
'no_leading_underscores_for_local_identifiers',
"The local variable '{0}' starts with an underscore.",
correctionMessage:
'Try renaming the variable to not start with an underscore.');
'Try renaming the variable to not start with an underscore.',
hasPublishedDocs: true);
NoLeadingUnderscoresForLocalIdentifiers()
: super(

View file

@ -61,7 +61,8 @@ class MyStateful extends StatefulWidget {
class NoLogicInCreateState extends LintRule {
static const LintCode code = LintCode(
'no_logic_in_create_state', "Don't put any logic in 'createState'.",
correctionMessage: "Try moving the logic out of 'createState'.");
correctionMessage: "Try moving the logic out of 'createState'.",
hasPublishedDocs: true);
NoLogicInCreateState()
: super(

View file

@ -47,7 +47,8 @@ var [a, _, b, _] = [1, 2, 3, 4];
class NoWildcardVariableUses extends LintRule {
static const LintCode code = LintCode(
'no_wildcard_variable_uses', 'The referenced identifier is a wildcard.',
correctionMessage: 'Use an identifier name that is not a wildcard.');
correctionMessage: 'Use an identifier name that is not a wildcard.',
hasPublishedDocs: true);
NoWildcardVariableUses()
: super(

View file

@ -37,7 +37,8 @@ class NonConstantIdentifierNames extends LintRule {
static const LintCode code = LintCode('non_constant_identifier_names',
"The variable name '{0}' isn't a lowerCamelCase identifier.",
correctionMessage:
'Try changing the name to follow the lowerCamelCase style.');
'Try changing the name to follow the lowerCamelCase style.',
hasPublishedDocs: true);
NonConstantIdentifierNames()
: super(

View file

@ -48,7 +48,8 @@ class NullCheckOnNullableTypeParameter extends LintRule {
'null_check_on_nullable_type_parameter',
"The null check operator shouldn't be used on a variable whose type is a "
'potentially nullable type parameter.',
correctionMessage: "Try explicitly testing for 'null'.");
correctionMessage: "Try explicitly testing for 'null'.",
hasPublishedDocs: true);
NullCheckOnNullableTypeParameter()
: super(

View file

@ -102,7 +102,8 @@ class OverriddenFields extends LintRule {
'overridden_fields', "Field overrides a field inherited from '{0}'.",
correctionMessage:
'Try removing the field, overriding the getter and setter if '
'necessary.');
'necessary.',
hasPublishedDocs: true);
OverriddenFields()
: super(

View file

@ -55,7 +55,8 @@ class PackagePrefixedLibraryNames extends LintRule {
'package_prefixed_library_names',
'The library name is not a dot-separated path prefixed by the package '
'name.',
correctionMessage: "Try changing the name to '{0}'.");
correctionMessage: "Try changing the name to '{0}'.",
hasPublishedDocs: true);
PackagePrefixedLibraryNames()
: super(

View file

@ -31,7 +31,8 @@ raiseAlarm(
class PreferAdjacentStringConcatenation extends LintRule {
static const LintCode code = LintCode('prefer_adjacent_string_concatenation',
"String literals shouldn't be concatenated by the '+' operator.",
correctionMessage: 'Try removing the operator to use adjacent strings.');
correctionMessage: 'Try removing the operator to use adjacent strings.',
hasPublishedDocs: true);
PreferAdjacentStringConcatenation()
: super(

View file

@ -59,7 +59,8 @@ void printHashMap(LinkedHashMap map) => printMap(map);
class PreferCollectionLiterals extends LintRule {
static const LintCode code = LintCode(
'prefer_collection_literals', 'Unnecessary constructor invocation.',
correctionMessage: 'Try using a collection literal.');
correctionMessage: 'Try using a collection literal.',
hasPublishedDocs: true);
PreferCollectionLiterals()
: super(

View file

@ -70,7 +70,8 @@ class PreferConditionalAssignment extends LintRule {
static const LintCode code = LintCode('prefer_conditional_assignment',
"The 'if' statement could be replaced by a null-aware assignment.",
correctionMessage:
"Try using the '??=' operator to conditionally assign a value.");
"Try using the '??=' operator to conditionally assign a value.",
hasPublishedDocs: true);
PreferConditionalAssignment()
: super(

View file

@ -58,7 +58,8 @@ class PreferConstConstructors extends LintRule {
static const LintCode code = LintCode('prefer_const_constructors',
"Use 'const' with the constructor to improve performance.",
correctionMessage:
"Try adding the 'const' keyword to the constructor invocation.");
"Try adding the 'const' keyword to the constructor invocation.",
hasPublishedDocs: true);
PreferConstConstructors()
: super(

View file

@ -43,7 +43,8 @@ class PreferConstConstructorsInImmutables extends LintRule {
static const LintCode code = LintCode(
'prefer_const_constructors_in_immutables',
"Constructors in '@immutable' classes should be declared as 'const'.",
correctionMessage: "Try adding 'const' to the constructor declaration.");
correctionMessage: "Try adding 'const' to the constructor declaration.",
hasPublishedDocs: true);
PreferConstConstructorsInImmutables()
: super(

View file

@ -40,7 +40,8 @@ class A {
class PreferConstDeclarations extends LintRule {
static const LintCode code = LintCode('prefer_const_declarations',
"Use 'const' for final variables initialized to a constant value.",
correctionMessage: "Try replacing 'final' with 'const'.");
correctionMessage: "Try replacing 'final' with 'const'.",
hasPublishedDocs: true);
PreferConstDeclarations()
: super(

View file

@ -41,7 +41,8 @@ class PreferConstLiteralsToCreateImmutables extends LintRule {
'prefer_const_literals_to_create_immutables',
"Use 'const' literals as arguments to constructors of '@immutable' "
'classes.',
correctionMessage: "Try adding 'const' before the literal.");
correctionMessage: "Try adding 'const' before the literal.",
hasPublishedDocs: true);
PreferConstLiteralsToCreateImmutables()
: super(

View file

@ -37,14 +37,16 @@ class PreferContains extends LintRule {
// rather than lints because they represent a bug rather than a style
// preference.
static const LintCode alwaysFalse = LintCode('prefer_contains',
'Always false because indexOf is always greater or equal -1.');
'Always false because indexOf is always greater or equal -1.',
hasPublishedDocs: true);
static const LintCode alwaysTrue = LintCode('prefer_contains',
'Always true because indexOf is always greater or equal -1.');
'Always true because indexOf is always greater or equal -1.',
hasPublishedDocs: true);
static const LintCode useContains = LintCode('prefer_contains',
"Unnecessary use of 'indexOf' to test for containment.",
correctionMessage: "Try using 'contains'.");
correctionMessage: "Try using 'contains'.", hasPublishedDocs: true);
PreferContains()
: super(

View file

@ -84,7 +84,8 @@ class NotAssignedInAllConstructors {
class PreferFinalFields extends LintRule {
static const LintCode code = LintCode(
'prefer_final_fields', "The private field {0} could be 'final'.",
correctionMessage: "Try making the field 'final'.");
correctionMessage: "Try making the field 'final'.",
hasPublishedDocs: true);
PreferFinalFields()
: super(

View file

@ -55,8 +55,8 @@ class PreferForElementsToMapFromIterable extends LintRule {
static const LintCode code = LintCode(
'prefer_for_elements_to_map_fromIterable',
"Use 'for' elements when building maps from iterables.",
correctionMessage:
"Try using a collection literal with a 'for' element.");
correctionMessage: "Try using a collection literal with a 'for' element.",
hasPublishedDocs: true);
PreferForElementsToMapFromIterable()
: super(

View file

@ -41,7 +41,8 @@ class PreferFunctionDeclarationsOverVariables extends LintRule {
'Use a function declaration rather than a variable assignment to bind a '
'function to a name.',
correctionMessage:
'Try rewriting the closure assignment as a function declaration.');
'Try rewriting the closure assignment as a function declaration.',
hasPublishedDocs: true);
PreferFunctionDeclarationsOverVariables()
: super(

View file

@ -35,7 +35,8 @@ typedef F = void Function();
class PreferGenericFunctionTypeAliases extends LintRule {
static const LintCode code = LintCode('prefer_generic_function_type_aliases',
"Use the generic function type syntax in 'typedef's.",
correctionMessage: "Try using the generic function type syntax ('{0}').");
correctionMessage: "Try using the generic function type syntax ('{0}').",
hasPublishedDocs: true);
PreferGenericFunctionTypeAliases()
: super(

View file

@ -29,7 +29,8 @@ v = a ?? b;
class PreferIfNullOperators extends LintRule {
static const LintCode code = LintCode('prefer_if_null_operators',
"Use the '??' operator rather than '?:' when testing for 'null'.",
correctionMessage: "Try rewriting the code to use '??'.");
correctionMessage: "Try rewriting the code to use '??'.",
hasPublishedDocs: true);
PreferIfNullOperators()
: super(

View file

@ -119,7 +119,8 @@ class PreferInitializingFormals extends LintRule {
static const LintCode code = LintCode('prefer_initializing_formals',
'Use an initializing formal to assign a parameter to a field.',
correctionMessage:
"Try using an initialing formal ('this.{0}') to initialize the field.");
"Try using an initialing formal ('this.{0}') to initialize the field.",
hasPublishedDocs: true);
PreferInitializingFormals()
: super(

View file

@ -30,11 +30,13 @@ var l2 = ['a', 'b', 'c'];
class PreferInlinedAdds extends LintRule {
static const LintCode single = LintCode(
'prefer_inlined_adds', 'The addition of a list item could be inlined.',
correctionMessage: 'Try adding the item to the list literal directly.');
correctionMessage: 'Try adding the item to the list literal directly.',
hasPublishedDocs: true);
static const LintCode multiple = LintCode('prefer_inlined_adds',
'The addition of multiple list items could be inlined.',
correctionMessage: 'Try adding the items to the list literal directly.');
correctionMessage: 'Try adding the items to the list literal directly.',
hasPublishedDocs: true);
PreferInlinedAdds()
: super(

View file

@ -34,7 +34,8 @@ class PreferInterpolationToComposeStrings extends LintRule {
'prefer_interpolation_to_compose_strings',
'Use interpolation to compose strings and values.',
correctionMessage:
'Try using string interpolation to build the composite string.');
'Try using string interpolation to build the composite string.',
hasPublishedDocs: true);
PreferInterpolationToComposeStrings()
: super(

View file

@ -43,24 +43,28 @@ class PreferIsEmpty extends LintRule {
static const LintCode alwaysFalse = LintCode(
'prefer_is_empty',
"The comparison is always 'false' because the length is always greater "
'than or equal to 0.');
'than or equal to 0.',
hasPublishedDocs: true);
static const LintCode alwaysTrue = LintCode(
'prefer_is_empty',
"The comparison is always 'true' because the length is always greater "
'than or equal to 0.');
'than or equal to 0.',
hasPublishedDocs: true);
static const LintCode useIsEmpty = LintCode(
'prefer_is_empty',
"Use 'isEmpty' instead of 'length' to test whether the collection is "
'empty.',
correctionMessage: "Try rewriting the expression to use 'isEmpty'.");
correctionMessage: "Try rewriting the expression to use 'isEmpty'.",
hasPublishedDocs: true);
static const LintCode useIsNotEmpty = LintCode(
'prefer_is_empty',
"Use 'isNotEmpty' instead of 'length' to test whether the collection is "
'empty.',
correctionMessage: "Try rewriting the expression to use 'isNotEmpty'.");
correctionMessage: "Try rewriting the expression to use 'isNotEmpty'.",
hasPublishedDocs: true);
PreferIsEmpty()
: super(

View file

@ -37,7 +37,8 @@ if (todo.isNotEmpty) {
class PreferIsNotEmpty extends LintRule {
static const LintCode code = LintCode('prefer_is_not_empty',
"Use 'isNotEmpty' rather than negating the result of 'isEmpty'.",
correctionMessage: "Try rewriting the expression to use 'isNotEmpty'.");
correctionMessage: "Try rewriting the expression to use 'isNotEmpty'.",
hasPublishedDocs: true);
PreferIsNotEmpty()
: super(

View file

@ -35,7 +35,8 @@ class PreferIsNotOperator extends LintRule {
"Use the 'is!' operator rather than negating the value of the 'is' "
'operator.',
correctionMessage:
"Try rewriting the condition to use the 'is!' operator.");
"Try rewriting the condition to use the 'is!' operator.",
hasPublishedDocs: true);
PreferIsNotOperator()
: super(

View file

@ -29,7 +29,8 @@ iterable.whereType<MyClass>();
class PreferIterableWhereType extends LintRule {
static const LintCode code = LintCode('prefer_iterable_whereType',
"Use 'whereType' to select elements of a given type.",
correctionMessage: "Try rewriting the expression to use 'whereType'.");
correctionMessage: "Try rewriting the expression to use 'whereType'.",
hasPublishedDocs: true);
PreferIterableWhereType()
: super(

View file

@ -31,7 +31,8 @@ class PreferNullAwareOperators extends LintRule {
'prefer_null_aware_operators',
"Use the null-aware operator '?.' rather than an explicit 'null' "
'comparison.',
correctionMessage: "Try using '?.'.");
correctionMessage: "Try using '?.'.",
hasPublishedDocs: true);
PreferNullAwareOperators()
: super(

View file

@ -35,7 +35,8 @@ import 'bar.dart';
class PreferRelativeImports extends LintRule {
static const LintCode code = LintCode('prefer_relative_imports',
"Use relative imports for files in the 'lib' directory.",
correctionMessage: 'Try converting the URI to a relative URI.');
correctionMessage: 'Try converting the URI to a relative URI.',
hasPublishedDocs: true);
PreferRelativeImports()
: super(

View file

@ -60,12 +60,14 @@ class PreferTypingUninitializedVariables extends LintRule {
static const LintCode forField = LintCode(
'prefer_typing_uninitialized_variables',
'An uninitialized field should have an explicit type annotation.',
correctionMessage: 'Try adding a type annotation.');
correctionMessage: 'Try adding a type annotation.',
hasPublishedDocs: true);
static const LintCode forVariable = LintCode(
'prefer_typing_uninitialized_variables',
'An uninitialized variable should have an explicit type annotation.',
correctionMessage: 'Try adding a type annotation.');
correctionMessage: 'Try adding a type annotation.',
hasPublishedDocs: true);
PreferTypingUninitializedVariables()
: super(

View file

@ -49,7 +49,7 @@ for any type of map or list:
class PreferVoidToNull extends LintRule {
static const LintCode code = LintCode(
'prefer_void_to_null', "Unnecessary use of the type 'Null'.",
correctionMessage: "Try using 'void' instead.");
correctionMessage: "Try using 'void' instead.", hasPublishedDocs: true);
PreferVoidToNull()
: super(

View file

@ -35,7 +35,8 @@ class ProvideDeprecationMessage extends LintRule {
static const LintCode code = LintCode(
'provide_deprecation_message', 'Missing a deprecation message.',
correctionMessage:
"Try using the constructor to provide a message ('@Deprecated(\"message\")').");
"Try using the constructor to provide a message ('@Deprecated(\"message\")').",
hasPublishedDocs: true);
ProvideDeprecationMessage()
: super(

View file

@ -48,7 +48,8 @@ class DependOnReferencedPackages extends LintRule {
static const LintCode code = LintCode('depend_on_referenced_packages',
"The imported package '{0}' isn't a dependency of the importing package.",
correctionMessage:
"Try adding a dependency for '{0}' in the 'pubspec.yaml' file.");
"Try adding a dependency for '{0}' in the 'pubspec.yaml' file.",
hasPublishedDocs: true);
DependOnReferencedPackages()
: super(

View file

@ -24,7 +24,8 @@ class PackageNames extends LintRule {
"The package name '{0}' isn't a lower_case_with_underscores identifier.",
correctionMessage:
'Try changing the name to follow the lower_case_with_underscores '
'style.');
'style.',
hasPublishedDocs: true);
PackageNames()
: super(

View file

@ -33,7 +33,8 @@ repository: https://github.com/dart-lang/example
class SecurePubspecUrls extends LintRule {
static const LintCode code = LintCode('secure_pubspec_urls',
"The '{0}' protocol shouldn't be used because it isn't secure.",
correctionMessage: "Try using a secure protocol, such as 'https'.");
correctionMessage: "Try using a secure protocol, such as 'https'.",
hasPublishedDocs: true);
SecurePubspecUrls()
: super(

View file

@ -19,7 +19,8 @@ class SortPubDependencies extends LintRule {
static const LintCode code = LintCode(
'sort_pub_dependencies', 'Dependencies not sorted alphabetically.',
correctionMessage:
'Try sorting the dependencies alphabetically (A to Z).');
'Try sorting the dependencies alphabetically (A to Z).',
hasPublishedDocs: true);
SortPubDependencies()
: super(

View file

@ -38,7 +38,8 @@ int get field => _field;
class RecursiveGetters extends LintRule {
static const LintCode code = LintCode(
'recursive_getters', "The getter '{0}' recursively returns itself.",
correctionMessage: 'Try changing the value being returned.');
correctionMessage: 'Try changing the value being returned.',
hasPublishedDocs: true);
RecursiveGetters()
: super(

View file

@ -50,7 +50,8 @@ Widget buildRow() {
class SizedBoxForWhitespace extends LintRule {
static const LintCode code = LintCode('sized_box_for_whitespace',
"Use a 'SizedBox' to add whitespace to a layout.",
correctionMessage: "Try using a 'SizedBox' rather than a 'Container'.");
correctionMessage: "Try using a 'SizedBox' rather than a 'Container'.",
hasPublishedDocs: true);
SizedBoxForWhitespace()
: super(

View file

@ -45,7 +45,8 @@ bool isJavaStyle(Comment comment) {
class SlashForDocComments extends LintRule {
static const LintCode code = LintCode('slash_for_doc_comments',
"Use the end-of-line form ('///') for doc comments.",
correctionMessage: "Try rewriting the comment to use '///'.");
correctionMessage: "Try rewriting the comment to use '///'.",
hasPublishedDocs: true);
SlashForDocComments()
: super(

View file

@ -84,7 +84,8 @@ class SortChildPropertiesLast extends LintRule {
static const LintCode code = LintCode('sort_child_properties_last',
"The '{0}' argument should be last in widget constructor invocations.",
correctionMessage:
'Try moving the argument to the end of the argument list.');
'Try moving the argument to the end of the argument list.',
hasPublishedDocs: true);
SortChildPropertiesLast()
: super(

View file

@ -70,7 +70,8 @@ class Good {
class TestTypesInEquals extends LintRule {
static const LintCode code = LintCode(
'test_types_in_equals', "Missing type test for '{0}' in '=='.",
correctionMessage: "Try testing the type of '{0}'.");
correctionMessage: "Try testing the type of '{0}'.",
hasPublishedDocs: true);
TestTypesInEquals()
: super(

View file

@ -51,7 +51,8 @@ class Ok {
class ThrowInFinally extends LintRule {
static const LintCode code = LintCode(
'throw_in_finally', "Use of '{0}' in 'finally' block.",
correctionMessage: "Try moving the '{0}' outside the 'finally' block.");
correctionMessage: "Try moving the '{0}' outside the 'finally' block.",
hasPublishedDocs: true);
ThrowInFinally()
: super(

View file

@ -69,7 +69,7 @@ class B extends A {
class TypeInitFormals extends LintRule {
static const LintCode code = LintCode('type_init_formals',
"Don't needlessly type annotate initializing formals.",
correctionMessage: 'Try removing the type.');
correctionMessage: 'Try removing the type.', hasPublishedDocs: true);
TypeInitFormals()
: super(

View file

@ -57,10 +57,8 @@ class TypeLiteralInConstantPattern extends LintRule {
static const String lintName = 'type_literal_in_constant_pattern';
static const LintCode code = LintCode(
lintName,
"Use 'TypeName _' instead of a type literal.",
correctionMessage: "Replace with 'TypeName _'.",
);
lintName, "Use 'TypeName _' instead of a type literal.",
correctionMessage: "Replace with 'TypeName _'.", hasPublishedDocs: true);
TypeLiteralInConstantPattern()
: super(

View file

@ -36,7 +36,7 @@ bool isIdentifierPart(Token? token) =>
class UnnecessaryBraceInStringInterps extends LintRule {
static const LintCode code = LintCode('unnecessary_brace_in_string_interps',
'Unnecessary braces in a string interpolation.',
correctionMessage: 'Try removing the braces.');
correctionMessage: 'Try removing the braces.', hasPublishedDocs: true);
UnnecessaryBraceInStringInterps()
: super(

View file

@ -36,7 +36,7 @@ m(){
class UnnecessaryConst extends LintRule {
static const LintCode code = LintCode(
'unnecessary_const', "Unnecessary 'const' keyword.",
correctionMessage: 'Try removing the keyword.');
correctionMessage: 'Try removing the keyword.', hasPublishedDocs: true);
UnnecessaryConst()
: super(

View file

@ -42,7 +42,7 @@ var makeA = A.new;
class UnnecessaryConstructorName extends LintRule {
static const LintCode code = LintCode(
'unnecessary_constructor_name', "Unnecessary '.new' constructor name.",
correctionMessage: "Try removing the '.new'.");
correctionMessage: "Try removing the '.new'.", hasPublishedDocs: true);
UnnecessaryConstructorName()
: super(

View file

@ -52,7 +52,8 @@ class UnnecessaryGettersSetters extends LintRule {
static const LintCode code = LintCode('unnecessary_getters_setters',
'Unnecessary use of getter and setter to wrap a field.',
correctionMessage:
'Try removing the getter and setter and renaming the field.');
'Try removing the getter and setter and renaming the field.',
hasPublishedDocs: true);
UnnecessaryGettersSetters()
: super(

View file

@ -44,7 +44,7 @@ class GoodExample {
class UnnecessaryLate extends LintRule {
static const LintCode code = LintCode(
'unnecessary_late', "Unnecessary 'late' modifier.",
correctionMessage: "Try removing the 'late'.");
correctionMessage: "Try removing the 'late'.", hasPublishedDocs: true);
UnnecessaryLate()
: super(

View file

@ -34,7 +34,8 @@ m(){
class UnnecessaryNew extends LintRule {
static const LintCode code = LintCode(
'unnecessary_new', "Unnecessary 'new' keyword.",
correctionMessage: "Try removing the 'new' keyword.");
correctionMessage: "Try removing the 'new' keyword.",
hasPublishedDocs: true);
UnnecessaryNew()
: super(

View file

@ -35,7 +35,8 @@ x ??= 1;
class UnnecessaryNullAwareAssignments extends LintRule {
static const LintCode code = LintCode(
'unnecessary_null_aware_assignments', "Unnecessary assignment of 'null'.",
correctionMessage: 'Try removing the assignment.');
correctionMessage: 'Try removing the assignment.',
hasPublishedDocs: true);
UnnecessaryNullAwareAssignments()
: super(

View file

@ -34,7 +34,8 @@ class UnnecessaryNullInIfNullOperators extends LintRule {
static const LintCode code = LintCode('unnecessary_null_in_if_null_operators',
"Unnecessary use of '??' with 'null'.",
correctionMessage:
"Try removing the '??' operator and the 'null' operand.");
"Try removing the '??' operator and the 'null' operand.",
hasPublishedDocs: true);
UnnecessaryNullInIfNullOperators()
: super(

Some files were not shown because too many files have changed in this diff Show more