Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/dart-lang/linter
Browse files Browse the repository at this point in the history
  • Loading branch information
pq committed Jul 22, 2017
2 parents e9b9657 + ced90f3 commit 1f24173
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 61 deletions.
2 changes: 1 addition & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ linter:
# - prefer_final_locals
# - prefer_is_empty # not recognized
- prefer_is_not_empty
# - prefer_single_quotes
- prefer_single_quotes
# - public_member_api_docs
# - recursive_getter # not recognized
- slash_for_doc_comments
Expand Down
20 changes: 10 additions & 10 deletions bin/linter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ isLinterErrorCode(int code) =>
code == unableToProcessExitCode || code == processFileFailedExitCode;

void printUsage(ArgParser parser, IOSink out, [String error]) {
var message = "Lints Dart source files and pubspecs.";
var message = 'Lints Dart source files and pubspecs.';
if (error != null) {
message = error;
}
Expand All @@ -51,11 +51,11 @@ void runLinter(List<String> args, LinterOptions initialLintOptions) {
var parser = new ArgParser(allowTrailingOptions: true);

parser
..addFlag("help",
abbr: "h", negatable: false, help: "Show usage information.")
..addFlag("stats",
abbr: "s", negatable: false, help: "Show lint statistics.")
..addFlag("benchmark", negatable: false, help: "Show lint benchmarks.")
..addFlag('help',
abbr: 'h', negatable: false, help: 'Show usage information.')
..addFlag('stats',
abbr: 's', negatable: false, help: 'Show lint statistics.')
..addFlag('benchmark', negatable: false, help: 'Show lint benchmarks.')
..addFlag('visit-transitive-closure',
help: 'Visit the transitive closure of imported/exported libraries.')
..addFlag('quiet', abbr: 'q', help: "Don't show individual lint errors.")
Expand Down Expand Up @@ -86,21 +86,21 @@ void runLinter(List<String> args, LinterOptions initialLintOptions) {
return;
}

if (options["help"]) {
if (options['help']) {
printUsage(parser, outSink);
return;
}

if (options.rest.isEmpty) {
printUsage(parser, errorSink,
"Please provide at least one file or directory to lint.");
'Please provide at least one file or directory to lint.');
exitCode = unableToProcessExitCode;
return;
}

var lintOptions = initialLintOptions;

var configFile = options["config"];
var configFile = options['config'];
if (configFile != null) {
var config = new LintConfig.parse(readFile(configFile));
lintOptions.configure(config);
Expand Down Expand Up @@ -137,7 +137,7 @@ void runLinter(List<String> args, LinterOptions initialLintOptions) {
var packageConfigFile = options['packages'];

if (customPackageRoot != null && packageConfigFile != null) {
errorSink.write("Cannot specify both '--package-root' and '--packages.");
errorSink.write("Cannot specify both '--package-root' and '--packages'.");
exitCode = unableToProcessExitCode;
return;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/rules/always_put_required_named_parameters_first.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ m({b, c, @required a}) ;
''';

/// The name of `meta` library, used to define analysis annotations.
String _META_LIB_NAME = "meta";
String _META_LIB_NAME = 'meta';

/// The name of the top-level variable used to mark a required named parameter.
String _REQUIRED_VAR_NAME = "required";
String _REQUIRED_VAR_NAME = 'required';

bool _isRequired(Element element) =>
element is PropertyAccessorElement &&
Expand Down
4 changes: 2 additions & 2 deletions lib/src/rules/always_require_non_null_named_parameters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ NOTE: Only asserts at the start of the bodies will be taken into account.
''';

/// The name of `meta` library, used to define analysis annotations.
String _META_LIB_NAME = "meta";
String _META_LIB_NAME = 'meta';

/// The name of the top-level variable used to mark a required named parameter.
String _REQUIRED_VAR_NAME = "required";
String _REQUIRED_VAR_NAME = 'required';

bool _isRequired(Element element) =>
element is PropertyAccessorElement &&
Expand Down
4 changes: 2 additions & 2 deletions lib/src/rules/always_specify_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ main() {
''';

/// The name of `meta` library, used to define analysis annotations.
String _META_LIB_NAME = "meta";
String _META_LIB_NAME = 'meta';

/// The name of the top-level variable used to mark a Class as having optional
/// type args.
String _OPTIONAL_TYPE_ARGS_VAR_NAME = "optionalTypeArgs";
String _OPTIONAL_TYPE_ARGS_VAR_NAME = 'optionalTypeArgs';

bool _isOptionallyParameterized(ParameterizedType type) {
List<ElementAnnotation> metadata = type.element?.metadata;
Expand Down
16 changes: 8 additions & 8 deletions lib/src/rules/non_constant_identifier_names.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,17 @@ class Visitor extends SimpleAstVisitor {
}
}

@override
visitConstructorDeclaration(ConstructorDeclaration node) {
if (node.name != null) {
checkIdentifier(node.name);
}
}

@override
visitFormalParameterList(FormalParameterList node) {
node.parameters.forEach((FormalParameter p) {
if (p is! FieldFormalParameter) {
if (p is! FieldFormalParameter && p.identifier != null) {
checkIdentifier(p.identifier, underscoresOk: true);
}
});
Expand All @@ -83,11 +90,4 @@ class Visitor extends SimpleAstVisitor {
}
});
}

@override
visitConstructorDeclaration(ConstructorDeclaration node) {
if (node.name != null) {
checkIdentifier(node.name);
}
}
}
4 changes: 2 additions & 2 deletions lib/src/rules/prefer_const_constructors_in_immutables.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ class A {
''';

/// The name of `meta` library, used to define analysis annotations.
String _META_LIB_NAME = "meta";
String _META_LIB_NAME = 'meta';

/// The name of the top-level variable used to mark a immutable class.
String _IMMUTABLE_VAR_NAME = "immutable";
String _IMMUTABLE_VAR_NAME = 'immutable';

bool _isImmutable(Element element) =>
element is PropertyAccessorElement &&
Expand Down
4 changes: 2 additions & 2 deletions lib/src/rules/prefer_contains.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ class _Visitor extends SimpleAstVisitor {

final DartObjectImpl rightValue =
binaryExpression.rightOperand.accept(visitor);
if (rightValue?.type?.name == "int") {
if (rightValue?.type?.name == 'int') {
// Constant is on right side of comparison operator
_checkConstant(binaryExpression, rightValue.toIntValue(), operator.type);
return;
}

final DartObjectImpl leftValue =
binaryExpression.leftOperand.accept(visitor);
if (leftValue?.type?.name == "int") {
if (leftValue?.type?.name == 'int') {
// Constants is on left side of comparison operator
_checkConstant(binaryExpression, leftValue.toIntValue(),
_invertedTokenType(operator.type));
Expand Down
4 changes: 2 additions & 2 deletions lib/src/rules/prefer_is_empty.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class Visitor extends SimpleAstVisitor {

DartObjectImpl rightValue = binaryExpression.rightOperand.accept(visitor);

if (rightValue?.type?.name == "int") {
if (rightValue?.type?.name == 'int') {
// Constants is on right side of comparison operator
int value = rightValue.toIntValue();
if (value == 0) {
Expand Down Expand Up @@ -179,7 +179,7 @@ class Visitor extends SimpleAstVisitor {

DartObjectImpl leftValue = binaryExpression.leftOperand.accept(visitor);

if (leftValue?.type?.name == "int") {
if (leftValue?.type?.name == 'int') {
// Constants is on left side of comparison operator
int value = leftValue.toIntValue();

Expand Down
2 changes: 1 addition & 1 deletion lib/src/rules/use_to_and_as_if_applicable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Bar {
''';

bool _beginsWithAsOrTo(String name) {
final regExp = new RegExp(r"(to|as|_to|_as)[A-Z]", caseSensitive: true);
final regExp = new RegExp(r'(to|as|_to|_as)[A-Z]', caseSensitive: true);
return regExp.matchAsPrefix(name) != null;
}

Expand Down
28 changes: 14 additions & 14 deletions test/integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,9 @@ defineTests() {
expect(
collectingOut.trim(),
stringContainsInOrder([
"Specify exports in a separate section after all imports.",
'Specify exports in a separate section after all imports.',
"export 'dummy.dart'; // LINT",
"Specify exports in a separate section after all imports.",
'Specify exports in a separate section after all imports.',
"export 'dummy2.dart'; // LINT",
'5 files analyzed, 2 issues found, in'
]));
Expand All @@ -316,29 +316,29 @@ defineTests() {
expect(
collectingOut.trim(),
stringContainsInOrder([
"Sort directive sections alphabetically.",
'Sort directive sections alphabetically.',
"import 'dart:convert'; // LINT",
"Sort directive sections alphabetically.",
'Sort directive sections alphabetically.',
"import 'package:charcode/ascii.dart'; // LINT",
"Sort directive sections alphabetically.",
'Sort directive sections alphabetically.',
"import 'package:ansicolor/ansicolor.dart'; // LINT",
"Sort directive sections alphabetically.",
'Sort directive sections alphabetically.',
"import 'package:linter/src/formatter.dart'; // LINT",
"Sort directive sections alphabetically.",
'Sort directive sections alphabetically.',
"import 'dummy3.dart'; // LINT",
"Sort directive sections alphabetically.",
'Sort directive sections alphabetically.',
"import 'dummy2.dart'; // LINT",
"Sort directive sections alphabetically.",
'Sort directive sections alphabetically.',
"import 'dummy1.dart'; // LINT",
"Sort directive sections alphabetically.",
'Sort directive sections alphabetically.',
"export 'dart:convert'; // LINT",
"Sort directive sections alphabetically.",
'Sort directive sections alphabetically.',
"export 'package:charcode/ascii.dart'; // LINT",
"Sort directive sections alphabetically.",
'Sort directive sections alphabetically.',
"export 'package:ansicolor/ansicolor.dart'; // LINT",
"Sort directive sections alphabetically.",
'Sort directive sections alphabetically.',
"export 'package:linter/src/formatter.dart'; // LINT",
"Sort directive sections alphabetically.",
'Sort directive sections alphabetically.',
"export 'dummy1.dart'; // LINT",
'5 files analyzed, 12 issues found, in'
]));
Expand Down
20 changes: 10 additions & 10 deletions test/mock_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ class HtmlElement {}
Source fromFileUri(Uri uri) {
String filePath = uri.path;
String libPath = '/lib';
if (!filePath.startsWith("$libPath/")) {
if (!filePath.startsWith('$libPath/')) {
return null;
}
for (SdkLibrary library in LIBRARIES) {
Expand All @@ -336,7 +336,7 @@ class HtmlElement {}
return null;
}
}
if (filePath.startsWith("$libraryPath/")) {
if (filePath.startsWith('$libraryPath/')) {
String pathInLibrary = filePath.substring(libraryPath.length + 1);
String path = '${library.shortName}/$pathInLibrary';
try {
Expand Down Expand Up @@ -365,14 +365,14 @@ class HtmlElement {}
@override
Source mapDartUri(String dartUri) {
const Map<String, String> uriToPath = const {
"dart:core": "/lib/core/core.dart",
"dart:html": "/lib/html/dartium/html_dartium.dart",
"dart:async": "/lib/async/async.dart",
"dart:async/stream.dart": "/lib/async/stream.dart",
"dart:collection": "/lib/collection/collection.dart",
"dart:convert": "/lib/convert/convert.dart",
"dart:io": "/lib/io/io.dart",
"dart:math": "/lib/math/math.dart"
'dart:core': '/lib/core/core.dart',
'dart:html': '/lib/html/dartium/html_dartium.dart',
'dart:async': '/lib/async/async.dart',
'dart:async/stream.dart': '/lib/async/stream.dart',
'dart:collection': '/lib/collection/collection.dart',
'dart:convert': '/lib/convert/convert.dart',
'dart:io': '/lib/io/io.dart',
'dart:math': '/lib/math/math.dart'
};

String path = uriToPath[dartUri];
Expand Down
2 changes: 1 addition & 1 deletion test/mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CollectingSink extends MockIOSink {
}

@override
writeln([Object obj = ""]) {
writeln([Object obj = '']) {
buffer.writeln(obj);
}
}
Expand Down
8 changes: 4 additions & 4 deletions tool/rule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ String toClassName(String ruleName) =>

void updateRuleRegistry(String ruleName) {
print("Don't forget to update lib/rules.dart with a line like:");
print(" ..register(new ${toClassName(ruleName)}())");
print("and add your rule to `example/all.yaml`.");
print("Then run your test like so:");
print(" pub run test -N $ruleName");
print(' ..register(new ${toClassName(ruleName)}())');
print('and add your rule to `example/all.yaml`.');
print('Then run your test like so:');
print(' pub run test -N $ruleName');
}

String _generateClass(String ruleName, String className) => """
Expand Down

0 comments on commit 1f24173

Please sign in to comment.