Skip to content

Commit eaf5817

Browse files
kevmoonatebosch
authored andcommitted
Fix latest pedantic lints, remove deprecated author field in pubspec (flutter#17)
1 parent a918e73 commit eaf5817

14 files changed

+139
-104
lines changed

analysis_options.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ analyzer:
55
linter:
66
rules:
77
- always_declare_return_types
8-
#- annotate_overrides
98
- avoid_bool_literals_in_conditional_expressions
109
- avoid_classes_with_only_static_members
1110
- avoid_empty_else
@@ -68,7 +67,6 @@ linter:
6867
- prefer_is_empty
6968
- prefer_is_not_empty
7069
- prefer_null_aware_operators
71-
#- prefer_single_quotes
7270
- prefer_typing_uninitialized_variables
7371
- recursive_getters
7472
- slash_for_doc_comments

example/example.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ num parseNumber(String source) {
1616

1717
// [Scanner.scan] tries to consume a [Pattern] and returns whether or not it
1818
// succeeded. It will move the scan pointer past the end of the pattern.
19-
var negative = scanner.scan("-");
19+
var negative = scanner.scan('-');
2020

2121
// [Scanner.expect] consumes a [Pattern] and throws a [FormatError] if it
2222
// fails. Like [Scanner.scan], it will move the scan pointer forward.
23-
scanner.expect(RegExp(r"\d+"));
23+
scanner.expect(RegExp(r'\d+'));
2424

2525
// [Scanner.lastMatch] holds the [MatchData] for the most recent call to
2626
// [Scanner.scan], [Scanner.expect], or [Scanner.matches].
2727
var number = num.parse(scanner.lastMatch[0]);
2828

29-
if (scanner.scan(".")) {
30-
scanner.expect(RegExp(r"\d+"));
29+
if (scanner.scan('.')) {
30+
scanner.expect(RegExp(r'\d+'));
3131
var decimal = scanner.lastMatch[0];
3232
number += int.parse(decimal) / math.pow(10, decimal.length);
3333
}

lib/src/eager_span_scanner.dart

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,38 @@ import 'span_scanner.dart';
1111
// sdk#23770 is fully complete, we should move the shared code into a mixin.
1212

1313
/// A regular expression matching newlines across platforms.
14-
final _newlineRegExp = RegExp(r"\r\n?|\n");
14+
final _newlineRegExp = RegExp(r'\r\n?|\n');
1515

1616
/// A [SpanScanner] that tracks the line and column eagerly, like [LineScanner].
1717
class EagerSpanScanner extends SpanScanner {
18+
@override
1819
int get line => _line;
1920
int _line = 0;
2021

22+
@override
2123
int get column => _column;
2224
int _column = 0;
2325

26+
@override
2427
LineScannerState get state =>
2528
_EagerSpanScannerState(this, position, line, column);
2629

2730
bool get _betweenCRLF => peekChar(-1) == $cr && peekChar() == $lf;
2831

32+
@override
2933
set state(LineScannerState state) {
3034
if (state is! _EagerSpanScannerState ||
3135
!identical((state as _EagerSpanScannerState)._scanner, this)) {
32-
throw ArgumentError("The given LineScannerState was not returned by "
33-
"this LineScanner.");
36+
throw ArgumentError('The given LineScannerState was not returned by '
37+
'this LineScanner.');
3438
}
3539

3640
super.position = state.position;
3741
_line = state.line;
3842
_column = state.column;
3943
}
4044

45+
@override
4146
set position(int newPosition) {
4247
var oldPosition = position;
4348
super.position = newPosition;
@@ -67,12 +72,14 @@ class EagerSpanScanner extends SpanScanner {
6772
EagerSpanScanner(String string, {sourceUrl, int position})
6873
: super(string, sourceUrl: sourceUrl, position: position);
6974

75+
@override
7076
bool scanChar(int character) {
7177
if (!super.scanChar(character)) return false;
7278
_adjustLineAndColumn(character);
7379
return true;
7480
}
7581

82+
@override
7683
int readChar() {
7784
var character = super.readChar();
7885
_adjustLineAndColumn(character);
@@ -89,6 +96,7 @@ class EagerSpanScanner extends SpanScanner {
8996
}
9097
}
9198

99+
@override
92100
bool scan(Pattern pattern) {
93101
if (!super.scan(pattern)) return false;
94102

@@ -115,8 +123,11 @@ class EagerSpanScanner extends SpanScanner {
115123
/// A class representing the state of an [EagerSpanScanner].
116124
class _EagerSpanScannerState implements LineScannerState {
117125
final EagerSpanScanner _scanner;
126+
@override
118127
final int position;
128+
@override
119129
final int line;
130+
@override
120131
final int column;
121132

122133
_EagerSpanScannerState(this._scanner, this.position, this.line, this.column);

lib/src/exception.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'string_scanner.dart';
88

99
/// An exception thrown by a [StringScanner] that failed to parse a string.
1010
class StringScannerException extends SourceSpanFormatException {
11+
@override
1112
String get source => super.source as String;
1213

1314
/// The URL of the source file being parsed.

lib/src/line_scanner.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import 'string_scanner.dart';
99
// Note that much of this code is duplicated in eager_span_scanner.dart.
1010

1111
/// A regular expression matching newlines across platforms.
12-
final _newlineRegExp = RegExp(r"\r\n?|\n");
12+
final _newlineRegExp = RegExp(r'\r\n?|\n');
1313

1414
/// A subclass of [StringScanner] that tracks line and column information.
1515
class LineScanner extends StringScanner {
@@ -37,15 +37,16 @@ class LineScanner extends StringScanner {
3737

3838
set state(LineScannerState state) {
3939
if (!identical(state._scanner, this)) {
40-
throw ArgumentError("The given LineScannerState was not returned by "
41-
"this LineScanner.");
40+
throw ArgumentError('The given LineScannerState was not returned by '
41+
'this LineScanner.');
4242
}
4343

4444
super.position = state.position;
4545
_line = state.line;
4646
_column = state.column;
4747
}
4848

49+
@override
4950
set position(int newPosition) {
5051
var oldPosition = position;
5152
super.position = newPosition;
@@ -75,12 +76,14 @@ class LineScanner extends StringScanner {
7576
LineScanner(String string, {sourceUrl, int position})
7677
: super(string, sourceUrl: sourceUrl, position: position);
7778

79+
@override
7880
bool scanChar(int character) {
7981
if (!super.scanChar(character)) return false;
8082
_adjustLineAndColumn(character);
8183
return true;
8284
}
8385

86+
@override
8487
int readChar() {
8588
var character = super.readChar();
8689
_adjustLineAndColumn(character);
@@ -97,6 +100,7 @@ class LineScanner extends StringScanner {
97100
}
98101
}
99102

103+
@override
100104
bool scan(Pattern pattern) {
101105
if (!super.scan(pattern)) return false;
102106

lib/src/relative_span_scanner.dart

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ class RelativeSpanScanner extends StringScanner implements SpanScanner {
2727
/// This is used to convert between span-relative and file-relative fields.
2828
final FileLocation _startLocation;
2929

30+
@override
3031
int get line =>
3132
_sourceFile.getLine(_startLocation.offset + position) -
3233
_startLocation.line;
3334

35+
@override
3436
int get column {
3537
var line = _sourceFile.getLine(_startLocation.offset + position);
3638
var column =
@@ -40,37 +42,44 @@ class RelativeSpanScanner extends StringScanner implements SpanScanner {
4042
: column;
4143
}
4244

45+
@override
4346
LineScannerState get state => _SpanScannerState(this, position);
4447

48+
@override
4549
set state(LineScannerState state) {
4650
if (state is! _SpanScannerState ||
4751
!identical((state as _SpanScannerState)._scanner, this)) {
48-
throw ArgumentError("The given LineScannerState was not returned by "
49-
"this LineScanner.");
52+
throw ArgumentError('The given LineScannerState was not returned by '
53+
'this LineScanner.');
5054
}
5155

5256
position = state.position;
5357
}
5458

59+
@override
5560
FileSpan get lastSpan => _lastSpan;
5661
FileSpan _lastSpan;
5762

63+
@override
5864
FileLocation get location =>
5965
_sourceFile.location(_startLocation.offset + position);
6066

67+
@override
6168
FileSpan get emptySpan => location.pointSpan();
6269

6370
RelativeSpanScanner(FileSpan span)
6471
: _sourceFile = span.file,
6572
_startLocation = span.start,
6673
super(span.text, sourceUrl: span.sourceUrl);
6774

75+
@override
6876
FileSpan spanFrom(LineScannerState startState, [LineScannerState endState]) {
6977
var endPosition = endState == null ? position : endState.position;
7078
return _sourceFile.span(_startLocation.offset + startState.position,
7179
_startLocation.offset + endPosition);
7280
}
7381

82+
@override
7483
bool matches(Pattern pattern) {
7584
if (!super.matches(pattern)) {
7685
_lastSpan = null;
@@ -82,6 +91,7 @@ class RelativeSpanScanner extends StringScanner implements SpanScanner {
8291
return true;
8392
}
8493

94+
@override
8595
void error(String message, {Match match, int position, int length}) {
8696
validateErrorArgs(string, match, position, length);
8797

@@ -100,8 +110,11 @@ class _SpanScannerState implements LineScannerState {
100110
/// The [SpanScanner] that created this.
101111
final RelativeSpanScanner _scanner;
102112

113+
@override
103114
final int position;
115+
@override
104116
int get line => _scanner._sourceFile.getLine(position);
117+
@override
105118
int get column => _scanner._sourceFile.getColumn(position);
106119

107120
_SpanScannerState(this._scanner, this.position);

lib/src/span_scanner.dart

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,20 @@ class SpanScanner extends StringScanner implements LineScanner {
1919
/// This caches line break information and is used to generate [FileSpan]s.
2020
final SourceFile _sourceFile;
2121

22+
@override
2223
int get line => _sourceFile.getLine(position);
24+
@override
2325
int get column => _sourceFile.getColumn(position);
2426

27+
@override
2528
LineScannerState get state => _SpanScannerState(this, position);
2629

30+
@override
2731
set state(LineScannerState state) {
2832
if (state is! _SpanScannerState ||
2933
!identical((state as _SpanScannerState)._scanner, this)) {
30-
throw ArgumentError("The given LineScannerState was not returned by "
31-
"this LineScanner.");
34+
throw ArgumentError('The given LineScannerState was not returned by '
35+
'this LineScanner.');
3236
}
3337

3438
position = state.position;
@@ -89,6 +93,7 @@ class SpanScanner extends StringScanner implements LineScanner {
8993
return _sourceFile.span(startState.position, endPosition);
9094
}
9195

96+
@override
9297
bool matches(Pattern pattern) {
9398
if (!super.matches(pattern)) {
9499
_lastSpan = null;
@@ -99,6 +104,7 @@ class SpanScanner extends StringScanner implements LineScanner {
99104
return true;
100105
}
101106

107+
@override
102108
void error(String message, {Match match, int position, int length}) {
103109
validateErrorArgs(string, match, position, length);
104110

@@ -116,8 +122,11 @@ class _SpanScannerState implements LineScannerState {
116122
/// The [SpanScanner] that created this.
117123
final SpanScanner _scanner;
118124

125+
@override
119126
final int position;
127+
@override
120128
int get line => _scanner._sourceFile.getLine(position);
129+
@override
121130
int get column => _scanner._sourceFile.getColumn(position);
122131

123132
_SpanScannerState(this._scanner, this.position);

lib/src/string_scanner.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class StringScanner {
2424
int get position => _position;
2525
set position(int position) {
2626
if (position < 0 || position > string.length) {
27-
throw ArgumentError("Invalid position $position");
27+
throw ArgumentError('Invalid position $position');
2828
}
2929

3030
_position = position;
@@ -68,7 +68,7 @@ class StringScanner {
6868
/// This throws a [FormatException] if the string has been fully consumed. It
6969
/// doesn't affect [lastMatch].
7070
int readChar() {
71-
if (isDone) _fail("more input");
71+
if (isDone) _fail('more input');
7272
return string.codeUnitAt(_position++);
7373
}
7474

@@ -144,10 +144,10 @@ class StringScanner {
144144
if (name == null) {
145145
if (pattern is RegExp) {
146146
var source = pattern.pattern;
147-
name = "/$source/";
147+
name = '/$source/';
148148
} else {
149149
name =
150-
pattern.toString().replaceAll("\\", "\\\\").replaceAll('"', '\\"');
150+
pattern.toString().replaceAll('\\', '\\\\').replaceAll('"', '\\"');
151151
name = '"$name"';
152152
}
153153
}
@@ -158,7 +158,7 @@ class StringScanner {
158158
/// [FormatException].
159159
void expectDone() {
160160
if (isDone) return;
161-
_fail("no more input");
161+
_fail('no more input');
162162
}
163163

164164
/// Returns whether or not [pattern] matches at the current position of the
@@ -210,6 +210,6 @@ class StringScanner {
210210
/// Throws a [FormatException] describing that [name] is expected at the
211211
/// current position in the string.
212212
void _fail(String name) {
213-
error("expected $name.", position: position, length: 0);
213+
error('expected $name.', position: position, length: 0);
214214
}
215215
}

lib/src/utils.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ void validateErrorArgs(String string, Match match, int position, int length) {
1212

1313
if (position != null) {
1414
if (position < 0) {
15-
throw RangeError("position must be greater than or equal to 0.");
15+
throw RangeError('position must be greater than or equal to 0.');
1616
} else if (position > string.length) {
17-
throw RangeError("position must be less than or equal to the "
18-
"string length.");
17+
throw RangeError('position must be less than or equal to the '
18+
'string length.');
1919
}
2020
}
2121

2222
if (length != null && length < 0) {
23-
throw RangeError("length must be greater than or equal to 0.");
23+
throw RangeError('length must be greater than or equal to 0.');
2424
}
2525

2626
if (position != null && length != null && position + length > string.length) {
27-
throw RangeError("position plus length must not go beyond the end of "
28-
"the string.");
27+
throw RangeError('position plus length must not go beyond the end of '
28+
'the string.');
2929
}
3030
}

pubspec.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ name: string_scanner
22
version: 1.0.5
33

44
description: A class for parsing strings using a sequence of patterns.
5-
author: Dart Team <[email protected]>
65
homepage: https://github.com/dart-lang/string_scanner
76

87
environment:

0 commit comments

Comments
 (0)