Skip to content

Commit

Permalink
Dart 3.4 requirement and fix linter warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
renggli committed May 25, 2024
1 parent 7106dd8 commit be485cd
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 59 deletions.
2 changes: 2 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ linter:
- comment_references
- directives_ordering
- invalid_case_patterns
- missing_code_block_language_in_doc_comment
- no_self_assignments
- no_wildcard_variable_uses
- omit_local_variable_types
Expand All @@ -33,6 +34,7 @@ linter:
- unnecessary_await_in_return
- unnecessary_breaks
- unnecessary_lambdas
- unnecessary_library_name
- unnecessary_null_aware_operator_on_extension_on_nullable
- unnecessary_null_checks
- unnecessary_parenthesis
Expand Down
2 changes: 1 addition & 1 deletion example/currencies.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// Prints currency exchange table using www.floatrates.com.
library currencies;
library;

import 'dart:convert';
import 'dart:io';
Expand Down
2 changes: 1 addition & 1 deletion example/feeds.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// A simple command-line based RSS feed reader.
library feeds;
library;

import 'dart:convert';
import 'dart:io';
Expand Down
2 changes: 1 addition & 1 deletion example/ip_api.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// IP Geolocation API using ip-api.com.
library ip_api;
library;

import 'dart:convert';
import 'dart:io';
Expand Down
2 changes: 1 addition & 1 deletion example/xml_flatten.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// XML flatten.
library xml_flatten;
library;

import 'dart:convert';
import 'dart:io';
Expand Down
2 changes: 1 addition & 1 deletion example/xml_grep.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// XML grep.
library xml_grep;
library;

import 'dart:io';

Expand Down
2 changes: 1 addition & 1 deletion example/xml_pos.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// XML position printer.
library xml_pos;
library;

import 'dart:io';
import 'dart:math';
Expand Down
2 changes: 1 addition & 1 deletion example/xml_pp.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// XML pretty printer and highlighter.
library xml_pp;
library;

import 'dart:io';

