Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit 4b22667

Browse files
committed
Enable and fix a number of lints, test on oldest supported SDK
Bump min SDK to Dart 2.0
1 parent 4c6d722 commit 4b22667

16 files changed

+210
-122
lines changed

.travis.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ language: dart
22

33
dart:
44
- dev
5-
- stable
5+
- 2.0.0
66

77
dart_task:
88
- test: --platform vm,chrome
@@ -13,7 +13,11 @@ matrix:
1313
- dart: dev
1414
dart_task: dartfmt
1515
- dart: dev
16-
dart_task: analyzer
16+
dart_task:
17+
dartanalyzer: --fatals-warnings --fatal-hints .
18+
- dart: 2.0.0
19+
dart_task:
20+
dartanalyzer: --fatals-warnings .
1721

1822
# Only building master means that we don't run two builds for each pull request.
1923
branches:

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.0.5
2+
3+
- Update Dart SDK constraint to `>=2.0.0 <3.0.0`.
4+
15
## 1.0.4
26

37
* Add @alwaysThrows annotation to error method.

analysis_options.yaml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
include: package:pedantic/analysis_options.yaml
2+
analyzer:
3+
# strong-mode:
4+
# implicit-casts: false
5+
linter:
6+
rules:
7+
- always_declare_return_types
8+
#- annotate_overrides
9+
- avoid_bool_literals_in_conditional_expressions
10+
- avoid_classes_with_only_static_members
11+
- avoid_empty_else
12+
- avoid_function_literals_in_foreach_calls
13+
- avoid_init_to_null
14+
- avoid_null_checks_in_equality_operators
15+
- avoid_relative_lib_imports
16+
- avoid_renaming_method_parameters
17+
- avoid_return_types_on_setters
18+
#- avoid_returning_null
19+
- avoid_returning_null_for_future
20+
- avoid_returning_null_for_void
21+
- avoid_returning_this
22+
- avoid_shadowing_type_parameters
23+
- avoid_single_cascade_in_expression_statements
24+
- avoid_types_as_parameter_names
25+
- avoid_unused_constructor_parameters
26+
- await_only_futures
27+
- camel_case_types
28+
- cancel_subscriptions
29+
#- cascade_invocations
30+
- comment_references
31+
- constant_identifier_names
32+
- control_flow_in_finally
33+
- directives_ordering
34+
- empty_catches
35+
- empty_constructor_bodies
36+
- empty_statements
37+
- file_names
38+
- hash_and_equals
39+
- implementation_imports
40+
- invariant_booleans
41+
- iterable_contains_unrelated_type
42+
- join_return_with_assignment
43+
- library_names
44+
- library_prefixes
45+
- list_remove_unrelated_type
46+
- literal_only_boolean_expressions
47+
- no_adjacent_strings_in_list
48+
- no_duplicate_case_values
49+
- non_constant_identifier_names
50+
- null_closures
51+
- omit_local_variable_types
52+
- only_throw_errors
53+
- overridden_fields
54+
- package_api_docs
55+
- package_names
56+
- package_prefixed_library_names
57+
- prefer_adjacent_string_concatenation
58+
- prefer_collection_literals
59+
- prefer_conditional_assignment
60+
- prefer_const_constructors
61+
- prefer_contains
62+
- prefer_equal_for_default_values
63+
- prefer_final_fields
64+
#- prefer_final_locals
65+
- prefer_generic_function_type_aliases
66+
- prefer_initializing_formals
67+
- prefer_interpolation_to_compose_strings
68+
- prefer_is_empty
69+
- prefer_is_not_empty
70+
- prefer_null_aware_operators
71+
#- prefer_single_quotes
72+
- prefer_typing_uninitialized_variables
73+
- recursive_getters
74+
- slash_for_doc_comments
75+
- test_types_in_equals
76+
- throw_in_finally
77+
- type_init_formals
78+
- unawaited_futures
79+
- unnecessary_await_in_return
80+
- unnecessary_brace_in_string_interps
81+
- unnecessary_const
82+
- unnecessary_getters_setters
83+
- unnecessary_lambdas
84+
- unnecessary_new
85+
- unnecessary_null_aware_assignments
86+
- unnecessary_parenthesis
87+
- unnecessary_statements
88+
- unnecessary_this
89+
- unrelated_type_equality_checks
90+
- use_function_type_syntax_for_parameters
91+
- use_rethrow_when_possible
92+
- valid_regexps
93+
- void_checks

