Skip to content

Commit cd6daa5

Browse files
authored
Enable and fix a number of lints, test on oldest supported Dart SDK (flutter#20)
1 parent c9c3e84 commit cd6daa5

File tree

6 files changed

+178
-100
lines changed

6 files changed

+178
-100
lines changed

.travis.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
language: dart
22
dart:
3+
- 2.0.0
34
- dev
45

56
dart_task:
67
- test: -p vm
78
- test: -p firefox
8-
- dartfmt
9-
- dartanalyzer
9+
- dartanalyzer: --fatal-infos --fatal-warnings .
10+
11+
matrix:
12+
include:
13+
# Only validate formatting using the dev release
14+
- dart: dev
15+
dart_task: dartfmt
1016

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

analysis_options.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
include: package:pedantic/analysis_options.yaml
2+
linter:
3+
rules:
4+
#- annotate_overrides
5+
- avoid_function_literals_in_foreach_calls
6+
- avoid_init_to_null
7+
- avoid_null_checks_in_equality_operators
8+
- avoid_relative_lib_imports
9+
- avoid_returning_null
10+
- avoid_unused_constructor_parameters
11+
- await_only_futures
12+
- camel_case_types
13+
- cancel_subscriptions
14+
- comment_references
15+
- constant_identifier_names
16+
- control_flow_in_finally
17+
- directives_ordering
18+
- empty_catches
19+
- empty_constructor_bodies
20+
- empty_statements
21+
- hash_and_equals
22+
- implementation_imports
23+
- invariant_booleans
24+
- iterable_contains_unrelated_type
25+
- library_names
26+
- library_prefixes
27+
- list_remove_unrelated_type
28+
- no_adjacent_strings_in_list
29+
- non_constant_identifier_names
30+
#- omit_local_variable_types
31+
- only_throw_errors
32+
- overridden_fields
33+
- package_api_docs
34+
- package_names
35+
- package_prefixed_library_names
36+
- prefer_adjacent_string_concatenation
37+
- prefer_collection_literals
38+
- prefer_conditional_assignment
39+
- prefer_const_constructors
40+
- prefer_final_fields
41+
- prefer_generic_function_type_aliases
42+
- prefer_initializing_formals
43+
- prefer_interpolation_to_compose_strings
44+
#- prefer_single_quotes
45+
- prefer_typing_uninitialized_variables
46+
- slash_for_doc_comments
47+
- test_types_in_equals
48+
- throw_in_finally
49+
- type_init_formals
50+
- unnecessary_brace_in_string_interps
51+
- unnecessary_const
52+
- unnecessary_getters_setters
53+
- unnecessary_lambdas
54+
- unnecessary_new
55+
- unnecessary_null_aware_assignments
56+
- unnecessary_statements
57+
- unnecessary_this

codereview.settings

Lines changed: 0 additions & 3 deletions
This file was deleted.

lib/typed_buffers.dart

Lines changed: 63 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/// They use an underlying buffer, and when that buffer becomes too small, it
99
/// is replaced by a new buffer.
1010
///
11-
/// That means that using the [TypedDataView.buffer] getter is not guaranteed
11+
/// That means that using the `buffer` getter is not guaranteed
1212
/// to return the same result each time it is used, and that the buffer may
1313
/// be larger than what the list is using.
1414
library typed_data.typed_buffers;
@@ -17,7 +17,7 @@ import "dart:collection" show ListBase;
1717
import "dart:typed_data";
1818

1919
abstract class _TypedDataBuffer<E> extends ListBase<E> {
20-
static const int INITIAL_LENGTH = 8;
20+
static const int _initialLength = 8;
2121

2222
/// The underlying data buffer.
2323
///
@@ -32,29 +32,30 @@ abstract class _TypedDataBuffer<E> extends ListBase<E> {
3232
int _length;
3333

3434
_TypedDataBuffer(List<E> buffer)
35-
: this._buffer = buffer,
36-
this._length = buffer.length;
35+
: _buffer = buffer,
36+
_length = buffer.length;
3737

3838
int get length => _length;
39+
3940
E operator [](int index) {
40-
if (index >= length) throw new RangeError.index(index, this);
41+
if (index >= length) throw RangeError.index(index, this);
4142
return _buffer[index];
4243
}
4344

4445
void operator []=(int index, E value) {
45-
if (index >= length) throw new RangeError.index(index, this);
46+
if (index >= length) throw RangeError.index(index, this);
4647
_buffer[index] = value;
4748
}
4849

49-
void set length(int newLength) {
50+
set length(int newLength) {
5051
if (newLength < _length) {
5152
E defaultValue = _defaultValue;
5253
for (int i = newLength; i < _length; i++) {
5354
_buffer[i] = defaultValue;
5455
}
5556
} else if (newLength > _buffer.length) {
5657
List<E> newBuffer;
57-
if (_buffer.length == 0) {
58+
if (_buffer.isEmpty) {
5859
newBuffer = _createBuffer(newLength);
5960
} else {
6061
newBuffer = _createBiggerBuffer(newLength);
@@ -89,7 +90,7 @@ abstract class _TypedDataBuffer<E> extends ListBase<E> {
8990
void addAll(Iterable<E> values, [int start = 0, int end]) {
9091
RangeError.checkNotNegative(start, "start");
9192
if (end != null && start > end) {
92-
throw new RangeError.range(end, start, null, "end");
93+
throw RangeError.range(end, start, null, "end");
9394
}
9495

9596
_addAll(values, start, end);
@@ -109,7 +110,7 @@ abstract class _TypedDataBuffer<E> extends ListBase<E> {
109110
RangeError.checkNotNegative(start, "start");
110111
if (end != null) {
111112
if (start > end) {
112-
throw new RangeError.range(end, start, null, "end");
113+
throw RangeError.range(end, start, null, "end");
113114
}
114115
if (start == end) return;
115116
}
@@ -147,10 +148,10 @@ abstract class _TypedDataBuffer<E> extends ListBase<E> {
147148
}
148149

149150
if (skipCount > 0) {
150-
throw new StateError("Too few elements");
151+
throw StateError("Too few elements");
151152
}
152153
if (end != null && writeIndex < end) {
153-
throw new RangeError.range(end, start, writeIndex, "end");
154+
throw RangeError.range(end, start, writeIndex, "end");
154155
}
155156

156157
// Swap [index.._length) and [_length..writeIndex) by double-reversing.
@@ -196,15 +197,15 @@ abstract class _TypedDataBuffer<E> extends ListBase<E> {
196197
if (i >= start) add(value);
197198
i++;
198199
}
199-
if (i < start) throw new StateError("Too few elements");
200+
if (i < start) throw StateError("Too few elements");
200201
}
201202

202203
/// Like [insertAll], but with a guaranteed non-`null` [start] and [end].
203204
void _insertKnownLength(int index, Iterable<E> values, int start, int end) {
204205
if (values is List) {
205206
end ??= values.length;
206207
if (start > values.length || end > values.length) {
207-
throw new StateError("Too few elements");
208+
throw StateError("Too few elements");
208209
}
209210
} else {
210211
assert(end != null);
@@ -222,7 +223,7 @@ abstract class _TypedDataBuffer<E> extends ListBase<E> {
222223

223224
void insert(int index, E element) {
224225
if (index < 0 || index > _length) {
225-
throw new RangeError.range(index, 0, _length);
226+
throw RangeError.range(index, 0, _length);
226227
}
227228
if (_length < _buffer.length) {
228229
_buffer.setRange(index + 1, _length + 1, _buffer, index);
@@ -258,8 +259,8 @@ abstract class _TypedDataBuffer<E> extends ListBase<E> {
258259
int newLength = _buffer.length * 2;
259260
if (requiredCapacity != null && newLength < requiredCapacity) {
260261
newLength = requiredCapacity;
261-
} else if (newLength < INITIAL_LENGTH) {
262-
newLength = INITIAL_LENGTH;
262+
} else if (newLength < _initialLength) {
263+
newLength = _initialLength;
263264
}
264265
return _createBuffer(newLength);
265266
}
@@ -272,7 +273,7 @@ abstract class _TypedDataBuffer<E> extends ListBase<E> {
272273
}
273274

274275
void setRange(int start, int end, Iterable<E> source, [int skipCount = 0]) {
275-
if (end > _length) throw new RangeError.range(end, 0, _length);
276+
if (end > _length) throw RangeError.range(end, 0, _length);
276277
_setRange(start, end, source, skipCount);
277278
}
278279

@@ -324,74 +325,87 @@ abstract class _FloatBuffer extends _TypedDataBuffer<double> {
324325
}
325326

326327
class Uint8Buffer extends _IntBuffer {
327-
Uint8Buffer([int initialLength = 0]) : super(new Uint8List(initialLength));
328-
Uint8List _createBuffer(int size) => new Uint8List(size);
328+
Uint8Buffer([int initialLength = 0]) : super(Uint8List(initialLength));
329+
330+
Uint8List _createBuffer(int size) => Uint8List(size);
329331
}
330332

331333
class Int8Buffer extends _IntBuffer {
332-
Int8Buffer([int initialLength = 0]) : super(new Int8List(initialLength));
333-
Int8List _createBuffer(int size) => new Int8List(size);
334+
Int8Buffer([int initialLength = 0]) : super(Int8List(initialLength));
335+
336+
Int8List _createBuffer(int size) => Int8List(size);
334337
}
335338

336339
class Uint8ClampedBuffer extends _IntBuffer {
337340
Uint8ClampedBuffer([int initialLength = 0])
338-
: super(new Uint8ClampedList(initialLength));
339-
Uint8ClampedList _createBuffer(int size) => new Uint8ClampedList(size);
341+
: super(Uint8ClampedList(initialLength));
342+
343+
Uint8ClampedList _createBuffer(int size) => Uint8ClampedList(size);
340344
}
341345

342346
class Uint16Buffer extends _IntBuffer {
343-
Uint16Buffer([int initialLength = 0]) : super(new Uint16List(initialLength));
344-
Uint16List _createBuffer(int size) => new Uint16List(size);
347+
Uint16Buffer([int initialLength = 0]) : super(Uint16List(initialLength));
348+
349+
Uint16List _createBuffer(int size) => Uint16List(size);
345350
}
346351

347352
class Int16Buffer extends _IntBuffer {
348-
Int16Buffer([int initialLength = 0]) : super(new Int16List(initialLength));
349-
Int16List _createBuffer(int size) => new Int16List(size);
353+
Int16Buffer([int initialLength = 0]) : super(Int16List(initialLength));
354+
355+
Int16List _createBuffer(int size) => Int16List(size);
350356
}
351357

352358
class Uint32Buffer extends _IntBuffer {
353-
Uint32Buffer([int initialLength = 0]) : super(new Uint32List(initialLength));
354-
Uint32List _createBuffer(int size) => new Uint32List(size);
359+
Uint32Buffer([int initialLength = 0]) : super(Uint32List(initialLength));
360+
361+
Uint32List _createBuffer(int size) => Uint32List(size);
355362
}
356363

357364
class Int32Buffer extends _IntBuffer {
358-
Int32Buffer([int initialLength = 0]) : super(new Int32List(initialLength));
359-
Int32List _createBuffer(int size) => new Int32List(size);
365+
Int32Buffer([int initialLength = 0]) : super(Int32List(initialLength));
366+
367+
Int32List _createBuffer(int size) => Int32List(size);
360368
}
361369

362370
class Uint64Buffer extends _IntBuffer {
363-
Uint64Buffer([int initialLength = 0]) : super(new Uint64List(initialLength));
364-
Uint64List _createBuffer(int size) => new Uint64List(size);
371+
Uint64Buffer([int initialLength = 0]) : super(Uint64List(initialLength));
372+
373+
Uint64List _createBuffer(int size) => Uint64List(size);
365374
}
366375

367376
class Int64Buffer extends _IntBuffer {
368-
Int64Buffer([int initialLength = 0]) : super(new Int64List(initialLength));
369-
Int64List _createBuffer(int size) => new Int64List(size);
377+
Int64Buffer([int initialLength = 0]) : super(Int64List(initialLength));
378+
379+
Int64List _createBuffer(int size) => Int64List(size);
370380
}
371381

372382
class Float32Buffer extends _FloatBuffer {
373-
Float32Buffer([int initialLength = 0])
374-
: super(new Float32List(initialLength));
375-
Float32List _createBuffer(int size) => new Float32List(size);
383+
Float32Buffer([int initialLength = 0]) : super(Float32List(initialLength));
384+
385+
Float32List _createBuffer(int size) => Float32List(size);
376386
}
377387

378388
class Float64Buffer extends _FloatBuffer {
379-
Float64Buffer([int initialLength = 0])
380-
: super(new Float64List(initialLength));
381-
Float64List _createBuffer(int size) => new Float64List(size);
389+
Float64Buffer([int initialLength = 0]) : super(Float64List(initialLength));
390+
391+
Float64List _createBuffer(int size) => Float64List(size);
382392
}
383393

384394
class Int32x4Buffer extends _TypedDataBuffer<Int32x4> {
385-
static Int32x4 _zero = new Int32x4(0, 0, 0, 0);
386-
Int32x4Buffer([int initialLength = 0])
387-
: super(new Int32x4List(initialLength));
395+
static final Int32x4 _zero = Int32x4(0, 0, 0, 0);
396+
397+
Int32x4Buffer([int initialLength = 0]) : super(Int32x4List(initialLength));
398+
388399
Int32x4 get _defaultValue => _zero;
389-
Int32x4List _createBuffer(int size) => new Int32x4List(size);
400+
401+
Int32x4List _createBuffer(int size) => Int32x4List(size);
390402
}
391403

392404
class Float32x4Buffer extends _TypedDataBuffer<Float32x4> {
393405
Float32x4Buffer([int initialLength = 0])
394-
: super(new Float32x4List(initialLength));
395-
Float32x4 get _defaultValue => new Float32x4.zero();
396-
Float32x4List _createBuffer(int size) => new Float32x4List(size);
406+
: super(Float32x4List(initialLength));
407+
408+
Float32x4 get _defaultValue => Float32x4.zero();
409+
410+
Float32x4List _createBuffer(int size) => Float32x4List(size);
397411
}

pubspec.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
name: typed_data
22
version: 1.1.6
33

4-
description: Utility functions and classes related to the 'dart:typed_data' library.
4+
description: >-
5+
Utility functions and classes related to the dart:typed_data library.
56
author: Dart Team <[email protected]>
67
homepage: https://github.com/dart-lang/typed_data
78

89
environment:
9-
sdk: '>=2.0.0-dev.16.0 <3.0.0'
10+
sdk: '>=2.0.0 <3.0.0'
1011

1112
dev_dependencies:
12-
test: '>=0.12.42 <2.0.0'
13+
pedantic: ^1.0.0
14+
test: ^1.0.0

0 commit comments

Comments
 (0)