diff --git a/example/main.dart b/example/main.dart index ebff8ce8d1..68f5ee964c 100644 --- a/example/main.dart +++ b/example/main.dart @@ -15,15 +15,15 @@ Future main(List rawArgs) async { exit(1); } - final String dsn = rawArgs.single; - final SentryClient client = SentryClient(dsn: dsn); + final dsn = rawArgs.single; + final client = SentryClient(dsn: dsn); try { await foo(); } catch (error, stackTrace) { print('Reporting the following stack trace: '); print(stackTrace); - final SentryResponse response = await client.captureException( + final response = await client.captureException( exception: error, stackTrace: stackTrace, ); diff --git a/lib/src/base.dart b/lib/src/base.dart index 3af2883a24..2bc611c4c4 100644 --- a/lib/src/base.dart +++ b/lib/src/base.dart @@ -121,12 +121,12 @@ abstract class SentryClient { @visibleForTesting String get postUri { - String port = dsnUri.hasPort && + var port = dsnUri.hasPort && ((dsnUri.scheme == 'http' && dsnUri.port != 80) || (dsnUri.scheme == 'https' && dsnUri.port != 443)) ? ':${dsnUri.port}' : ''; - int pathLength = dsnUri.pathSegments.length; + var pathLength = dsnUri.pathSegments.length; String apiPath; if (pathLength > 1) { // some paths would present before the projectID in the dsnUri @@ -143,16 +143,16 @@ abstract class SentryClient { @required Event event, StackFrameFilter stackFrameFilter, }) async { - final DateTime now = _clock(); - String authHeader = 'Sentry sentry_version=6, sentry_client=$sentryClient, ' + final now = _clock(); + var authHeader = 'Sentry sentry_version=6, sentry_client=$sentryClient, ' 'sentry_timestamp=${now.millisecondsSinceEpoch}, sentry_key=$publicKey'; if (secretKey != null) { authHeader += ', sentry_secret=$secretKey'; } - final Map headers = buildHeaders(authHeader); + final headers = buildHeaders(authHeader); - final Map data = { + final data = { 'project': projectId, 'event_id': _uuidGenerator(), 'timestamp': formatDateAsIso8601WithSecondPrecision(now), @@ -179,15 +179,14 @@ abstract class SentryClient { final body = bodyEncoder(data, headers); - final Response response = await httpClient.post( + final response = await httpClient.post( postUri, headers: headers, body: body, ); if (response.statusCode != 200) { - String errorMessage = - 'Sentry.io responded with HTTP ${response.statusCode}'; + var errorMessage = 'Sentry.io responded with HTTP ${response.statusCode}'; if (response.headers['x-sentry-error'] != null) { errorMessage += ': ${response.headers['x-sentry-error']}'; } @@ -203,7 +202,7 @@ abstract class SentryClient { @required dynamic exception, dynamic stackTrace, }) { - final Event event = Event( + final event = Event( exception: exception, stackTrace: stackTrace, ); @@ -430,7 +429,7 @@ class Event { /// Serializes this event to JSON. Map toJson( {StackFrameFilter stackFrameFilter, String origin}) { - final Map json = { + final json = { 'platform': sdkPlatform, 'sdk': { 'version': sdkVersion, @@ -568,6 +567,7 @@ class Contexts { /// Produces a [Map] that can be serialized to JSON. Map toJson() { + // ignore: omit_local_variable_types final Map json = {}; Map deviceMap; @@ -593,25 +593,25 @@ class Contexts { if (runtimes != null) { if (runtimes.length == 1) { - final Runtime runtime = runtimes[0]; + final runtime = runtimes[0]; if (runtime != null) { - final String key = runtime.key ?? 'runtime'; + final key = runtime.key ?? 'runtime'; json[key] = runtime.toJson(); } } else if (runtimes.length > 1) { for (final runtime in runtimes) { if (runtime != null) { - String key = runtime.key ?? runtime.name.toLowerCase(); + var key = runtime.key ?? runtime.name.toLowerCase(); if (json.containsKey(key)) { - int k = 0; + var k = 0; while (json.containsKey(key)) { key = '$key$k'; k++; } } - json[key] = runtime.toJson()..addAll({"type": "runtime"}); + json[key] = runtime.toJson()..addAll({'type': 'runtime'}); } } } @@ -736,16 +736,17 @@ class Device { /// Produces a [Map] that can be serialized to JSON. Map toJson() { + // ignore: omit_local_variable_types final Map json = {}; String orientation; switch (this.orientation) { case Orientation.portrait: - orientation = "portait"; + orientation = 'portait'; break; case Orientation.landscape: - orientation = "landscape"; + orientation = 'landscape'; break; } @@ -848,6 +849,7 @@ class OperatingSystem { /// Produces a [Map] that can be serialized to JSON. Map toJson() { + // ignore: omit_local_variable_types final Map json = {}; if (name != null) json['name'] = name; @@ -891,10 +893,12 @@ class Runtime { final String rawDescription; const Runtime({this.key, this.name, this.version, this.rawDescription}) + // ignore: prefer_is_empty : assert(key == null || key.length >= 1); /// Produces a [Map] that can be serialized to JSON. Map toJson() { + // ignore: omit_local_variable_types final Map json = {}; if (name != null) json['name'] = name; @@ -945,6 +949,7 @@ class App { /// Produces a [Map] that can be serialized to JSON. Map toJson() { + // ignore: omit_local_variable_types final Map json = {}; if (name != null) json['app_name'] = name; @@ -980,6 +985,7 @@ class Browser { /// Produces a [Map] that can be serialized to JSON. Map toJson() { + // ignore: omit_local_variable_types final Map json = {}; if (name != null) json['name'] = name; @@ -1039,11 +1045,11 @@ class User { /// Produces a [Map] that can be serialized to JSON. Map toJson() { return { - "id": id, - "username": username, - "email": email, - "ip_address": ipAddress, - "extras": extras, + 'id': id, + 'username': username, + 'email': email, + 'ip_address': ipAddress, + 'extras': extras, }; } } @@ -1169,8 +1175,8 @@ class Dsn { }); static Dsn parse(String dsn) { - final Uri uri = Uri.parse(dsn); - final List userInfo = uri.userInfo.split(':'); + final uri = Uri.parse(dsn); + final userInfo = uri.userInfo.split(':'); assert(() { if (uri.pathSegments.isEmpty) { diff --git a/lib/src/io.dart b/lib/src/io.dart index b9a4ffaf27..f49734db20 100644 --- a/lib/src/io.dart +++ b/lib/src/io.dart @@ -102,7 +102,7 @@ class SentryIOClient extends SentryClient { ) { // [SentryIOClient] implement gzip compression // gzip compression is not available on browser - List body = utf8.encode(json.encode(data)); + var body = utf8.encode(json.encode(data)); if (compressPayload) { headers['Content-Encoding'] = 'gzip'; body = gzip.encode(body); diff --git a/lib/src/stack_trace.dart b/lib/src/stack_trace.dart index effbbb7857..ac488852c6 100644 --- a/lib/src/stack_trace.dart +++ b/lib/src/stack_trace.dart @@ -31,12 +31,12 @@ List> encodeStackTrace( assert(stackTrace is String || stackTrace is StackTrace); origin ??= ''; - final Chain chain = stackTrace is StackTrace + final chain = stackTrace is StackTrace ? Chain.forTrace(stackTrace) : Chain.parse(stackTrace); - final List> frames = >[]; - for (int t = 0; t < chain.traces.length; t += 1) { + final frames = >[]; + for (var t = 0; t < chain.traces.length; t += 1) { final encodedFrames = chain.traces[t].frames .map((f) => encodeStackTraceFrame(f, origin: origin)); @@ -52,7 +52,7 @@ List> encodeStackTrace( Map encodeStackTraceFrame(Frame frame, {String origin}) { origin ??= ''; - final Map json = { + final json = { 'abs_path': '$origin${_absolutePathForCrashReport(frame)}', 'function': frame.member, 'lineno': frame.line, diff --git a/lib/src/utils.dart b/lib/src/utils.dart index 25f824c2f4..197c55b7a9 100644 --- a/lib/src/utils.dart +++ b/lib/src/utils.dart @@ -27,7 +27,7 @@ void mergeAttributes(Map attributes, } String formatDateAsIso8601WithSecondPrecision(DateTime date) { - String iso = date.toIso8601String(); + var iso = date.toIso8601String(); final millisecondSeparatorIndex = iso.lastIndexOf('.'); if (millisecondSeparatorIndex != -1) { iso = iso.substring(0, millisecondSeparatorIndex); diff --git a/test/event_test.dart b/test/event_test.dart index 47177641ac..15f51cabea 100644 --- a/test/event_test.dart +++ b/test/event_test.dart @@ -10,10 +10,10 @@ void main() { test('$Breadcrumb serializes', () { expect( Breadcrumb( - "example log", + 'example log', DateTime.utc(2019), level: SeverityLevel.debug, - category: "test", + category: 'test', ).toJson(), { 'timestamp': '2019-01-01T00:00:00', @@ -25,15 +25,15 @@ void main() { }); test('serializes to JSON', () { final user = User( - id: "user_id", - username: "username", - email: "email@email.com", - ipAddress: "127.0.0.1", - extras: {"foo": "bar"}); + id: 'user_id', + username: 'username', + email: 'email@email.com', + ipAddress: '127.0.0.1', + extras: {'foo': 'bar'}); final breadcrumbs = [ - Breadcrumb("test log", DateTime.utc(2019), - level: SeverityLevel.debug, category: "test"), + Breadcrumb('test log', DateTime.utc(2019), + level: SeverityLevel.debug, category: 'test'), ]; expect( diff --git a/test/sentry_browser_test.dart b/test/sentry_browser_test.dart index c7713139c0..2299d06a25 100644 --- a/test/sentry_browser_test.dart +++ b/test/sentry_browser_test.dart @@ -1,7 +1,7 @@ // Copyright 2017 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -@TestOn("browser") +@TestOn('browser') import 'package:sentry/browser_client.dart'; import 'package:sentry/sentry.dart'; diff --git a/test/sentry_io_test.dart b/test/sentry_io_test.dart index db1e7255b0..07de56a1f7 100644 --- a/test/sentry_io_test.dart +++ b/test/sentry_io_test.dart @@ -1,7 +1,7 @@ // Copyright 2017 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -@TestOn("vm") +@TestOn('vm') import 'dart:io'; diff --git a/test/stack_trace_test.dart b/test/stack_trace_test.dart index 3a7c3c355d..ad19aa8a3b 100644 --- a/test/stack_trace_test.dart +++ b/test/stack_trace_test.dart @@ -9,7 +9,7 @@ import 'package:test/test.dart'; void main() { group('encodeStackTraceFrame', () { test('marks dart: frames as not app frames', () { - final Frame frame = Frame(Uri.parse('dart:core'), 1, 2, 'buzz'); + final frame = Frame(Uri.parse('dart:core'), 1, 2, 'buzz'); expect(encodeStackTraceFrame(frame), { 'abs_path': 'dart:core', 'function': 'buzz', @@ -21,8 +21,7 @@ void main() { }); test('cleanses absolute paths', () { - final Frame frame = - Frame(Uri.parse('file://foo/bar/baz.dart'), 1, 2, 'buzz'); + final frame = Frame(Uri.parse('file://foo/bar/baz.dart'), 1, 2, 'buzz'); expect(encodeStackTraceFrame(frame)['abs_path'], 'baz.dart'); }); }); @@ -81,6 +80,7 @@ void main() { }); test('allows changing the stack frame list before sending', () { + // ignore: omit_local_variable_types StackFrameFilter filter = (list) => list.where((f) => f['abs_path'] != 'secret.dart').toList(); diff --git a/test/test_utils.dart b/test/test_utils.dart index 3d47bba7df..29dc7e3edd 100644 --- a/test/test_utils.dart +++ b/test/test_utils.dart @@ -23,7 +23,7 @@ void testHeaders( bool compressPayload = true, bool withSecret = true, }) { - final Map expectedHeaders = { + final expectedHeaders = { 'Content-Type': 'application/json', 'X-Sentry-Auth': 'Sentry sentry_version=6, ' 'sentry_client=${SentryClient.sentryClient}, ' @@ -43,17 +43,17 @@ void testHeaders( expect(headers, expectedHeaders); } -testCaptureException( +void testCaptureException( bool compressPayload, Codec, List> gzip, bool isWeb, ) async { - final ClockProvider fakeClockProvider = () => DateTime.utc(2017, 1, 2); + final fakeClockProvider = () => DateTime.utc(2017, 1, 2); String postUri; Map headers; List body; - final MockClient httpMock = MockClient((Request request) async { + final httpMock = MockClient((Request request) async { if (request.method == 'POST') { postUri = request.url.toString(); headers = request.headers; @@ -63,7 +63,7 @@ testCaptureException( fail('Unexpected request on ${request.method} ${request.url} in HttpMock'); }); - final SentryClient client = SentryClient( + final client = SentryClient( dsn: testDsn, httpClient: httpMock, clock: fakeClockProvider, @@ -79,7 +79,7 @@ testCaptureException( try { throw ArgumentError('Test error'); } catch (error, stackTrace) { - final SentryResponse response = + final response = await client.captureException(exception: error, stackTrace: stackTrace); expect(response.isSuccessful, true); expect(response.eventId, 'test-event-id'); @@ -172,7 +172,7 @@ testCaptureException( void runTest({Codec, List> gzip, bool isWeb = false}) { test('can parse DSN', () async { - final SentryClient client = SentryClient(dsn: testDsn); + final client = SentryClient(dsn: testDsn); expect(client.dsnUri, Uri.parse(testDsn)); expect(client.postUri, 'https://sentry.example.com/api/1/store/'); expect(client.publicKey, 'public'); @@ -182,7 +182,7 @@ void runTest({Codec, List> gzip, bool isWeb = false}) { }); test('can parse DSN without secret', () async { - final SentryClient client = SentryClient(dsn: _testDsnWithoutSecret); + final client = SentryClient(dsn: _testDsnWithoutSecret); expect(client.dsnUri, Uri.parse(_testDsnWithoutSecret)); expect(client.postUri, 'https://sentry.example.com/api/1/store/'); expect(client.publicKey, 'public'); @@ -192,7 +192,7 @@ void runTest({Codec, List> gzip, bool isWeb = false}) { }); test('can parse DSN with path', () async { - final SentryClient client = SentryClient(dsn: _testDsnWithPath); + final client = SentryClient(dsn: _testDsnWithPath); expect(client.dsnUri, Uri.parse(_testDsnWithPath)); expect(client.postUri, 'https://sentry.example.com/path/api/1/store/'); expect(client.publicKey, 'public'); @@ -201,7 +201,7 @@ void runTest({Codec, List> gzip, bool isWeb = false}) { await client.close(); }); test('can parse DSN with port', () async { - final SentryClient client = SentryClient(dsn: _testDsnWithPort); + final client = SentryClient(dsn: _testDsnWithPort); expect(client.dsnUri, Uri.parse(_testDsnWithPort)); expect(client.postUri, 'https://sentry.example.com:8888/api/1/store/'); expect(client.publicKey, 'public'); @@ -210,11 +210,11 @@ void runTest({Codec, List> gzip, bool isWeb = false}) { await client.close(); }); test('sends client auth header without secret', () async { - final ClockProvider fakeClockProvider = () => DateTime.utc(2017, 1, 2); + final fakeClockProvider = () => DateTime.utc(2017, 1, 2); Map headers; - final MockClient httpMock = MockClient((Request request) async { + final httpMock = MockClient((Request request) async { if (request.method == 'POST') { headers = request.headers; return Response('{"id": "test-event-id"}', 200); @@ -223,7 +223,7 @@ void runTest({Codec, List> gzip, bool isWeb = false}) { 'Unexpected request on ${request.method} ${request.url} in HttpMock'); }); - final SentryClient client = SentryClient( + final client = SentryClient( dsn: _testDsnWithoutSecret, httpClient: httpMock, clock: fakeClockProvider, @@ -239,7 +239,7 @@ void runTest({Codec, List> gzip, bool isWeb = false}) { try { throw ArgumentError('Test error'); } catch (error, stackTrace) { - final SentryResponse response = await client.captureException( + final response = await client.captureException( exception: error, stackTrace: stackTrace); expect(response.isSuccessful, true); expect(response.eventId, 'test-event-id'); @@ -268,9 +268,9 @@ void runTest({Codec, List> gzip, bool isWeb = false}) { }); test('reads error message from the x-sentry-error header', () async { - final ClockProvider fakeClockProvider = () => DateTime.utc(2017, 1, 2); + final fakeClockProvider = () => DateTime.utc(2017, 1, 2); - final MockClient httpMock = MockClient((Request request) async { + final httpMock = MockClient((Request request) async { if (request.method == 'POST') { return Response('', 401, headers: { 'x-sentry-error': 'Invalid api key', @@ -280,7 +280,7 @@ void runTest({Codec, List> gzip, bool isWeb = false}) { 'Unexpected request on ${request.method} ${request.url} in HttpMock'); }); - final SentryClient client = SentryClient( + final client = SentryClient( dsn: testDsn, httpClient: httpMock, clock: fakeClockProvider, @@ -296,7 +296,7 @@ void runTest({Codec, List> gzip, bool isWeb = false}) { try { throw ArgumentError('Test error'); } catch (error, stackTrace) { - final SentryResponse response = await client.captureException( + final response = await client.captureException( exception: error, stackTrace: stackTrace); expect(response.isSuccessful, false); expect(response.eventId, null); @@ -308,10 +308,10 @@ void runTest({Codec, List> gzip, bool isWeb = false}) { }); test('$Event userContext overrides client', () async { - final ClockProvider fakeClockProvider = () => DateTime.utc(2017, 1, 2); + final fakeClockProvider = () => DateTime.utc(2017, 1, 2); String loggedUserId; // used to find out what user context was sent - final MockClient httpMock = MockClient((Request request) async { + final httpMock = MockClient((Request request) async { if (request.method == 'POST') { var bodyData = request.bodyBytes; var decoded = Utf8Codec().decode(bodyData); @@ -326,18 +326,18 @@ void runTest({Codec, List> gzip, bool isWeb = false}) { }); final clientUserContext = User( - id: "client_user", - username: "username", - email: "email@email.com", - ipAddress: "127.0.0.1"); + id: 'client_user', + username: 'username', + email: 'email@email.com', + ipAddress: '127.0.0.1'); final eventUserContext = User( - id: "event_user", - username: "username", - email: "email@email.com", - ipAddress: "127.0.0.1", - extras: {"foo": "bar"}); + id: 'event_user', + username: 'username', + email: 'email@email.com', + ipAddress: '127.0.0.1', + extras: {'foo': 'bar'}); - final SentryClient client = SentryClient( + final client = SentryClient( dsn: testDsn, httpClient: httpMock, clock: fakeClockProvider, diff --git a/test/utils_test.dart b/test/utils_test.dart index 54d52155a2..8354eb5235 100644 --- a/test/utils_test.dart +++ b/test/utils_test.dart @@ -9,7 +9,7 @@ import 'package:sentry/src/utils.dart'; void main() { group('mergeAttributes', () { test('merges attributes', () { - final Map target = { + final target = { 'overwritten': 1, 'unchanged': 2, 'recursed': { @@ -18,7 +18,7 @@ void main() { }, }; - final Map attributes = { + final attributes = { 'overwritten': 2, 'recursed': { 'overwritten_child': [4, 5, 6], @@ -58,7 +58,7 @@ void main() { group('formatDateAsIso8601WithSecondPrecision', () { test('strips sub-millisecond parts', () { - final DateTime testDate = + final testDate = DateTime.fromMillisecondsSinceEpoch(1502467721598, isUtc: true); expect(testDate.toIso8601String(), '2017-08-11T16:08:41.598Z'); expect(formatDateAsIso8601WithSecondPrecision(testDate),