lib/src/eager_span_scanner.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ 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 = new 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 {
@@ -22,14 +22,14 @@ class EagerSpanScanner extends SpanScanner {
2222
int _column = 0;
2323

2424
LineScannerState get state =>
25-
new _EagerSpanScannerState(this, position, line, column);
25+
_EagerSpanScannerState(this, position, line, column);
2626

2727
bool get _betweenCRLF => peekChar(-1) == $cr && peekChar() == $lf;
2828

2929
set state(LineScannerState state) {
3030
if (state is! _EagerSpanScannerState ||
3131
!identical((state as _EagerSpanScannerState)._scanner, this)) {
32-
throw new ArgumentError("The given LineScannerState was not returned by "
32+
throw ArgumentError("The given LineScannerState was not returned by "
3333
"this LineScanner.");
3434
}
3535

lib/src/exception.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import 'package:source_span/source_span.dart';
66

7+
import 'string_scanner.dart';
8+
79
/// An exception thrown by a [StringScanner] that failed to parse a string.
810
class StringScannerException extends SourceSpanFormatException {
911
String get source => super.source;

lib/src/line_scanner.dart

Lines changed: 3 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 = new 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 {
@@ -29,15 +29,15 @@ class LineScanner extends StringScanner {
2929
///
3030
/// This does not include the scanner's match information.
3131
LineScannerState get state =>
32-
new LineScannerState._(this, position, line, column);
32+
LineScannerState._(this, position, line, column);
3333

3434
/// Whether the current position is between a CR character and an LF
3535
/// charactet.
3636
bool get _betweenCRLF => peekChar(-1) == $cr && peekChar() == $lf;
3737

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

lib/src/relative_span_scanner.dart

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import 'utils.dart';
1919
class RelativeSpanScanner extends StringScanner implements SpanScanner {
2020
/// The source of the scanner.
2121
///
22-
/// This caches line break information and is used to generate [Span]s.
22+
/// This caches line break information and is used to generate [SourceSpan]s.
2323
final SourceFile _sourceFile;
2424

2525
/// The start location of the span within which this scanner is scanning.
@@ -40,16 +40,16 @@ class RelativeSpanScanner extends StringScanner implements SpanScanner {
4040
: column;
4141
}
4242

43-
LineScannerState get state => new _SpanScannerState(this, position);
43+
LineScannerState get state => _SpanScannerState(this, position);
4444

4545
set state(LineScannerState state) {
4646
if (state is! _SpanScannerState ||
4747
!identical((state as _SpanScannerState)._scanner, this)) {
48-
throw new ArgumentError("The given LineScannerState was not returned by "
48+
throw ArgumentError("The given LineScannerState was not returned by "
4949
"this LineScanner.");
5050
}
5151

52-
this.position = state.position;
52+
position = state.position;
5353
}
5454

5555
FileSpan get lastSpan => _lastSpan;
@@ -86,14 +86,12 @@ class RelativeSpanScanner extends StringScanner implements SpanScanner {
8686
validateErrorArgs(string, match, position, length);
8787

8888
if (match == null && position == null && length == null) match = lastMatch;
89-
if (position == null) {
90-
position = match == null ? this.position : match.start;
91-
}
92-
if (length == null) length = match == null ? 1 : match.end - match.start;
89+
position ??= match == null ? this.position : match.start;
90+
length ??= match == null ? 1 : match.end - match.start;
9391

9492
var span = _sourceFile.span(_startLocation.offset + position,
9593
_startLocation.offset + position + length);
96-
throw new StringScannerException(message, span, string);
94+
throw StringScannerException(message, span, string);
9795
}
9896
}
9997

lib/src/span_scanner.dart

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,26 @@ import 'string_scanner.dart';
1212
import 'utils.dart';
1313

1414
/// A subclass of [LineScanner] that exposes matched ranges as source map
15-
/// [Span]s.
15+
/// [FileSpan]s.
1616
class SpanScanner extends StringScanner implements LineScanner {
1717
/// The source of the scanner.
1818
///
19-
/// This caches line break information and is used to generate [Span]s.
19+
/// This caches line break information and is used to generate [FileSpan]s.
2020
final SourceFile _sourceFile;
2121

2222
int get line => _sourceFile.getLine(position);
2323
int get column => _sourceFile.getColumn(position);
2424

25-
LineScannerState get state => new _SpanScannerState(this, position);
25+
LineScannerState get state => _SpanScannerState(this, position);
2626

2727
set state(LineScannerState state) {
2828
if (state is! _SpanScannerState ||
2929
!identical((state as _SpanScannerState)._scanner, this)) {
30-
throw new ArgumentError("The given LineScannerState was not returned by "
30+
throw ArgumentError("The given LineScannerState was not returned by "
3131
"this LineScanner.");
3232
}
3333

34-
this.position = state.position;
34+
position = state.position;
3535
}
3636

3737
/// The [FileSpan] for [lastMatch].
@@ -57,7 +57,7 @@ class SpanScanner extends StringScanner implements LineScanner {
5757
/// [FileSpan]s as well as for error reporting. It can be a [String], a
5858
/// [Uri], or `null`.
5959
SpanScanner(String string, {sourceUrl, int position})
60-
: _sourceFile = new SourceFile.fromString(string, url: sourceUrl),
60+
: _sourceFile = SourceFile.fromString(string, url: sourceUrl),
6161
super(string, sourceUrl: sourceUrl, position: position);
6262

6363
/// Creates a new [SpanScanner] that eagerly computes line and column numbers.
@@ -76,9 +76,9 @@ class SpanScanner extends StringScanner implements LineScanner {
7676

7777
/// Creates a new [SpanScanner] that scans within [span].
7878
///
79-
/// This scans through [span.text], but emits new spans from [span.file] in
79+
/// This scans through [span]`.text, but emits new spans from [span]`.file` in
8080
/// their appropriate relative positions. The [string] field contains only
81-
/// [span.text], and [position], [line], and [column] are all relative to the
81+
/// [span]`.text`, and [position], [line], and [column] are all relative to the
8282
/// span.
8383
factory SpanScanner.within(FileSpan span) = RelativeSpanScanner;
8484

@@ -103,13 +103,11 @@ class SpanScanner extends StringScanner implements LineScanner {
103103
validateErrorArgs(string, match, position, length);
104104

105105
if (match == null && position == null && length == null) match = lastMatch;
106-
if (position == null) {
107-
position = match == null ? this.position : match.start;
108-
}
109-
if (length == null) length = match == null ? 0 : match.end - match.start;
106+
position ??= match == null ? this.position : match.start;
107+
length ??= match == null ? 0 : match.end - match.start;
110108

111109
var span = _sourceFile.span(position, position + length);
112-
throw new StringScannerException(message, span, string);
110+
throw StringScannerException(message, span, string);
113111
}
114112
}
115113

lib/src/string_scanner.dart

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import 'utils.dart';
1212
/// When compiled to JS, forward slashes are always escaped in [RegExp.pattern].
1313
///
1414
/// See issue 17998.
15-
final _slashAutoEscape = new RegExp("/").pattern == "\\/";
15+
final _slashAutoEscape = RegExp("/").pattern == "\\/";
1616

1717
/// A class that scans through a string using [Pattern]s.
1818
class StringScanner {
@@ -29,7 +29,7 @@ class StringScanner {
2929
int get position => _position;
3030
set position(int position) {
3131
if (position < 0 || position > string.length) {
32-
throw new ArgumentError("Invalid position $position");
32+
throw ArgumentError("Invalid position $position");
3333
}
3434

3535
_position = position;
@@ -84,7 +84,7 @@ class StringScanner {
8484
/// This returns `null` if [offset] points outside the string. It doesn't
8585
/// affect [lastMatch].
8686
int peekChar([int offset]) {
87-
if (offset == null) offset = 0;
87+
offset ??= 0;
8888
var index = position + offset;
8989
if (index < 0 || index >= string.length) return null;
9090
return string.codeUnitAt(index);
@@ -115,7 +115,7 @@ class StringScanner {
115115
} else if (character == $double_quote) {
116116
name = r'"\""';
117117
} else {
118-
name = '"${new String.fromCharCode(character)}"';
118+
name = '"${String.fromCharCode(character)}"';
119119
}
120120
}
121121

@@ -181,7 +181,7 @@ class StringScanner {
181181
/// Unlike [String.substring], [end] defaults to [position] rather than the
182182
/// end of the string.
183183
String substring(int start, [int end]) {
184-
if (end == null) end = position;
184+
end ??= position;
185185
return string.substring(start, end);
186186
}
187187

@@ -203,20 +203,18 @@ class StringScanner {
203203
validateErrorArgs(string, match, position, length);
204204

205205
if (match == null && position == null && length == null) match = lastMatch;
206-
if (position == null) {
207-
position = match == null ? this.position : match.start;
208-
}
209-
if (length == null) length = match == null ? 0 : match.end - match.start;
206+
position ??= match == null ? this.position : match.start;
207+
length ??= match == null ? 0 : match.end - match.start;
210208

211-
var sourceFile = new SourceFile.fromString(string, url: sourceUrl);
209+
var sourceFile = SourceFile.fromString(string, url: sourceUrl);
212210
var span = sourceFile.span(position, position + length);
213-
throw new StringScannerException(message, span, string);
211+
throw StringScannerException(message, span, string);
214212
}
215213

216214
// TODO(nweiz): Make this handle long lines more gracefully.
217215
/// Throws a [FormatException] describing that [name] is expected at the
218216
/// current position in the string.
219217
void _fail(String name) {
220-
error("expected $name.", position: this.position, length: 0);
218+
error("expected $name.", position: position, length: 0);
221219
}
222220
}

0 commit comments

Comments
 (0)