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

Commit

Permalink
lint with dart_flutter_team_lints (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
devoncarew authored Jan 30, 2023
1 parent 52d9185 commit f118e00
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 67 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## 0.15.2-dev

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

Expand Down
43 changes: 2 additions & 41 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,49 +1,10 @@
include: package:lints/recommended.yaml
include: package:dart_flutter_team_lints/analysis_options.yaml

analyzer:
language:
strict-casts: true
strict-raw-types: true
errors:
lines_longer_than_80_chars: ignore
# https://github.com/dart-lang/linter/issues/1649
prefer_collection_literals: ignore

linter:
rules:
- always_declare_return_types
- avoid_dynamic_calls
- avoid_function_literals_in_foreach_calls
- avoid_returning_null
- avoid_unused_constructor_parameters
- await_only_futures
- camel_case_types
- cancel_subscriptions
- comment_references
- constant_identifier_names
- control_flow_in_finally
- directives_ordering
- empty_statements
- hash_and_equals
- implementation_imports
- iterable_contains_unrelated_type
- list_remove_unrelated_type
- no_adjacent_strings_in_list
- non_constant_identifier_names
- only_throw_errors
- overridden_fields
- package_api_docs
- package_names
- package_prefixed_library_names
- prefer_const_constructors
- prefer_final_locals
- prefer_initializing_formals
- prefer_interpolation_to_compose_strings
- prefer_typing_uninitialized_variables
- test_types_in_equals
- throw_in_finally
- type_annotate_public_apis
- unnecessary_brace_in_string_interps
- unnecessary_getters_setters
- unnecessary_lambdas
- unnecessary_null_aware_assignments
- unnecessary_statements
2 changes: 1 addition & 1 deletion lib/dom.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class AttributeName implements Comparable<Object> {
int compareTo(Object other) {
// Not sure about this sort order
if (other is! AttributeName) return 1;
var cmp = (prefix ?? '').compareTo((other.prefix ?? ''));
var cmp = (prefix ?? '').compareTo(other.prefix ?? '');
if (cmp != 0) return cmp;
cmp = name.compareTo(other.name);
if (cmp != 0) return cmp;
Expand Down
14 changes: 7 additions & 7 deletions lib/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,15 @@ class HtmlParser {
String? sourceUrl,
TreeBuilder? tree})
: tree = tree ?? TreeBuilder(true),
tokenizer = (input is HtmlTokenizer
tokenizer = input is HtmlTokenizer
? input
: HtmlTokenizer(input,
encoding: encoding,
parseMeta: parseMeta,
lowercaseElementName: lowercaseElementName,
lowercaseAttrName: lowercaseAttrName,
generateSpans: generateSpans,
sourceUrl: sourceUrl)) {
sourceUrl: sourceUrl) {
tokenizer.parser = this;
}

Expand Down Expand Up @@ -653,9 +653,9 @@ class InitialPhase extends Phase {
final systemId = token.systemId;
final correct = token.correct;

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

Expand Down Expand Up @@ -1573,8 +1573,8 @@ class InBodyPhase extends Phase {

void startTagFrameset(StartTagToken token) {
parser.parseError(token.span, 'unexpected-start-tag', {'name': 'frameset'});
if ((tree.openElements.length == 1 ||
tree.openElements[1].localName != 'body')) {
if (tree.openElements.length == 1 ||
tree.openElements[1].localName != 'body') {
assert(parser.innerHTMLMode);
} else if (parser.framesetOK) {
if (tree.openElements[1].parentNode != null) {
Expand Down Expand Up @@ -2121,7 +2121,7 @@ class InBodyPhase extends Phase {
}
// Step 6.4
if (lastNode == furthestBlock) {
bookmark = (tree.activeFormattingElements.indexOf(node) + 1);
bookmark = tree.activeFormattingElements.indexOf(node) + 1;
}
// Step 6.5
//cite = node.parent
Expand Down
2 changes: 1 addition & 1 deletion lib/src/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ const Map<String, String> errorMessages = {
'unexpected-end-tag-after-body': 'Unexpected end tag token (%(name)s)'
' in the after body phase.',
'unexpected-char-in-frameset':
'Unepxected characters in the frameset phase. Characters ignored.',
'Unexpected characters in the frameset phase. Characters ignored.',
'unexpected-start-tag-in-frameset': 'Unexpected start tag token (%(name)s)'
' in the frameset phase. Ignored.',
'unexpected-frameset-in-frameset-innerhtml':
Expand Down
27 changes: 16 additions & 11 deletions lib/src/encoding_parser.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import 'constants.dart';
import 'html_input_stream.dart';

// TODO(jmesserly): I converted StopIteration to StateError("No more elements").
// Seems strange to throw this from outside of an iterator though.
/// String-like object with an associated position and various extra methods
/// String-like object with an associated position and various extra methods.
///
/// If the position is ever greater than the string length then an exception is
/// raised.
class EncodingBytes {
Expand All @@ -17,7 +16,7 @@ class EncodingBytes {
String _next() {
final p = __position = __position + 1;
if (p >= _length) {
throw StateError('No more elements');
throw _EncodingRangeException('No more elements');
} else if (p < 0) {
throw RangeError(p);
}
Expand All @@ -27,7 +26,7 @@ class EncodingBytes {
String _previous() {
var p = __position;
if (p >= _length) {
throw StateError('No more elements');
throw _EncodingRangeException('No more elements');
} else if (p < 0) {
throw RangeError(p);
}
Expand All @@ -37,14 +36,14 @@ class EncodingBytes {

set _position(int value) {
if (__position >= _length) {
throw StateError('No more elements');
throw _EncodingRangeException('No more elements');
}
__position = value;
}

int get _position {
if (__position >= _length) {
throw StateError('No more elements');
throw _EncodingRangeException('No more elements');
}
if (__position >= 0) {
return __position;
Expand Down Expand Up @@ -108,7 +107,7 @@ class EncodingBytes {
__position = newPosition + bytes.length - 1;
return true;
} else {
throw StateError('No more elements');
throw _EncodingRangeException('No more elements');
}
}

Expand Down Expand Up @@ -161,7 +160,7 @@ class EncodingParser {
}
_data._position += 1;
}
} on StateError catch (_) {
} on _EncodingRangeException catch (_) {
// Catch this here to match behavior of Python's StopIteration
// TODO(jmesserly): refactor to not use exceptions
}
Expand Down Expand Up @@ -355,12 +354,12 @@ class ContentAttrParser {
try {
data._skipUntil(isWhitespace);
return data._slice(oldPosition, data._position);
} on StateError catch (_) {
} on _EncodingRangeException catch (_) {
//Return the whole remaining value
return data._slice(oldPosition);
}
}
} on StateError catch (_) {
} on _EncodingRangeException catch (_) {
return null;
}
}
Expand All @@ -371,3 +370,9 @@ bool _isSpaceOrAngleBracket(String char) {
}

typedef _CharPredicate = bool Function(String char);

class _EncodingRangeException implements Exception {
final String message;

_EncodingRangeException(this.message);
}
2 changes: 1 addition & 1 deletion lib/src/html_input_stream.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class HtmlInputStream {
/// The name of the character encoding.
String? charEncodingName;

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

final bool generateSpans;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ dependencies:
source_span: ^1.8.0

dev_dependencies:
lints: ^2.0.0
dart_flutter_team_lints: ^0.1.0
path: ^1.8.0
test: ^1.16.0
2 changes: 1 addition & 1 deletion test/selectors/level1_lib.dart
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ void runValidSelectorTest(String type, SelectorAdaptor root,
final exclude = s['exclude'];

if ((exclude is! List ||
(!(exclude).contains(nodeType) && !exclude.contains(docType))) &&
(!exclude.contains(nodeType) && !exclude.contains(docType))) &&
((s['testType'] as int) & testType != 0)) {
//console.log("Running tests " + nodeType + ": " + s["testType"] + "&" + testType + "=" + (s["testType"] & testType) + ": " + JSON.stringify(s))
late List<Element> foundall;
Expand Down
4 changes: 2 additions & 2 deletions test/tokenizer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ Map<String, dynamic> unescape(Map<String, dynamic> testInfo) {
token as List;
token[1] = decode(token[1] as String);

if ((token).length > 2) {
for (var pair in (token[2] as List)) {
if (token.length > 2) {
for (var pair in token[2] as List) {
pair as List;
final key = pair[0] as String;
final value = pair[1] as String;
Expand Down

0 comments on commit f118e00

Please sign in to comment.