Skip to content

Commit 94eefff

Browse files
Bump name.remal.sonarlint from 3.4.0 to 4.2.2 (#1120)
* Bump name.remal.sonarlint from 3.4.0 to 4.2.2 Dependabot couldn't find the original pull request head commit, 532f5fe. * Fix sonarlint issues * Revert usage of when keyword --------- Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Connor Schweighoefer <[email protected]>
1 parent 8e62887 commit 94eefff

File tree

13 files changed

+34
-65
lines changed

13 files changed

+34
-65
lines changed

application/src/main/java/org/togetherjava/tjbot/features/bookmarks/BookmarksListRemoveHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ private static int getPageOfBookmark(int bookmarkIndex) {
291291
private static int clampPageIndex(List<BookmarksRecord> bookmarks, int pageIndex) {
292292
int maxPageIndex = getLastPageIndex(bookmarks);
293293

294-
return Math.min(Math.max(0, pageIndex), maxPageIndex);
294+
return Math.clamp(pageIndex, 0, maxPageIndex);
295295
}
296296

297297
private enum RequestType {

application/src/main/java/org/togetherjava/tjbot/features/jshell/renderer/RendererUtils.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ private RendererUtils() {}
2424
static String abortionCauseToString(JShellEvalAbortionCause abortionCause) {
2525
return switch (abortionCause) {
2626
case JShellEvalAbortionCause.TimeoutAbortionCause ignored -> "Allowed time exceeded.";
27-
case JShellEvalAbortionCause.UnhandledExceptionAbortionCause c ->
28-
"Uncaught exception:\n" + c.exceptionClass() + ":" + c.exceptionMessage();
29-
case JShellEvalAbortionCause.CompileTimeErrorAbortionCause c ->
30-
"The code doesn't compile:\n" + String.join("\n", c.errors());
27+
case JShellEvalAbortionCause.UnhandledExceptionAbortionCause(String exceptionClass, String exceptionMessage) ->
28+
"Uncaught exception:\n" + exceptionClass + ":" + exceptionMessage;
29+
case JShellEvalAbortionCause.CompileTimeErrorAbortionCause(List<String> errors) ->
30+
"The code doesn't compile:\n" + String.join("\n", errors);
3131
case JShellEvalAbortionCause.SyntaxErrorAbortionCause ignored ->
3232
"The code doesn't compile, there are syntax errors in this code.";
3333
};

application/src/main/java/org/togetherjava/tjbot/features/moderation/audit/AuditCommand.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.togetherjava.tjbot.features.moderation.ModerationAction;
2626
import org.togetherjava.tjbot.features.moderation.ModerationActionsStore;
2727
import org.togetherjava.tjbot.features.moderation.ModerationUtils;
28-
import org.togetherjava.tjbot.features.utils.Pagination;
2928

3029
import javax.annotation.Nullable;
3130

@@ -116,7 +115,7 @@ private <R extends MessageRequest<R>> RestAction<R> auditUser(
116115
if (pageNumber == -1) {
117116
pageNumberInLimits = totalPages;
118117
} else {
119-
pageNumberInLimits = Pagination.clamp(1, pageNumber, totalPages);
118+
pageNumberInLimits = Math.clamp(pageNumber, 1, totalPages);
120119
}
121120

122121
return jda.retrieveUserById(targetId)

application/src/main/java/org/togetherjava/tjbot/features/reminder/ReminderCommand.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.togetherjava.tjbot.features.CommandVisibility;
2929
import org.togetherjava.tjbot.features.SlashCommandAdapter;
3030
import org.togetherjava.tjbot.features.utils.MessageUtils;
31-
import org.togetherjava.tjbot.features.utils.Pagination;
3231
import org.togetherjava.tjbot.features.utils.StringDistances;
3332

3433
import java.time.Duration;
@@ -221,7 +220,7 @@ private MessageCreateData createPendingRemindersPage(
221220
// 12 reminders, 10 per page, ceil(12 / 10) = 2
222221
int totalPages = Math.ceilDiv(pendingReminders.size(), REMINDERS_PER_PAGE);
223222

224-
pageToShow = Pagination.clamp(1, pageToShow, totalPages);
223+
pageToShow = Math.clamp(pageToShow, 1, totalPages);
225224

226225
EmbedBuilder remindersEmbed = new EmbedBuilder().setTitle("Pending reminders")
227226
.setColor(RemindRoutine.AMBIENT_COLOR);

application/src/main/java/org/togetherjava/tjbot/features/tags/TagManageCommand.java

+16-10
Original file line numberDiff line numberDiff line change
@@ -318,19 +318,25 @@ private Optional<String> getTagContent(Subcommand subcommand, String id) {
318318
* @param event the event to send messages with
319319
* @return whether the status of the given tag is <b>not equal</b> to the required status
320320
*/
321+
// ToDo: gradle task :application:spotlessJava throws internal exception if this method uses new
322+
// when keyword
323+
@SuppressWarnings("java:S6916")
321324
private boolean isWrongTagStatusAndHandle(TagStatus requiredTagStatus, String id,
322325
IReplyCallback event) {
323-
if (requiredTagStatus == TagStatus.EXISTS) {
324-
return tagSystem.handleIsUnknownTag(id, event);
325-
} else if (requiredTagStatus == TagStatus.NOT_EXISTS) {
326-
if (tagSystem.hasTag(id)) {
327-
event.reply("The tag with id '%s' already exists.".formatted(id))
328-
.setEphemeral(true)
329-
.queue();
330-
return true;
326+
switch (requiredTagStatus) {
327+
case TagStatus.EXISTS -> {
328+
return tagSystem.handleIsUnknownTag(id, event);
329+
}
330+
case TagStatus.NOT_EXISTS -> {
331+
if (tagSystem.hasTag(id)) {
332+
event.reply("The tag with id '%s' already exists.".formatted(id))
333+
.setEphemeral(true)
334+
.queue();
335+
return true;
336+
}
331337
}
332-
} else {
333-
throw new AssertionError("Unknown tag status '%s'".formatted(requiredTagStatus));
338+
default ->
339+
throw new AssertionError("Unknown tag status '%s'".formatted(requiredTagStatus));
334340
}
335341
return false;
336342
}

application/src/main/java/org/togetherjava/tjbot/features/utils/Pagination.java

-23
This file was deleted.

application/src/test/java/org/togetherjava/tjbot/features/mathcommands/TeXCommandTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ private SlashCommandInteractionEvent triggerSlashCommand(String latex) {
3939
return event;
4040
}
4141

42-
private void verifySuccessfulResponse(SlashCommandInteractionEvent event, String query) {
42+
private void verifySuccessfulResponse(String query) {
4343
ArgumentMatcher<FileUpload> attachmentIsTexPng =
4444
attachment -> attachment != null && "tex.png".equals(attachment.getName());
4545

@@ -71,10 +71,10 @@ void canRenderSupportedQuery(String supportedQuery) {
7171
// GIVEN a supported latex query
7272

7373
// WHEN triggering the command
74-
SlashCommandInteractionEvent event = triggerSlashCommand(supportedQuery);
74+
triggerSlashCommand(supportedQuery);
7575

7676
// THEN the command send a successful response
77-
verifySuccessfulResponse(event, supportedQuery);
77+
verifySuccessfulResponse(supportedQuery);
7878
}
7979

8080
private static List<String> provideBadInlineQueries() {

application/src/test/java/org/togetherjava/tjbot/features/mediaonly/MediaOnlyChannelListenerTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void sendsAuthorDmUponDeletion() {
9595
MessageCreateData message = new MessageCreateBuilder().setContent("any").build();
9696

9797
// WHEN sending the message
98-
MessageReceivedEvent event = sendMessage(message);
98+
sendMessage(message);
9999

100100
// THEN the author receives a DM
101101
verify(jdaTester.getPrivateChannelSpy()).sendMessage(any(MessageCreateData.class));

application/src/test/java/org/togetherjava/tjbot/features/reminder/RemindRoutineTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ void sendsPendingReminderChannelNotFoundAuthorFound() {
159159
void reminderIsNotSendIfNotPending() {
160160
// GIVEN a reminder that is not pending yet
161161
Instant remindAt = Instant.now().plus(1, ChronoUnit.HOURS);
162-
String reminderContent = "foo";
163162
rawReminders.insertReminder("foo", remindAt);
164163

165164
// WHEN running the routine

application/src/test/java/org/togetherjava/tjbot/jda/JdaTester.java

-2
Original file line numberDiff line numberDiff line change
@@ -745,8 +745,6 @@ private void mockMessage(Message message, ChannelType channelType) {
745745
*/
746746
public Message clientMessageToReceivedMessageMock(MessageCreateData clientMessage) {
747747
Message receivedMessage = mock(Message.class);
748-
var foo = clientMessage.getComponents();
749-
750748
when(receivedMessage.getJDA()).thenReturn(jda);
751749
when(receivedMessage.getEmbeds()).thenReturn(clientMessage.getEmbeds());
752750
when(receivedMessage.getContentRaw()).thenReturn(clientMessage.getContent());

application/src/test/java/org/togetherjava/tjbot/jda/SlashCommandInteractionEventBuilder.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ private PayloadSlashCommand createEvent() {
272272
// TODO Validate that required options are set, check that subcommand is given if the
273273
// command has one
274274
// TODO Make as much of this configurable as needed
275-
PayloadUser user = new PayloadUser(false, 0, userId, "286b894dc74634202d251d591f63537d",
276-
"Test-User", "3452");
275+
PayloadUser user =
276+
new PayloadUser(false, 0, userId, "286b894dc74634202d251d591f63537d", "Test-User");
277277
PayloadMember member = new PayloadMember(null, null, "2021-09-07T18:25:16.615000+00:00",
278278
"1099511627775", List.of(), false, false, false, null, false, user);
279279
PayloadChannel channel = new PayloadChannel(channelId, 1);
@@ -309,7 +309,7 @@ private static <T> String serializeOptionValue(T value, OptionType type) {
309309
if (type == OptionType.STRING) {
310310
return (String) value;
311311
} else if (type == OptionType.INTEGER) {
312-
if (value instanceof Long asLong) {
312+
if (value instanceof Long) {
313313
return value.toString();
314314
}
315315

application/src/test/java/org/togetherjava/tjbot/jda/payloads/PayloadUser.java

+3-12
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,19 @@ public final class PayloadUser {
1212
private String id;
1313
private String avatar;
1414
private String username;
15-
private String discriminator;
1615

1716
public PayloadUser(boolean bot, long publicFlags, String id, @Nullable String avatar,
18-
String username, String discriminator) {
17+
String username) {
18+
this.bot = bot;
1919
this.publicFlags = publicFlags;
2020
this.id = id;
2121
this.avatar = avatar;
2222
this.username = username;
23-
this.discriminator = discriminator;
2423
}
2524

2625
public static PayloadUser of(User user) {
2726
return new PayloadUser(user.isBot(), user.getFlagsRaw(), user.getId(), user.getAvatarId(),
28-
user.getName(), user.getDiscriminator());
27+
user.getName());
2928
}
3029

3130
public boolean isBot() {
@@ -68,12 +67,4 @@ public String getUsername() {
6867
public void setUsername(String username) {
6968
this.username = username;
7069
}
71-
72-
public String getDiscriminator() {
73-
return discriminator;
74-
}
75-
76-
public void setDiscriminator(String discriminator) {
77-
this.discriminator = discriminator;
78-
}
7970
}

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ plugins {
22
id 'java'
33
id "com.diffplug.spotless" version "6.25.0"
44
id "org.sonarqube" version "5.0.0.4638"
5-
id "name.remal.sonarlint" version "3.4.0"
5+
id "name.remal.sonarlint" version "4.2.2"
66
}
77

88
group 'org.togetherjava'

0 commit comments

Comments
 (0)