Skip to content
This repository was archived by the owner on Nov 1, 2024. It is now read-only.

Commit f118e00

Browse files
authored
lint with dart_flutter_team_lints (#201)
1 parent 52d9185 commit f118e00

File tree

10 files changed

+33
-67
lines changed

10 files changed

+33
-67
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## 0.15.2-dev
22

33
- Add additional types at the API boundary (in `lib/parser.dart` and others).
4-
- Update to `package:lints` 2.0.
4+
- Adopted the `package:dart_flutter_team_lints` linting rules.
55
- Fixed an issue with `querySelector` where it would fail in some cases with
66
descendant or sibling combinators (#157).
77

analysis_options.yaml

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,10 @@
1-
include: package:lints/recommended.yaml
1+
include: package:dart_flutter_team_lints/analysis_options.yaml
22

33
analyzer:
44
language:
55
strict-casts: true
66
strict-raw-types: true
77
errors:
8+
lines_longer_than_80_chars: ignore
89
# https://github.com/dart-lang/linter/issues/1649
910
prefer_collection_literals: ignore
10-
11-
linter:
12-
rules:
13-
- always_declare_return_types
14-
- avoid_dynamic_calls
15-
- avoid_function_literals_in_foreach_calls
16-
- avoid_returning_null
17-
- avoid_unused_constructor_parameters
18-
- await_only_futures
19-
- camel_case_types
20-
- cancel_subscriptions
21-
- comment_references
22-
- constant_identifier_names
23-
- control_flow_in_finally
24-
- directives_ordering
25-
- empty_statements
26-
- hash_and_equals
27-
- implementation_imports
28-
- iterable_contains_unrelated_type
29-
- list_remove_unrelated_type
30-
- no_adjacent_strings_in_list
31-
- non_constant_identifier_names
32-
- only_throw_errors
33-
- overridden_fields
34-
- package_api_docs
35-
- package_names
36-
- package_prefixed_library_names
37-
- prefer_const_constructors
38-
- prefer_final_locals
39-
- prefer_initializing_formals
40-
- prefer_interpolation_to_compose_strings
41-
- prefer_typing_uninitialized_variables
42-
- test_types_in_equals
43-
- throw_in_finally
44-
- type_annotate_public_apis
45-
- unnecessary_brace_in_string_interps
46-
- unnecessary_getters_setters
47-
- unnecessary_lambdas
48-
- unnecessary_null_aware_assignments
49-
- unnecessary_statements

lib/dom.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class AttributeName implements Comparable<Object> {
6060
int compareTo(Object other) {
6161
// Not sure about this sort order
6262
if (other is! AttributeName) return 1;
63-
var cmp = (prefix ?? '').compareTo((other.prefix ?? ''));
63+
var cmp = (prefix ?? '').compareTo(other.prefix ?? '');
6464
if (cmp != 0) return cmp;
6565
cmp = name.compareTo(other.name);
6666
if (cmp != 0) return cmp;

lib/parser.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,15 @@ class HtmlParser {
151151
String? sourceUrl,
152152
TreeBuilder? tree})
153153
: tree = tree ?? TreeBuilder(true),
154-
tokenizer = (input is HtmlTokenizer
154+
tokenizer = input is HtmlTokenizer
155155
? input
156156
: HtmlTokenizer(input,
157157
encoding: encoding,
158158
parseMeta: parseMeta,
159159
lowercaseElementName: lowercaseElementName,
160160
lowercaseAttrName: lowercaseAttrName,
161161
generateSpans: generateSpans,
162-
sourceUrl: sourceUrl)) {
162+
sourceUrl: sourceUrl) {
163163
tokenizer.parser = this;
164164
}
165165

@@ -653,9 +653,9 @@ class InitialPhase extends Phase {
653653
final systemId = token.systemId;
654654
final correct = token.correct;
655655

656-
if ((name != 'html' ||
656+
if (name != 'html' ||
657657
publicId != null ||
658-
systemId != null && systemId != 'about:legacy-compat')) {
658+
systemId != null && systemId != 'about:legacy-compat') {
659659
parser.parseError(token.span, 'unknown-doctype');
660660
}
661661

@@ -1573,8 +1573,8 @@ class InBodyPhase extends Phase {
15731573

15741574
void startTagFrameset(StartTagToken token) {
15751575
parser.parseError(token.span, 'unexpected-start-tag', {'name': 'frameset'});
1576-
if ((tree.openElements.length == 1 ||
1577-
tree.openElements[1].localName != 'body')) {
1576+
if (tree.openElements.length == 1 ||
1577+
tree.openElements[1].localName != 'body') {
15781578
assert(parser.innerHTMLMode);
15791579
} else if (parser.framesetOK) {
15801580
if (tree.openElements[1].parentNode != null) {
@@ -2121,7 +2121,7 @@ class InBodyPhase extends Phase {
21212121
}
21222122
// Step 6.4
21232123
if (lastNode == furthestBlock) {
2124-
bookmark = (tree.activeFormattingElements.indexOf(node) + 1);
2124+
bookmark = tree.activeFormattingElements.indexOf(node) + 1;
21252125
}
21262126
// Step 6.5
21272127
//cite = node.parent

lib/src/constants.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ const Map<String, String> errorMessages = {
200200
'unexpected-end-tag-after-body': 'Unexpected end tag token (%(name)s)'
201201
' in the after body phase.',
202202
'unexpected-char-in-frameset':
203-
'Unepxected characters in the frameset phase. Characters ignored.',
203+
'Unexpected characters in the frameset phase. Characters ignored.',
204204
'unexpected-start-tag-in-frameset': 'Unexpected start tag token (%(name)s)'
205205
' in the frameset phase. Ignored.',
206206
'unexpected-frameset-in-frameset-innerhtml':

lib/src/encoding_parser.dart

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import 'constants.dart';
22
import 'html_input_stream.dart';
33

4-
// TODO(jmesserly): I converted StopIteration to StateError("No more elements").
5-
// Seems strange to throw this from outside of an iterator though.
6-
/// String-like object with an associated position and various extra methods
4+
/// String-like object with an associated position and various extra methods.
5+
///
76
/// If the position is ever greater than the string length then an exception is
87
/// raised.
98
class EncodingBytes {
@@ -17,7 +16,7 @@ class EncodingBytes {
1716
String _next() {
1817
final p = __position = __position + 1;
1918
if (p >= _length) {
20-
throw StateError('No more elements');
19+
throw _EncodingRangeException('No more elements');
2120
} else if (p < 0) {
2221
throw RangeError(p);
2322
}
@@ -27,7 +26,7 @@ class EncodingBytes {
2726
String _previous() {
2827
var p = __position;
2928
if (p >= _length) {
30-
throw StateError('No more elements');
29+
throw _EncodingRangeException('No more elements');
3130
} else if (p < 0) {
3231
throw RangeError(p);
3332
}
@@ -37,14 +36,14 @@ class EncodingBytes {
3736

3837
set _position(int value) {
3938
if (__position >= _length) {
40-
throw StateError('No more elements');
39+
throw _EncodingRangeException('No more elements');
4140
}
4241
__position = value;
4342
}
4443

4544
int get _position {
4645
if (__position >= _length) {
47-
throw StateError('No more elements');
46+
throw _EncodingRangeException('No more elements');
4847
}
4948
if (__position >= 0) {
5049
return __position;
@@ -108,7 +107,7 @@ class EncodingBytes {
108107
__position = newPosition + bytes.length - 1;
109108
return true;
110109
} else {
111-
throw StateError('No more elements');
110+
throw _EncodingRangeException('No more elements');
112111
}
113112
}
114113

@@ -161,7 +160,7 @@ class EncodingParser {
161160
}
162161
_data._position += 1;
163162
}
164-
} on StateError catch (_) {
163+
} on _EncodingRangeException catch (_) {
165164
// Catch this here to match behavior of Python's StopIteration
166165
// TODO(jmesserly): refactor to not use exceptions
167166
}
@@ -355,12 +354,12 @@ class ContentAttrParser {
355354
try {
356355
data._skipUntil(isWhitespace);
357356
return data._slice(oldPosition, data._position);
358-
} on StateError catch (_) {
357+
} on _EncodingRangeException catch (_) {
359358
//Return the whole remaining value
360359
return data._slice(oldPosition);
361360
}
362361
}
363-
} on StateError catch (_) {
362+
} on _EncodingRangeException catch (_) {
364363
return null;
365364
}
366365
}
@@ -371,3 +370,9 @@ bool _isSpaceOrAngleBracket(String char) {
371370
}
372371

373372
typedef _CharPredicate = bool Function(String char);
373+
374+
class _EncodingRangeException implements Exception {
375+
final String message;
376+
377+
_EncodingRangeException(this.message);
378+
}

lib/src/html_input_stream.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class HtmlInputStream {
2222
/// The name of the character encoding.
2323
String? charEncodingName;
2424

25-
/// True if we are certain about [charEncodingName], false for tenative.
25+
/// True if we are certain about [charEncodingName], false for tentative.
2626
bool charEncodingCertain = true;
2727

2828
final bool generateSpans;

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ dependencies:
1111
source_span: ^1.8.0
1212

1313
dev_dependencies:
14-
lints: ^2.0.0
14+
dart_flutter_team_lints: ^0.1.0
1515
path: ^1.8.0
1616
test: ^1.16.0

test/selectors/level1_lib.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ void runValidSelectorTest(String type, SelectorAdaptor root,
195195
final exclude = s['exclude'];
196196

197197
if ((exclude is! List ||
198-
(!(exclude).contains(nodeType) && !exclude.contains(docType))) &&
198+
(!exclude.contains(nodeType) && !exclude.contains(docType))) &&
199199
((s['testType'] as int) & testType != 0)) {
200200
//console.log("Running tests " + nodeType + ": " + s["testType"] + "&" + testType + "=" + (s["testType"] & testType) + ": " + JSON.stringify(s))
201201
late List<Element> foundall;

test/tokenizer_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ Map<String, dynamic> unescape(Map<String, dynamic> testInfo) {
266266
token as List;
267267
token[1] = decode(token[1] as String);
268268

269-
if ((token).length > 2) {
270-
for (var pair in (token[2] as List)) {
269+
if (token.length > 2) {
270+
for (var pair in token[2] as List) {
271271
pair as List;
272272
final key = pair[0] as String;
273273
final value = pair[1] as String;

0 commit comments

Comments
 (0)