Skip to content

Commit

Permalink
chore: Add java lint (google-java-format)
Browse files Browse the repository at this point in the history
  • Loading branch information
krystofwoldrich committed Oct 15, 2024
1 parent 7ba218b commit ed9294c
Show file tree
Hide file tree
Showing 15 changed files with 1,767 additions and 1,656 deletions.
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@
"clean": "lerna run clean",
"circularDepCheck": "lerna run circularDepCheck",
"test": "lerna run test",
"fix": "lerna run fix",
"lint": "lerna run lint",
"fix": "run-s fix:lerna fix:android",
"fix:lerna": "lerna run fix",
"fix:android": "./scripts/google-java-format.sh fix",
"lint": "run-s lint:lerna lint:android",
"lint:lerna": "lerna run lint",
"lint:android": "./scripts/google-java-format.sh lint",
"run-ios": "cd samples/react-native && yarn react-native run-ios",
"run-android": "cd samples/react-native && yarn react-native run-android",
"set-version-samples": "lerna run set-version"
},
"devDependencies": {
"@sentry/cli": "2.37.0",
"downlevel-dts": "^0.11.0",
"google-java-format": "^1.4.0",
"lerna": "^8.1.8",
"npm-run-all2": "^6.2.2",
"prettier": "^2.0.5",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,87 +1,84 @@
package io.sentry.react;

import com.facebook.react.bridge.ReadableMap;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Map;

import io.sentry.Breadcrumb;
import io.sentry.SentryLevel;
import java.util.Map;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class RNSentryBreadcrumb {

@Nullable
public static String getCurrentScreenFrom(ReadableMap from) {
final @Nullable String maybeCategory = from.hasKey("category") ? from.getString("category") : null;
if (maybeCategory == null || !maybeCategory.equals("navigation")) {
return null;
}

final @Nullable ReadableMap maybeData = from.hasKey("data") ? from.getMap("data") : null;
if (maybeData == null) {
return null;
}
@Nullable
public static String getCurrentScreenFrom(ReadableMap from) {
final @Nullable String maybeCategory =
from.hasKey("category") ? from.getString("category") : null;
if (maybeCategory == null || !maybeCategory.equals("navigation")) {
return null;
}

try {
// getString might throw if cast to string fails (data.to is not enforced by TS to be a string)
return maybeData.hasKey("to") ? maybeData.getString("to") : null;
} catch (Throwable exception) {
return null;
}
final @Nullable ReadableMap maybeData = from.hasKey("data") ? from.getMap("data") : null;
if (maybeData == null) {
return null;
}

@NotNull
public static Breadcrumb fromMap(ReadableMap from) {
final @NotNull Breadcrumb breadcrumb = new Breadcrumb();
try {
// getString might throw if cast to string fails (data.to is not enforced by TS to be a
// string)
return maybeData.hasKey("to") ? maybeData.getString("to") : null;
} catch (Throwable exception) {
return null;
}
}

if (from.hasKey("message")) {
breadcrumb.setMessage(from.getString("message"));
}
@NotNull
public static Breadcrumb fromMap(ReadableMap from) {
final @NotNull Breadcrumb breadcrumb = new Breadcrumb();

if (from.hasKey("type")) {
breadcrumb.setType(from.getString("type"));
}
if (from.hasKey("message")) {
breadcrumb.setMessage(from.getString("message"));
}

if (from.hasKey("category")) {
breadcrumb.setCategory(from.getString("category"));
}
if (from.hasKey("type")) {
breadcrumb.setType(from.getString("type"));
}

if (from.hasKey("level")) {
switch (from.getString("level")) {
case "fatal":
breadcrumb.setLevel(SentryLevel.FATAL);
break;
case "warning":
breadcrumb.setLevel(SentryLevel.WARNING);
break;
case "debug":
breadcrumb.setLevel(SentryLevel.DEBUG);
break;
case "error":
breadcrumb.setLevel(SentryLevel.ERROR);
break;
case "info":
default:
breadcrumb.setLevel(SentryLevel.INFO);
break;
}
}
if (from.hasKey("category")) {
breadcrumb.setCategory(from.getString("category"));
}

if (from.hasKey("level")) {
switch (from.getString("level")) {
case "fatal":
breadcrumb.setLevel(SentryLevel.FATAL);
break;
case "warning":
breadcrumb.setLevel(SentryLevel.WARNING);
break;
case "debug":
breadcrumb.setLevel(SentryLevel.DEBUG);
break;
case "error":
breadcrumb.setLevel(SentryLevel.ERROR);
break;
case "info":
default:
breadcrumb.setLevel(SentryLevel.INFO);
break;
}
}

if (from.hasKey("data")) {
final ReadableMap data = from.getMap("data");
for (final Map.Entry<String, Object> entry : data.toHashMap().entrySet()) {
final Object value = entry.getValue();
// data is ConcurrentHashMap and can't have null values
if (value != null) {
breadcrumb.setData(entry.getKey(), entry.getValue());
}
}
if (from.hasKey("data")) {
final ReadableMap data = from.getMap("data");
for (final Map.Entry<String, Object> entry : data.toHashMap().entrySet()) {
final Object value = entry.getValue();
// data is ConcurrentHashMap and can't have null values
if (value != null) {
breadcrumb.setData(entry.getKey(), entry.getValue());
}

return breadcrumb;
}
}

return breadcrumb;
}
}
Loading

0 comments on commit ed9294c

Please sign in to comment.