Skip to content
This repository was archived by the owner on Dec 6, 2023. It is now read-only.

Commit b58ef8b

Browse files
Use package lints (#712)
1 parent a8fbc15 commit b58ef8b

15 files changed

+90
-74
lines changed

analysis_options.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Dart analyzer dislikes this line. https://github.com/dart-lang/dart-pad/issues/1720
22
# include: package:pedantic/analysis_options.1.11.0.yaml
3+
include: package:lints/recommended.yaml
34

45
analyzer:
56
language:
@@ -16,9 +17,12 @@ analyzer:
1617

1718
linter:
1819
rules:
20+
- always_declare_return_types
1921
- directives_ordering
2022
- prefer_final_fields
2123
- prefer_final_in_for_each
2224
- prefer_final_locals
2325
- prefer_relative_imports
26+
- prefer_single_quotes
2427
- sort_pub_dependencies
28+
- unawaited_futures

lib/src/analysis_server.dart

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ final Logger _logger = Logger('analysis_server');
2727
/// to stdout.
2828
bool dumpServerMessages = false;
2929

30-
const String _WARMUP_SRC_HTML =
30+
const String _warmupSrcHtml =
3131
"import 'dart:html'; main() { int b = 2; b++; b. }";
32-
const String _WARMUP_SRC = 'main() { int b = 2; b++; b. }';
32+
const String _warmupSrc = 'main() { int b = 2; b++; b. }';
3333

3434
// Use very long timeouts to ensure that the server has enough time to restart.
35-
const Duration _ANALYSIS_SERVER_TIMEOUT = Duration(seconds: 35);
35+
const Duration _analysisServerTimeout = Duration(seconds: 35);
3636

3737
class DartAnalysisServerWrapper extends AnalysisServerWrapper {
3838
DartAnalysisServerWrapper(this._nullSafety) : super(Sdk.sdkPath);
@@ -102,7 +102,7 @@ abstract class AnalysisServerWrapper {
102102
final analysisComplete = getAnalysisCompleteCompleter();
103103
await analysisServer.analysis
104104
.setAnalysisRoots(<String>[_sourceDirPath], <String>[]);
105-
await _sendAddOverlays(<String, String>{mainPath: _WARMUP_SRC});
105+
await _sendAddOverlays(<String, String>{mainPath: _warmupSrc});
106106
await analysisComplete.future;
107107
await _sendRemoveOverlays();
108108

@@ -262,7 +262,7 @@ abstract class AnalysisServerWrapper {
262262
}
263263

264264
return m;
265-
}, timeoutDuration: _ANALYSIS_SERVER_TIMEOUT));
265+
}, timeoutDuration: _analysisServerTimeout));
266266
}
267267

268268
Future<proto.AnalysisResults> analyze(String source) {
@@ -322,7 +322,7 @@ abstract class AnalysisServerWrapper {
322322
return proto.AnalysisResults()
323323
..issues.addAll(issues)
324324
..packageImports.addAll(packageImports);
325-
}, timeoutDuration: _ANALYSIS_SERVER_TIMEOUT));
325+
}, timeoutDuration: _analysisServerTimeout));
326326
}
327327

328328
Future<AssistsResult> _getAssistsImpl(
@@ -344,7 +344,7 @@ abstract class AnalysisServerWrapper {
344344
await analysisServer.edit.getAssists(path, offset, length);
345345
await _unloadSources();
346346
return assists;
347-
}, timeoutDuration: _ANALYSIS_SERVER_TIMEOUT));
347+
}, timeoutDuration: _analysisServerTimeout));
348348
}
349349

350350
/// Convert between the Analysis Server type and the API protocol types.
@@ -469,7 +469,7 @@ abstract class AnalysisServerWrapper {
469469
final results = await getCompletionResults(id.id);
470470
await _unloadSources();
471471
return results;
472-
}, timeoutDuration: _ANALYSIS_SERVER_TIMEOUT));
472+
}, timeoutDuration: _analysisServerTimeout));
473473
}
474474

475475
Future<FixesResult> _getFixesImpl(
@@ -489,7 +489,7 @@ abstract class AnalysisServerWrapper {
489489
final fixes = await analysisServer.edit.getFixes(path, offset);
490490
await _unloadSources();
491491
return fixes;
492-
}, timeoutDuration: _ANALYSIS_SERVER_TIMEOUT));
492+
}, timeoutDuration: _analysisServerTimeout));
493493
}
494494

495495
Future<FormatResult> _formatImpl(String src, int offset) async {
@@ -500,7 +500,7 @@ abstract class AnalysisServerWrapper {
500500
final result = await analysisServer.edit.format(mainPath, offset, 0);
501501
await _unloadSources();
502502
return result;
503-
}, timeoutDuration: _ANALYSIS_SERVER_TIMEOUT));
503+
}, timeoutDuration: _analysisServerTimeout));
504504
}
505505

