Fix remaining prefer_single_quotes and fail travis on lints (dart-lang/source_span#48)
Missed saving some files in my editor in https://github.com/dart-lang/source_span/pull/47
The travis config was not set to fail for lints.
diff --git a/pkgs/source_span/.travis.yml b/pkgs/source_span/.travis.yml
index ace10ab..edb90e6 100644
--- a/pkgs/source_span/.travis.yml
+++ b/pkgs/source_span/.travis.yml
@@ -13,7 +13,8 @@
- dart: dev
dart_task: dartfmt
- dart: dev
- dart_task: dartanalyzer
+ dart_task:
+ dartanalyzer: --fatal-warnings --fatal-infos .
# Only building master means that we don't run two builds for each pull request.
branches:
diff --git a/pkgs/source_span/lib/source_span.dart b/pkgs/source_span/lib/source_span.dart
index 6ed10a0..534a3a7 100644
--- a/pkgs/source_span/lib/source_span.dart
+++ b/pkgs/source_span/lib/source_span.dart
@@ -2,10 +2,10 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-export "src/file.dart";
-export "src/location.dart";
-export "src/location_mixin.dart";
-export "src/span.dart";
-export "src/span_exception.dart";
-export "src/span_mixin.dart";
-export "src/span_with_context.dart";
+export 'src/file.dart';
+export 'src/location.dart';
+export 'src/location_mixin.dart';
+export 'src/span.dart';
+export 'src/span_exception.dart';
+export 'src/span_mixin.dart';
+export 'src/span_with_context.dart';
diff --git a/pkgs/source_span/lib/src/highlighter.dart b/pkgs/source_span/lib/src/highlighter.dart
index 94bc857..f3af75f 100644
--- a/pkgs/source_span/lib/src/highlighter.dart
+++ b/pkgs/source_span/lib/src/highlighter.dart
@@ -90,7 +90,7 @@
/// newlines.
static SourceSpanWithContext _normalizeNewlines(SourceSpanWithContext span) {
final text = span.text;
- if (!text.contains("\r\n")) return span;
+ if (!text.contains('\r\n')) return span;
var endOffset = span.end.offset;
for (var i = 0; i < text.length - 1; i++) {
@@ -105,8 +105,8 @@
sourceUrl: span.sourceUrl,
line: span.end.line,
column: span.end.column),
- text.replaceAll("\r\n", "\n"),
- span.context.replaceAll("\r\n", "\n"));
+ text.replaceAll('\r\n', '\n'),
+ span.context.replaceAll('\r\n', '\n'));
}
/// Normalizes [span] to remove a trailing newline from `span.context`.
@@ -115,17 +115,17 @@
/// the trailing newline used to be.
static SourceSpanWithContext _normalizeTrailingNewline(
SourceSpanWithContext span) {
- if (!span.context.endsWith("\n")) return span;
+ if (!span.context.endsWith('\n')) return span;
// If there's a full blank line on the end of [span.context], it's probably
// significant, so we shouldn't trim it.
- if (span.text.endsWith("\n\n")) return span;
+ if (span.text.endsWith('\n\n')) return span;
final context = span.context.substring(0, span.context.length - 1);
var text = span.text;
var start = span.start;
var end = span.end;
- if (span.text.endsWith("\n") && _isTextAtEndOfContext(span)) {
+ if (span.text.endsWith('\n') && _isTextAtEndOfContext(span)) {
text = span.text.substring(0, span.text.length - 1);
end = SourceLocation(span.end.offset - 1,
sourceUrl: span.sourceUrl,
@@ -163,9 +163,9 @@
if (text.codeUnitAt(text.length - 1) == $lf) {
return text.length == 1
? 0
- : text.length - text.lastIndexOf("\n", text.length - 2) - 1;
+ : text.length - text.lastIndexOf('\n', text.length - 2) - 1;
} else {
- return text.length - text.lastIndexOf("\n") - 1;
+ return text.length - text.lastIndexOf('\n') - 1;
}
}
@@ -202,11 +202,11 @@
// [findLineStart] is guaranteed to return a position immediately after a
// newline. Including that newline would add an extra empty line to the
// end of [lines].
- final lines = context.substring(0, lineStart - 1).split("\n");
+ final lines = context.substring(0, lineStart - 1).split('\n');
var lineNumber = _span.start.line - lines.length;
for (var line in lines) {
_writeSidebar(line: lineNumber);
- _buffer.write(" " * _paddingAfterSidebar);
+ _buffer.write(' ' * _paddingAfterSidebar);
_writeText(line);
_buffer.writeln();
lineNumber++;
@@ -214,7 +214,7 @@
context = context.substring(lineStart);
}
- final lines = context.split("\n");
+ final lines = context.split('\n');
final lastLineIndex = _span.end.line - _span.start.line;
if (lines.last.isEmpty && lines.length > lastLineIndex + 1) {
@@ -247,16 +247,16 @@
// If the span covers the entire first line other than initial whitespace,
// don't bother pointing out exactly where it begins.
if (_multiline && _isOnlyWhitespace(textBefore)) {
- _buffer.write(" ");
+ _buffer.write(' ');
_colorize(() {
- _buffer..write(glyph.glyphOrAscii("┌", "/"))..write(" ");
+ _buffer..write(glyph.glyphOrAscii('┌', '/'))..write(' ');
_writeText(line);
});
_buffer.writeln();
return;
}
- _buffer.write(" " * _paddingAfterSidebar);
+ _buffer.write(' ' * _paddingAfterSidebar);
_writeText(textBefore);
final textInside = line.substring(startColumn, endColumn);
_colorize(() => _writeText(textInside));
@@ -274,17 +274,17 @@
// single-line span, and a pointer to the beginning of a multi-line span.
_writeSidebar();
if (_multiline) {
- _buffer.write(" ");
+ _buffer.write(' ');
_colorize(() {
_buffer
..write(glyph.topLeftCorner)
..write(glyph.horizontalLine * (startColumn + 1))
- ..write("^");
+ ..write('^');
});
} else {
- _buffer.write(" " * (startColumn + 1));
+ _buffer.write(' ' * (startColumn + 1));
_colorize(
- () => _buffer.write("^" * math.max(endColumn - startColumn, 1)));
+ () => _buffer.write('^' * math.max(endColumn - startColumn, 1)));
}
_buffer.writeln();
}
@@ -298,9 +298,9 @@
for (var line in lines) {
_writeSidebar(line: lineNumber);
- _buffer.write(" ");
+ _buffer.write(' ');
_colorize(() {
- _buffer..write(glyph.verticalLine)..write(" ");
+ _buffer..write(glyph.verticalLine)..write(' ');
_writeText(line);
});
_buffer.writeln();
@@ -320,19 +320,19 @@
// If the span covers the entire last line, don't bother pointing out
// exactly where it ends.
if (_multiline && endColumn == line.length) {
- _buffer.write(" ");
+ _buffer.write(' ');
_colorize(() {
- _buffer..write(glyph.glyphOrAscii("└", "\\"))..write(" ");
+ _buffer..write(glyph.glyphOrAscii('└', '\\'))..write(' ');
_writeText(line);
});
_buffer.writeln();
return;
}
- _buffer.write(" ");
+ _buffer.write(' ');
final textInside = line.substring(0, endColumn);
_colorize(() {
- _buffer..write(glyph.verticalLine)..write(" ");
+ _buffer..write(glyph.verticalLine)..write(' ');
_writeText(textInside);
});
_writeText(line.substring(endColumn));
@@ -346,12 +346,12 @@
// Write the highlight for the final line, which is an arrow pointing to the
// end of the span.
_writeSidebar();
- _buffer.write(" ");
+ _buffer.write(' ');
_colorize(() {
_buffer
..write(glyph.bottomLeftCorner)
..write(glyph.horizontalLine * endColumn)
- ..write("^");
+ ..write('^');
});
_buffer.writeln();
}
@@ -362,7 +362,7 @@
var lineNumber = _span.end.line + 1;
for (var line in lines) {
_writeSidebar(line: lineNumber);
- _buffer.write(" " * _paddingAfterSidebar);
+ _buffer.write(' ' * _paddingAfterSidebar);
_writeText(line);
_buffer.writeln();
lineNumber++;
@@ -374,7 +374,7 @@
void _writeText(String text) {
for (var char in text.codeUnits) {
if (char == $tab) {
- _buffer.write(" " * _spacesPerTab);
+ _buffer.write(' ' * _spacesPerTab);
} else {
_buffer.writeCharCode(char);
}
@@ -390,7 +390,7 @@
// numbers to human-friendly 1-indexed line numbers.
_buffer.write((line + 1).toString().padRight(_paddingBeforeSidebar));
} else {
- _buffer.write(" " * _paddingBeforeSidebar);
+ _buffer.write(' ' * _paddingBeforeSidebar);
}
_buffer.write(end ?? glyph.verticalLine);
}, color: colors.blue);
diff --git a/pkgs/source_span/lib/src/span.dart b/pkgs/source_span/lib/src/span.dart
index 87ce846..48dfae7 100644
--- a/pkgs/source_span/lib/src/span.dart
+++ b/pkgs/source_span/lib/src/span.dart
@@ -96,7 +96,7 @@
SourceSpanBase(this.start, this.end, this.text) {
if (end.sourceUrl != start.sourceUrl) {
- throw ArgumentError("Source URLs \"${start.sourceUrl}\" and "
+ throw ArgumentError('Source URLs \"${start.sourceUrl}\" and '
" \"${end.sourceUrl}\" don't match.");
} else if (end.offset < start.offset) {
throw ArgumentError('End $end must come after start $start.');
diff --git a/pkgs/source_span/lib/src/span_exception.dart b/pkgs/source_span/lib/src/span_exception.dart
index 2ce0f1a..02c8974 100644
--- a/pkgs/source_span/lib/src/span_exception.dart
+++ b/pkgs/source_span/lib/src/span_exception.dart
@@ -30,7 +30,7 @@
@override
String toString({color}) {
if (span == null) return message;
- return "Error on ${span.message(message, color: color)}";
+ return 'Error on ${span.message(message, color: color)}';
}
}
diff --git a/pkgs/source_span/lib/src/utils.dart b/pkgs/source_span/lib/src/utils.dart
index 33791de..63ff01c 100644
--- a/pkgs/source_span/lib/src/utils.dart
+++ b/pkgs/source_span/lib/src/utils.dart
@@ -31,7 +31,7 @@
if (text.isEmpty) {
var beginningOfLine = 0;
while (true) {
- final index = context.indexOf("\n", beginningOfLine);
+ final index = context.indexOf('\n', beginningOfLine);
if (index == -1) {
return context.length - beginningOfLine >= column
? beginningOfLine
diff --git a/pkgs/source_span/test/file_test.dart b/pkgs/source_span/test/file_test.dart
index 499f8ef..9192200 100644
--- a/pkgs/source_span/test/file_test.dart
+++ b/pkgs/source_span/test/file_test.dart
@@ -384,23 +384,23 @@
final result = span.expand(other);
expect(result.start, equals(span.start));
expect(result.end, equals(other.end));
- expect(result.text, equals("ar baz\nwhiz"));
+ expect(result.text, equals('ar baz\nwhiz'));
});
- test("works with a following overlapping span", () {
+ test('works with a following overlapping span', () {
final other = file.span(9, 16);
final result = span.expand(other);
expect(result.start, equals(span.start));
expect(result.end, equals(other.end));
- expect(result.text, equals("ar baz\nwhiz"));
+ expect(result.text, equals('ar baz\nwhiz'));
});
- test("works with an internal overlapping span", () {
+ test('works with an internal overlapping span', () {
final other = file.span(7, 10);
expect(span.expand(other), equals(span));
});
- test("works with an external overlapping span", () {
+ test('works with an external overlapping span', () {
final other = file.span(0, 16);
expect(span.expand(other), equals(other));
});
diff --git a/pkgs/source_span/test/location_test.dart b/pkgs/source_span/test/location_test.dart
index c0e9c07..c22a148 100644
--- a/pkgs/source_span/test/location_test.dart
+++ b/pkgs/source_span/test/location_test.dart
@@ -8,7 +8,7 @@
void main() {
SourceLocation location;
setUp(() {
- location = SourceLocation(15, line: 2, column: 6, sourceUrl: "foo.dart");
+ location = SourceLocation(15, line: 2, column: 6, sourceUrl: 'foo.dart');
});
group('errors', () {
@@ -36,7 +36,7 @@
});
test('fields work correctly', () {
- expect(location.sourceUrl, equals(Uri.parse("foo.dart")));
+ expect(location.sourceUrl, equals(Uri.parse('foo.dart')));
expect(location.offset, equals(15));
expect(location.line, equals(2));
expect(location.column, equals(6));
@@ -53,44 +53,44 @@
});
});
- test("distance returns the absolute distance between locations", () {
- final other = SourceLocation(10, sourceUrl: "foo.dart");
+ test('distance returns the absolute distance between locations', () {
+ final other = SourceLocation(10, sourceUrl: 'foo.dart');
expect(location.distance(other), equals(5));
expect(other.distance(location), equals(5));
});
- test("pointSpan returns an empty span at location", () {
+ test('pointSpan returns an empty span at location', () {
final span = location.pointSpan();
expect(span.start, equals(location));
expect(span.end, equals(location));
expect(span.text, isEmpty);
});
- group("compareTo()", () {
- test("sorts by offset", () {
- final other = SourceLocation(20, sourceUrl: "foo.dart");
+ group('compareTo()', () {
+ test('sorts by offset', () {
+ final other = SourceLocation(20, sourceUrl: 'foo.dart');
expect(location.compareTo(other), lessThan(0));
expect(other.compareTo(location), greaterThan(0));
});
- test("considers equal locations equal", () {
+ test('considers equal locations equal', () {
expect(location.compareTo(location), equals(0));
});
});
- group("equality", () {
- test("two locations with the same offset and source are equal", () {
- final other = SourceLocation(15, sourceUrl: "foo.dart");
+ group('equality', () {
+ test('two locations with the same offset and source are equal', () {
+ final other = SourceLocation(15, sourceUrl: 'foo.dart');
expect(location, equals(other));
});
test("a different offset isn't equal", () {
- final other = SourceLocation(10, sourceUrl: "foo.dart");
+ final other = SourceLocation(10, sourceUrl: 'foo.dart');
expect(location, isNot(equals(other)));
});
test("a different source isn't equal", () {
- final other = SourceLocation(15, sourceUrl: "bar.dart");
+ final other = SourceLocation(15, sourceUrl: 'bar.dart');
expect(location, isNot(equals(other)));
});
});