From 64ab40762a4b2756098e3a8c6eb5f2adcf19d1f6 Mon Sep 17 00:00:00 2001 From: Jonas Franz Date: Fri, 31 Jul 2020 17:46:47 +0200 Subject: [PATCH] Replace double quoted strings to single quoted --- analysis_options.yaml | 1 + lib/src/models/connection.dart | 22 +++++------ lib/src/models/connection_type.dart | 6 +-- lib/src/models/connection_type_converter.dart | 2 +- lib/src/models/construction_report.dart | 38 +++++++++---------- lib/src/models/region.dart | 26 ++++++------- lib/src/models/region_converter.dart | 2 +- lib/src/services/connection_service.dart | 4 +- pubspec.yaml | 3 -- test/connection_test.dart | 20 +++++----- test/construction_report_test.dart | 10 ++--- test/db_construction_site_test.dart | 2 +- 12 files changed, 66 insertions(+), 70 deletions(-) create mode 100644 analysis_options.yaml diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 0000000..108d105 --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1 @@ +include: package:pedantic/analysis_options.yaml diff --git a/lib/src/models/connection.dart b/lib/src/models/connection.dart index 9ae3a77..ee66b79 100644 --- a/lib/src/models/connection.dart +++ b/lib/src/models/connection.dart @@ -10,30 +10,30 @@ part 'connection.g.dart'; class Connection { final String id; final String name; - @JsonKey(name: "von") + @JsonKey(name: 'von') final String origin; - @JsonKey(name: "nach") + @JsonKey(name: 'nach') final String destination; - @JsonKey(name: "kbnr") + @JsonKey(name: 'kbnr') final String courseBookNumber; - @JsonKey(name: "verlauf") + @JsonKey(name: 'verlauf') final List stops; - @JsonKey(name: "via") + @JsonKey(name: 'via') final String via; final DateTime timestamp; - @JsonKey(name: "verfall") + @JsonKey(name: 'verfall') final DateTime expiryDate; - @JsonKey(name: "verbindung") + @JsonKey(name: 'verbindung') final ConnectionType type; - @JsonKey(name: "land") + @JsonKey(name: 'land') final Region region; final String url; - @JsonKey(name: "ics") + @JsonKey(name: 'ics') final String icsUrl; - @JsonKey(name: "doc") + @JsonKey(name: 'doc') final String documentUrl; - @JsonKey(name: "meldungen") + @JsonKey(name: 'meldungen') final List reports; const Connection({ diff --git a/lib/src/models/connection_type.dart b/lib/src/models/connection_type.dart index 87edf8d..46a7d6a 100644 --- a/lib/src/models/connection_type.dart +++ b/lib/src/models/connection_type.dart @@ -1,10 +1,10 @@ import 'package:json_annotation/json_annotation.dart'; enum ConnectionType { - @JsonValue("fern") + @JsonValue('fern') longDistance, - @JsonValue("regional") + @JsonValue('regional') regional, - @JsonValue("sbahn") + @JsonValue('sbahn') sBahn, } diff --git a/lib/src/models/connection_type_converter.dart b/lib/src/models/connection_type_converter.dart index ee4357b..e80c35d 100644 --- a/lib/src/models/connection_type_converter.dart +++ b/lib/src/models/connection_type_converter.dart @@ -11,5 +11,5 @@ class ConnectionTypeConverter { const ConnectionTypeConverter(this.type); @JsonKey(ignore: true) - String get value => _$ConnectionTypeConverterToJson(this)["type"]; + String get value => _$ConnectionTypeConverterToJson(this)['type']; } diff --git a/lib/src/models/construction_report.dart b/lib/src/models/construction_report.dart index daca8c7..5d340c5 100644 --- a/lib/src/models/construction_report.dart +++ b/lib/src/models/construction_report.dart @@ -5,46 +5,46 @@ part 'construction_report.g.dart'; @JsonSerializable(createToJson: false) class ConstructionReport { final String id; - @JsonKey(name: "nr", fromJson: int.parse) + @JsonKey(name: 'nr', fromJson: int.parse) final int index; - @JsonKey(name: "termin", fromJson: _parseListOrString) + @JsonKey(name: 'termin', fromJson: _parseListOrString) final List timePeriodTexts; - @JsonKey(name: "termin_pins", fromJson: _parseListOrString) + @JsonKey(name: 'termin_pins', fromJson: _parseListOrString) final List timePeriodPinsTexts; - @JsonKey(name: "termin_zeit", fromJson: _parseListOrString) + @JsonKey(name: 'termin_zeit', fromJson: _parseListOrString) final List timePeriodTimeTexts; final String headline; final String headlinePins; - @JsonKey(name: "meldung", fromJson: _parseListOrString) + @JsonKey(name: 'meldung', fromJson: _parseListOrString) final List messages; - @JsonKey(name: "meldung_pins", fromJson: _parseListOrString) + @JsonKey(name: 'meldung_pins', fromJson: _parseListOrString) final List messagesPins; - @JsonKey(name: "meldung_hinweis", fromJson: _parseListOrString) + @JsonKey(name: 'meldung_hinweis', fromJson: _parseListOrString) final List messagesHint; - @JsonKey(name: "hinweis_tabelle", fromJson: _parseListOrString) + @JsonKey(name: 'hinweis_tabelle', fromJson: _parseListOrString) final List hintTable; - @JsonKey(name: "grund") + @JsonKey(name: 'grund') final String reason; - @JsonKey(name: "abschnitt") + @JsonKey(name: 'abschnitt') final List affectedStations; final DateTime lastChange; - @JsonKey(name: "ics") + @JsonKey(name: 'ics') final String icsUrl; - @JsonKey(name: "termine", fromJson: _parseTimeRanges) + @JsonKey(name: 'termine', fromJson: _parseTimeRanges) final List timeRanges; - @JsonKey(name: "von") + @JsonKey(name: 'von') final DateTime startDate; - @JsonKey(name: "bis") + @JsonKey(name: 'bis') final DateTime endDate; ConstructionReport( @@ -97,11 +97,11 @@ class TimeRange { const TimeRange({this.begin, this.end, this.allDay, this.weekdays}); TimeRange._fromJson(Map json) - : begin = _parseTimeStamp(json, "von"), - end = _parseTimeStamp(json, "bis"), - allDay = json["ganztaegig"] == "1", - weekdays = json["wochentage"] is List - ? (json["wochentage"] as List) + : begin = _parseTimeStamp(json, 'von'), + end = _parseTimeStamp(json, 'bis'), + allDay = json['ganztaegig'] == '1', + weekdays = json['wochentage'] is List + ? (json['wochentage'] as List) .map((day) => int.parse(day)) .toList() : null; diff --git a/lib/src/models/region.dart b/lib/src/models/region.dart index 8d16da9..bd92a58 100644 --- a/lib/src/models/region.dart +++ b/lib/src/models/region.dart @@ -2,54 +2,54 @@ import 'package:json_annotation/json_annotation.dart'; enum Region { /// Lower Saxony and Bremen - @JsonValue("niedersachen-bremen") + @JsonValue('niedersachen-bremen') lowerSaxonyBremen, /// Schleswig Holstein - @JsonValue("norden") + @JsonValue('norden') north, /// Mecklenburg Western Pomerania - @JsonValue("mvp") + @JsonValue('mvp') mecklenburgWesternPomerania, /// Berlin and Brandenburg - @JsonValue("berlin-bb") + @JsonValue('berlin-bb') berlinBrandenburg, /// Saxony-Anhalt - @JsonValue("sachsen-anhalt") + @JsonValue('sachsen-anhalt') saxonyAnhalt, /// Saxony - @JsonValue("sachsen") + @JsonValue('sachsen') saxony, /// Bavaria - @JsonValue("bayern") + @JsonValue('bayern') bavaria, /// Thuringia - @JsonValue("thueringen") + @JsonValue('thueringen') thuringia, /// Baden-Württemberg - @JsonValue("baden-w") + @JsonValue('baden-w') badenWuerttemberg, /// Rhineland Palatinate - @JsonValue("rheinland-pfalz") + @JsonValue('rheinland-pfalz') rhinelandPalatinate, /// Hesse - @JsonValue("hessen") + @JsonValue('hessen') hesse, /// Northrhine-Westphalia - @JsonValue("nrw") + @JsonValue('nrw') northrhineWestphalia, /// Long distance trains with multiple regions - @JsonValue("fernverkehr") + @JsonValue('fernverkehr') longDistance, } diff --git a/lib/src/models/region_converter.dart b/lib/src/models/region_converter.dart index 2df4318..860b16e 100644 --- a/lib/src/models/region_converter.dart +++ b/lib/src/models/region_converter.dart @@ -11,5 +11,5 @@ class RegionConverter { const RegionConverter(this.region); @JsonKey(ignore: true) - String get value => _$RegionConverterToJson(this)["region"]; + String get value => _$RegionConverterToJson(this)['region']; } diff --git a/lib/src/services/connection_service.dart b/lib/src/services/connection_service.dart index 2e82ccf..e5c250d 100644 --- a/lib/src/services/connection_service.dart +++ b/lib/src/services/connection_service.dart @@ -1,5 +1,4 @@ import 'dart:convert'; -import 'dart:io'; import 'package:db_construction_site/src/models/connection.dart'; import 'package:db_construction_site/src/models/connection_type.dart'; @@ -23,8 +22,7 @@ class ConnectionService { } final result = await http.get(url); if (result.statusCode ~/ 100 != 2) { - throw HttpException("unexpected status code ${result.statusCode}", - uri: result.request.url); + throw Exception('unexpected status code ${result.statusCode}'); } final List connections = JsonDecoder().convert(result.body); return connections diff --git a/pubspec.yaml b/pubspec.yaml index faedccb..f88544a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,6 +16,3 @@ dev_dependencies: build_runner: ^1.10.1 json_serializable: ^3.3.0 pedantic: ^1.9.2 - -# enable linting rules -include: package:pedantic/analysis_options.yaml diff --git a/test/connection_test.dart b/test/connection_test.dart index c0ef67b..904a8c8 100644 --- a/test/connection_test.dart +++ b/test/connection_test.dart @@ -6,7 +6,7 @@ import 'package:test/test.dart'; void main() { test('test if json parsing works as expected', () { - const exampleConnectionJsonString = """ + const exampleConnectionJsonString = ''' { "id": "3", "name": "RE 17", @@ -33,23 +33,23 @@ void main() { "meldungen": [], "infos": [] } - """; + '''; Map json; try { json = JsonDecoder().convert(exampleConnectionJsonString); assert(json != null); } catch (e) { - print("JSON decoding failed, skipping test."); + print('JSON decoding failed, skipping test.'); return; } final connection = Connection.fromJson(json); - expect(connection.id, "3"); - expect(connection.name, "RE 17"); - expect(connection.courseBookNumber, "430"); - expect(connection.origin, "Warburg"); - expect(connection.stops, contains("Hagen Hbf")); - expect(connection.destination, "Kassel"); - expect(connection.via, ""); + expect(connection.id, '3'); + expect(connection.name, 'RE 17'); + expect(connection.courseBookNumber, '430'); + expect(connection.origin, 'Warburg'); + expect(connection.stops, contains('Hagen Hbf')); + expect(connection.destination, 'Kassel'); + expect(connection.via, ''); expect(connection.timestamp, DateTime(2018, 11, 16, 05, 15, 43)); expect(connection.expiryDate, DateTime(2018, 12, 02, 23, 15, 00)); expect(connection.type, ConnectionType.regional); diff --git a/test/construction_report_test.dart b/test/construction_report_test.dart index 176039f..7b78456 100644 --- a/test/construction_report_test.dart +++ b/test/construction_report_test.dart @@ -5,7 +5,7 @@ import 'package:test/test.dart'; void main() { test('test if json parsing works as expected', () { - const exampleReportJsonString = """ + const exampleReportJsonString = ''' { "id": "5604", "nr": "1", @@ -65,20 +65,20 @@ void main() { } ] } - """; + '''; Map json; try { json = JsonDecoder().convert(exampleReportJsonString); assert(json != null); } catch (e) { - print("JSON decoding failed, skipping test."); + print('JSON decoding failed, skipping test.'); return; } final connection = ConstructionReport.fromJson(json); - expect(connection.id, "5604"); + expect(connection.id, '5604'); expect(connection.index, 1); expect(connection.messages, [ - "Die Züge der Linien RE 4 und RE 14 enden/beginnen in Frankfurt-Höchst und fallen zwischen Frankfurt-Höchst und Frankfurt (Main) Hbf aus. Als Ersatz nutzen Sie bitte die noch verkehrenden Züge in diesem Abschnitt." + 'Die Züge der Linien RE 4 und RE 14 enden/beginnen in Frankfurt-Höchst und fallen zwischen Frankfurt-Höchst und Frankfurt (Main) Hbf aus. Als Ersatz nutzen Sie bitte die noch verkehrenden Züge in diesem Abschnitt.' ]); expect(connection.timeRanges.length, 1); expect(connection.timeRanges[0].begin, connection.startDate); diff --git a/test/db_construction_site_test.dart b/test/db_construction_site_test.dart index e74d9b2..21e73d6 100644 --- a/test/db_construction_site_test.dart +++ b/test/db_construction_site_test.dart @@ -14,7 +14,7 @@ void main() { await DBConstructionSite(baseUrl: 'https://noanurl.local') .connections .findConnections(Region.hesse); - fail("Request succeeds although it should fail"); + fail('Request succeeds although it should fail'); } catch (e) { // success }