Skip to content

Commit

Permalink
Enforce and fix prefer_single_quotes (dart-lang/source_span#47)
Browse files Browse the repository at this point in the history
We will soon be enforcing this with `package:pedantic`.
  • Loading branch information
natebosch authored Nov 14, 2019
1 parent 35ff099 commit be21022
Show file tree
Hide file tree
Showing 8 changed files with 337 additions and 337 deletions.
2 changes: 1 addition & 1 deletion pkgs/source_span/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ linter:
- prefer_is_empty
- prefer_is_not_empty
- prefer_null_aware_operators
#- prefer_single_quotes
- prefer_single_quotes
- prefer_typing_uninitialized_variables
- recursive_getters
- slash_for_doc_comments
Expand Down
50 changes: 25 additions & 25 deletions pkgs/source_span/lib/src/file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class SourceFile {
/// This constructor is deprecated.
///
/// Use [new SourceFile.fromString] instead.
@Deprecated("Will be removed in 2.0.0")
@Deprecated('Will be removed in 2.0.0')
SourceFile(String text, {url}) : this.decoded(text.runes, url: url);

/// Creates a new source file from [text].
Expand Down Expand Up @@ -98,10 +98,10 @@ class SourceFile {
/// Gets the 0-based line corresponding to [offset].
int getLine(int offset) {
if (offset < 0) {
throw RangeError("Offset may not be negative, was $offset.");
throw RangeError('Offset may not be negative, was $offset.');
} else if (offset > length) {
throw RangeError("Offset $offset must not be greater than the number "
"of characters in the file, $length.");
throw RangeError('Offset $offset must not be greater than the number '
'of characters in the file, $length.');
}

if (offset < _lineStarts.first) return -1;
Expand Down Expand Up @@ -163,24 +163,24 @@ class SourceFile {
/// is used to more efficiently compute the column.
int getColumn(int offset, {int line}) {
if (offset < 0) {
throw RangeError("Offset may not be negative, was $offset.");
throw RangeError('Offset may not be negative, was $offset.');
} else if (offset > length) {
throw RangeError("Offset $offset must be not be greater than the "
"number of characters in the file, $length.");
throw RangeError('Offset $offset must be not be greater than the '
'number of characters in the file, $length.');
}

if (line == null) {
line = getLine(offset);
} else if (line < 0) {
throw RangeError("Line may not be negative, was $line.");
throw RangeError('Line may not be negative, was $line.');
} else if (line >= lines) {
throw RangeError("Line $line must be less than the number of "
"lines in the file, $lines.");
throw RangeError('Line $line must be less than the number of '
'lines in the file, $lines.');
}

final lineStart = _lineStarts[line];
if (lineStart > offset) {
throw RangeError("Line $line comes after offset $offset.");
throw RangeError('Line $line comes after offset $offset.');
}

return offset - lineStart;
Expand All @@ -193,12 +193,12 @@ class SourceFile {
column ??= 0;

if (line < 0) {
throw RangeError("Line may not be negative, was $line.");
throw RangeError('Line may not be negative, was $line.');
} else if (line >= lines) {
throw RangeError("Line $line must be less than the number of "
"lines in the file, $lines.");
throw RangeError('Line $line must be less than the number of '
'lines in the file, $lines.');
} else if (column < 0) {
throw RangeError("Column may not be negative, was $column.");
throw RangeError('Column may not be negative, was $column.');
}

final result = _lineStarts[line] + column;
Expand Down Expand Up @@ -241,10 +241,10 @@ class FileLocation extends SourceLocationMixin implements SourceLocation {

FileLocation._(this.file, this.offset) {
if (offset < 0) {
throw RangeError("Offset may not be negative, was $offset.");
throw RangeError('Offset may not be negative, was $offset.');
} else if (offset > file.length) {
throw RangeError("Offset $offset must not be greater than the number "
"of characters in the file, ${file.length}.");
throw RangeError('Offset $offset must not be greater than the number '
'of characters in the file, ${file.length}.');
}
}

Expand Down Expand Up @@ -328,7 +328,7 @@ class _FileSpan extends SourceSpanMixin implements FileSpan {
// ...unless this is a point span, in which case we want to include the
// next line (or the empty string if this is the end of the file).
return endLine == file.lines - 1
? ""
? ''
: file.getText(
file.getOffset(endLine), file.getOffset(endLine + 1));
}
Expand All @@ -351,10 +351,10 @@ class _FileSpan extends SourceSpanMixin implements FileSpan {
if (_end < _start) {
throw ArgumentError('End $_end must come after start $_start.');
} else if (_end > file.length) {
throw RangeError("End $_end must not be greater than the number "
"of characters in the file, ${file.length}.");
throw RangeError('End $_end must not be greater than the number '
'of characters in the file, ${file.length}.');
} else if (_start < 0) {
throw RangeError("Start may not be negative, was $_start.");
throw RangeError('Start may not be negative, was $_start.');
}
}

Expand All @@ -375,11 +375,11 @@ class _FileSpan extends SourceSpanMixin implements FileSpan {

if (other is _FileSpan) {
if (_start > other._end || other._start > _end) {
throw ArgumentError("Spans $this and $other are disjoint.");
throw ArgumentError('Spans $this and $other are disjoint.');
}
} else {
if (_start > other.end.offset || other.start.offset > _end) {
throw ArgumentError("Spans $this and $other are disjoint.");
throw ArgumentError('Spans $this and $other are disjoint.');
}
}

Expand Down Expand Up @@ -409,7 +409,7 @@ class _FileSpan extends SourceSpanMixin implements FileSpan {
@override
FileSpan expand(FileSpan other) {
if (sourceUrl != other.sourceUrl) {
throw ArgumentError("Source URLs \"$sourceUrl\" and "
throw ArgumentError('Source URLs \"$sourceUrl\" and '
" \"${other.sourceUrl}\" don't match.");
}

Expand Down
12 changes: 6 additions & 6 deletions pkgs/source_span/lib/src/location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ class SourceLocation implements Comparable<SourceLocation> {
line = line == null ? 0 : line,
column = column == null ? offset : column {
if (offset < 0) {
throw RangeError("Offset may not be negative, was $offset.");
throw RangeError('Offset may not be negative, was $offset.');
} else if (line != null && line < 0) {
throw RangeError("Line may not be negative, was $line.");
throw RangeError('Line may not be negative, was $line.');
} else if (column != null && column < 0) {
throw RangeError("Column may not be negative, was $column.");
throw RangeError('Column may not be negative, was $column.');
}
}

Expand All @@ -61,22 +61,22 @@ class SourceLocation implements Comparable<SourceLocation> {
/// This always returns a non-negative value.
int distance(SourceLocation other) {
if (sourceUrl != other.sourceUrl) {
throw ArgumentError("Source URLs \"$sourceUrl\" and "
throw ArgumentError('Source URLs \"$sourceUrl\" and '
"\"${other.sourceUrl}\" don't match.");
}
return (offset - other.offset).abs();
}

/// Returns a span that covers only a single point: this location.
SourceSpan pointSpan() => SourceSpan(this, this, "");
SourceSpan pointSpan() => SourceSpan(this, this, '');

/// Compares two locations.
///
/// [other] must have the same source URL as `this`.
@override
int compareTo(SourceLocation other) {
if (sourceUrl != other.sourceUrl) {
throw ArgumentError("Source URLs \"$sourceUrl\" and "
throw ArgumentError('Source URLs \"$sourceUrl\" and '
"\"${other.sourceUrl}\" don't match.");
}
return offset - other.offset;
Expand Down
6 changes: 3 additions & 3 deletions pkgs/source_span/lib/src/location_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ abstract class SourceLocationMixin implements SourceLocation {
@override
int distance(SourceLocation other) {
if (sourceUrl != other.sourceUrl) {
throw ArgumentError("Source URLs \"$sourceUrl\" and "
throw ArgumentError('Source URLs \"$sourceUrl\" and '
"\"${other.sourceUrl}\" don't match.");
}
return (offset - other.offset).abs();
}

@override
SourceSpan pointSpan() => SourceSpan(this, this, "");
SourceSpan pointSpan() => SourceSpan(this, this, '');

@override
int compareTo(SourceLocation other) {
if (sourceUrl != other.sourceUrl) {
throw ArgumentError("Source URLs \"$sourceUrl\" and "
throw ArgumentError('Source URLs \"$sourceUrl\" and '
"\"${other.sourceUrl}\" don't match.");
}
return offset - other.offset;
Expand Down
6 changes: 3 additions & 3 deletions pkgs/source_span/lib/src/span_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ abstract class SourceSpanMixin implements SourceSpan {
@override
SourceSpan union(SourceSpan other) {
if (sourceUrl != other.sourceUrl) {
throw ArgumentError("Source URLs \"$sourceUrl\" and "
throw ArgumentError('Source URLs \"$sourceUrl\" and '
" \"${other.sourceUrl}\" don't match.");
}

Expand All @@ -41,7 +41,7 @@ abstract class SourceSpanMixin implements SourceSpan {
final endSpan = end == this.end ? this : other;

if (beginSpan.end.compareTo(endSpan.start) < 0) {
throw ArgumentError("Spans $this and $other are disjoint.");
throw ArgumentError('Spans $this and $other are disjoint.');
}

final text = beginSpan.text +
Expand All @@ -68,7 +68,7 @@ abstract class SourceSpanMixin implements SourceSpan {

@override
String highlight({color}) {
if (this is! SourceSpanWithContext && length == 0) return "";
if (this is! SourceSpanWithContext && length == 0) return '';
return Highlighter(this, color: color).highlight();
}

Expand Down
Loading

0 comments on commit be21022

Please sign in to comment.