Skip to content

Commit 29a9b67

Browse files
chore: Add java lint (google-java-format) (#4175)
1 parent 5444136 commit 29a9b67

File tree

15 files changed

+1776
-1656
lines changed

15 files changed

+1776
-1656
lines changed

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,20 @@
77
"clean": "lerna run clean",
88
"circularDepCheck": "lerna run circularDepCheck",
99
"test": "lerna run test",
10-
"fix": "lerna run fix",
11-
"lint": "lerna run lint",
10+
"fix": "run-s fix:lerna fix:android",
11+
"fix:lerna": "lerna run fix",
12+
"fix:android": "./scripts/google-java-format.sh fix",
13+
"lint": "run-s lint:lerna lint:android",
14+
"lint:lerna": "lerna run lint",
15+
"lint:android": "./scripts/google-java-format.sh lint",
1216
"run-ios": "cd samples/react-native && yarn react-native run-ios",
1317
"run-android": "cd samples/react-native && yarn react-native run-android",
1418
"set-version-samples": "lerna run set-version"
1519
},
1620
"devDependencies": {
1721
"@sentry/cli": "2.37.0",
1822
"downlevel-dts": "^0.11.0",
23+
"google-java-format": "^1.4.0",
1924
"lerna": "^8.1.8",
2025
"npm-run-all2": "^6.2.2",
2126
"prettier": "^2.0.5",
Lines changed: 63 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,84 @@
11
package io.sentry.react;
22

33
import com.facebook.react.bridge.ReadableMap;
4-
5-
import org.jetbrains.annotations.NotNull;
6-
import org.jetbrains.annotations.Nullable;
7-
8-
import java.util.Map;
9-
104
import io.sentry.Breadcrumb;
115
import io.sentry.SentryLevel;
6+
import java.util.Map;
7+
import org.jetbrains.annotations.NotNull;
8+
import org.jetbrains.annotations.Nullable;
129

1310
public class RNSentryBreadcrumb {
1411

15-
@Nullable
16-
public static String getCurrentScreenFrom(ReadableMap from) {
17-
final @Nullable String maybeCategory = from.hasKey("category") ? from.getString("category") : null;
18-
if (maybeCategory == null || !maybeCategory.equals("navigation")) {
19-
return null;
20-
}
21-
22-
final @Nullable ReadableMap maybeData = from.hasKey("data") ? from.getMap("data") : null;
23-
if (maybeData == null) {
24-
return null;
25-
}
12+
@Nullable
13+
public static String getCurrentScreenFrom(ReadableMap from) {
14+
final @Nullable String maybeCategory =
15+
from.hasKey("category") ? from.getString("category") : null;
16+
if (maybeCategory == null || !maybeCategory.equals("navigation")) {
17+
return null;
18+
}
2619

27-
try {
28-
// getString might throw if cast to string fails (data.to is not enforced by TS to be a string)
29-
return maybeData.hasKey("to") ? maybeData.getString("to") : null;
30-
} catch (Throwable exception) {
31-
return null;
32-
}
20+
final @Nullable ReadableMap maybeData = from.hasKey("data") ? from.getMap("data") : null;
21+
if (maybeData == null) {
22+
return null;
3323
}
3424

35-
@NotNull
36-
public static Breadcrumb fromMap(ReadableMap from) {
37-
final @NotNull Breadcrumb breadcrumb = new Breadcrumb();
25+
try {
26+
// getString might throw if cast to string fails (data.to is not enforced by TS to be a
27+
// string)
28+
return maybeData.hasKey("to") ? maybeData.getString("to") : null;
29+
} catch (Throwable exception) {
30+
return null;
31+
}
32+
}
3833

39-
if (from.hasKey("message")) {
40-
breadcrumb.setMessage(from.getString("message"));
41-
}
34+
@NotNull
35+
public static Breadcrumb fromMap(ReadableMap from) {
36+
final @NotNull Breadcrumb breadcrumb = new Breadcrumb();
4237

43-
if (from.hasKey("type")) {
44-
breadcrumb.setType(from.getString("type"));
45-
}
38+
if (from.hasKey("message")) {
39+
breadcrumb.setMessage(from.getString("message"));
40+
}
4641

47-
if (from.hasKey("category")) {
48-
breadcrumb.setCategory(from.getString("category"));
49-
}
42+
if (from.hasKey("type")) {
43+
breadcrumb.setType(from.getString("type"));
44+
}
5045

51-
if (from.hasKey("level")) {
52-
switch (from.getString("level")) {
53-
case "fatal":
54-
breadcrumb.setLevel(SentryLevel.FATAL);
55-
break;
56-
case "warning":
57-
breadcrumb.setLevel(SentryLevel.WARNING);
58-
break;
59-
case "debug":
60-
breadcrumb.setLevel(SentryLevel.DEBUG);
61-
break;
62-
case "error":
63-
breadcrumb.setLevel(SentryLevel.ERROR);
64-
break;
65-
case "info":
66-
default:
67-
breadcrumb.setLevel(SentryLevel.INFO);
68-
break;
69-
}
70-
}
46+
if (from.hasKey("category")) {
47+
breadcrumb.setCategory(from.getString("category"));
48+
}
7149

50+
if (from.hasKey("level")) {
51+
switch (from.getString("level")) {
52+
case "fatal":
53+
breadcrumb.setLevel(SentryLevel.FATAL);
54+
break;
55+
case "warning":
56+
breadcrumb.setLevel(SentryLevel.WARNING);
57+
break;
58+
case "debug":
59+
breadcrumb.setLevel(SentryLevel.DEBUG);
60+
break;
61+
case "error":
62+
breadcrumb.setLevel(SentryLevel.ERROR);
63+
break;
64+
case "info":
65+
default:
66+
breadcrumb.setLevel(SentryLevel.INFO);
67+
break;
68+
}
69+
}
7270

73-
if (from.hasKey("data")) {
74-
final ReadableMap data = from.getMap("data");
75-
for (final Map.Entry<String, Object> entry : data.toHashMap().entrySet()) {
76-
final Object value = entry.getValue();
77-
// data is ConcurrentHashMap and can't have null values
78-
if (value != null) {
79-
breadcrumb.setData(entry.getKey(), entry.getValue());
80-
}
81-
}
71+
if (from.hasKey("data")) {
72+
final ReadableMap data = from.getMap("data");
73+
for (final Map.Entry<String, Object> entry : data.toHashMap().entrySet()) {
74+
final Object value = entry.getValue();
75+
// data is ConcurrentHashMap and can't have null values
76+
if (value != null) {
77+
breadcrumb.setData(entry.getKey(), entry.getValue());
8278
}
83-
84-
return breadcrumb;
79+
}
8580
}
8681

82+
return breadcrumb;
83+
}
8784
}

0 commit comments

Comments
 (0)