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

Use package lints #712

Merged
merged 4 commits into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Dart analyzer dislikes this line. https://github.com/dart-lang/dart-pad/issues/1720
# include: package:pedantic/analysis_options.1.11.0.yaml
include: package:lints/recommended.yaml

analyzer:
language:
Expand All @@ -16,9 +17,12 @@ analyzer:

linter:
rules:
- always_declare_return_types
- directives_ordering
- prefer_final_fields
- prefer_final_in_for_each
- prefer_final_locals
- prefer_relative_imports
- prefer_single_quotes
- sort_pub_dependencies
- unawaited_futures
22 changes: 11 additions & 11 deletions lib/src/analysis_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ final Logger _logger = Logger('analysis_server');
/// to stdout.
bool dumpServerMessages = false;

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

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

class DartAnalysisServerWrapper extends AnalysisServerWrapper {
DartAnalysisServerWrapper(this._nullSafety) : super(Sdk.sdkPath);
Expand Down Expand Up @@ -102,7 +102,7 @@ abstract class AnalysisServerWrapper {
final analysisComplete = getAnalysisCompleteCompleter();
await analysisServer.analysis
.setAnalysisRoots(<String>[_sourceDirPath], <String>[]);
await _sendAddOverlays(<String, String>{mainPath: _WARMUP_SRC});
await _sendAddOverlays(<String, String>{mainPath: _warmupSrc});
await analysisComplete.future;
await _sendRemoveOverlays();

Expand Down Expand Up @@ -262,7 +262,7 @@ abstract class AnalysisServerWrapper {
}

return m;
}, timeoutDuration: _ANALYSIS_SERVER_TIMEOUT));
}, timeoutDuration: _analysisServerTimeout));
}

Future<proto.AnalysisResults> analyze(String source) {
Expand Down Expand Up @@ -322,7 +322,7 @@ abstract class AnalysisServerWrapper {
return proto.AnalysisResults()
..issues.addAll(issues)
..packageImports.addAll(packageImports);
}, timeoutDuration: _ANALYSIS_SERVER_TIMEOUT));
}, timeoutDuration: _analysisServerTimeout));
}

Future<AssistsResult> _getAssistsImpl(
Expand All @@ -344,7 +344,7 @@ abstract class AnalysisServerWrapper {
await analysisServer.edit.getAssists(path, offset, length);
await _unloadSources();
return assists;
}, timeoutDuration: _ANALYSIS_SERVER_TIMEOUT));
}, timeoutDuration: _analysisServerTimeout));
}

/// Convert between the Analysis Server type and the API protocol types.
Expand Down Expand Up @@ -469,7 +469,7 @@ abstract class AnalysisServerWrapper {
final results = await getCompletionResults(id.id);
await _unloadSources();
return results;
}, timeoutDuration: _ANALYSIS_SERVER_TIMEOUT));
}, timeoutDuration: _analysisServerTimeout));
}

Future<FixesResult> _getFixesImpl(
Expand All @@ -489,7 +489,7 @@ abstract class AnalysisServerWrapper {
final fixes = await analysisServer.edit.getFixes(path, offset);
await _unloadSources();
return fixes;
}, timeoutDuration: _ANALYSIS_SERVER_TIMEOUT));
}, timeoutDuration: _analysisServerTimeout));
}

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

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

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

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

Expand Down
44 changes: 22 additions & 22 deletions lib/src/common_server_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,88 +19,88 @@ export 'common_server_impl.dart' show log, ServerContainer;

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

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

