diff --git a/CHANGELOG.md b/CHANGELOG.md index 6124708..2588fea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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). diff --git a/analysis_options.yaml b/analysis_options.yaml index 715ea40..90d920e 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -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 diff --git a/lib/dom.dart b/lib/dom.dart index 5ffc15f..28d7594 100644 --- a/lib/dom.dart +++ b/lib/dom.dart @@ -60,7 +60,7 @@ class AttributeName implements Comparable { 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; diff --git a/lib/parser.dart b/lib/parser.dart index c4bd1ed..3eb7a97 100644 --- a/lib/parser.dart +++ b/lib/parser.dart @@ -151,7 +151,7 @@ class HtmlParser { String? sourceUrl, TreeBuilder? tree}) : tree = tree ?? TreeBuilder(true), - tokenizer = (input is HtmlTokenizer + tokenizer = input is HtmlTokenizer ? input : HtmlTokenizer(input, encoding: encoding, @@ -159,7 +159,7 @@ class HtmlParser { lowercaseElementName: lowercaseElementName, lowercaseAttrName: lowercaseAttrName, generateSpans: generateSpans, - sourceUrl: sourceUrl)) { + sourceUrl: sourceUrl) { tokenizer.parser = this; } @@ -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'); } @@ -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) { @@ -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 diff --git a/lib/src/constants.dart b/lib/src/constants.dart index 152f85b..5c41f81 100644 --- a/lib/src/constants.dart +++ b/lib/src/constants.dart @@ -200,7 +200,7 @@ const Map 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': diff --git a/lib/src/encoding_parser.dart b/lib/src/encoding_parser.dart index defe57e..2ecd5c4 100644 --- a/lib/src/encoding_parser.dart +++ b/lib/src/encoding_parser.dart @@ -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 { @@ -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); } @@ -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); } @@ -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; @@ -108,7 +107,7 @@ class EncodingBytes { __position = newPosition + bytes.length - 1; return true; } else { - throw StateError('No more elements'); + throw _EncodingRangeException('No more elements'); } } @@ -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 } @@ -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; } } @@ -371,3 +370,9 @@ bool _isSpaceOrAngleBracket(String char) { } typedef _CharPredicate = bool Function(String char); + +class _EncodingRangeException implements Exception { + final String message; + + _EncodingRangeException(this.message); +} diff --git a/lib/src/html_input_stream.dart b/lib/src/html_input_stream.dart index 54e0231..1c1bcc8 100644 --- a/lib/src/html_input_stream.dart +++ b/lib/src/html_input_stream.dart @@ -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; diff --git a/pubspec.yaml b/pubspec.yaml index 831bce0..2a61ef4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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 diff --git a/test/selectors/level1_lib.dart b/test/selectors/level1_lib.dart index 2f62103..833e702 100644 --- a/test/selectors/level1_lib.dart +++ b/test/selectors/level1_lib.dart @@ -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 foundall; diff --git a/test/tokenizer_test.dart b/test/tokenizer_test.dart index d804184..1281906 100644 --- a/test/tokenizer_test.dart +++ b/test/tokenizer_test.dart @@ -266,8 +266,8 @@ Map unescape(Map 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;