Expand Down
65 changes: 38 additions & 27 deletions lib/src/xml/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ class XmlBuilder {
///
/// For example, to generate the text `Hello World` one would write:
///
/// builder.text('Hello World');
///
/// ```dart
/// builder.text('Hello World');
/// ```
void text(Object text) {
final children = _stack.last.children;
if (children.isNotEmpty) {
Expand All @@ -64,8 +65,9 @@ class XmlBuilder {
/// For example, to generate an XML CDATA element `<![CDATA[Hello World]]>`
/// one would write:
///
/// builder.cdata('Hello World');
///
/// ```dart
/// builder.cdata('Hello World');
/// ```
void cdata(Object text) {
_stack.last.children.add(XmlCDATA(text.toString()));
}
Expand All @@ -75,8 +77,9 @@ class XmlBuilder {
/// For example, to generate an XML declaration `<?xml version="1.0"
/// encoding="utf-8"?>` one would write:
///
/// builder.declaration(encoding: 'UTF-8');
///
/// ```dart
/// builder.declaration(encoding: 'UTF-8');
/// ```
void declaration(
{String version = '1.0',
String? encoding,
Expand All @@ -93,8 +96,9 @@ class XmlBuilder {
/// For example, to generate an XML doctype element `<!DOCTYPE note SYSTEM
/// "note.dtd">` one would write:
///
/// builder.doctype('note', systemId: 'note.dtd');
///
/// ```dart
/// builder.doctype('note', systemId: 'note.dtd');
/// ```
void doctype(String name,
{String? publicId, String? systemId, String? internalSubset}) {
if (publicId != null && systemId == null) {
Expand All @@ -115,8 +119,9 @@ class XmlBuilder {
/// For example, to generate an XML processing element `<?xml-stylesheet
/// href="/style.css"?>` one would write:
///
/// builder.processing('xml-stylesheet', 'href="/style.css"');
///
/// ```dart
/// builder.processing('xml-stylesheet', 'href="/style.css"');
/// ```
void processing(String target, Object text) {
_stack.last.children.add(XmlProcessing(target, text.toString()));
}
Expand All @@ -126,8 +131,9 @@ class XmlBuilder {
/// For example, to generate an XML comment `<!--Hello World-->` one would
/// write:
///
/// builder.comment('Hello World');
///
/// ```dart
/// builder.comment('Hello World');
/// ```
void comment(Object text) {
_stack.last.children.add(XmlComment(text.toString()));
}
Expand All @@ -152,15 +158,18 @@ class XmlBuilder {
/// For example, to generate an XML element with the tag _message_ and the
/// contained text _Hello World_ one would write:
///
/// builder.element('message', nest: 'Hello World');
/// ```dart
/// builder.element('message', nest: 'Hello World');
/// ```
///
/// To add multiple child elements one would use:
///
/// builder.element('message', nest: () {
/// builder..text('Hello World')
/// ..element('break');
/// });
///
/// ```dart
/// builder.element('message', nest: () {
/// builder..text('Hello World')
/// ..element('break');
/// });
/// ```
void element(
String name, {
String? namespace,
Expand Down Expand Up @@ -205,10 +214,11 @@ class XmlBuilder {
/// To generate an element with the tag _message_ and the
/// attribute _lang="en"_ one would write:
///
/// builder.element('message', nest: () {
/// builder.attribute('lang', 'en');
/// });
///
/// ```dart
/// builder.element('message', nest: () {
/// builder.attribute('lang', 'en');
/// });
/// ```
void attribute(String name, Object? value,
{String? namespace, XmlAttributeType? attributeType}) {
final attributes = _stack.last.attributes;
Expand Down Expand Up @@ -237,11 +247,12 @@ class XmlBuilder {
/// To generate a bookshelf element with two predefined book elements, one
/// would write:
///
/// builder.element('bookshelf', nest: () {
/// builder.xml('<book><title>Growing a Language</title></book>');
/// builder.xml('<book><title>Learning XML</title></book>');
/// });
///
/// ```dart
/// builder.element('bookshelf', nest: () {
/// builder.xml('<book><title>Growing a Language</title></book>');
/// builder.xml('<book><title>Learning XML</title></book>');
/// });
/// ```
void xml(String input, {XmlEntityMapping? entityMapping}) {
final fragment =
XmlDocumentFragment.parse(input, entityMapping: entityMapping);
Expand Down
33 changes: 19 additions & 14 deletions lib/src/xml/nodes/document.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ class XmlDocument extends XmlNode with XmlHasChildren<XmlNode> {
///
/// For example, the following code prints `Hello World`:
///
/// final document = new XmlDocument.parse('<?xml?><root message="Hello World" />');
/// print(document.rootElement.getAttribute('message'));
/// ```dart
/// final document = new XmlDocument.parse('<?xml?><root message="Hello World" />');
/// print(document.rootElement.getAttribute('message'));
/// ```
///
/// Note: It is the responsibility of the caller to provide a standard Dart
/// [String] using the default UTF-16 encoding.
Expand All @@ -44,10 +46,11 @@ class XmlDocument extends XmlNode with XmlHasChildren<XmlNode> {
///
/// For example the following code prints `<?xml version="1.0">`:
///
/// var xml = '<?xml version="1.0">'
/// '<shelf></shelf>';
/// print(XmlDocument.parse(xml).doctypeElement);
///
/// ```dart
/// var xml = '<?xml version="1.0">'
/// '<shelf></shelf>';
/// print(XmlDocument.parse(xml).doctypeElement);
/// ```
XmlDeclaration? get declaration {
for (final node in children) {
if (node is XmlDeclaration) {
Expand All @@ -61,10 +64,11 @@ class XmlDocument extends XmlNode with XmlHasChildren<XmlNode> {
///
/// For example, the following code prints `<!DOCTYPE html>`:
///
/// var xml = '<!DOCTYPE html>'
/// '<html><body></body></html>';
/// print(XmlDocument.parse(xml).doctypeElement);
///
/// ```dart
/// var xml = '<!DOCTYPE html>'
/// '<html><body></body></html>';
/// print(XmlDocument.parse(xml).doctypeElement);
/// ```
XmlDoctype? get doctypeElement {
for (final node in children) {
if (node is XmlDoctype) {
Expand All @@ -79,10 +83,11 @@ class XmlDocument extends XmlNode with XmlHasChildren<XmlNode> {
///
/// For example, the following code prints `<books />`:
///
/// var xml = '<?xml version="1.0"?>'
/// '<books />';
/// print(XmlDocument.parse(xml).rootElement);
///
/// ```dart
/// var xml = '<?xml version="1.0"?>'
/// '<books />';
/// print(XmlDocument.parse(xml).rootElement);
/// ```
XmlElement get rootElement {
for (final node in children) {
if (node is XmlElement) {
Expand Down
2 changes: 1 addition & 1 deletion lib/xml.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// Dart XML is a lightweight library for parsing, traversing, querying and
/// building XML documents.
library xml;
library;

export 'src/xml/builder.dart' show XmlBuilder;
export 'src/xml/entities/default_mapping.dart'
Expand Down
15 changes: 8 additions & 7 deletions lib/xml_events.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// Dart XML Events is an event based library to asynchronously parse XML
/// documents and to convert them to other representations.
library xml_events;
library;

import 'src/xml/entities/default_mapping.dart';
import 'src/xml/entities/entity_mapping.dart';
Expand Down Expand Up @@ -74,12 +74,13 @@ export 'src/xml_events/visitor.dart' show XmlEventVisitor;
///
/// For example, to print all trimmed non-empty text elements one would write:
///
/// parseEvents(bookstoreXml)
/// .whereType<XmlTextEvent>()
/// .map((event) => event.text.trim())
/// .where((text) => text.isNotEmpty)
/// .forEach(print);
///
/// ```dart
/// parseEvents(bookstoreXml)
/// .whereType<XmlTextEvent>()
/// .map((event) => event.text.trim())
/// .where((text) => text.isNotEmpty)
/// .forEach(print);
/// ```
Iterable<XmlEvent> parseEvents(
String input, {
XmlEntityMapping? entityMapping,
Expand Down
2 changes: 1 addition & 1 deletion lib/xpath.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// Dart XPath adds support of XPath 1.0 expressions to the XML library.
library xpath;
library;

import 'package:meta/meta.dart' show experimental;
import 'package:petitparser/core.dart' show Failure;
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ topics:
- xpath

environment:
sdk: ^3.3.0
sdk: ^3.4.0
dependencies:
collection: ^1.18.0
meta: ^1.9.0
petitparser: ^6.0.0
dev_dependencies:
args: ^2.4.0
lints: ^3.0.0
lints: ^4.0.0
test: ^1.24.0

0 comments on commit be485cd

Please sign in to comment.