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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 16 additions & 10 deletions
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

Lines changed: 0 additions & 23 deletions
This file was deleted.

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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 2 deletions
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());

0 commit comments

Comments
 (0)