Skip to content

fix: Linter issues #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 11, 2020
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
6 changes: 3 additions & 3 deletions example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ Future<Null> main(List<String> 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,
);
Expand Down
56 changes: 31 additions & 25 deletions lib/src/base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<String, String> headers = buildHeaders(authHeader);
final headers = buildHeaders(authHeader);

final Map<String, dynamic> data = <String, dynamic>{
final data = <String, dynamic>{
'project': projectId,
'event_id': _uuidGenerator(),
'timestamp': formatDateAsIso8601WithSecondPrecision(now),
Expand All @@ -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']}';
}
Expand All @@ -203,7 +202,7 @@ abstract class SentryClient {
@required dynamic exception,
dynamic stackTrace,
}) {
final Event event = Event(
final event = Event(
exception: exception,
stackTrace: stackTrace,
);
Expand Down Expand Up @@ -430,7 +429,7 @@ class Event {
/// Serializes this event to JSON.
Map<String, dynamic> toJson(
{StackFrameFilter stackFrameFilter, String origin}) {
final Map<String, dynamic> json = <String, dynamic>{
final json = <String, dynamic>{
'platform': sdkPlatform,
'sdk': {
'version': sdkVersion,
Expand Down Expand Up @@ -568,6 +567,7 @@ class Contexts {

/// Produces a [Map] that can be serialized to JSON.
Map<String, dynamic> toJson() {
// ignore: omit_local_variable_types
final Map<String, dynamic> json = {};

Map<String, dynamic> deviceMap;
Expand All @@ -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'});
}
}
}
Expand Down Expand Up @@ -736,16 +736,17 @@ class Device {

/// Produces a [Map] that can be serialized to JSON.
Map<String, dynamic> toJson() {
// ignore: omit_local_variable_types
final Map<String, dynamic> json = {};

String orientation;

switch (this.orientation) {
case Orientation.portrait:
orientation = "portait";
orientation = 'portait';
break;
case Orientation.landscape:
orientation = "landscape";
orientation = 'landscape';
break;
}

Expand Down Expand Up @@ -848,6 +849,7 @@ class OperatingSystem {

/// Produces a [Map] that can be serialized to JSON.
Map<String, dynamic> toJson() {
// ignore: omit_local_variable_types
final Map<String, dynamic> json = {};

if (name != null) json['name'] = name;
Expand Down Expand Up @@ -891,10 +893,12 @@ class Runtime {
final String rawDescription;

const Runtime({this.key, this.name, this.version, this.rawDescription})
// ignore: prefer_is_empty
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the prefer_is_empty suggestion is taken here it fails with Invalid constant value.dart(invalid_constant).

Copy link
Member Author

@bruno-garcia bruno-garcia Apr 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this one is affecting the score on pub.dev:

image

Would be nice to find a solution. Or does this // ignore: affect the scoring?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a gap in the language. /cc @lrhn @leafpetersen @eernstg

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, .length is literally called out specially in the spec as one of the only things you're allowed to do in constants. Expanding the scope of what you can do in constants is a frequent request, so noted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, then it's a linter issue. The linter should not be in a conflict with the language. Which quickly led me to https://github.com/dart-lang/linter/issues/1719

: assert(key == null || key.length >= 1);

/// Produces a [Map] that can be serialized to JSON.
Map<String, dynamic> toJson() {
// ignore: omit_local_variable_types
final Map<String, dynamic> json = {};

if (name != null) json['name'] = name;
Expand Down Expand Up @@ -945,6 +949,7 @@ class App {

/// Produces a [Map] that can be serialized to JSON.
Map<String, dynamic> toJson() {
// ignore: omit_local_variable_types
final Map<String, dynamic> json = {};

if (name != null) json['app_name'] = name;
Expand Down Expand Up @@ -980,6 +985,7 @@ class Browser {

/// Produces a [Map] that can be serialized to JSON.
Map<String, dynamic> toJson() {
// ignore: omit_local_variable_types
final Map<String, dynamic> json = {};

if (name != null) json['name'] = name;
Expand Down Expand Up @@ -1039,11 +1045,11 @@ class User {
/// Produces a [Map] that can be serialized to JSON.
Map<String, dynamic> toJson() {
return {
"id": id,
"username": username,
"email": email,
"ip_address": ipAddress,
"extras": extras,
'id': id,
'username': username,
'email': email,
'ip_address': ipAddress,
'extras': extras,
};
}
}
Expand Down Expand Up @@ -1169,8 +1175,8 @@ class Dsn {
});

static Dsn parse(String dsn) {
final Uri uri = Uri.parse(dsn);
final List<String> userInfo = uri.userInfo.split(':');
final uri = Uri.parse(dsn);
final userInfo = uri.userInfo.split(':');

assert(() {
if (uri.pathSegments.isEmpty) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class SentryIOClient extends SentryClient {
) {
// [SentryIOClient] implement gzip compression
// gzip compression is not available on browser
List<int> body = utf8.encode(json.encode(data));
var body = utf8.encode(json.encode(data));
if (compressPayload) {
headers['Content-Encoding'] = 'gzip';
body = gzip.encode(body);
Expand Down
8 changes: 4 additions & 4 deletions lib/src/stack_trace.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ List<Map<String, dynamic>> 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<Map<String, dynamic>> frames = <Map<String, dynamic>>[];
for (int t = 0; t < chain.traces.length; t += 1) {
final frames = <Map<String, dynamic>>[];
for (var t = 0; t < chain.traces.length; t += 1) {
final encodedFrames = chain.traces[t].frames
.map((f) => encodeStackTraceFrame(f, origin: origin));

Expand All @@ -52,7 +52,7 @@ List<Map<String, dynamic>> encodeStackTrace(
Map<String, dynamic> encodeStackTraceFrame(Frame frame, {String origin}) {
origin ??= '';

final Map<String, dynamic> json = <String, dynamic>{
final json = <String, dynamic>{
'abs_path': '$origin${_absolutePathForCrashReport(frame)}',
'function': frame.member,
'lineno': frame.line,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void mergeAttributes(Map<String, dynamic> 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);
Expand Down
18 changes: 9 additions & 9 deletions test/event_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
<String, dynamic>{
'timestamp': '2019-01-01T00:00:00',
Expand All @@ -25,15 +25,15 @@ void main() {
});
test('serializes to JSON', () {
final user = User(
id: "user_id",
username: "username",
email: "[email protected]",
ipAddress: "127.0.0.1",
extras: {"foo": "bar"});
id: 'user_id',
username: 'username',
email: '[email protected]',
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(
Expand Down
2 changes: 1 addition & 1 deletion test/sentry_browser_test.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion test/sentry_io_test.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
6 changes: 3 additions & 3 deletions test/stack_trace_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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');
});
});
Expand Down Expand Up @@ -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();

Expand Down
Loading