Skip to content

Commit 12d13fb

Browse files
authored
Fixed linter issues (#71)
1 parent a6acdbe commit 12d13fb

27 files changed

+121
-97
lines changed

analysis_options.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include: package:pedantic/analysis_options.yaml

example/cars_server.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'dart:io';
44
import 'package:json_api/server.dart';
55
import 'package:json_api/src/server/server_document_factory.dart';
66
import 'package:json_api/url_design.dart';
7+
import 'package:pedantic/pedantic.dart';
78

89
import 'cars_server/controller.dart';
910
import 'cars_server/dao.dart';
@@ -63,6 +64,6 @@ Future<HttpServer> createServer(InternetAddress addr, int port) async {
6364
ServerDocumentFactory(urlDesign, pagination: pagination);
6465
final jsonApiServer = JsonApiServer(urlDesign, controller, documentFactory);
6566

66-
httpServer.forEach(jsonApiServer.serve);
67+
unawaited(httpServer.forEach(jsonApiServer.serve));
6768
return httpServer;
6869
}

example/cars_server/controller.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,6 @@ class CarsController implements JsonApiController {
205205
return resource;
206206
}
207207

208-
Map<T, R> _filter<T, R>(Map<T, R> map, bool f(T t)) =>
208+
Map<T, R> _filter<T, R>(Map<T, R> map, bool Function(T t) f) =>
209209
{...map}..removeWhere((k, _) => !f(k));
210210
}

example/cars_server/dao.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,14 @@ abstract class DAO<T> {
4949
}
5050

5151
class ModelDAO extends DAO<Model> {
52+
@override
5253
Resource toResource(Model _) =>
5354
Resource('models', _.id, attributes: {'name': _.name});
5455

56+
@override
5557
void insert(Model model) => _collection[model.id] = model;
5658

59+
@override
5760
Model create(Resource r) {
5861
return Model(r.id)..name = r.attributes['name'];
5962
}
@@ -66,17 +69,21 @@ class ModelDAO extends DAO<Model> {
6669
}
6770

6871
class CityDAO extends DAO<City> {
72+
@override
6973
Resource toResource(City _) =>
7074
Resource('cities', _.id, attributes: {'name': _.name});
7175

76+
@override
7277
void insert(City city) => _collection[city.id] = city;
7378

79+
@override
7480
City create(Resource r) {
7581
return City(r.id)..name = r.attributes['name'];
7682
}
7783
}
7884

7985
class CompanyDAO extends DAO<Company> {
86+
@override
8087
Resource toResource(Company company) =>
8188
Resource('companies', company.id, attributes: {
8289
'name': company.name,
@@ -90,11 +97,13 @@ class CompanyDAO extends DAO<Company> {
9097
'models': company.models.map((_) => Identifier('models', _)).toList()
9198
});
9299

100+
@override
93101
void insert(Company company) {
94102
company.updatedAt = DateTime.now();
95103
_collection[company.id] = company;
96104
}
97105

106+
@override
98107
Company create(Resource r) {
99108
return Company(r.id)
100109
..name = r.attributes['name']
@@ -104,7 +113,7 @@ class CompanyDAO extends DAO<Company> {
104113
@override
105114
int deleteById(String id) {
106115
final company = fetchById(id);
107-
int deps = company.headquarters == null ? 0 : 1;
116+
var deps = company.headquarters == null ? 0 : 1;
108117
deps += company.models.length;
109118
_collection.remove(id);
110119
return deps;

example/cars_server/job_queue.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ class Job {
1010
Resource resource;
1111

1212
Job(Future<Resource> create) : id = Uuid().v4() {
13-
create.then((_) => this.resource = _);
13+
create.then((_) => resource = _);
1414
}
1515
}

example/cars_server/model.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class Company {
22
final String id;
33
String headquarters;
4-
final models = Set<String>();
4+
final models = <String>{};
55

66
/// Company name
77
String name;

lib/src/client/json_api_client.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class JsonApiClient {
195195
..body = json.encode(doc);
196196

197197
Future<Response<D>> _call<D extends PrimaryData>(
198-
http.Request request, D decodePrimaryData(Object _)) async {
198+
http.Request request, D Function(Object _) decodePrimaryData) async {
199199
final response =
200200
await http.Response.fromStream(await httpClient.send(request));
201201
_onHttpCall(request, response);
@@ -217,6 +217,7 @@ class JsonApiClient {
217217

218218
/// Defines the hook which gets called when the HTTP response is received from
219219
/// the HTTP Client.
220-
typedef void OnHttpCall(http.Request request, http.Response response);
220+
typedef OnHttpCall = void Function(
221+
http.Request request, http.Response response);
221222

222-
_doNothing(http.Request request, http.Response response) {}
223+
void _doNothing(http.Request request, http.Response response) {}

lib/src/document/api.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Api {
99
final Map<String, Object> meta;
1010

1111
Api({this.version, Map<String, Object> meta})
12-
: this.meta = meta == null ? null : Map.unmodifiable(meta);
12+
: meta = meta == null ? null : Map.unmodifiable(meta);
1313

1414
static Api fromJson(Object json) {
1515
if (json is Map) {

lib/src/document/document.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,27 @@ class Document<Data extends PrimaryData> {
2020

2121
/// Create a document with primary data
2222
Document(this.data, {Map<String, Object> meta, this.api})
23-
: this.errors = null,
24-
this.meta = (meta == null) ? null : Map.unmodifiable(meta);
23+
: errors = null,
24+
meta = (meta == null) ? null : Map.unmodifiable(meta);
2525

2626
/// Create a document with errors (no primary data)
2727
Document.error(Iterable<JsonApiError> errors,
2828
{Map<String, Object> meta, this.api})
29-
: this.data = null,
30-
this.meta = (meta == null) ? null : Map.unmodifiable(meta),
31-
this.errors = List.unmodifiable(errors);
29+
: data = null,
30+
meta = (meta == null) ? null : Map.unmodifiable(meta),
31+
errors = List.unmodifiable(errors);
3232

3333
/// Create an empty document (no primary data and no errors)
3434
Document.empty(Map<String, Object> meta, {this.api})
35-
: this.data = null,
36-
this.meta = (meta == null) ? null : Map.unmodifiable(meta),
37-
this.errors = null {
35+
: data = null,
36+
meta = (meta == null) ? null : Map.unmodifiable(meta),
37+
errors = null {
3838
ArgumentError.checkNotNull(meta, 'meta');
3939
}
4040

4141
/// Reconstructs a document with the specified primary data
4242
static Document<Data> fromJson<Data extends PrimaryData>(
43-
Object json, Data primaryData(Object json)) {
43+
Object json, Data Function(Object json) primaryData) {
4444
if (json is Map) {
4545
Api api;
4646
if (json.containsKey('jsonapi')) {

lib/src/document/identifier.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ class Identifier {
2323
other.type == type &&
2424
other.id == id;
2525

26-
String toString() => "Identifier($type:$id)";
26+
@override
27+
String toString() => 'Identifier($type:$id)';
2728
}

0 commit comments

Comments
 (0)