class CommonServerApi {
final CommonServerImpl _impl;

CommonServerApi(this._impl);

@Route.post('$PROTO_API_URL_PREFIX/analyze')
@Route.post('$protoApiUrlPrefix/analyze')
Future<Response> analyze(Request request, String apiVersion) =>
_processRequest(request,
decodeFromJSON: (json) =>
proto.SourceRequest.create()..mergeFromProto3Json(json),
decodeFromProto: (bytes) => proto.SourceRequest.fromBuffer(bytes),
transform: _impl.analyze);

@Route.post('$PROTO_API_URL_PREFIX/compile')
@Route.post('$protoApiUrlPrefix/compile')
Future<Response> compile(Request request, String apiVersion) =>
_processRequest(request,
decodeFromJSON: (json) =>
proto.CompileRequest.create()..mergeFromProto3Json(json),
decodeFromProto: (bytes) => proto.CompileRequest.fromBuffer(bytes),
transform: _impl.compile);

@Route.post('$PROTO_API_URL_PREFIX/compileDDC')
@Route.post('$protoApiUrlPrefix/compileDDC')
Future<Response> compileDDC(Request request, String apiVersion) =>
_processRequest(request,
decodeFromJSON: (json) =>
proto.CompileDDCRequest.create()..mergeFromProto3Json(json),
decodeFromProto: (bytes) => proto.CompileDDCRequest.fromBuffer(bytes),
transform: _impl.compileDDC);

@Route.post('$PROTO_API_URL_PREFIX/complete')
@Route.post('$protoApiUrlPrefix/complete')
Future<Response> complete(Request request, String apiVersion) =>
_processRequest(request,
decodeFromJSON: (json) =>
proto.SourceRequest.create()..mergeFromProto3Json(json),
decodeFromProto: (bytes) => proto.SourceRequest.fromBuffer(bytes),
transform: _impl.complete);

@Route.post('$PROTO_API_URL_PREFIX/fixes')
@Route.post('$protoApiUrlPrefix/fixes')
Future<Response> fixes(Request request, String apiVersion) =>
_processRequest(request,
decodeFromJSON: (json) =>
proto.SourceRequest.create()..mergeFromProto3Json(json),
decodeFromProto: (bytes) => proto.SourceRequest.fromBuffer(bytes),
transform: _impl.fixes);

@Route.post('$PROTO_API_URL_PREFIX/assists')
@Route.post('$protoApiUrlPrefix/assists')
Future<Response> assists(Request request, String apiVersion) =>
_processRequest(request,
decodeFromJSON: (json) =>
proto.SourceRequest.create()..mergeFromProto3Json(json),
decodeFromProto: (bytes) => proto.SourceRequest.fromBuffer(bytes),
transform: _impl.assists);

@Route.post('$PROTO_API_URL_PREFIX/format')
@Route.post('$protoApiUrlPrefix/format')
Future<Response> format(Request request, String apiVersion) =>
_processRequest(request,
decodeFromJSON: (json) =>
proto.SourceRequest.create()..mergeFromProto3Json(json),
decodeFromProto: (bytes) => proto.SourceRequest.fromBuffer(bytes),
transform: _impl.format);

@Route.post('$PROTO_API_URL_PREFIX/document')
@Route.post('$protoApiUrlPrefix/document')
Future<Response> document(Request request, String apiVersion) =>
_processRequest(request,
decodeFromJSON: (json) =>
proto.SourceRequest.create()..mergeFromProto3Json(json),
decodeFromProto: (bytes) => proto.SourceRequest.fromBuffer(bytes),
transform: _impl.document);

@Route.post('$PROTO_API_URL_PREFIX/version')
@Route.post('$protoApiUrlPrefix/version')
Future<Response> versionPost(Request request, String apiVersion) =>
_processRequest(request,
decodeFromJSON: (json) =>
proto.VersionRequest.create()..mergeFromProto3Json(json),
decodeFromProto: (bytes) => proto.VersionRequest.fromBuffer(bytes),
transform: _impl.version);

@Route.get('$PROTO_API_URL_PREFIX/version')
@Route.get('$protoApiUrlPrefix/version')
Future<Response> versionGet(Request request, String apiVersion) =>
_processRequest(request,
decodeFromJSON: (json) =>
Expand All @@ -121,7 +121,7 @@ class CommonServerApi {
@required I Function(Object json) decodeFromJSON,
@required Future<O> Function(I input) transform,
}) async {
if (request.mimeType == PROTOBUF_CONTENT_TYPE) {
if (request.mimeType == protobufContentType) {
// Dealing with binary Protobufs
final body = <int>[];
await for (final chunk in request.read()) {
Expand All @@ -131,11 +131,11 @@ class CommonServerApi {
final response = await transform(decodeFromProto(body));
return Response.ok(
response.writeToBuffer(),
headers: _PROTOBUF_HEADERS,
headers: _protobufHeaders,
);
} on BadRequest catch (e) {
return Response(400,
headers: _PROTOBUF_HEADERS,
headers: _protobufHeaders,
body: (proto.BadRequest.create()
..error = (proto.ErrorMessage.create()..message = e.cause))
.writeToBuffer());
Expand All @@ -149,11 +149,11 @@ class CommonServerApi {
return Response.ok(
_jsonEncoder.convert(response.toProto3Json()),
encoding: utf8,
headers: _JSON_HEADERS,
headers: _jsonHeaders,
);
} on BadRequest catch (e) {
return Response(400,
headers: _JSON_HEADERS,
headers: _jsonHeaders,
encoding: utf8,
body: _jsonEncoder.convert((proto.BadRequest.create()
..error = (proto.ErrorMessage.create()..message = e.cause))
Expand All @@ -164,13 +164,13 @@ class CommonServerApi {

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

static const _JSON_HEADERS = {
static const _jsonHeaders = {
'Access-Control-Allow-Origin': '*',
'Content-Type': JSON_CONTENT_TYPE
'Content-Type': jsonContentType
};

static const _PROTOBUF_HEADERS = {
static const _protobufHeaders = {
'Access-Control-Allow-Origin': '*',
'Content-Type': PROTOBUF_CONTENT_TYPE
'Content-Type': protobufContentType
};
}
2 changes: 1 addition & 1 deletion lib/src/compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class CompilationProblem implements Comparable<CompilationProblem> {
/// * If [from] and [to] are canonically the same, no operation occurs.
///
/// Returns a future that completes when complete.
Future<Null> copyPath(String from, String to) async {
Future<void> copyPath(String from, String to) async {
if (_doNothing(from, to)) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/server_cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class RedisCache implements ServerCache {
key = _genKey(key);
if (!_isConnected()) {
log.warning('$_logPrefix: no cache available when setting key $key');
return null;
return;
}

final commands = redisClient.asCommands<String, String>();
Expand Down
16 changes: 8 additions & 8 deletions lib/src/summarize.dart
Original file line number Diff line number Diff line change
Expand Up @@ -242,18 +242,18 @@ class Summarizer {
}
summary += '${_sentenceFiller('errorCount', storage.errorCount)} ';
summary += 'errors and warnings';
summary += '${_featureList(_codeSearch())}';
summary += '${_htmlCSS()}';
summary += '${_packageList(storage.packageImports, source: 'packages')}';
summary += '${_additionList(_additionSearch())}';
summary += _featureList(_codeSearch());
summary += _htmlCSS();
summary += _packageList(storage.packageImports, source: 'packages');
summary += _additionList(_additionSearch());
return summary.trim();
} else {
var summary = 'Summary: ';
summary += 'This is a ${_sentenceFiller('size', storage.linesCode)} ';
summary += '${_sentenceFiller('compiledQuantifier')}';
summary += '${_featureList(_codeSearch())}';
summary += '${_htmlCSS()}';
summary += '${_additionList(_additionSearch())}';
summary += _sentenceFiller('compiledQuantifier');
summary += _featureList(_codeSearch());
summary += _htmlCSS();
summary += _additionList(_additionSearch());
return summary.trim();
}
}
Expand Down
7 changes: 7 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.1"
lints:
dependency: "direct dev"
description:
name: lints
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
logging:
dependency: "direct main"
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dev_dependencies:
coverage: ^0.15.2
expected_output: ^2.0.0
grinder: ^0.9.0
lints: ^1.0.1
mock_request: ^1.0.7
pedantic: ^1.11.0
shelf_router_generator: ^0.7.0+1
Expand Down
4 changes: 2 additions & 2 deletions test/common_server_api_protobuf_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void defineTests() {
assert(commonServerApi != null);
final uri = Uri.parse('/api/$path');
final request = MockHttpRequest('POST', uri);
request.headers.add('content-type', JSON_CONTENT_TYPE);
request.headers.add('content-type', jsonContentType);
request.add(utf8.encode(json.encode(message.toProto3Json())));
await request.close();
await shelf_io.handleRequest(request, commonServerApi.router);
Expand All @@ -80,7 +80,7 @@ void defineTests() {
assert(commonServerApi != null);
final uri = Uri.parse('/api/$path');
final request = MockHttpRequest('POST', uri);
request.headers.add('content-type', JSON_CONTENT_TYPE);
request.headers.add('content-type', jsonContentType);
await request.close();
await shelf_io.handleRequest(request, commonServerApi.router);
return request.response;
Expand Down
4 changes: 2 additions & 2 deletions test/common_server_api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ void defineTests() {
assert(commonServerApi != null);
final uri = Uri.parse('/api/$path');
final request = MockHttpRequest('POST', uri);
request.headers.add('content-type', JSON_CONTENT_TYPE);
request.headers.add('content-type', jsonContentType);
request.add(utf8.encode(json.encode(jsonData)));
await request.close();
await shelf_io.handleRequest(request, commonServerApi.router);
Expand All @@ -265,7 +265,7 @@ void defineTests() {
assert(commonServerApi != null);
final uri = Uri.parse('/api/$path');
final request = MockHttpRequest('POST', uri);
request.headers.add('content-type', JSON_CONTENT_TYPE);
request.headers.add('content-type', jsonContentType);
await request.close();
await shelf_io.handleRequest(request, commonServerApi.router);
return request.response;
Expand Down
4 changes: 4 additions & 0 deletions test/flutter_web_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,21 @@ void defineTests() {
}

class _FakeImportDirective implements ImportDirective {
@override
final _FakeStringLiteral uri;

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

@override
dynamic noSuchMethod(_) => throw UnimplementedError();
}

class _FakeStringLiteral implements StringLiteral {
@override
final String stringValue;

_FakeStringLiteral(this.stringValue);

@override
dynamic noSuchMethod(_) => throw UnimplementedError();
}
Loading