diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..0258c52f --- /dev/null +++ b/.editorconfig @@ -0,0 +1,3 @@ +[{*.kt,*.kts}] +disabled_rules = no-wildcard-imports +ij_kotlin_imports_layout = *, java.**, javax.**, kotlin.**, ^ \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 820d252a..56d22aff 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,7 +13,8 @@ # name: Build -on: [ push, pull_request ] + # Trigger the workflow on pushes to only the 'main' branch (this avoids duplicate checks being run e.g. for dependabot pull requests) + on: [ push, pull_request ] jobs: @@ -64,9 +65,9 @@ jobs: - name: Verify Plugin run: ./gradlew verifyPlugin - # Run test Gradle task - - name: Run Tests - run: ./gradlew test + # Run check Gradle task - includes tests + - name: Run Checks + run: ./gradlew check # Build plugin with buildPlugin Gradle task and provide the artifact for the next workflow jobs # Requires test job to be passed diff --git a/build.gradle.kts b/build.gradle.kts index 1ba49d72..81f78cc6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -16,7 +16,7 @@ plugins { // detekt linter - read more: https://detekt.github.io/detekt/kotlindsl.html id("io.gitlab.arturbosch.detekt") version "1.10.0-RC1" // ktlint - id("org.jlleitschuh.gradle.ktlint") version "10.0.0" + id("org.jmailen.kotlinter") version "3.9.0" } group = properties("pluginGroup") @@ -46,6 +46,10 @@ tasks.withType { useJUnitPlatform() } +tasks.check { + dependsOn("installKotlinterPrePushHook") +} + // Configure gradle-intellij-plugin plugin. // Read more: https://github.com/JetBrains/gradle-intellij-plugin intellij { @@ -126,4 +130,11 @@ tasks { useJUnitPlatform() } + kotlinter { + ignoreFailures = false + indentSize = 4 + reporters = arrayOf("checkstyle", "plain") + experimentalRules = false + } + } diff --git a/src/main/kotlin/com/launchdarkly/intellij/FlagStore.kt b/src/main/kotlin/com/launchdarkly/intellij/FlagStore.kt index 1c260adf..ddd0df68 100644 --- a/src/main/kotlin/com/launchdarkly/intellij/FlagStore.kt +++ b/src/main/kotlin/com/launchdarkly/intellij/FlagStore.kt @@ -11,6 +11,7 @@ import com.launchdarkly.api.ApiException import com.launchdarkly.api.model.FeatureFlag import com.launchdarkly.api.model.FeatureFlags import com.launchdarkly.intellij.coderefs.FlagAliases +/* ktlint-disable no-unused-imports */ import com.launchdarkly.intellij.featurestore.* import com.launchdarkly.intellij.messaging.AppDefaultMessageBusService import com.launchdarkly.intellij.messaging.ConfigurationNotifier @@ -26,7 +27,6 @@ import com.launchdarkly.sdk.server.interfaces.FlagChangeListener import java.time.Duration import java.util.concurrent.TimeUnit - /** * Instance to provide other classes access to LaunchDarkly Flag Metadata. * Handles refreshing of the flags and notifying attached listeners of changes. @@ -42,7 +42,6 @@ class FlagStore(private var project: Project) { private val settings = LaunchDarklyMergedSettings.getInstance(project) private var envList = listOf(settings.environment) - /** * This method is gets the latest flags via REST API. * @param project the Intellij project open @@ -89,7 +88,6 @@ class FlagStore(private var project: Project) { * @param project the Intellij project open * @param client {link #com.launchdarkly.sdk.server.LDClient} * @param store {link #com.launchdarkly.sdk.server.interfaces.DataStore} - */ private fun flagListener(client: LDClient, store: DataStore) { val listenForChanges = FlagChangeListener { event -> @@ -164,7 +162,6 @@ class FlagStore(private var project: Project) { ApplicationManager.getApplication().executeOnPooledThread { try { setupStore() - } catch (err: ApiException) { val notify = ConfigNotifier() notify.notify(project, "Project: ${settings.project} Error: $err") @@ -178,7 +175,8 @@ class FlagStore(private var project: Project) { EdtExecutorService.getScheduledExecutorInstance() .scheduleWithFixedDelay({ flags = flagsNotify(rebuild = true) }, refreshRate, refreshRate, TimeUnit.MINUTES) - project.messageBus.connect().subscribe(appBusService.configurationEnabledTopic, + project.messageBus.connect().subscribe( + appBusService.configurationEnabledTopic, object : ConfigurationNotifier { override fun notify(isConfigured: Boolean) { if (isConfigured && !settings.projectOverrides()) { @@ -192,9 +190,11 @@ class FlagStore(private var project: Project) { } } } - }) + } + ) - project.messageBus.connect().subscribe(messageBusService.configurationEnabledTopic, + project.messageBus.connect().subscribe( + messageBusService.configurationEnabledTopic, object : ConfigurationNotifier { override fun notify(isConfigured: Boolean) { if (isConfigured) { @@ -203,7 +203,7 @@ class FlagStore(private var project: Project) { } } } - }) + } + ) } - -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/launchdarkly/intellij/DocumentationProvider.kt b/src/main/kotlin/com/launchdarkly/intellij/LDDocumentationProvider.kt similarity index 99% rename from src/main/kotlin/com/launchdarkly/intellij/DocumentationProvider.kt rename to src/main/kotlin/com/launchdarkly/intellij/LDDocumentationProvider.kt index 4e85c456..65b5243e 100644 --- a/src/main/kotlin/com/launchdarkly/intellij/DocumentationProvider.kt +++ b/src/main/kotlin/com/launchdarkly/intellij/LDDocumentationProvider.kt @@ -164,5 +164,4 @@ class LDDocumentationProvider : AbstractDocumentationProvider() { return null } - -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/launchdarkly/intellij/Icons.kt b/src/main/kotlin/com/launchdarkly/intellij/LDIcons.kt similarity index 99% rename from src/main/kotlin/com/launchdarkly/intellij/Icons.kt rename to src/main/kotlin/com/launchdarkly/intellij/LDIcons.kt index 99e58b29..70526dc9 100644 --- a/src/main/kotlin/com/launchdarkly/intellij/Icons.kt +++ b/src/main/kotlin/com/launchdarkly/intellij/LDIcons.kt @@ -42,6 +42,5 @@ class LDIcons { @JvmField val VARIATION = IconLoader.getIcon("/icons/variation.svg", javaClass) - } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/launchdarkly/intellij/LaunchDarklyApiClient.kt b/src/main/kotlin/com/launchdarkly/intellij/LaunchDarklyApiClient.kt index 7a620ab9..5f6cccbe 100644 --- a/src/main/kotlin/com/launchdarkly/intellij/LaunchDarklyApiClient.kt +++ b/src/main/kotlin/com/launchdarkly/intellij/LaunchDarklyApiClient.kt @@ -11,7 +11,6 @@ import com.launchdarkly.api.auth.ApiKeyAuth import com.launchdarkly.intellij.settings.LaunchDarklyApplicationConfig import com.launchdarkly.intellij.settings.LaunchDarklyMergedSettings - class LaunchDarklyApiClient() { companion object { @@ -24,7 +23,7 @@ class LaunchDarklyApiClient() { val pluginVersion = PluginManagerCore.getPlugin(PluginId.getId("com.github.intheclouddan.intellijpluginld"))?.version ?: "noversion" client.setUserAgent("launchdarkly-intellij/$pluginVersion") - client.basePath = "${ldBaseUri}/api/v2" + client.basePath = "$ldBaseUri/api/v2" val token = client.getAuthentication("Token") as ApiKeyAuth token.apiKey = ldApiKey @@ -41,11 +40,10 @@ class LaunchDarklyApiClient() { val pluginVersion = PluginManagerCore.getPlugin(PluginId.getId("com.github.intheclouddan.intellijpluginld"))?.version ?: "noversion" client.setUserAgent("launchdarkly-intellij/$pluginVersion") - client.basePath = "${ldBaseUri}/api/v2" + client.basePath = "$ldBaseUri/api/v2" val token = client.getAuthentication("Token") as ApiKeyAuth token.apiKey = ldApiKey return ProjectsApi() } } - -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/launchdarkly/intellij/action/ChangeFallthroughAction.kt b/src/main/kotlin/com/launchdarkly/intellij/action/ChangeFallthroughAction.kt index 13f24e02..03b79730 100644 --- a/src/main/kotlin/com/launchdarkly/intellij/action/ChangeFallthroughAction.kt +++ b/src/main/kotlin/com/launchdarkly/intellij/action/ChangeFallthroughAction.kt @@ -101,7 +101,6 @@ class ChangeFallthroughAction : AnAction { } .createPopup() .showUnderneathOf(currentComponent) - } /** @@ -121,4 +120,4 @@ class ChangeFallthroughAction : AnAction { } } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/launchdarkly/intellij/action/ChangeOffVariationAction.kt b/src/main/kotlin/com/launchdarkly/intellij/action/ChangeOffVariationAction.kt index 608efc24..af9f9c3b 100644 --- a/src/main/kotlin/com/launchdarkly/intellij/action/ChangeOffVariationAction.kt +++ b/src/main/kotlin/com/launchdarkly/intellij/action/ChangeOffVariationAction.kt @@ -101,7 +101,6 @@ class ChangeOffVariationAction : AnAction { } .createPopup() .showUnderneathOf(currentComponent) - } /** @@ -121,4 +120,4 @@ class ChangeOffVariationAction : AnAction { } } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/launchdarkly/intellij/action/CopyKeyAction.kt b/src/main/kotlin/com/launchdarkly/intellij/action/CopyKeyAction.kt index d5183ddc..0f0ec1cf 100644 --- a/src/main/kotlin/com/launchdarkly/intellij/action/CopyKeyAction.kt +++ b/src/main/kotlin/com/launchdarkly/intellij/action/CopyKeyAction.kt @@ -3,17 +3,14 @@ package com.launchdarkly.intellij.action import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.components.service -import com.launchdarkly.intellij.toolwindow.FlagNodeBase import com.launchdarkly.intellij.toolwindow.FlagNodeParent import com.launchdarkly.intellij.toolwindow.FlagToolWindow -import com.launchdarkly.intellij.toolwindow.InfoNode import java.awt.Toolkit import java.awt.datatransfer.Clipboard import java.awt.datatransfer.StringSelection import javax.swing.Icon import javax.swing.tree.DefaultMutableTreeNode - const val FLAG_NAME_DEPTH = 1 const val FLAG_NAME_PATH = 2 @@ -76,7 +73,8 @@ class CopyKeyAction : AnAction { if (project != null) { if (project.service().getPanel().tree.lastSelectedPathComponent != null) { val selectedNode = - project.service().getPanel().tree.lastSelectedPathComponent as DefaultMutableTreeNode + project.service() + .getPanel().tree.lastSelectedPathComponent as DefaultMutableTreeNode val isFlagParentNode = selectedNode.userObject as? FlagNodeParent e.presentation.isEnabledAndVisible = @@ -86,4 +84,4 @@ class CopyKeyAction : AnAction { e.presentation.isEnabledAndVisible = false } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/launchdarkly/intellij/action/OpenInBrowserAction.kt b/src/main/kotlin/com/launchdarkly/intellij/action/OpenInBrowserAction.kt index 5c6d664a..f88607cd 100644 --- a/src/main/kotlin/com/launchdarkly/intellij/action/OpenInBrowserAction.kt +++ b/src/main/kotlin/com/launchdarkly/intellij/action/OpenInBrowserAction.kt @@ -4,11 +4,10 @@ import com.intellij.ide.browsers.BrowserLauncher import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.components.service +import com.launchdarkly.intellij.notifications.GeneralNotifier import com.launchdarkly.intellij.settings.LaunchDarklyMergedSettings import com.launchdarkly.intellij.toolwindow.FlagNodeParent import com.launchdarkly.intellij.toolwindow.FlagToolWindow -import com.launchdarkly.intellij.notifications.GeneralNotifier -import com.launchdarkly.intellij.toolwindow.FlagNodeBase import javax.swing.Icon import javax.swing.tree.DefaultMutableTreeNode @@ -55,18 +54,17 @@ class OpenInBrowserAction : AnAction { project.service().getPanel().tree.lastSelectedPathComponent as DefaultMutableTreeNode // If cast fails, it means the root node with project/env info was selected, so we'll open that. val nodeInfo: FlagNodeParent? = selectedNode.userObject as? FlagNodeParent - if (nodeInfo != null) { - val url = "${settings.baseUri}/${settings.project}/${settings.environment}/features/${nodeInfo.flag.key}" - BrowserLauncher.instance.open(url) - } else { - val url = "${settings.baseUri}/${settings.project}/${settings.environment}/features" - BrowserLauncher.instance.open(url) - } + if (nodeInfo != null) { + val url = "${settings.baseUri}/${settings.project}/${settings.environment}/features/${nodeInfo.flag.key}" + BrowserLauncher.instance.open(url) + } else { + val url = "${settings.baseUri}/${settings.project}/${settings.environment}/features" + BrowserLauncher.instance.open(url) + } } else { val notifier = GeneralNotifier() notifier.notify(project, "Error opening in browser, please try again.") } - } /** @@ -86,4 +84,4 @@ class OpenInBrowserAction : AnAction { } } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/launchdarkly/intellij/action/RefreshAction.kt b/src/main/kotlin/com/launchdarkly/intellij/action/RefreshAction.kt index f38e230d..944bd721 100644 --- a/src/main/kotlin/com/launchdarkly/intellij/action/RefreshAction.kt +++ b/src/main/kotlin/com/launchdarkly/intellij/action/RefreshAction.kt @@ -6,7 +6,6 @@ import com.intellij.openapi.components.service import com.launchdarkly.intellij.FlagStore import javax.swing.Icon - /** * Action class to demonstrate how to interact with the IntelliJ Platform. * The only action this class performs is to provide the user with a popup dialog as feedback. @@ -59,4 +58,4 @@ class RefreshAction : AnAction { val project = e.project e.presentation.isEnabledAndVisible = project != null } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/launchdarkly/intellij/action/RunCoderefsAction.kt b/src/main/kotlin/com/launchdarkly/intellij/action/RunCoderefsAction.kt index 7a6a538b..67df1733 100644 --- a/src/main/kotlin/com/launchdarkly/intellij/action/RunCoderefsAction.kt +++ b/src/main/kotlin/com/launchdarkly/intellij/action/RunCoderefsAction.kt @@ -50,11 +50,11 @@ class RunCoderefsAction : AnAction { val projectPath = project.basePath val tmpDir = FileUtilRt.createTempDirectory("ld-", null) val commands = arrayListOf("") - val aliasFile = "${tmpDir}/coderefs_temp_file_scan.csv" + val aliasFile = "$tmpDir/coderefs_temp_file_scan.csv" commands.add("ld-find-code-refs") - commands.add("--dir=${projectPath}") + commands.add("--dir=$projectPath") commands.add("--dryRun") - commands.add("--outDir=${tmpDir}") + commands.add("--outDir=$tmpDir") commands.add("--repoName=CHANGEME") commands.add("--projectKey=${project.name}") commands.add("--baseUri=CHANGEME") @@ -65,9 +65,8 @@ class RunCoderefsAction : AnAction { val procEnv = mapOf("LD_ACCESS_TOKEN" to "test", "GOMAXPROCS" to "1") generalCommandLine.withEnvironment(procEnv) generalCommandLine.setCharset(Charset.forName("UTF-8")) - //generalCommandLine.setWorkDirectory() + // generalCommandLine.setWorkDirectory() val snykResultJsonStr = ScriptRunnerUtil.getProcessOutput(generalCommandLine) - } /** @@ -87,4 +86,4 @@ class RunCoderefsAction : AnAction { } } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/launchdarkly/intellij/action/ToggleFlagAction.kt b/src/main/kotlin/com/launchdarkly/intellij/action/ToggleFlagAction.kt index d4644fd4..38b59e45 100644 --- a/src/main/kotlin/com/launchdarkly/intellij/action/ToggleFlagAction.kt +++ b/src/main/kotlin/com/launchdarkly/intellij/action/ToggleFlagAction.kt @@ -77,7 +77,6 @@ class ToggleFlagAction : AnAction { e.printStackTrace() } } - } } @@ -100,4 +99,4 @@ class ToggleFlagAction : AnAction { } } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/launchdarkly/intellij/codeInsight/FlagJavaCompletion.kt b/src/main/kotlin/com/launchdarkly/intellij/codeInsight/JavaCompletionContributor.kt similarity index 97% rename from src/main/kotlin/com/launchdarkly/intellij/codeInsight/FlagJavaCompletion.kt rename to src/main/kotlin/com/launchdarkly/intellij/codeInsight/JavaCompletionContributor.kt index c9045951..8d8b0e5e 100644 --- a/src/main/kotlin/com/launchdarkly/intellij/codeInsight/FlagJavaCompletion.kt +++ b/src/main/kotlin/com/launchdarkly/intellij/codeInsight/JavaCompletionContributor.kt @@ -84,7 +84,8 @@ class JavaCompletionContributor : CompletionContributor() { } init { - extend(CompletionType.BASIC, + extend( + CompletionType.BASIC, psiElement().andOr(FLAG_KEY_BOOL, FLAG_KEY_BOOL_DETAILS), object : CompletionProvider() { override fun addCompletions( @@ -105,7 +106,8 @@ class JavaCompletionContributor : CompletionContributor() { } } ) - extend(CompletionType.BASIC, + extend( + CompletionType.BASIC, psiElement().andOr(FLAG_KEY_STRING, FLAG_KEY_STRING_DETAILS), object : CompletionProvider() { override fun addCompletions( @@ -126,7 +128,8 @@ class JavaCompletionContributor : CompletionContributor() { } } ) - extend(CompletionType.BASIC, + extend( + CompletionType.BASIC, psiElement().andOr(FLAG_KEY_JSON, FLAG_KEY_JSON_DETAILS), object : CompletionProvider() { override fun addCompletions( @@ -147,6 +150,5 @@ class JavaCompletionContributor : CompletionContributor() { } } ) - } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/launchdarkly/intellij/coderefs/CodeRefs.kt b/src/main/kotlin/com/launchdarkly/intellij/coderefs/CodeRefs.kt index f2edc0db..292101c9 100644 --- a/src/main/kotlin/com/launchdarkly/intellij/coderefs/CodeRefs.kt +++ b/src/main/kotlin/com/launchdarkly/intellij/coderefs/CodeRefs.kt @@ -18,7 +18,6 @@ import java.net.URL import java.nio.file.Path import java.nio.file.Paths - class CodeRefs { val codeRefsVerion = "2.4.0" val codeRefsPath = PathManager.getPluginsPath() + "/intellij-plugin-ld/bin/coderefs/" @@ -26,9 +25,12 @@ class CodeRefs { fun downloadCodeRefs(project: Project? = null): DownloadResult { val result = ProgressManager.getInstance() - .runProcessWithProgressSynchronously(ThrowableComputable { - downloadCodeRefsSynchronously() - }, "Download LaunchDarkly CodeRefs", true, project) + .runProcessWithProgressSynchronously( + ThrowableComputable { + downloadCodeRefsSynchronously() + }, + "Download LaunchDarkly CodeRefs", true, project + ) when (result) { is DownloadResult.Ok -> { @@ -121,13 +123,13 @@ class CodeRefs { private val codeRefsUrl: URL get() { return when { - SystemInfo.isMac -> URL("https://github.com/launchdarkly/ld-find-code-refs/releases/download/${codeRefsVerion}/ld-find-code-refs_${codeRefsVerion}_darwin_amd64.tar.gz") - SystemInfo.isLinux -> URL("https://github.com/launchdarkly/ld-find-code-refs/releases/download/${codeRefsVerion}/ld-find-code-refs_${codeRefsVerion}_linux_amd64.tar.gz") + SystemInfo.isMac -> URL("https://github.com/launchdarkly/ld-find-code-refs/releases/download/$codeRefsVerion/ld-find-code-refs_${codeRefsVerion}_darwin_amd64.tar.gz") + SystemInfo.isLinux -> URL("https://github.com/launchdarkly/ld-find-code-refs/releases/download/$codeRefsVerion/ld-find-code-refs_${codeRefsVerion}_linux_amd64.tar.gz") SystemInfo.isWindows -> { if (CpuArch.isIntel64()) { - URL("https://github.com/launchdarkly/ld-find-code-refs/releases/download/${codeRefsVerion}/ld-find-code-refs_${codeRefsVerion}_windows_amd64.tar.gz") + URL("https://github.com/launchdarkly/ld-find-code-refs/releases/download/$codeRefsVerion/ld-find-code-refs_${codeRefsVerion}_windows_amd64.tar.gz") } else { - URL("https://github.com/launchdarkly/ld-find-code-refs/releases/download/${codeRefsVerion}/ld-find-code-refs_${codeRefsVerion}_windows_386.tar.gz") + URL("https://github.com/launchdarkly/ld-find-code-refs/releases/download/$codeRefsVerion/ld-find-code-refs_${codeRefsVerion}_windows_386.tar.gz") } } else -> return URL("") @@ -138,5 +140,4 @@ class CodeRefs { class Ok(val crDir: File) : DownloadResult() object Failed : DownloadResult() } - -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/launchdarkly/intellij/coderefs/FlagAliases.kt b/src/main/kotlin/com/launchdarkly/intellij/coderefs/FlagAliases.kt index 005721e6..eb820996 100644 --- a/src/main/kotlin/com/launchdarkly/intellij/coderefs/FlagAliases.kt +++ b/src/main/kotlin/com/launchdarkly/intellij/coderefs/FlagAliases.kt @@ -16,7 +16,6 @@ import java.io.File import java.nio.charset.Charset import java.util.concurrent.TimeUnit - @Service class FlagAliases(private var project: Project) { var aliases = mutableMapOf() @@ -27,7 +26,7 @@ class FlagAliases(private var project: Project) { csvReader().open(file) { readAllWithHeaderAsSequence().forEach { row: Map -> if (row["aliases"] !== "") { - //aliases.set(row["aliases"], row["flagKey"]) + // aliases.set(row["aliases"], row["flagKey"]) aliases[row["aliases"]!!] = row["flagKey"]!! } } @@ -71,15 +70,13 @@ class FlagAliases(private var project: Project) { readAliases(aliasPath) break } - Runtime.getRuntime().addShutdownHook(Thread(process::destroy)); + Runtime.getRuntime().addShutdownHook(Thread(process::destroy)) } catch (exception: ExecutionException) { println(exception) } - } catch (err: Exception) { println(err) } - } fun checkCodeRefs(): Boolean { @@ -118,4 +115,4 @@ class FlagAliases(private var project: Project) { } } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/launchdarkly/intellij/featurestore/DataStoreFactoryWithStoreAccess.kt b/src/main/kotlin/com/launchdarkly/intellij/featurestore/DataStoreFactoryWithStoreAccess.kt index 4c0dddbf..5e535f7e 100644 --- a/src/main/kotlin/com/launchdarkly/intellij/featurestore/DataStoreFactoryWithStoreAccess.kt +++ b/src/main/kotlin/com/launchdarkly/intellij/featurestore/DataStoreFactoryWithStoreAccess.kt @@ -13,7 +13,6 @@ import com.launchdarkly.sdk.server.interfaces.DataStoreTypes.KeyedItems import com.launchdarkly.sdk.server.interfaces.DataStoreUpdates import java.util.* - // This class allows us to access the LDClient's DataStore directly after the client has been created. // It assumes that you do not create more than one client instance per instance of this class. class DataStoreFactoryWithStoreAccess internal constructor(underlyingFactory: DataStoreFactory) : DataStoreFactory { @@ -81,4 +80,4 @@ fun getFlagsAsJSONStrings(store: DataStore): List? { fun getFlagAsJSONString(store: DataStore, flagKey: String): String { val item: ItemDescriptor = store.get(DataModel.FEATURES, flagKey) return DataModel.FEATURES.serialize(item) -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/launchdarkly/intellij/featurestore/FlagConfiguration.kt b/src/main/kotlin/com/launchdarkly/intellij/featurestore/FlagConfiguration.kt index a16d16f4..7e1ba8e0 100644 --- a/src/main/kotlin/com/launchdarkly/intellij/featurestore/FlagConfiguration.kt +++ b/src/main/kotlin/com/launchdarkly/intellij/featurestore/FlagConfiguration.kt @@ -14,4 +14,4 @@ data class FlagConfiguration( var rules: Array, var on: Boolean, var version: Number -) \ No newline at end of file +) diff --git a/src/main/kotlin/com/launchdarkly/intellij/messaging/AppConfiguration.kt b/src/main/kotlin/com/launchdarkly/intellij/messaging/AppConfiguration.kt index 6a8342cd..3f00cb1b 100644 --- a/src/main/kotlin/com/launchdarkly/intellij/messaging/AppConfiguration.kt +++ b/src/main/kotlin/com/launchdarkly/intellij/messaging/AppConfiguration.kt @@ -22,4 +22,4 @@ class AppDefaultMessageBusService : MessageBusService { "LD_APP_FLAGS_UPDATED", FlagNotifier::class.java ) -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/launchdarkly/intellij/messaging/Configuration.kt b/src/main/kotlin/com/launchdarkly/intellij/messaging/Configuration.kt index ba88e0f8..a2a9c341 100644 --- a/src/main/kotlin/com/launchdarkly/intellij/messaging/Configuration.kt +++ b/src/main/kotlin/com/launchdarkly/intellij/messaging/Configuration.kt @@ -15,7 +15,6 @@ interface MessageBusService { val configurationEnabledTopic: Topic val flagsUpdatedTopic: Topic - } @Service @@ -31,4 +30,4 @@ class DefaultMessageBusService : MessageBusService { "LD_FLAGS_UPDATED", FlagNotifier::class.java ) -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/launchdarkly/intellij/messaging/FlagNotification.kt b/src/main/kotlin/com/launchdarkly/intellij/messaging/FlagNotifier.kt similarity index 99% rename from src/main/kotlin/com/launchdarkly/intellij/messaging/FlagNotification.kt rename to src/main/kotlin/com/launchdarkly/intellij/messaging/FlagNotifier.kt index 689a2598..65871a96 100644 --- a/src/main/kotlin/com/launchdarkly/intellij/messaging/FlagNotification.kt +++ b/src/main/kotlin/com/launchdarkly/intellij/messaging/FlagNotifier.kt @@ -4,4 +4,3 @@ interface FlagNotifier { fun notify(isConfigured: Boolean, flag: String = "", rebuild: Boolean = false) fun reinit() } - diff --git a/src/main/kotlin/com/launchdarkly/intellij/notifications/ConfigNotifier.kt b/src/main/kotlin/com/launchdarkly/intellij/notifications/ConfigNotifier.kt index ef65c8b7..3136b172 100644 --- a/src/main/kotlin/com/launchdarkly/intellij/notifications/ConfigNotifier.kt +++ b/src/main/kotlin/com/launchdarkly/intellij/notifications/ConfigNotifier.kt @@ -12,4 +12,4 @@ class ConfigNotifier { notification.notify(project) return notification } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/launchdarkly/intellij/notifications/GeneralNotifier.kt b/src/main/kotlin/com/launchdarkly/intellij/notifications/GeneralNotifier.kt index 35aff86f..3e75b6bc 100644 --- a/src/main/kotlin/com/launchdarkly/intellij/notifications/GeneralNotifier.kt +++ b/src/main/kotlin/com/launchdarkly/intellij/notifications/GeneralNotifier.kt @@ -12,4 +12,4 @@ class GeneralNotifier { notification.notify(project) return notification } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/launchdarkly/intellij/settings/LDSettingsInt.kt b/src/main/kotlin/com/launchdarkly/intellij/settings/LDSettings.kt similarity index 99% rename from src/main/kotlin/com/launchdarkly/intellij/settings/LDSettingsInt.kt rename to src/main/kotlin/com/launchdarkly/intellij/settings/LDSettings.kt index 811de244..321c01c2 100644 --- a/src/main/kotlin/com/launchdarkly/intellij/settings/LDSettingsInt.kt +++ b/src/main/kotlin/com/launchdarkly/intellij/settings/LDSettings.kt @@ -11,4 +11,4 @@ interface LDSettings { var codeReferencesRefreshRate: Int fun isConfigured(): Boolean -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/launchdarkly/intellij/settings/LaunchDarklyApplicationSettings.kt b/src/main/kotlin/com/launchdarkly/intellij/settings/LaunchDarklyApplicationSettings.kt index b3826775..bf3ea5b2 100644 --- a/src/main/kotlin/com/launchdarkly/intellij/settings/LaunchDarklyApplicationSettings.kt +++ b/src/main/kotlin/com/launchdarkly/intellij/settings/LaunchDarklyApplicationSettings.kt @@ -65,7 +65,6 @@ open class LaunchDarklyApplicationConfig : PersistentStateComponent { val projectApi = LaunchDarklyApiClient.projectInstance(null, apiKey, baseUri) return projectApi.projects.items.sortedBy { it.key } as MutableList } - } diff --git a/src/main/kotlin/com/launchdarkly/intellij/settings/LaunchDarklyMergedSettings.kt b/src/main/kotlin/com/launchdarkly/intellij/settings/LaunchDarklyMergedSettings.kt index 9e42c69f..86084fc9 100644 --- a/src/main/kotlin/com/launchdarkly/intellij/settings/LaunchDarklyMergedSettings.kt +++ b/src/main/kotlin/com/launchdarkly/intellij/settings/LaunchDarklyMergedSettings.kt @@ -1,6 +1,5 @@ package com.launchdarkly.intellij.settings -import com.intellij.openapi.components.ServiceManager import com.intellij.openapi.project.Project class LaunchDarklyMergedSettings(private val myProject: Project) : LDSettings { @@ -68,15 +67,15 @@ class LaunchDarklyMergedSettings(private val myProject: Project) : LDSettings { * Check if project is using application defaults. */ fun projectOverrides(): Boolean { - if (projSettings.ldState.credName.isNotEmpty() - || projSettings.ldState.authorization.isNotEmpty() - || projSettings.ldState.refreshRate != -1 - || projSettings.ldState.environment.isNotEmpty() - || projSettings.ldState.project.isNotEmpty() - || projSettings.ldState.baseUri.isNotEmpty() + if (projSettings.ldState.credName.isNotEmpty() || + projSettings.ldState.authorization.isNotEmpty() || + projSettings.ldState.refreshRate != -1 || + projSettings.ldState.environment.isNotEmpty() || + projSettings.ldState.project.isNotEmpty() || + projSettings.ldState.baseUri.isNotEmpty() ) { return true } return false } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/launchdarkly/intellij/settings/LaunchDarklySettings.kt b/src/main/kotlin/com/launchdarkly/intellij/settings/LaunchDarklySettings.kt index e6fc3a92..2b58ce7e 100644 --- a/src/main/kotlin/com/launchdarkly/intellij/settings/LaunchDarklySettings.kt +++ b/src/main/kotlin/com/launchdarkly/intellij/settings/LaunchDarklySettings.kt @@ -12,11 +12,11 @@ import com.intellij.ui.SimpleListCellRenderer import com.intellij.ui.dsl.builder.* import com.launchdarkly.api.ApiException import com.launchdarkly.api.model.Environment -import com.launchdarkly.api.model.Project as LDProject import com.launchdarkly.intellij.LaunchDarklyApiClient import com.launchdarkly.intellij.messaging.DefaultMessageBusService import javax.swing.DefaultComboBoxModel import javax.swing.JPanel +import com.launchdarkly.api.model.Project as LDProject /* * Maintain state of what LaunchDarkly Project to connect to. @@ -79,7 +79,8 @@ open class LaunchDarklyConfig(val project: Project) : PersistentStateComponent() private val mergedSettings = project.service() private val settings = LaunchDarklyConfig.getInstance(project).ldState @@ -163,7 +163,6 @@ class LaunchDarklyConfigurable(private val project: Project) : BoundConfigurable envUpdatedSelection = true } } - } catch (err: Exception) { println(err) } @@ -283,7 +282,6 @@ class LaunchDarklyConfigurable(private val project: Project) : BoundConfigurable publisher.notify(true) println("notifying") } - } private fun getProjects(apiKey: String?, baseUri: String?): MutableList { @@ -310,5 +308,4 @@ class LaunchDarklyConfigurable(private val project: Project) : BoundConfigurable tempProj.environments = listOf(tempEnv) return tempProj } - -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/launchdarkly/intellij/toolwindow/FlagNode.kt b/src/main/kotlin/com/launchdarkly/intellij/toolwindow/FlagNode.kt index 3c86a1bb..dc7144af 100644 --- a/src/main/kotlin/com/launchdarkly/intellij/toolwindow/FlagNode.kt +++ b/src/main/kotlin/com/launchdarkly/intellij/toolwindow/FlagNode.kt @@ -16,7 +16,7 @@ class RootNode(private val flags: FeatureFlags, private val settings: LDSettings override fun getChildren(): Array { when { myChildren.isEmpty() && flags.items != null -> { - myChildren.add(InfoNode("${settings.project} / ${settings.environment}", )) + myChildren.add(InfoNode("${settings.project} / ${settings.environment}",)) for (flag in flags.items) { myChildren.add(FlagNodeParent(flag, flags, intProject)) } @@ -32,7 +32,6 @@ class RootNode(private val flags: FeatureFlags, private val settings: LDSettings super.update(data) data.presentableText = "root" } - } class FlagNodeVariations(private var flag: FeatureFlag) : SimpleNode() { @@ -76,7 +75,6 @@ class FlagNodeTags(tags: List) : SimpleNode() { var tags: List = tags private var myChildren: MutableList = ArrayList() - override fun getChildren(): Array { for (tag in tags) { myChildren.add(FlagNodeBase(tag)) @@ -124,7 +122,6 @@ class FlagNodeRollout(private var rollout: Rollout, private var variations: List for (variation in rollout.variations) { myChildren.add(FlagNodeBase("Variation: ${variations[variation.variation].name ?: variations[variation.variation].value}")) myChildren.add(FlagNodeBase("Weight: ${variation.weight / 1000.0}%")) - } return myChildren.toTypedArray() } @@ -198,4 +195,4 @@ class FlagNodeTargets(private var flag: FeatureFlag, private var targets: List { if (children.isEmpty()) { buildChildren() @@ -40,11 +39,11 @@ class FlagNodeParent(FFlag: FeatureFlag, private var flags: FeatureFlags, myProj if (env.rules.isNotEmpty()) children.add(FlagNodeBase("Rules: ${env.rules.size}", LDIcons.RULES)) if (env.fallthrough != null) children.add(FlagNodeFallthrough(flag, env)) if (env.offVariation != null) children.add( - FlagNodeBase( - "Off Variation: ${flag.variations[env.offVariation as Int].name ?: flag.variations[env.offVariation as Int].value}", - LDIcons.OFF_VARIATION - ) + FlagNodeBase( + "Off Variation: ${flag.variations[env.offVariation as Int].name ?: flag.variations[env.offVariation as Int].value}", + LDIcons.OFF_VARIATION ) + ) if (flag.tags.size > 0) children.add(FlagNodeTags(flag.tags)) } @@ -60,4 +59,4 @@ class FlagNodeParent(FFlag: FeatureFlag, private var flags: FeatureFlags, myProj data.presentableText = label data.setIcon(enabledIcon) } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/launchdarkly/intellij/toolwindow/FlagPanel.kt b/src/main/kotlin/com/launchdarkly/intellij/toolwindow/FlagPanel.kt index b45c2ff4..90e6d427 100644 --- a/src/main/kotlin/com/launchdarkly/intellij/toolwindow/FlagPanel.kt +++ b/src/main/kotlin/com/launchdarkly/intellij/toolwindow/FlagPanel.kt @@ -31,7 +31,6 @@ import javax.swing.tree.DefaultMutableTreeNode import javax.swing.tree.TreePath import javax.swing.tree.TreeSelectionModel - private const val SPLITTER_PROPERTY = "BuildAttribution.Splitter.Proportion" /* @@ -110,7 +109,8 @@ class FlagPanel(private val myProject: Project, messageBusService: MessageBusSer add(changeFallthroughAction) add(changeOffVariationAction) }, - ActionPlaces.POPUP) + ActionPlaces.POPUP + ) } fun updateNode(event: String) { @@ -141,7 +141,6 @@ class FlagPanel(private val myProject: Project, messageBusService: MessageBusSer } break } - } else { continue } @@ -207,7 +206,8 @@ class FlagPanel(private val myProject: Project, messageBusService: MessageBusSer start = true } try { - myProject.messageBus.connect().subscribe(messageBusService.flagsUpdatedTopic, + myProject.messageBus.connect().subscribe( + messageBusService.flagsUpdatedTopic, object : FlagNotifier { override fun notify(isConfigured: Boolean, flag: String, rebuild: Boolean) { if (isConfigured) { @@ -250,10 +250,11 @@ class FlagPanel(private val myProject: Project, messageBusService: MessageBusSer updateNodeInfo() } } - }) + } + ) } catch (err: Error) { println(err) println("something went wrong") } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/launchdarkly/intellij/toolwindow/FlagToolWindow.kt b/src/main/kotlin/com/launchdarkly/intellij/toolwindow/FlagToolWindow.kt index dd990d32..7991a31e 100644 --- a/src/main/kotlin/com/launchdarkly/intellij/toolwindow/FlagToolWindow.kt +++ b/src/main/kotlin/com/launchdarkly/intellij/toolwindow/FlagToolWindow.kt @@ -1,7 +1,6 @@ package com.launchdarkly.intellij.toolwindow import com.intellij.openapi.Disposable -import com.intellij.openapi.components.ServiceManager import com.intellij.openapi.components.service import com.intellij.openapi.project.DumbAware import com.intellij.openapi.project.Project @@ -35,5 +34,4 @@ class FlagToolWindow(project: Project) : DumbAware, Disposable { } override fun dispose() {} - } diff --git a/src/main/kotlin/com/launchdarkly/intellij/toolwindow/FlagToolWindowFactory.kt b/src/main/kotlin/com/launchdarkly/intellij/toolwindow/FlagToolWindowFactory.kt index 24430ba1..162f17bd 100644 --- a/src/main/kotlin/com/launchdarkly/intellij/toolwindow/FlagToolWindowFactory.kt +++ b/src/main/kotlin/com/launchdarkly/intellij/toolwindow/FlagToolWindowFactory.kt @@ -4,12 +4,9 @@ import com.intellij.openapi.project.Project import com.intellij.openapi.wm.ToolWindow import com.intellij.openapi.wm.ToolWindowFactory - class FlagToolWindowFactory : ToolWindowFactory { override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) { val flagExplorer = FlagToolWindow.getInstance(project) flagExplorer.initializePanel(toolWindow) - } - -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/launchdarkly/intellij/toolwindow/FlagTreeSearch.kt b/src/main/kotlin/com/launchdarkly/intellij/toolwindow/FlagTreeSearch.kt index 0d03f554..9b9c1702 100644 --- a/src/main/kotlin/com/launchdarkly/intellij/toolwindow/FlagTreeSearch.kt +++ b/src/main/kotlin/com/launchdarkly/intellij/toolwindow/FlagTreeSearch.kt @@ -8,12 +8,12 @@ import javax.swing.tree.TreePath class FlagTreeSearch(tree: JTree) : TreeSpeedSearch(tree) { override fun getElementText(element: Any?): String? { val path: TreePath = element as TreePath - val node = path.getLastPathComponent() as DefaultMutableTreeNode; - val flagNode = node.userObject; + val node = path.getLastPathComponent() as DefaultMutableTreeNode + val flagNode = node.userObject if (flagNode is FlagNodeParent) { return flagNode.key + " " + flagNode.toString() } else { return flagNode.toString() } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/launchdarkly/intellij/toolwindow/FlagTreeStructure.kt b/src/main/kotlin/com/launchdarkly/intellij/toolwindow/FlagTreeStructure.kt index 9a56db57..d5f028d8 100644 --- a/src/main/kotlin/com/launchdarkly/intellij/toolwindow/FlagTreeStructure.kt +++ b/src/main/kotlin/com/launchdarkly/intellij/toolwindow/FlagTreeStructure.kt @@ -4,7 +4,6 @@ import com.intellij.openapi.project.Project import com.intellij.ui.treeStructure.SimpleNode import com.intellij.ui.treeStructure.SimpleTreeStructure - class FlagTreeStructure(private val myProject: Project, private val myRootElement: SimpleNode) : SimpleTreeStructure() { override fun getRootElement(): SimpleNode { return myRootElement @@ -13,4 +12,4 @@ class FlagTreeStructure(private val myProject: Project, private val myRootElemen override fun isToBuildChildrenInBackground(element: Any): Boolean { return true } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/launchdarkly/intellij/toolwindow/InfoNode.kt b/src/main/kotlin/com/launchdarkly/intellij/toolwindow/InfoNode.kt index f2de3a99..23b5a98d 100644 --- a/src/main/kotlin/com/launchdarkly/intellij/toolwindow/InfoNode.kt +++ b/src/main/kotlin/com/launchdarkly/intellij/toolwindow/InfoNode.kt @@ -15,4 +15,4 @@ class InfoNode(var label: String) : SimpleNode() { data.tooltip = label data.setIcon(LDIcons.LOGO) } -} \ No newline at end of file +} diff --git a/src/test/kotlin/com/launchdarkly/intellij/toolwindow/FlagNodeBaseTest.kt b/src/test/kotlin/com/launchdarkly/intellij/toolwindow/FlagNodeBaseTest.kt index 3d3bcbbd..3420fe45 100644 --- a/src/test/kotlin/com/launchdarkly/intellij/toolwindow/FlagNodeBaseTest.kt +++ b/src/test/kotlin/com/launchdarkly/intellij/toolwindow/FlagNodeBaseTest.kt @@ -1,8 +1,7 @@ package com.launchdarkly.intellij.toolwindow -import org.junit.jupiter.api.Test - import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Test internal class FlagNodeBaseTest { private val testBase: FlagNodeBase = FlagNodeBase(label = "Test") @@ -17,4 +16,4 @@ internal class FlagNodeBaseTest { val expected = "Test" assertEquals(expected, testBase.label) } -} \ No newline at end of file +} diff --git a/src/test/kotlin/com/launchdarkly/intellij/toolwindow/FlagNodeTargetsTest.kt b/src/test/kotlin/com/launchdarkly/intellij/toolwindow/FlagNodeTargetsTest.kt index a5198a3a..6a5b7240 100644 --- a/src/test/kotlin/com/launchdarkly/intellij/toolwindow/FlagNodeTargetsTest.kt +++ b/src/test/kotlin/com/launchdarkly/intellij/toolwindow/FlagNodeTargetsTest.kt @@ -3,9 +3,8 @@ package com.launchdarkly.intellij.toolwindow import com.launchdarkly.api.model.FeatureFlag import com.launchdarkly.api.model.Target import com.launchdarkly.api.model.Variation -import org.junit.jupiter.api.Test - import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Test internal class FlagNodeTargetsTest { @@ -29,9 +28,11 @@ internal class FlagNodeTargetsTest { val flag = FeatureFlag().apply { key = "test" name = "test" - variations = listOf(Variation().apply { - value = false - }) + variations = listOf( + Variation().apply { + value = false + } + ) } val target = Target().apply { variation = 0 @@ -53,7 +54,7 @@ internal class FlagNodeTargetsTest { assertEquals(targets.size, testTargets.childCount) } - private fun createFlag(flagKey: String ="test"): FeatureFlag { + private fun createFlag(flagKey: String = "test"): FeatureFlag { val flag = FeatureFlag().apply { key = flagKey name = flagKey @@ -72,7 +73,6 @@ internal class FlagNodeTargetsTest { return flag } - private fun createTargets(): List { val target1 = Target().apply { variation = 0 @@ -86,4 +86,4 @@ internal class FlagNodeTargetsTest { return listOf(target1, target2) } -} \ No newline at end of file +}