506506
Map<String, String> _getOverlayMapWithPaths(Map<String, String> overlay) {
@@ -516,7 +516,7 @@ abstract class AnalysisServerWrapper {
516516

517517
/// Warm up the analysis server to be ready for use.
518518
Future<proto.CompleteResponse> warmup({bool useHtml = false}) =>
519-
complete(useHtml ? _WARMUP_SRC_HTML : _WARMUP_SRC, 10);
519+
complete(useHtml ? _warmupSrcHtml : _warmupSrc, 10);
520520

521521
final Set<String> _overlayPaths = <String>{};
522522

lib/src/common_server_api.dart

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,88 +19,88 @@ export 'common_server_impl.dart' show log, ServerContainer;
1919

2020
part 'common_server_api.g.dart'; // generated with 'pub run build_runner build'
2121

22-
const PROTOBUF_CONTENT_TYPE = 'application/x-protobuf';
23-
const JSON_CONTENT_TYPE = 'application/json; charset=utf-8';
24-
const PROTO_API_URL_PREFIX = '/api/dartservices/<apiVersion>';
22+
const protobufContentType = 'application/x-protobuf';
23+
const jsonContentType = 'application/json; charset=utf-8';
24+
const protoApiUrlPrefix = '/api/dartservices/<apiVersion>';
2525

2626
class CommonServerApi {
2727
final CommonServerImpl _impl;
2828

2929
CommonServerApi(this._impl);
3030

31-
@Route.post('$PROTO_API_URL_PREFIX/analyze')
31+
@Route.post('$protoApiUrlPrefix/analyze')
3232
Future<Response> analyze(Request request, String apiVersion) =>
3333
_processRequest(request,
3434
decodeFromJSON: (json) =>
3535
proto.SourceRequest.create()..mergeFromProto3Json(json),
3636
decodeFromProto: (bytes) => proto.SourceRequest.fromBuffer(bytes),
3737
transform: _impl.analyze);
3838

39-
@Route.post('$PROTO_API_URL_PREFIX/compile')
39+
@Route.post('$protoApiUrlPrefix/compile')
4040
Future<Response> compile(Request request, String apiVersion) =>
4141
_processRequest(request,
4242
decodeFromJSON: (json) =>
4343
proto.CompileRequest.create()..mergeFromProto3Json(json),
4444
decodeFromProto: (bytes) => proto.CompileRequest.fromBuffer(bytes),
4545
transform: _impl.compile);
4646

47-
@Route.post('$PROTO_API_URL_PREFIX/compileDDC')
47+
@Route.post('$protoApiUrlPrefix/compileDDC')
4848
Future<Response> compileDDC(Request request, String apiVersion) =>
4949
_processRequest(request,
5050
decodeFromJSON: (json) =>
5151
proto.CompileDDCRequest.create()..mergeFromProto3Json(json),
5252
decodeFromProto: (bytes) => proto.CompileDDCRequest.fromBuffer(bytes),
5353
transform: _impl.compileDDC);
5454

55-
@Route.post('$PROTO_API_URL_PREFIX/complete')
55+
@Route.post('$protoApiUrlPrefix/complete')
5656
Future<Response> complete(Request request, String apiVersion) =>
5757
_processRequest(request,
5858
decodeFromJSON: (json) =>
5959
proto.SourceRequest.create()..mergeFromProto3Json(json),
6060
decodeFromProto: (bytes) => proto.SourceRequest.fromBuffer(bytes),
6161
transform: _impl.complete);
6262

63-
@Route.post('$PROTO_API_URL_PREFIX/fixes')
63+
@Route.post('$protoApiUrlPrefix/fixes')
6464
Future<Response> fixes(Request request, String apiVersion) =>
6565
_processRequest(request,
6666
decodeFromJSON: (json) =>
6767
proto.SourceRequest.create()..mergeFromProto3Json(json),
6868
decodeFromProto: (bytes) => proto.SourceRequest.fromBuffer(bytes),
6969
transform: _impl.fixes);
7070

71-
@Route.post('$PROTO_API_URL_PREFIX/assists')
71+
@Route.post('$protoApiUrlPrefix/assists')
7272
Future<Response> assists(Request request, String apiVersion) =>
7373
_processRequest(request,
7474
decodeFromJSON: (json) =>
7575
proto.SourceRequest.create()..mergeFromProto3Json(json),
7676
decodeFromProto: (bytes) => proto.SourceRequest.fromBuffer(bytes),
7777
transform: _impl.assists);
7878

79-
@Route.post('$PROTO_API_URL_PREFIX/format')
79+
@Route.post('$protoApiUrlPrefix/format')
8080
Future<Response> format(Request request, String apiVersion) =>
8181
_processRequest(request,
8282
decodeFromJSON: (json) =>
8383
proto.SourceRequest.create()..mergeFromProto3Json(json),
8484
decodeFromProto: (bytes) => proto.SourceRequest.fromBuffer(bytes),
8585
transform: _impl.format);
8686

87-
@Route.post('$PROTO_API_URL_PREFIX/document')
87+
@Route.post('$protoApiUrlPrefix/document')
8888
Future<Response> document(Request request, String apiVersion) =>
8989
_processRequest(request,
9090
decodeFromJSON: (json) =>
9191
proto.SourceRequest.create()..mergeFromProto3Json(json),
9292
decodeFromProto: (bytes) => proto.SourceRequest.fromBuffer(bytes),
9393
transform: _impl.document);
9494

95-
@Route.post('$PROTO_API_URL_PREFIX/version')
95+
@Route.post('$protoApiUrlPrefix/version')
9696
Future<Response> versionPost(Request request, String apiVersion) =>
9797
_processRequest(request,
9898
decodeFromJSON: (json) =>
9999
proto.VersionRequest.create()..mergeFromProto3Json(json),
100100
decodeFromProto: (bytes) => proto.VersionRequest.fromBuffer(bytes),
101101
transform: _impl.version);
102102

103-
@Route.get('$PROTO_API_URL_PREFIX/version')
103+
@Route.get('$protoApiUrlPrefix/version')
104104
Future<Response> versionGet(Request request, String apiVersion) =>
105105
_processRequest(request,
106106
decodeFromJSON: (json) =>
@@ -121,7 +121,7 @@ class CommonServerApi {
121121
@required I Function(Object json) decodeFromJSON,
122122
@required Future<O> Function(I input) transform,
123123
}) async {
124-
if (request.mimeType == PROTOBUF_CONTENT_TYPE) {
124+
if (request.mimeType == protobufContentType) {
125125
// Dealing with binary Protobufs
126126
final body = <int>[];
127127
await for (final chunk in request.read()) {
@@ -131,11 +131,11 @@ class CommonServerApi {
131131
final response = await transform(decodeFromProto(body));
132132
return Response.ok(
133133
response.writeToBuffer(),
134-
headers: _PROTOBUF_HEADERS,
134+
headers: _protobufHeaders,
135135
);
136136
} on BadRequest catch (e) {
137137
return Response(400,
138-
headers: _PROTOBUF_HEADERS,
138+
headers: _protobufHeaders,
139139
body: (proto.BadRequest.create()
140140
..error = (proto.ErrorMessage.create()..message = e.cause))
141141
.writeToBuffer());
@@ -149,11 +149,11 @@ class CommonServerApi {
149149
return Response.ok(
150150
_jsonEncoder.convert(response.toProto3Json()),
151151
encoding: utf8,
152-
headers: _JSON_HEADERS,
152+
headers: _jsonHeaders,
153153
);
154154
} on BadRequest catch (e) {
155155
return Response(400,
156-
headers: _JSON_HEADERS,
156+
headers: _jsonHeaders,
157157
encoding: utf8,
158158
body: _jsonEncoder.convert((proto.BadRequest.create()
159159
..error = (proto.ErrorMessage.create()..message = e.cause))
@@ -164,13 +164,13 @@ class CommonServerApi {
164164

165165
final JsonEncoder _jsonEncoder = const JsonEncoder.withIndent(' ');
166166

167-
static const _JSON_HEADERS = {
167+
static const _jsonHeaders = {
168168
'Access-Control-Allow-Origin': '*',
169-
'Content-Type': JSON_CONTENT_TYPE
169+
'Content-Type': jsonContentType
170170
};
171171

172-
static const _PROTOBUF_HEADERS = {
172+
static const _protobufHeaders = {
173173
'Access-Control-Allow-Origin': '*',
174-
'Content-Type': PROTOBUF_CONTENT_TYPE
174+
'Content-Type': protobufContentType
175175
};
176176
}

lib/src/compiler.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ class CompilationProblem implements Comparable<CompilationProblem> {
279279
/// * If [from] and [to] are canonically the same, no operation occurs.
280280
///
281281
/// Returns a future that completes when complete.
282-
Future<Null> copyPath(String from, String to) async {
282+
Future<void> copyPath(String from, String to) async {
283283
if (_doNothing(from, to)) {
284284
return;
285285
}

lib/src/server_cache.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class RedisCache implements ServerCache {
191191
key = _genKey(key);
192192
if (!_isConnected()) {
193193
log.warning('$_logPrefix: no cache available when setting key $key');
194-
return null;
194+
return;
195195
}
196196

197197
final commands = redisClient.asCommands<String, String>();

lib/src/summarize.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,18 +242,18 @@ class Summarizer {
242242
}
243243
summary += '${_sentenceFiller('errorCount', storage.errorCount)} ';
244244
summary += 'errors and warnings';
245-
summary += '${_featureList(_codeSearch())}';
246-
summary += '${_htmlCSS()}';
247-
summary += '${_packageList(storage.packageImports, source: 'packages')}';
248-
summary += '${_additionList(_additionSearch())}';
245+
summary += _featureList(_codeSearch());
246+
summary += _htmlCSS();
247+
summary += _packageList(storage.packageImports, source: 'packages');
248+
summary += _additionList(_additionSearch());
249249
return summary.trim();
250250
} else {
251251
var summary = 'Summary: ';
252252
summary += 'This is a ${_sentenceFiller('size', storage.linesCode)} ';
253-
summary += '${_sentenceFiller('compiledQuantifier')}';
254-
summary += '${_featureList(_codeSearch())}';
255-
summary += '${_htmlCSS()}';
256-
summary += '${_additionList(_additionSearch())}';
253+
summary += _sentenceFiller('compiledQuantifier');
254+
summary += _featureList(_codeSearch());
255+
summary += _htmlCSS();
256+
summary += _additionList(_additionSearch());
257257
return summary.trim();
258258
}
259259
}

pubspec.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,13 @@ packages:
274274
url: "https://pub.dartlang.org"
275275
source: hosted
276276
version: "4.0.1"
277+
lints:
278+
dependency: "direct dev"
279+
description:
280+
name: lints
281+
url: "https://pub.dartlang.org"
282+
source: hosted
283+
version: "1.0.1"
277284
logging:
278285
dependency: "direct main"
279286
description:

pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ dev_dependencies:
2828
coverage: ^0.15.2
2929
expected_output: ^2.0.0
3030
grinder: ^0.9.0
31+
lints: ^1.0.1
3132
mock_request: ^1.0.7
3233
pedantic: ^1.11.0
3334
shelf_router_generator: ^0.7.0+1

test/common_server_api_protobuf_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void defineTests() {
6767
assert(commonServerApi != null);
6868
final uri = Uri.parse('/api/$path');
6969
final request = MockHttpRequest('POST', uri);
70-
request.headers.add('content-type', JSON_CONTENT_TYPE);
70+
request.headers.add('content-type', jsonContentType);
7171
request.add(utf8.encode(json.encode(message.toProto3Json())));
7272
await request.close();
7373
await shelf_io.handleRequest(request, commonServerApi.router);
@@ -80,7 +80,7 @@ void defineTests() {
8080
assert(commonServerApi != null);
8181
final uri = Uri.parse('/api/$path');
8282
final request = MockHttpRequest('POST', uri);
83-
request.headers.add('content-type', JSON_CONTENT_TYPE);
83+
request.headers.add('content-type', jsonContentType);
8484
await request.close();
8585
await shelf_io.handleRequest(request, commonServerApi.router);
8686
return request.response;

test/common_server_api_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ void defineTests() {
252252
assert(commonServerApi != null);
253253
final uri = Uri.parse('/api/$path');
254254
final request = MockHttpRequest('POST', uri);
255-
request.headers.add('content-type', JSON_CONTENT_TYPE);
255+
request.headers.add('content-type', jsonContentType);
256256
request.add(utf8.encode(json.encode(jsonData)));
257257
await request.close();
258258
await shelf_io.handleRequest(request, commonServerApi.router);
@@ -265,7 +265,7 @@ void defineTests() {
265265
assert(commonServerApi != null);
266266
final uri = Uri.parse('/api/$path');
267267
final request = MockHttpRequest('POST', uri);
268-
request.headers.add('content-type', JSON_CONTENT_TYPE);
268+
request.headers.add('content-type', jsonContentType);
269269
await request.close();
270270
await shelf_io.handleRequest(request, commonServerApi.router);
271271
return request.response;

test/flutter_web_test.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,21 @@ void defineTests() {
8282
}
8383

8484
class _FakeImportDirective implements ImportDirective {
85+
@override
8586
final _FakeStringLiteral uri;
8687

8788
_FakeImportDirective(String uri) : uri = _FakeStringLiteral(uri);
8889

90+
@override
8991
dynamic noSuchMethod(_) => throw UnimplementedError();
9092
}
9193

9294
class _FakeStringLiteral implements StringLiteral {
95+
@override
9396
final String stringValue;
9497

9598
_FakeStringLiteral(this.stringValue);
9699

100+
@override
97101
dynamic noSuchMethod(_) => throw UnimplementedError();
98102
}

0 commit comments

Comments
 (0)