Skip to content

Commit

Permalink
Bump name.remal.sonarlint from 3.4.0 to 4.2.2 (Together-Java#1120)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
dependabot[bot] and SquidXTV authored May 23, 2024
1 parent 8e62887 commit 94eefff
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ private static int getPageOfBookmark(int bookmarkIndex) {
private static int clampPageIndex(List<BookmarksRecord> bookmarks, int pageIndex) {
int maxPageIndex = getLastPageIndex(bookmarks);

return Math.min(Math.max(0, pageIndex), maxPageIndex);
return Math.clamp(pageIndex, 0, maxPageIndex);
}

private enum RequestType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ private RendererUtils() {}
static String abortionCauseToString(JShellEvalAbortionCause abortionCause) {
return switch (abortionCause) {
case JShellEvalAbortionCause.TimeoutAbortionCause ignored -> "Allowed time exceeded.";
case JShellEvalAbortionCause.UnhandledExceptionAbortionCause c ->
"Uncaught exception:\n" + c.exceptionClass() + ":" + c.exceptionMessage();
case JShellEvalAbortionCause.CompileTimeErrorAbortionCause c ->
"The code doesn't compile:\n" + String.join("\n", c.errors());
case JShellEvalAbortionCause.UnhandledExceptionAbortionCause(String exceptionClass, String exceptionMessage) ->
"Uncaught exception:\n" + exceptionClass + ":" + exceptionMessage;
case JShellEvalAbortionCause.CompileTimeErrorAbortionCause(List<String> errors) ->
"The code doesn't compile:\n" + String.join("\n", errors);
case JShellEvalAbortionCause.SyntaxErrorAbortionCause ignored ->
"The code doesn't compile, there are syntax errors in this code.";
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.togetherjava.tjbot.features.moderation.ModerationAction;
import org.togetherjava.tjbot.features.moderation.ModerationActionsStore;
import org.togetherjava.tjbot.features.moderation.ModerationUtils;
import org.togetherjava.tjbot.features.utils.Pagination;

import javax.annotation.Nullable;

Expand Down Expand Up @@ -116,7 +115,7 @@ private <R extends MessageRequest<R>> RestAction<R> auditUser(
if (pageNumber == -1) {
pageNumberInLimits = totalPages;
} else {
pageNumberInLimits = Pagination.clamp(1, pageNumber, totalPages);
pageNumberInLimits = Math.clamp(pageNumber, 1, totalPages);
}

return jda.retrieveUserById(targetId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.togetherjava.tjbot.features.CommandVisibility;
import org.togetherjava.tjbot.features.SlashCommandAdapter;
import org.togetherjava.tjbot.features.utils.MessageUtils;
import org.togetherjava.tjbot.features.utils.Pagination;
import org.togetherjava.tjbot.features.utils.StringDistances;

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

pageToShow = Pagination.clamp(1, pageToShow, totalPages);
pageToShow = Math.clamp(pageToShow, 1, totalPages);

EmbedBuilder remindersEmbed = new EmbedBuilder().setTitle("Pending reminders")
.setColor(RemindRoutine.AMBIENT_COLOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,19 +318,25 @@ private Optional<String> getTagContent(Subcommand subcommand, String id) {
* @param event the event to send messages with
* @return whether the status of the given tag is <b>not equal</b> to the required status
*/
// ToDo: gradle task :application:spotlessJava throws internal exception if this method uses new
// when keyword
@SuppressWarnings("java:S6916")
private boolean isWrongTagStatusAndHandle(TagStatus requiredTagStatus, String id,
IReplyCallback event) {
if (requiredTagStatus == TagStatus.EXISTS) {
return tagSystem.handleIsUnknownTag(id, event);
} else if (requiredTagStatus == TagStatus.NOT_EXISTS) {
if (tagSystem.hasTag(id)) {
event.reply("The tag with id '%s' already exists.".formatted(id))
.setEphemeral(true)
.queue();
return true;
switch (requiredTagStatus) {
case TagStatus.EXISTS -> {
return tagSystem.handleIsUnknownTag(id, event);
}
case TagStatus.NOT_EXISTS -> {
if (tagSystem.hasTag(id)) {
event.reply("The tag with id '%s' already exists.".formatted(id))
.setEphemeral(true)
.queue();
return true;
}
}
} else {
throw new AssertionError("Unknown tag status '%s'".formatted(requiredTagStatus));
default ->
throw new AssertionError("Unknown tag status '%s'".formatted(requiredTagStatus));
}
return false;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private SlashCommandInteractionEvent triggerSlashCommand(String latex) {
return event;
}

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

Expand Down Expand Up @@ -71,10 +71,10 @@ void canRenderSupportedQuery(String supportedQuery) {
// GIVEN a supported latex query

// WHEN triggering the command
SlashCommandInteractionEvent event = triggerSlashCommand(supportedQuery);
triggerSlashCommand(supportedQuery);

// THEN the command send a successful response
verifySuccessfulResponse(event, supportedQuery);
verifySuccessfulResponse(supportedQuery);
}

private static List<String> provideBadInlineQueries() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void sendsAuthorDmUponDeletion() {
MessageCreateData message = new MessageCreateBuilder().setContent("any").build();

// WHEN sending the message
MessageReceivedEvent event = sendMessage(message);
sendMessage(message);

// THEN the author receives a DM
verify(jdaTester.getPrivateChannelSpy()).sendMessage(any(MessageCreateData.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ void sendsPendingReminderChannelNotFoundAuthorFound() {
void reminderIsNotSendIfNotPending() {
// GIVEN a reminder that is not pending yet
Instant remindAt = Instant.now().plus(1, ChronoUnit.HOURS);
String reminderContent = "foo";
rawReminders.insertReminder("foo", remindAt);

// WHEN running the routine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -745,8 +745,6 @@ private void mockMessage(Message message, ChannelType channelType) {
*/
public Message clientMessageToReceivedMessageMock(MessageCreateData clientMessage) {
Message receivedMessage = mock(Message.class);
var foo = clientMessage.getComponents();

when(receivedMessage.getJDA()).thenReturn(jda);
when(receivedMessage.getEmbeds()).thenReturn(clientMessage.getEmbeds());
when(receivedMessage.getContentRaw()).thenReturn(clientMessage.getContent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ private PayloadSlashCommand createEvent() {
// TODO Validate that required options are set, check that subcommand is given if the
// command has one
// TODO Make as much of this configurable as needed
PayloadUser user = new PayloadUser(false, 0, userId, "286b894dc74634202d251d591f63537d",
"Test-User", "3452");
PayloadUser user =
new PayloadUser(false, 0, userId, "286b894dc74634202d251d591f63537d", "Test-User");
PayloadMember member = new PayloadMember(null, null, "2021-09-07T18:25:16.615000+00:00",
"1099511627775", List.of(), false, false, false, null, false, user);
PayloadChannel channel = new PayloadChannel(channelId, 1);
Expand Down Expand Up @@ -309,7 +309,7 @@ private static <T> String serializeOptionValue(T value, OptionType type) {
if (type == OptionType.STRING) {
return (String) value;
} else if (type == OptionType.INTEGER) {
if (value instanceof Long asLong) {
if (value instanceof Long) {
return value.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,19 @@ public final class PayloadUser {
private String id;
private String avatar;
private String username;
private String discriminator;

public PayloadUser(boolean bot, long publicFlags, String id, @Nullable String avatar,
String username, String discriminator) {
String username) {
this.bot = bot;
this.publicFlags = publicFlags;
this.id = id;
this.avatar = avatar;
this.username = username;
this.discriminator = discriminator;
}

public static PayloadUser of(User user) {
return new PayloadUser(user.isBot(), user.getFlagsRaw(), user.getId(), user.getAvatarId(),
user.getName(), user.getDiscriminator());
user.getName());
}

public boolean isBot() {
Expand Down Expand Up @@ -68,12 +67,4 @@ public String getUsername() {
public void setUsername(String username) {
this.username = username;
}

public String getDiscriminator() {
return discriminator;
}

public void setDiscriminator(String discriminator) {
this.discriminator = discriminator;
}
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id 'java'
id "com.diffplug.spotless" version "6.25.0"
id "org.sonarqube" version "5.0.0.4638"
id "name.remal.sonarlint" version "3.4.0"
id "name.remal.sonarlint" version "4.2.2"
}

group 'org.togetherjava'
Expand Down

0 comments on commit 94eefff

Please sign in to comment.