Re-enable lint disabled in the last PR (dart-lang/source_span#53) Some of these were lints that had been enabled while the review was ongoing, some were lints that had been around a while but ignored. Drop author field from pubspec
diff --git a/pkgs/source_span/CHANGELOG.md b/pkgs/source_span/CHANGELOG.md index 014cc4c..c24535b 100644 --- a/pkgs/source_span/CHANGELOG.md +++ b/pkgs/source_span/CHANGELOG.md
@@ -1,3 +1,5 @@ +# 1.6.1-dev + # 1.6.0 * Add support for highlighting multiple source spans at once, providing more
diff --git a/pkgs/source_span/analysis_options.yaml b/pkgs/source_span/analysis_options.yaml index 0ce7911..ab5a4f2 100644 --- a/pkgs/source_span/analysis_options.yaml +++ b/pkgs/source_span/analysis_options.yaml
@@ -2,9 +2,6 @@ analyzer: strong-mode: implicit-casts: false - errors: - # TODO(natebosch): fix and re-enable. - prefer_single_quotes: ignore linter: rules: - always_declare_return_types @@ -29,8 +26,7 @@ - await_only_futures - camel_case_types - cancel_subscriptions - # TODO(natebosch): fix and re-enable. - #- cascade_invocations + - cascade_invocations - comment_references - constant_identifier_names - control_flow_in_finally @@ -63,12 +59,10 @@ - prefer_contains - prefer_equal_for_default_values - prefer_final_fields - # TODO(natebosch): fix and re-enable. - #- prefer_final_locals + - prefer_final_locals - prefer_generic_function_type_aliases - prefer_initializing_formals - # TODO(natebosch): fix and re-enable. - #- prefer_interpolation_to_compose_strings + - prefer_interpolation_to_compose_strings - prefer_is_empty - prefer_is_not_empty - prefer_null_aware_operators
diff --git a/pkgs/source_span/lib/src/highlighter.dart b/pkgs/source_span/lib/src/highlighter.dart index feb5594..cef6f79 100644 --- a/pkgs/source_span/lib/src/highlighter.dart +++ b/pkgs/source_span/lib/src/highlighter.dart
@@ -114,8 +114,8 @@ /// file that aren't adjacent in the original file. static bool _contiguous(List<_Line> lines) { for (var i = 0; i < lines.length - 1; i++) { - var thisLine = lines[i]; - var nextLine = lines[i + 1]; + final thisLine = lines[i]; + final nextLine = lines[i + 1]; if (thisLine.number + 1 != nextLine.number && thisLine.url == nextLine.url) { return false; @@ -127,7 +127,7 @@ /// Collect all the source lines from the contexts of all spans in /// [highlights], and associates them with the highlights that cover them. static List<_Line> _collateLines(List<_Highlight> highlights) { - var highlightsByUrl = + final highlightsByUrl = groupBy(highlights, (highlight) => highlight.span.sourceUrl); for (var list in highlightsByUrl.values) { list.sort((highlight1, highlight2) => @@ -137,19 +137,19 @@ return highlightsByUrl.values.expand((highlightsForFile) { // First, create a list of all the lines in the current file that we have // context for along with their line numbers. - var lines = <_Line>[]; + final lines = <_Line>[]; for (var highlight in highlightsForFile) { - var context = highlight.span.context; + final context = highlight.span.context; // If [highlight.span.context] contains lines prior to the one // [highlight.span.text] appears on, write those first. - var lineStart = findLineStart( + final lineStart = findLineStart( context, highlight.span.text, highlight.span.start.column); assert(lineStart != null); // enforced by [_normalizeContext] - var linesBeforeSpan = + final linesBeforeSpan = '\n'.allMatches(context.substring(0, lineStart)).length; - var url = highlight.span.sourceUrl; + final url = highlight.span.sourceUrl; var lineNumber = highlight.span.start.line - linesBeforeSpan; for (var line in context.split('\n')) { // Only add a line if it hasn't already been added for a previous span. @@ -161,14 +161,14 @@ } // Next, associate each line with each highlights that covers it. - var activeHighlights = <_Highlight>[]; + final activeHighlights = <_Highlight>[]; var highlightIndex = 0; for (var line in lines) { activeHighlights.removeWhere((highlight) => highlight.span.sourceUrl != line.url || highlight.span.end.line < line.number); - var oldHighlightLength = activeHighlights.length; + final oldHighlightLength = activeHighlights.length; for (var highlight in highlightsForFile.skip(highlightIndex)) { if (highlight.span.start.line > line.number) break; if (highlight.span.sourceUrl != line.url) break; @@ -192,12 +192,12 @@ // Each index of this list represents a column after the sidebar that could // contain a line indicating an active highlight. If it's `null`, that // column is empty; if it contains a highlight, it should be drawn for that column. - var highlightsByColumn = List<_Highlight>(_maxMultilineSpans); + final highlightsByColumn = List<_Highlight>(_maxMultilineSpans); for (var i = 0; i < _lines.length; i++) { - var line = _lines[i]; + final line = _lines[i]; if (i > 0) { - var lastLine = _lines[i - 1]; + final lastLine = _lines[i - 1]; if (lastLine.url != line.url) { _writeSidebar(end: glyph.upEnd); _buffer.writeln(); @@ -226,7 +226,7 @@ _writeMultilineHighlights(line, highlightsByColumn); if (highlightsByColumn.isNotEmpty) _buffer.write(' '); - var primary = line.highlights + final primary = line.highlights .firstWhere((highlight) => highlight.isPrimary, orElse: () => null); if (primary != null) { _writeHighlightedText( @@ -263,9 +263,9 @@ _writeSidebar(end: glyph.downEnd); } else { _writeSidebar(end: glyph.topLeftCorner); - _colorize(() => _buffer.write("${glyph.horizontalLine * 2}>"), + _colorize(() => _buffer.write('${glyph.horizontalLine * 2}>'), color: colors.blue); - _buffer.write(" ${p.prettyUri(url)}"); + _buffer.write(' ${p.prettyUri(url)}'); } _buffer.writeln(); } @@ -284,13 +284,13 @@ var openedOnThisLine = false; String openedOnThisLineColor; - var currentColor = current == null + final currentColor = current == null ? null : current.isPrimary ? _primaryColor : _secondaryColor; var foundCurrent = false; for (var highlight in highlightsByColumn) { - var startLine = highlight?.span?.start?.line; - var endLine = highlight?.span?.end?.line; + final startLine = highlight?.span?.start?.line; + final endLine = highlight?.span?.end?.line; if (current != null && highlight == current) { foundCurrent = true; assert(startLine == line.number || endLine == line.number); @@ -312,7 +312,7 @@ } } else { _colorize(() { - var vertical = openedOnThisLine ? glyph.cross : glyph.verticalLine; + final vertical = openedOnThisLine ? glyph.cross : glyph.verticalLine; if (current != null) { _buffer.write(vertical); } else if (startLine == line.number) { @@ -354,7 +354,7 @@ /// This may either add or remove [highlight] from [highlightsByColumn]. void _writeIndicator( _Line line, _Highlight highlight, List<_Highlight> highlightsByColumn) { - var color = highlight.isPrimary ? _primaryColor : _secondaryColor; + final color = highlight.isPrimary ? _primaryColor : _secondaryColor; if (!isMultiline(highlight.span)) { _writeSidebar(); _buffer.write(' '); @@ -363,7 +363,7 @@ _colorize(() { _writeUnderline(line, highlight.span, - highlight.isPrimary ? "^" : glyph.horizontalLineBold); + highlight.isPrimary ? '^' : glyph.horizontalLineBold); _writeLabel(highlight.label); }, color: color); _buffer.writeln(); @@ -378,7 +378,7 @@ color: color); _buffer.writeln(); } else if (highlight.span.end.line == line.number) { - var coversWholeLine = highlight.span.end.column == line.text.length; + final coversWholeLine = highlight.span.end.column == line.text.length; if (coversWholeLine && highlight.label == null) { replaceWithNull(highlightsByColumn, highlight); return; @@ -413,13 +413,14 @@ // Adjust the start and end columns to account for any tabs that were // converted to spaces. - var tabsBefore = _countTabs(line.text.substring(0, startColumn)); - var tabsInside = _countTabs(line.text.substring(startColumn, endColumn)); + final tabsBefore = _countTabs(line.text.substring(0, startColumn)); + final tabsInside = _countTabs(line.text.substring(startColumn, endColumn)); startColumn += tabsBefore * (_spacesPerTab - 1); endColumn += (tabsBefore + tabsInside) * (_spacesPerTab - 1); - _buffer.write(" " * startColumn); - _buffer.write(character * math.max(endColumn - startColumn, 1)); + _buffer + ..write(' ' * startColumn) + ..write(character * math.max(endColumn - startColumn, 1)); } /// Write an arrow pointing to column [column] in [line]. @@ -427,15 +428,16 @@ /// If the arrow points to a tab character, this will point to the beginning /// of the tab if [beginning] is `true` and the end if it's `false`. void _writeArrow(_Line line, int column, {bool beginning = true}) { - var tabs = _countTabs(line.text.substring(0, column + (beginning ? 0 : 1))); + final tabs = + _countTabs(line.text.substring(0, column + (beginning ? 0 : 1))); _buffer ..write(glyph.horizontalLine * (1 + column + tabs * (_spacesPerTab - 1))) - ..write("^"); + ..write('^'); } /// Writes a space followed by [label] if [label] isn't `null`. void _writeLabel(String label) { - if (label != null) _buffer.write(" $label"); + if (label != null) _buffer.write(' $label'); } /// Writes a snippet from the source text, converting hard tab characters into @@ -462,8 +464,9 @@ // human-friendly 1-indexed line numbers. if (line != null) text = (line + 1).toString(); _colorize(() { - _buffer.write((text ?? '').padRight(_paddingBeforeSidebar)); - _buffer.write(end ?? glyph.verticalLine); + _buffer + ..write((text ?? '').padRight(_paddingBeforeSidebar)) + ..write(end ?? glyph.verticalLine); }, color: colors.blue); } @@ -612,7 +615,7 @@ text, // If the context also ends with a newline, it's possible that we don't // have the full context for that line, so we shouldn't print it at all. - span.context.endsWith("\n") + span.context.endsWith('\n') ? span.context.substring(0, span.context.length - 1) : span.context); } @@ -640,11 +643,11 @@ @override String toString() { - var buffer = StringBuffer(); - if (isPrimary) buffer.write("primary "); - buffer.write("${span.start.line}:${span.start.column}-" - "${span.end.line}:${span.end.column}"); - if (label != null) buffer.write(" ($label)"); + final buffer = StringBuffer(); + if (isPrimary) buffer.write('primary '); + buffer.write('${span.start.line}:${span.start.column}-' + '${span.end.line}:${span.end.column}'); + if (label != null) buffer.write(' ($label)'); return buffer.toString(); } }
diff --git a/pkgs/source_span/lib/src/span_exception.dart b/pkgs/source_span/lib/src/span_exception.dart index 5b33d06..32aaa4e 100644 --- a/pkgs/source_span/lib/src/span_exception.dart +++ b/pkgs/source_span/lib/src/span_exception.dart
@@ -92,11 +92,12 @@ useColor = true; } - return "Error on " + - span.messageMultiple(message, primaryLabel, secondarySpans, - color: useColor, - primaryColor: primaryColor, - secondaryColor: secondaryColor); + final formatted = span.messageMultiple( + message, primaryLabel, secondarySpans, + color: useColor, + primaryColor: primaryColor, + secondaryColor: secondaryColor); + return 'Error on $formatted'; } }
diff --git a/pkgs/source_span/lib/src/utils.dart b/pkgs/source_span/lib/src/utils.dart index 12b15b3..5cb5e90 100644 --- a/pkgs/source_span/lib/src/utils.dart +++ b/pkgs/source_span/lib/src/utils.dart
@@ -35,16 +35,16 @@ /// Sets the first `null` element of [list] to [element]. void replaceFirstNull<E>(List<E> list, E element) { - var index = list.indexOf(null); - if (index < 0) throw ArgumentError("$list contains no null elements."); + final index = list.indexOf(null); + if (index < 0) throw ArgumentError('$list contains no null elements.'); list[index] = element; } /// Sets the element of [list] that currently contains [element] to `null`. void replaceWithNull<E>(List<E> list, E element) { - var index = list.indexOf(element); + final index = list.indexOf(element); if (index < 0) { - throw ArgumentError("$list contains no elements matching $element."); + throw ArgumentError('$list contains no elements matching $element.'); } list[index] = null;
diff --git a/pkgs/source_span/pubspec.yaml b/pkgs/source_span/pubspec.yaml index 2054423..fce2124 100644 --- a/pkgs/source_span/pubspec.yaml +++ b/pkgs/source_span/pubspec.yaml
@@ -1,8 +1,7 @@ name: source_span -version: 1.6.0 +version: 1.6.1-dev description: A library for identifying source spans and locations. -author: Dart Team <misc@dartlang.org> homepage: https://github.com/dart-lang/source_span environment:
diff --git a/pkgs/source_span/test/multiple_highlight_test.dart b/pkgs/source_span/test/multiple_highlight_test.dart index f0cceed..d9d1b30 100644 --- a/pkgs/source_span/test/multiple_highlight_test.dart +++ b/pkgs/source_span/test/multiple_highlight_test.dart
@@ -26,13 +26,13 @@ fwee fwoo fwip argle bargle boo gibble bibble bop -''', url: "file1.txt"); +''', url: 'file1.txt'); }); - test("highlights spans on separate lines", () { + test('highlights spans on separate lines', () { expect( file.span(17, 21).highlightMultiple( - "one", {file.span(31, 34): "two", file.span(4, 7): "three"}), + 'one', {file.span(31, 34): 'two', file.span(4, 7): 'three'}), equals(""" , 1 | foo bar baz @@ -44,10 +44,10 @@ '""")); }); - test("highlights spans on the same line", () { + test('highlights spans on the same line', () { expect( file.span(17, 21).highlightMultiple( - "one", {file.span(22, 26): "two", file.span(12, 16): "three"}), + 'one', {file.span(22, 26): 'two', file.span(12, 16): 'three'}), equals(""" , 2 | whiz bang boom @@ -57,10 +57,10 @@ '""")); }); - test("highlights overlapping spans on the same line", () { + test('highlights overlapping spans on the same line', () { expect( file.span(17, 21).highlightMultiple( - "one", {file.span(20, 26): "two", file.span(12, 18): "three"}), + 'one', {file.span(20, 26): 'two', file.span(12, 18): 'three'}), equals(""" , 2 | whiz bang boom @@ -70,10 +70,10 @@ '""")); }); - test("highlights multiple multiline spans", () { + test('highlights multiple multiline spans', () { expect( file.span(27, 54).highlightMultiple( - "one", {file.span(54, 89): "two", file.span(0, 27): "three"}), + 'one', {file.span(54, 89): 'two', file.span(0, 27): 'three'}), equals(""" , 1 | / foo bar baz @@ -88,10 +88,10 @@ '""")); }); - test("highlights multiple overlapping multiline spans", () { + test('highlights multiple overlapping multiline spans', () { expect( file.span(12, 70).highlightMultiple( - "one", {file.span(54, 89): "two", file.span(0, 27): "three"}), + 'one', {file.span(54, 89): 'two', file.span(0, 27): 'three'}), equals(""" , 1 | /- foo bar baz @@ -106,12 +106,12 @@ '""")); }); - test("highlights many layers of overlaps", () { + test('highlights many layers of overlaps', () { expect( - file.span(0, 54).highlightMultiple("one", { - file.span(12, 77): "two", - file.span(27, 84): "three", - file.span(39, 88): "four" + file.span(0, 54).highlightMultiple('one', { + file.span(12, 77): 'two', + file.span(27, 84): 'three', + file.span(39, 88): 'four' }), equals(""" , @@ -129,11 +129,11 @@ }); group("highlights a multiline span that's a subset", () { - test("with no first or last line overlap", () { + test('with no first or last line overlap', () { expect( file .span(27, 53) - .highlightMultiple("inner", {file.span(12, 70): "outer"}), + .highlightMultiple('inner', {file.span(12, 70): 'outer'}), equals(""" , 2 | /- whiz bang boom @@ -145,11 +145,11 @@ '""")); }); - test("overlapping the whole first line", () { + test('overlapping the whole first line', () { expect( file .span(12, 53) - .highlightMultiple("inner", {file.span(12, 70): "outer"}), + .highlightMultiple('inner', {file.span(12, 70): 'outer'}), equals(""" , 2 | // whiz bang boom @@ -161,11 +161,11 @@ '""")); }); - test("overlapping part of first line", () { + test('overlapping part of first line', () { expect( file .span(17, 53) - .highlightMultiple("inner", {file.span(12, 70): "outer"}), + .highlightMultiple('inner', {file.span(12, 70): 'outer'}), equals(""" , 2 | /- whiz bang boom @@ -178,11 +178,11 @@ '""")); }); - test("overlapping the whole last line", () { + test('overlapping the whole last line', () { expect( file .span(27, 70) - .highlightMultiple("inner", {file.span(12, 70): "outer"}), + .highlightMultiple('inner', {file.span(12, 70): 'outer'}), equals(""" , 2 | /- whiz bang boom @@ -194,11 +194,11 @@ '""")); }); - test("overlapping part of the last line", () { + test('overlapping part of the last line', () { expect( file .span(27, 66) - .highlightMultiple("inner", {file.span(12, 70): "outer"}), + .highlightMultiple('inner', {file.span(12, 70): 'outer'}), equals(""" , 2 | /- whiz bang boom @@ -211,12 +211,12 @@ }); }); - group("a single-line span in a multiline span", () { - test("on the first line", () { + group('a single-line span in a multiline span', () { + test('on the first line', () { expect( file .span(17, 21) - .highlightMultiple("inner", {file.span(12, 70): "outer"}), + .highlightMultiple('inner', {file.span(12, 70): 'outer'}), equals(""" , 2 | / whiz bang boom @@ -228,11 +228,11 @@ '""")); }); - test("in the middle", () { + test('in the middle', () { expect( file .span(31, 34) - .highlightMultiple("inner", {file.span(12, 70): "outer"}), + .highlightMultiple('inner', {file.span(12, 70): 'outer'}), equals(""" , 2 | / whiz bang boom @@ -244,11 +244,11 @@ '""")); }); - test("on the last line", () { + test('on the last line', () { expect( file .span(60, 66) - .highlightMultiple("inner", {file.span(12, 70): "outer"}), + .highlightMultiple('inner', {file.span(12, 70): 'outer'}), equals(""" , 2 | / whiz bang boom @@ -261,13 +261,13 @@ }); }); - test("highlights multiple files with their URLs", () { - var file2 = SourceFile.fromString(''' + test('highlights multiple files with their URLs', () { + final file2 = SourceFile.fromString(''' quibble bibble boop -''', url: "file2.txt"); +''', url: 'file2.txt'); expect( - file.span(31, 34).highlightMultiple("one", {file2.span(8, 14): "two"}), + file.span(31, 34).highlightMultiple('one', {file2.span(8, 14): 'two'}), equals(""" ,--> file1.txt 3 | zip zap zop