Skip to content

Commit

Permalink
Merge pull request #527 from FWDekker/inspections-fixes
Browse files Browse the repository at this point in the history
Inspections fixes
  • Loading branch information
FWDekker authored Jan 17, 2024
2 parents 97c8f66 + 0f62751 commit 0cb5449
Show file tree
Hide file tree
Showing 18 changed files with 115 additions and 90 deletions.
8 changes: 4 additions & 4 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ assignees: FWDekker
<!-- If applicable, add screenshots to help explain your problem. -->

**Version information**
- Randomness version [e.g. 2.7.7]: <!-- Check `Settings -> Plugins` in your IDE and search for `Randomness` -->
- IDE version [e.g. IntelliJ Community 2023.1.3]: <!-- Check `Help -> About` in your IDE -->
- Operating system [e.g. Windows 11, Ubuntu 22.04.2, macOS 13.4.1]: <!-- Use a search engine for help if you don't know -->
- Java version [e.g. 17.0.5, 19.0.2]: <!-- Run `java -version` in a terminal or check https://www.java.com/en/download/help/version_manual.xml -->
- Randomness version [e.g. 3.2.0]: <!-- Check `Settings -> Plugins` in your IDE and search for `Randomness` -->
- IDE version [e.g. IntelliJ Community 2023.3.3]: <!-- Check `Help -> About` in your IDE -->
- Operating system [e.g. Windows 11, Ubuntu 22.04.3, macOS 14.2.1]: <!-- Use a search engine for help if you don't know -->
- Java version [e.g. 17.0.9, 21.0.1]: <!-- Run `java -version` in a terminal or check https://www.java.com/en/download/help/version_manual.xml -->

