Skip to content

Commit

Permalink
Tidying lint warnings (#1691)
Browse files Browse the repository at this point in the history
  • Loading branch information
domesticmouse authored and kwalrath committed Jul 2, 2019
1 parent a9c5ac3 commit f44923d
Show file tree
Hide file tree
Showing 49 changed files with 74 additions and 64 deletions.
1 change: 0 additions & 1 deletion deploy/effective-dart-rules/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ linter:
- slash_for_doc_comments
- sort_constructors_first
- sort_unnamed_constructors_first
- super_goes_last
- test_types_in_equals
- throw_in_finally
# - type_annotate_public_apis
Expand Down
28 changes: 14 additions & 14 deletions deploy/effective-dart-rules/bin/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore_for_file: sort_constructors_first
import 'dart:async';
import 'dart:io';

Expand All @@ -14,13 +15,13 @@ Future<Null> main() async {
"design.md"
];
List<Section> sections =
filenames.map((name) => new Section(dirPath, name)).toList();
filenames.map((name) => Section(dirPath, name)).toList();

for (var section in sections) {
var lines = section.file.readAsLinesSync();
// Ignore the YAML front matter (can lead to false H3 elements.
lines = lines.skip(1).skipWhile((line) => line.trim() != '---').toList();
var document = new md.Document();
var document = md.Document();

// Commented out the following line because the parseRefLinks has
// disappeared. Unfortunately, that means I had to hand-patch the TOC
Expand All @@ -32,19 +33,19 @@ Future<Null> main() async {
var nodes = document.parseLines(lines);
for (md.Element element in nodes.where((node) => node is md.Element)) {
if (element.tag == "h2") {
var subsection = new Subsection(element);
var subsection = Subsection(element);
section.subsections.add(subsection);
continue;
}

if (element.tag == "h3") {
var rule = new Rule(element);
var rule = Rule(element);
section.subsections.last.rules.add(rule);
}
}
}

var outFile = new File(path.join(dirPath, "toc.md"));
var outFile = File(path.join(dirPath, "toc.md"));
IOSink out;
try {
out = outFile.openWrite();
Expand Down Expand Up @@ -105,12 +106,11 @@ class Section {
final Uri uri;
final File file;
final String name;
List<Subsection> subsections = new List<Subsection>();
List<Subsection> subsections = List<Subsection>();

Section(String dirPath, String filename)
: file = new File(path.join(dirPath, filename)),
uri = Uri
.parse("/guides/language/effective-dart/")
: file = File(path.join(dirPath, filename)),
uri = Uri.parse("/guides/language/effective-dart/")
.resolve(filename.split('.').first),
name = "${filename[0].toUpperCase()}"
"${filename.substring(1).split('.').first}";
Expand All @@ -119,7 +119,7 @@ class Section {
class Subsection {
final String name;
final String fragment;
List<Rule> rules = new List<Rule>();
List<Rule> rules = List<Rule>();
Subsection(md.Element element)
: name = _concatenatedText(element),
fragment = generateAnchorHash(element);
Expand All @@ -129,15 +129,15 @@ class Subsection {
String generateAnchorHash(md.Element element) => _concatenatedText(element)
.toLowerCase()
.trim()
.replaceFirst(new RegExp(r'^[^a-z]+'), '')
.replaceAll(new RegExp(r'[^a-z0-9 _-]'), '')
.replaceAll(new RegExp(r'\s'), '-');
.replaceFirst(RegExp(r'^[^a-z]+'), '')
.replaceAll(RegExp(r'[^a-z0-9 _-]'), '')
.replaceAll(RegExp(r'\s'), '-');

/// Concatenates the text found in all the children of [element].
String _concatenatedText(md.Element element) => element.children
.map((child) =>
(child is md.Text) ? unescape(child.text) : _concatenatedText(child))
.join('');

final _unescape = new HtmlUnescape();
final _unescape = HtmlUnescape();
String unescape(String input) => _unescape.convert(input);
1 change: 0 additions & 1 deletion examples/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ analyzer:

linter:
rules:
avoid_shadowing_type_parameters: false # TODO: reinstate?
- annotate_overrides
- await_only_futures
- camel_case_types
Expand Down
2 changes: 1 addition & 1 deletion examples/httpserver/bin/basic_writer_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ Future main() async {
..statusCode = HttpStatus.methodNotAllowed
..write("Unsupported request: ${req.method}.");
}
response.close();
await response.close();
}
}
5 changes: 2 additions & 3 deletions examples/httpserver/bin/hello_world_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ Future main() async {

// #docregion listen
await for (HttpRequest request in server) {
request.response
..write('Hello, world!')
..close();
request.response.write('Hello, world!');
await request.response.close();
}
// #enddocregion listen
}
5 changes: 2 additions & 3 deletions examples/httpserver/bin/hello_world_server_secure.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ Future main() async {
);
print('Listening on localhost:${server.port}');
await for (HttpRequest request in server) {
request.response
..write('Hello, world!')
..close();
request.response.write('Hello, world!');
await request.response.close();
}
}
5 changes: 2 additions & 3 deletions examples/httpserver/bin/mini_file_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ Future main() async {
}
} else {
print("Can't open ${targetFile.path}.");
req.response
..statusCode = HttpStatus.notFound
..close();
req.response.statusCode = HttpStatus.notFound;
await req.response.close();
}
}
}
2 changes: 1 addition & 1 deletion examples/httpserver/bin/note_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Future listenForRequests(HttpServer requests) async {
await for (HttpRequest request in requests) {
switch (request.method) {
case 'POST':
handlePost(request);
await handlePost(request);
break;
case 'OPTION':
handleOptions(request);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore_for_file: sort_constructors_first
import 'dart:async';

/// Combines incoming strings into a single stream and outputs its lines.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'dart:io';
Future<void> runServer(String basePath) async {
final server = await HttpServer.bind('127.0.0.1', 8082);
await for (HttpRequest request in server) {
handleRequest(basePath, request);
await handleRequest(basePath, request);
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/misc/lib/articles/io/io_http_server_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ Future<void> main() async {
final server = await HttpServer.bind('127.0.0.1', 8082);
await for (HttpRequest request in server) {
request.response.write('Hello, world');
request.response.close();
await request.response.close();
}
}
2 changes: 1 addition & 1 deletion examples/misc/lib/effective_dart/design_bad.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ignore_for_file: type_annotate_public_apis, unused_element, unused_local_variable, avoid_types_as_parameter_names
// ignore_for_file: type_annotate_public_apis, unused_element, unused_local_variable, avoid_types_as_parameter_names, sort_constructors_first

import 'dart:async';

Expand Down
4 changes: 2 additions & 2 deletions examples/misc/lib/effective_dart/design_good.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ignore_for_file: type_annotate_public_apis, unused_element, unused_local_variable
// ignore_for_file: type_annotate_public_apis, unused_element, unused_local_variable, sort_constructors_first

import 'dart:async';
import 'dart:collection';
Expand Down Expand Up @@ -122,7 +122,7 @@ void miscDeclAnalyzedButNotTested() {

// #docregion annotate-declaration
bool isEmpty(String parameter) {
bool result = parameter.length == 0;
bool result = parameter.isEmpty;
return result;
}
// #enddocregion annotate-declaration
Expand Down
2 changes: 1 addition & 1 deletion examples/misc/lib/effective_dart/style_bad.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ignore_for_file: constant_identifier_names, non_constant_identifier_names, type_annotate_public_apis
// ignore_for_file: constant_identifier_names, non_constant_identifier_names, type_annotate_public_apis, curly_braces_in_flow_control_structures
import 'dart:math';

// #docregion const-names
Expand Down
2 changes: 1 addition & 1 deletion examples/misc/lib/effective_dart/usage_bad.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ignore_for_file: avoid_init_to_null, empty_constructor_bodies, final_not_initialized_constructor_1, prefer_is_not_empty, sort_constructors_first, type_annotate_public_apis, type_init_formals, unnecessary_brace_in_string_interps, unnecessary_getters_setters, unused_element, unused_local_variable, prefer_equal_for_default_values, use_rethrow_when_possible
// ignore_for_file: avoid_init_to_null, empty_constructor_bodies, final_not_initialized_constructor_1, prefer_is_not_empty, sort_constructors_first, type_annotate_public_apis, type_init_formals, unnecessary_brace_in_string_interps, unnecessary_getters_setters, unused_element, unused_local_variable, prefer_equal_for_default_values, use_rethrow_when_possible, prefer_is_empty
import 'dart:async';
import 'dart:io';
import 'dart:math';
Expand Down
2 changes: 1 addition & 1 deletion examples/misc/lib/effective_dart/usage_good.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ignore_for_file: type_annotate_public_apis, unused_element, unused_local_variable
// ignore_for_file: type_annotate_public_apis, unused_element, unused_local_variable, sort_constructors_first
import 'dart:async';
import 'dart:io';
import 'dart:math';
Expand Down
2 changes: 1 addition & 1 deletion examples/misc/lib/language_tour/async.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ignore_for_file: unused_element, unused_local_variable
// ignore_for_file: unused_element, unused_local_variable, unawaited_futures
typedef Async0 = Future Function();
typedef Async1 = Future Function(dynamic);
typedef Async2 = Future Function(dynamic, dynamic);
Expand Down
2 changes: 1 addition & 1 deletion examples/misc/lib/language_tour/classes/employee.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ignore_for_file: unnecessary_cast
// ignore_for_file: unnecessary_cast, sort_constructors_first

Map getDefaultData() => {}; // stub

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore_for_file: sort_constructors_first
class ImmutablePoint {
static final ImmutablePoint origin =
const ImmutablePoint(0, 0);
Expand Down
2 changes: 1 addition & 1 deletion examples/misc/lib/language_tour/classes/impostor.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ignore_for_file: annotate_overrides
// ignore_for_file: sort_constructors_first, annotate_overrides
// A person. The implicit interface contains greet().
class Person {
// In the interface, but visible only in this library.
Expand Down
1 change: 1 addition & 0 deletions examples/misc/lib/language_tour/classes/logger.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore_for_file: sort_constructors_first
// #docregion
class Logger {
final String name;
Expand Down
1 change: 1 addition & 0 deletions examples/misc/lib/language_tour/classes/orchestra.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore_for_file: sort_constructors_first
// #docregion Musical
mixin Musical {
bool canPlayPiano = false;
Expand Down
1 change: 1 addition & 0 deletions examples/misc/lib/language_tour/classes/point.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore_for_file: sort_constructors_first
// #docregion class-with-distanceTo
import 'dart:math';

Expand Down
1 change: 1 addition & 0 deletions examples/misc/lib/language_tour/classes/point_alt.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore_for_file: sort_constructors_first
/// Example of:
///
/// - A constructor initializing fields in the body "the long way"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore_for_file: sort_constructors_first
class Point {
num x, y;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore_for_file: sort_constructors_first
import 'dart:math';

class Point {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore_for_file: sort_constructors_first
import 'dart:math';

class Point {
Expand Down
1 change: 1 addition & 0 deletions examples/misc/lib/language_tour/classes/rectangle.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore_for_file: sort_constructors_first
class Rectangle {
num left, top, width, height;

Expand Down
1 change: 1 addition & 0 deletions examples/misc/lib/language_tour/classes/vector.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore_for_file: sort_constructors_first
// #docregion ''
class Vector {
final int x, y;
Expand Down
1 change: 1 addition & 0 deletions examples/misc/lib/language_tour/metadata/todo.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore_for_file: sort_constructors_first
library todo;

class Todo {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore_for_file: sort_constructors_first
class SortedCollection {
Function compare;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore_for_file: sort_constructors_first
typedef Compare = int Function(Object a, Object b);

class SortedCollection {
Expand Down
1 change: 1 addition & 0 deletions examples/misc/lib/library_tour/core/comparable.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore_for_file: sort_constructors_first
class Line implements Comparable<Line> {
final int length;
const Line(this.length);
Expand Down
1 change: 1 addition & 0 deletions examples/misc/lib/library_tour/core/exception.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore_for_file: sort_constructors_first
class FooException implements Exception {
final String msg;

Expand Down
2 changes: 1 addition & 1 deletion examples/misc/lib/library_tour/core/hash_code.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ignore_for_file: unrelated_type_equality_checks
// ignore_for_file: sort_constructors_first, unrelated_type_equality_checks
// #docregion
class Person {
final String firstName, lastName;
Expand Down
2 changes: 1 addition & 1 deletion examples/misc/lib/pi_monte_carlo.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ignore_for_file: type_annotate_public_apis
// ignore_for_file: sort_constructors_first, type_annotate_public_apis

// WARNING:
//
Expand Down
1 change: 1 addition & 0 deletions examples/misc/lib/samples/spacecraft.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore_for_file: sort_constructors_first
// #docregion class
class Spacecraft {
String name;
Expand Down
2 changes: 1 addition & 1 deletion examples/misc/test/language_tour/async_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ignore_for_file: type_annotate_public_apis
// ignore_for_file: type_annotate_public_apis, curly_braces_in_flow_control_structures
import 'package:test/test.dart';

void main() {
Expand Down
4 changes: 2 additions & 2 deletions examples/misc/test/library_tour/core_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ void main() {

// Remove all elements from a list.
fruits.clear();
assert(fruits.length == 0);
assert(fruits.isEmpty);
// #enddocregion List
assert(vegetables.length == 0);
assert(vegetables.isEmpty);
});

test('indexOf', () {
Expand Down
2 changes: 1 addition & 1 deletion examples/misc/test/library_tour/io_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void main() {
expect(logFile.readAsStringSync(),
startsWith('FILE ACCESSED'));
} finally {
logFile?.delete();
await logFile?.delete();
}
});

Expand Down
1 change: 1 addition & 0 deletions examples/strong/lib/bounded/my_collection.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore_for_file: sort_constructors_first
class C<T extends Iterable> {
final T collection;
C(this.collection);
Expand Down
2 changes: 1 addition & 1 deletion examples/strong/lib/common_fixes_analysis.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// NOTE: Declarations in this file are analyzed but not tested.
// ignore_for_file: unused_element, unused_local_variable
// ignore_for_file: sort_constructors_first, unused_element, unused_local_variable

import 'dart:html';

Expand Down
2 changes: 1 addition & 1 deletion examples/strong/lib/common_problems_analysis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Include in this file only excerpts used to illustrate common problems.
// The specific errors generated by the analyzer are included in the markdown.
//
// ignore_for_file: unused_element, unused_local_variable
// ignore_for_file: sort_constructors_first, unused_element, unused_local_variable

import 'dart:html';

Expand Down
1 change: 1 addition & 0 deletions examples/strong/lib/dart_1_my_list_hello_world.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// ignore_for_file: invalid_override_from_base
// ignore_for_file: invalid_override, type_annotate_public_apis
// ignore_for_file: conflicting_generic_interfaces
// ignore_for_file: sort_constructors_first
// #docregion MyList-and-main
import 'dart:collection';

Expand Down
Loading

0 comments on commit f44923d

Please sign in to comment.