Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix code inspection warnings #331

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/kotlin/uk/co/ben_gibson/git/link/GitLinkBundle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ object GitLinkBundle : DynamicBundle(BUNDLE) {
}

fun openRepository() {
BrowserLauncher.instance.open("https://github.com/ben-gibson/GitLink");
BrowserLauncher.instance.open("https://github.com/ben-gibson/GitLink")
}

fun plugin() = PluginManagerCore.getPlugin(PluginId.getId("uk.co.ben-gibson.remote.repository.mapper"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ val GitRemote.httpUrl : URL? get() {
// will result in an invalid URL when the repository name is made up of digits.
// See https://github.com/ben-gibson/GitLink/issues/94
if (!url.startsWith("git@")) {
url = url.replace(":\\d{1,5}".toRegex(), ""); // remove the port
url = url.replace(":\\d{1,5}".toRegex(), "") // remove the port
}

// Hack for azure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Pipeline(private val project: Project) {
val middleware = queue.remove()

return middleware(pass) {
return@middleware next(queue, pass);
return@middleware next(queue, pass)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ForceHttps : Middleware {
return url.toHttps()
}

return url;
return url
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class GenerateUrl : Middleware {
val commit = repository.currentCommit() ?: return null

if (!pullRequestWorkflowSupported || !settings.shouldCheckRemote) {
return commit;
return commit
}

return if (remote.contains(repository, commit)) commit else null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class RecordHit : Middleware {
override fun invoke(pass: Pass, next: () -> URL?) : URL? {
val url = next() ?: return null

service<ApplicationSettings>().recordHit();
service<ApplicationSettings>().recordHit()

return url;
return url
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SendSupportNotification : Middleware {
sendNotification(Notification.star())
}

return url;
return url
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ class Timer : Middleware {

val url = next()

val total = System.currentTimeMillis() - startTime;
val total = System.currentTimeMillis() - startTime

if (total > 1000) {
sendNotification(Notification.performanceTips(pass.project), pass.project)
}

return url;
return url
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import uk.co.ben_gibson.git.link.GitLinkBundle.message
import uk.co.ben_gibson.git.link.ui.Icons
import java.util.UUID
import javax.swing.Icon
import uk.co.ben_gibson.url.Host;
import uk.co.ben_gibson.url.Host
import java.util.regex.Pattern

sealed class Platform(val id: UUID, val name: String, val icon: Icon, val domains: Set<Host> = setOf(), val domainPattern: Pattern? = null, val pullRequestWorkflowSupported: Boolean = true) {
Expand All @@ -15,9 +15,7 @@ sealed class Platform(val id: UUID, val name: String, val icon: Icon, val domain

other as Platform

if (id != other.id) return false

return true
return id == other.id
}

override fun hashCode(): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private val EXISTING_PLATFORMS = setOf(
@Service
class PlatformRepository {
fun getById(id: String) = getById(UUID.fromString(id))
fun getById(id: UUID) = load().firstOrNull() { it.id == id }
fun getById(id: UUID) = load().firstOrNull { it.id == id }
fun getByDomain(domain: Host): Platform? {
val platforms = load()
return platforms.firstOrNull { it.domains.contains(domain) } ?: platforms.firstOrNull { it.domainPattern?.matcher(domain.toString())?.matches() == true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.intellij.openapi.components.PersistentStateComponent
import com.intellij.openapi.components.State
import com.intellij.openapi.components.Storage
import com.intellij.util.xmlb.XmlSerializerUtil
import com.intellij.util.xmlb.annotations.Tag;
import com.intellij.util.xmlb.annotations.Tag
import uk.co.ben_gibson.url.Host
import java.util.UUID

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ProjectSettings : PersistentStateComponent<ProjectSettings?> {
var host: String? = null
var fallbackBranch = "main"
var remote = "origin"
var checkCommitOnRemote = true
private var checkCommitOnRemote = true
var shouldCheckRemote
get() = checkCommitOnRemote
set(value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ abstract class Action(private val type: Type): DumbAwareAction() {

if (host == null) {
event.presentation.isEnabledAndVisible = false
return;
return
}

event.presentation.isEnabled = shouldBeEnabled(event)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ data class Notification(
Finding GitLink useful? Show your support 💖 and ⭐ the repository 🙏.
""".trimIndent(),
actions = setOf(
NotificationAction.openRepository() {
service<ApplicationSettings>().requestSupport = false;
NotificationAction.openRepository {
service<ApplicationSettings>().requestSupport = false
},
NotificationAction.doNotAskAgain() {
service<ApplicationSettings>().requestSupport = false;
NotificationAction.doNotAskAgain {
service<ApplicationSettings>().requestSupport = false
}
)
)
Expand Down Expand Up @@ -76,9 +76,6 @@ data class Notification(
Type.TRANSIENT,
)
}

fun isTransient() = type == Type.TRANSIENT
fun isPersistent() = !isTransient();
}

data class NotificationAction(val title: String, val run: (dismiss: () -> Unit) -> Unit) {
Expand All @@ -101,12 +98,12 @@ data class NotificationAction(val title: String, val run: (dismiss: () -> Unit)

fun openUrl(url: URL, title: String = message("actions.take-me-there")) = NotificationAction(title) { dismiss ->
dismiss()
BrowserLauncher.instance.open(url.toString());
BrowserLauncher.instance.open(url.toString())
}

fun disableRemoteCheck(project: Project) = NotificationAction(message("actions.disable")) { dismiss ->
dismiss()
project.service<ProjectSettings>().shouldCheckRemote = false;
project.service<ProjectSettings>().shouldCheckRemote = false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fun sendNotification(notification : Notification, project : Project? = null) {

notification.actions.forEach { action ->
intellijNotification.addAction(DumbAwareAction.create(action.title) {
action.run() {
action.run {
intellijNotification.expire()
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private class CustomPlatformDialog(customPlatform: CustomHostSettings? = null) :
textField()
.bindText(platform::displayName)
.focused()
.validationOnApply() { notBlank(it.text) ?: alphaNumeric(it.text) ?: length(it.text, 3, 15) }
.validationOnApply { notBlank(it.text) ?: alphaNumeric(it.text) ?: length(it.text, 3, 15) }
.comment(message("settings.custom-platform.add-dialog.field.name.comment"))
}
row(message("settings.custom-platform.add-dialog.field.domain.label")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class DomainRegistrySettings : BoundConfigurable(message("settings.domain-regist
.setEditAction { editDomain() }
.setRemoveAction { removeDomain() }
.setEditActionUpdater { canModifyDomain() }
.setRemoveActionUpdater() { canModifyDomain() }
.setRemoveActionUpdater { canModifyDomain() }
.createPanel()

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fun ValidationInfoBuilder.domain(value: String): ValidationInfo? {
Host(value)
null
} catch (e: IllegalArgumentException) {
error(message("validation.invalid-domain"));
error(message("validation.invalid-domain"))
}
}

Expand All @@ -46,7 +46,7 @@ fun ValidationInfoBuilder.exists(value: String, existing: Collection<String>): V

fun ValidationInfoBuilder.length(value: String, min: Int, max: Int): ValidationInfo? {
if (value.isEmpty()) {
return null;
return null
}

return when {
Expand All @@ -58,7 +58,7 @@ fun ValidationInfoBuilder.length(value: String, min: Int, max: Int): ValidationI

fun ValidationInfoBuilder.fileAtCommitTemplate(value: String): ValidationInfo? {
if (value.isEmpty()) {
return null;
return null
}

val options = UrlOptionsFileAtCommit(
Expand All @@ -73,7 +73,7 @@ fun ValidationInfoBuilder.fileAtCommitTemplate(value: String): ValidationInfo? {

fun ValidationInfoBuilder.fileAtBranchTemplate(value: String): ValidationInfo? {
if (value.isEmpty()) {
return null;
return null
}

val options = UrlOptionsFileAtBranch(
Expand All @@ -88,15 +88,15 @@ fun ValidationInfoBuilder.fileAtBranchTemplate(value: String): ValidationInfo? {

fun ValidationInfoBuilder.commitTemplate(value: String): ValidationInfo? {
if (value.isEmpty()) {
return null;
return null
}

val options = UrlOptionsCommit(
URL.fromString("https://example.com"),
Commit("734232a3c18f0625843bd161c3f5da272b9d53c1")
)

return urlTemplate(options, commit = value);
return urlTemplate(options, commit = value)
}

private fun ValidationInfoBuilder.urlTemplate(
Expand All @@ -105,7 +105,7 @@ private fun ValidationInfoBuilder.urlTemplate(
fileAtCommit: String = "",
commit: String = ""
) : ValidationInfo? {
val factory = TemplatedUrlFactory(UrlTemplates(fileAtBranch, fileAtCommit, commit));
val factory = TemplatedUrlFactory(UrlTemplates(fileAtBranch, fileAtCommit, commit))

return try {
factory.createUrl(options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class TemplatedUrlFactory(private val templates: UrlTemplates) : UrlFactory {
processed = processed.replace("{remote:url:path:${position}}", pathParts.getOrElse(position) { "" })
}

return processed;
return processed
}

private fun processBranch(template: String, branch: String) = template
Expand All @@ -83,7 +83,7 @@ class TemplatedUrlFactory(private val templates: UrlTemplates) : UrlFactory {
private fun processFile(template: String, file: File) = template
.replace("{object}", if (file.isDirectory) "tree" else "blob")
.replace("{file:name}", if (file.isRoot) "" else escape.apply(file.name))
.replace("{file:path}", file.path.split("/").map { escape.apply(it) }.joinToString("/"))
.replace("{file:path}", file.path.split("/").joinToString("/") { escape.apply(it) })

private fun processCommit(template: String, commit: Commit) = template
.replace("{commit}", commit.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ val PLATFORM_MAP = mapOf(
)

@Service
class TemplatedUrlFactoryProvider() {
class TemplatedUrlFactoryProvider {
fun forPlatform(platform: Platform): TemplatedUrlFactory {
if (platform is Custom) {
return customPlatform(platform)
Expand Down
Loading