**Additional context**
<!-- Add any other context about the problem here. -->
2 changes: 1 addition & 1 deletion .github/SECURITY.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Security policy
The security of Randomness is important to me.
If you find a vulnerability in Randomness, please
[report the vulnerability](https://github.com/FWDekker/mommy/security/advisories/new) as soon as possible.
[report the vulnerability](https://github.com/FWDekker/intellij-randomness/security/advisories/new) as soon as possible.

Please note that Randomness is distinct from IntelliJ and other IDEs developed by JetBrains.
To report a vulnerability in IntelliJ or another JetBrains product, please
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
# Changelog
## [Unreleased]
### Changed
* Rewrote error reporter from scratch, now ensuring all relevant data is included, and allowing non-GitHub users to report issues. ([#455](https://github.com/FWDekker/intellij-randomness/issues/455))
* Significantly reduced plugin size by removing unnecessary dependencies. ([#526](https://github.com/FWDekker/intellij-randomness/issues/526))

### Fixed
* Various incorrect uses of the platform API. ([#526](https://github.com/FWDekker/intellij-randomness/issues/526))


## 3.2.0 -- 2024-01-10
### Added
* Added support for UUID versions 6, 7, and 8. ([#513](https://github.com/FWDekker/intellij-randomness/issues/513))
Expand Down
44 changes: 22 additions & 22 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ fun properties(key: String) = project.findProperty(key).toString()
/// Plugins
plugins {
// Compilation
id("org.jetbrains.kotlin.jvm") version "1.9.21" // Use latest version, ignoring `gradle.properties`
id("org.jetbrains.kotlin.jvm") version "1.8.0" // Set to latest version compatible with `pluginSinceBuild`, cf. https://plugins.jetbrains.com/docs/intellij/using-kotlin.html#kotlin-standard-library
id("org.jetbrains.intellij") version "1.16.1"

// Tests/coverage
id("org.jetbrains.kotlinx.kover") version "0.7.5"

// Static analysis
id("io.gitlab.arturbosch.detekt") version "1.23.4" // See also `gradle.properties`
id("io.gitlab.arturbosch.detekt") version "1.23.4" // cf. `gradle.properties`

// Documentation
id("org.jetbrains.changelog") version "2.2.0"
id("org.jetbrains.dokka") version "1.9.10" // See also `buildscript { dependencies` below and `gradle.properties`
id("org.jetbrains.dokka") version "1.9.10" // cf. `buildscript { dependencies` below and `gradle.properties`
}

buildscript {
dependencies {
classpath("org.jetbrains.dokka:dokka-base:1.9.10") // See also `plugins` above and `gradle.properties`
classpath("org.jetbrains.dokka:versioning-plugin:1.9.10") // See also `plugins` above and `gradle.properties`
classpath("org.jetbrains.dokka", "dokka-base", "1.9.10") // cf. `plugins` above and `gradle.properties`
classpath("org.jetbrains.dokka", "versioning-plugin", "1.9.10") // cf. `plugins` above and `gradle.properties`
}
}

Expand All @@ -45,22 +45,22 @@ repositories {
}

dependencies {
implementation("com.fasterxml.uuid:java-uuid-generator:${properties("uuidGeneratorVersion")}")
implementation("com.github.sisyphsu:dateparser:${properties("dateparserVersion")}")
implementation("com.github.curious-odd-man:rgxgen:${properties("rgxgenVersion")}")
implementation("com.vdurmont:emoji-java:${properties("emojiVersion")}")
implementation("org.eclipse.mylyn.github:org.eclipse.egit.github.core:${properties("githubCore")}")
api("org.jetbrains.kotlin:kotlin-reflect")

testImplementation("org.assertj:assertj-swing-junit:${properties("assertjSwingVersion")}")
testRuntimeOnly("org.junit.platform:junit-platform-runner:${properties("junitRunnerVersion")}")
testImplementation("org.junit.vintage:junit-vintage-engine:${properties("junitVersion")}")
testImplementation("io.kotest:kotest-assertions-core:${properties("kotestVersion")}")
testImplementation("io.kotest:kotest-framework-datatest:${properties("kotestVersion")}")
testImplementation("io.kotest:kotest-runner-junit5:${properties("kotestVersion")}")

detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:${properties("detektVersion")}")
dokkaHtmlPlugin("org.jetbrains.dokka:versioning-plugin:${properties("dokkaVersion")}")
implementation("com.fasterxml.uuid", "java-uuid-generator", properties("uuidGeneratorVersion"))
implementation("com.github.sisyphsu", "dateparser", properties("dateparserVersion")) {
exclude(group = "org.projectlombok", module = "lombok") // cf. https://github.com/sisyphsu/dateparser/issues/30
}
implementation("com.github.curious-odd-man", "rgxgen", properties("rgxgenVersion"))
implementation("org.eclipse.mylyn.github", "org.eclipse.egit.github.core", properties("githubCore"))

testImplementation("org.assertj", "assertj-swing-junit", properties("assertjSwingVersion"))
testRuntimeOnly("org.junit.platform", "junit-platform-runner", properties("junitRunnerVersion"))
testImplementation("org.junit.vintage", "junit-vintage-engine", properties("junitVersion"))
testImplementation("io.kotest", "kotest-assertions-core", properties("kotestVersion"))
testImplementation("io.kotest", "kotest-framework-datatest", properties("kotestVersion"))
testImplementation("io.kotest", "kotest-runner-junit5", properties("kotestVersion"))

detektPlugins("io.gitlab.arturbosch.detekt", "detekt-formatting", properties("detektVersion"))
dokkaHtmlPlugin("org.jetbrains.dokka", "versioning-plugin", properties("dokkaVersion"))
}


Expand All @@ -74,7 +74,7 @@ tasks {
withType<KotlinCompile> {
kotlinOptions {
jvmTarget = properties("javaVersion")
apiVersion = properties("kotlinApiVersion")
apiVersion = properties("kotlinVersion")
languageVersion = properties("kotlinVersion")
}
}
Expand Down
10 changes: 4 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ pluginVerifierIdeVersions=IC-2023.1.5, IC-2023.2.5, IC-2023.3, CL-2023.1.5, CL-2
# Java version should be the one used by the oldest Randomness-supported version of IntelliJ. See also
# https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html#platformVersions.
#
# * Kotlin
# * `kotlinVersion` is the same as `kotlinApiVersion`.
# * Kotlin version should be bundled stdlib version of oldest supported IntelliJ version. See also
# https://plugins.jetbrains.com/docs/intellij/using-kotlin.html#kotlin-standard-library.
# * Kotlin:
# * Kotlin version should be bundled stdlib version of oldest supported IntelliJ version. See also
# https://plugins.jetbrains.com/docs/intellij/using-kotlin.html#kotlin-standard-library.
# * Ensure the version of the `org.jetbrains.kotlin.jvm` in `build.gradle.kts` is updated accordingly.
javaVersion=17
kotlinVersion=1.8
kotlinApiVersion=1.8

# Dependencies
# * Detekt should also be updated in `plugins` block.
Expand All @@ -36,7 +35,6 @@ assertjSwingVersion=3.17.1
dateparserVersion=1.0.11
detektVersion=1.23.3
dokkaVersion=1.9.10
emojiVersion=5.1.1
githubCore=2.1.5
junitVersion=5.10.1
junitRunnerVersion=1.10.1
Expand Down
44 changes: 30 additions & 14 deletions src/main/kotlin/com/fwdekker/randomness/ErrorReporter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import javax.crypto.spec.SecretKeySpec
* Heavily inspired by [Patrick Scheibe's error reporter](https://github.com/halirutan/Wolfram-Language-IntelliJ-Plugin-Archive/tree/e3dd72f9cd344d678ac892aaa7bf59abd84871e8/src/de/halirutan/mathematica/errorreporting).
*/
@Suppress("detekt:MaxLineLength") // Necessary because of the long link in the docs above
class ErrorReporter : ErrorReportSubmitter() {
internal class ErrorReporter : ErrorReportSubmitter() {
/**
* Interacts with GitHub.
*/
Expand Down Expand Up @@ -150,7 +150,7 @@ private class GitHubReporter {
fun report(issueData: IssueData): SubmittedReportInfo =
try {
synchronized(this) {
val duplicate = issueService.pageIssues(repo).flatSequence().firstOrNull(issueData::isDuplicateOf)
val duplicate = issueService.pageIssues(repo).flatSequence().firstOrNull { issueData.isDuplicateOf(it) }

val context: Issue
if (duplicate == null) {
Expand Down Expand Up @@ -241,7 +241,7 @@ private object GitHubScrambler {
* The URL at which a newer token may be available.
*/
private val URL =
URL("http://raw.githubusercontent.com/FWDekker/intellij-randomness/main/src/main/resources/reporter/token.bin")
URL("https://raw.githubusercontent.com/FWDekker/intellij-randomness/main/src/main/resources/reporter/token.bin")


/**
Expand Down Expand Up @@ -340,16 +340,27 @@ private class IssueData(
*/
val body: String =
emptySequence<Pair<String, String>>()
.plus("User-supplied comments" to additionalInfo.ifNullOrBlank { "_No comments supplied._" }.trim())
.plus(
Bundle("reporter.issue.body.comments.title") to
additionalInfo.ifNullOrBlank { italic(Bundle("reporter.issue.body.comments.body_empty")) }.trim()
)
.plus(
events
.map { it.throwableText }
.filterNot { it.isBlank() }
.mapIndexed { idx: Int, body: String -> "Stacktrace ${idx + 1}" to spoiler(code(body, "java")) }
.mapIndexed { idx: Int, body: String ->
Bundle("reporter.issue.body.stacktrace.title", idx + 1) to
spoiler(code(body, "java"))
}
)
.plus(
attachments.map {
Bundle("reporter.issue.body.attachment.title", it.name) to
spoiler(code(it.displayText))
}
)
.plus(attachments.map { "Attachment: `${it.name}`" to spoiler(code(it.displayText)) })
.plus(
"Version information" to
Bundle("reporter.issue.body.version.title") to
"""
- Randomness version: ${pluginDescriptor.version ?: "_Unknown_"}
- IDE version: ${ApplicationInfo.getInstance().apiVersion}
Expand All @@ -358,7 +369,7 @@ private class IssueData(
""".trimIndent()
)
.joinToString(separator = "\n\n") { section(it.first, it.second) }
.plus("\n\n---\n\n_This issue report was generated automatically for an anonymous user._")
.let { italic(Bundle("reporter.issue.body.header")) + "\n\n---\n\n" + it }


/**
Expand All @@ -382,6 +393,17 @@ private class IssueData(
* Holds constants.
*/
companion object {
/**
* Creates a Markdown code block containing [body] and using the given [language].
*/
private fun code(body: String, language: String = ""): String =
"```$language\n$body\n```"

/**
* Creates an italicized piece of Markdown.
*/
private fun italic(body: String) = "_${body}_"

/**
* Creates a Markdown section with the given [title] and [body].
*/
Expand All @@ -394,12 +416,6 @@ private class IssueData(
private fun spoiler(body: String, heading: String = "Click to show"): String =
"<details>\n <summary>${heading.trim()}</summary>\n\n${body.prependIndent(" ")}\n\n</details>"

/**
* Creates a Markdown code block containing [body] and using the given [language].
*/
private fun code(body: String, language: String = ""): String =
"```$language\n$body\n```"


/**
* Returns [this] if [this] is neither `null` nor blank, and returns the output of [then] otherwise.
Expand Down
22 changes: 11 additions & 11 deletions src/main/kotlin/com/fwdekker/randomness/Icons.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,57 +18,57 @@ object Icons {
/**
* The main icon of Randomness.
*/
val RANDOMNESS = IconLoader.findIcon("/icons/randomness.svg", this.javaClass.classLoader)!!
val RANDOMNESS = IconLoader.getIcon("/icons/randomness.svg", this.javaClass.classLoader)

/**
* The template icon for template icons.
*/
val TEMPLATE = IconLoader.findIcon("/icons/template.svg", this.javaClass.classLoader)!!
val TEMPLATE = IconLoader.getIcon("/icons/template.svg", this.javaClass.classLoader)

/**
* The template icon for scheme icons.
*/
val SCHEME = IconLoader.findIcon("/icons/scheme.svg", this.javaClass.classLoader)!!
val SCHEME = IconLoader.getIcon("/icons/scheme.svg", this.javaClass.classLoader)

/**
* An icon for settings.
*/
val SETTINGS = IconLoader.findIcon("/icons/settings.svg", this.javaClass.classLoader)!!
val SETTINGS = IconLoader.getIcon("/icons/settings.svg", this.javaClass.classLoader)

/**
* A filled-in version of [SETTINGS].
*/
val SETTINGS_FILLED = IconLoader.findIcon("/icons/settings-filled.svg", this.javaClass.classLoader)!!
val SETTINGS_FILLED = IconLoader.getIcon("/icons/settings-filled.svg", this.javaClass.classLoader)

/**
* An icon for arrays.
*/
val ARRAY = IconLoader.findIcon("/icons/array.svg", this.javaClass.classLoader)!!
val ARRAY = IconLoader.getIcon("/icons/array.svg", this.javaClass.classLoader)

/**
* A filled-in version of [ARRAY].
*/
val ARRAY_FILLED = IconLoader.findIcon("/icons/array-filled.svg", this.javaClass.classLoader)!!
val ARRAY_FILLED = IconLoader.getIcon("/icons/array-filled.svg", this.javaClass.classLoader)

/**
* An icon for references.
*/
val REFERENCE = IconLoader.findIcon("/icons/reference.svg", this.javaClass.classLoader)!!
val REFERENCE = IconLoader.getIcon("/icons/reference.svg", this.javaClass.classLoader)

/**
* A filled-in version of [REFERENCE].
*/
val REFERENCE_FILLED = IconLoader.findIcon("/icons/reference-filled.svg", this.javaClass.classLoader)!!
val REFERENCE_FILLED = IconLoader.getIcon("/icons/reference-filled.svg", this.javaClass.classLoader)

/**
* An icon for repeated insertions.
*/
val REPEAT = IconLoader.findIcon("/icons/repeat.svg", this.javaClass.classLoader)!!
val REPEAT = IconLoader.getIcon("/icons/repeat.svg", this.javaClass.classLoader)

/**
* A filled-in version of [REPEAT].
*/
val REPEAT_FILLED = IconLoader.findIcon("/icons/repeat-filled.svg", this.javaClass.classLoader)!!
val REPEAT_FILLED = IconLoader.getIcon("/icons/repeat-filled.svg", this.javaClass.classLoader)
}


Expand Down
11 changes: 7 additions & 4 deletions src/main/kotlin/com/fwdekker/randomness/InsertAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.options.Configurable
import com.intellij.openapi.options.newEditor.SettingsDialogFactory
import com.intellij.util.alsoIfNull
import javax.swing.Icon


Expand Down Expand Up @@ -66,8 +67,10 @@ abstract class InsertAction(
val project = event.getData(CommonDataKeys.PROJECT) ?: return

configurable?.also {
if (!SettingsDialogFactory.getInstance().create(project, text, it, false, false).showAndGet())
return
SettingsDialogFactory.getInstance()
.create(project, text, it, false, false)
.showAndGet()
.alsoIfNull { return }
}

val data =
Expand All @@ -89,7 +92,7 @@ abstract class InsertAction(
return
}

WriteCommandAction.runWriteCommandAction(project) {
WriteCommandAction.runWriteCommandAction(project, Bundle("misc.insert_command_name"), null, {
editor.caretModel.allCarets.forEachIndexed { i, caret ->
val start = caret.selectionStart
val end = caret.selectionEnd
Expand All @@ -98,7 +101,7 @@ abstract class InsertAction(
editor.document.replaceString(start, end, data[i])
caret.setSelection(start, newEnd)
}
}
})
}


Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/com/fwdekker/randomness/Notifier.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import com.intellij.notification.NotificationType
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.application.PathManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.startup.StartupActivity
import com.intellij.openapi.startup.ProjectActivity
import com.intellij.openapi.ui.MessageDialogBuilder


/**
* Displays notifications when a project is opened.
*/
class Notifier : StartupActivity {
internal class Notifier : ProjectActivity {
/**
* Shows startup notifications.
*/
override fun runActivity(project: Project) = showWelcomeToV3(project)
override suspend fun execute(project: Project) = showWelcomeToV3(project)

/**
* Shows a notification introducing the user to version 3 of Randomness.
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/fwdekker/randomness/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ data class Settings(
],
category = SettingsCategory.PLUGINS,
)
class PersistentSettings : PersistentStateComponent<Element> {
internal class PersistentSettings : PersistentStateComponent<Element> {
/**
* The [Settings] that should be persisted.
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/fwdekker/randomness/Timely.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object Timely {
try {
return executor.submit<T> { generator() }.get(GENERATOR_TIMEOUT, TimeUnit.MILLISECONDS)
} catch (exception: TimeoutException) {
throw DataGenerationException(Bundle("helpers.error.timed_out"), exception)
throw DataGenerationException(Bundle("misc.timed_out"), exception)
} catch (exception: ExecutionException) {
throw DataGenerationException(exception.cause?.message ?: exception.message, exception)
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ data class StringScheme(
/**
* The default value of the [capitalization] field.
*/
val DEFAULT_CAPITALIZATION get() = CapitalizationMode.RETAIN
val DEFAULT_CAPITALIZATION = CapitalizationMode.RETAIN

/**
* The default value of the [removeLookAlikeSymbols] field.
Expand Down
Loading

0 comments on commit 0cb5449

Please sign in to comment.