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

Add Linter #13

Closed
wants to merge 11 commits into from
Closed
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
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[{*.kt,*.kts}]
disabled_rules = no-wildcard-imports
ij_kotlin_imports_layout = *, java.**, javax.**, kotlin.**, ^
9 changes: 5 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -46,6 +46,10 @@ tasks.withType<Test> {
useJUnitPlatform()
}

tasks.check {
dependsOn("installKotlinterPrePushHook")
}

// Configure gradle-intellij-plugin plugin.
// Read more: https://github.com/JetBrains/gradle-intellij-plugin
intellij {
Expand Down Expand Up @@ -126,4 +130,11 @@ tasks {
useJUnitPlatform()
}

kotlinter {
ignoreFailures = false
indentSize = 4
reporters = arrayOf("checkstyle", "plain")
experimentalRules = false
}

}
20 changes: 10 additions & 10 deletions src/main/kotlin/com/launchdarkly/intellij/FlagStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an upstream comment on an open issue: pinterest/ktlint#1277 (comment)

Without this disable line the import on line 15 will be removed.

import com.launchdarkly.intellij.featurestore.*
import com.launchdarkly.intellij.messaging.AppDefaultMessageBusService
import com.launchdarkly.intellij.messaging.ConfigurationNotifier
Expand All @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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 ->
Expand Down Expand Up @@ -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")
Expand All @@ -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()) {
Expand All @@ -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) {
Expand All @@ -203,7 +203,7 @@ class FlagStore(private var project: Project) {
}
}
}
})
}
)
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,4 @@ class LDDocumentationProvider : AbstractDocumentationProvider() {

return null
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,5 @@ class LDIcons {

@JvmField
val VARIATION = IconLoader.getIcon("/icons/variation.svg", javaClass)

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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

Expand All @@ -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()
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ class ChangeFallthroughAction : AnAction {
}
.createPopup()
.showUnderneathOf(currentComponent)

}

/**
Expand All @@ -121,4 +120,4 @@ class ChangeFallthroughAction : AnAction {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ class ChangeOffVariationAction : AnAction {
}
.createPopup()
.showUnderneathOf(currentComponent)

}

/**
Expand All @@ -121,4 +120,4 @@ class ChangeOffVariationAction : AnAction {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -76,7 +73,8 @@ class CopyKeyAction : AnAction {
if (project != null) {
if (project.service<FlagToolWindow>().getPanel().tree.lastSelectedPathComponent != null) {
val selectedNode =
project.service<FlagToolWindow>().getPanel().tree.lastSelectedPathComponent as DefaultMutableTreeNode
project.service<FlagToolWindow>()
.getPanel().tree.lastSelectedPathComponent as DefaultMutableTreeNode
val isFlagParentNode = selectedNode.userObject as? FlagNodeParent

e.presentation.isEnabledAndVisible =
Expand All @@ -86,4 +84,4 @@ class CopyKeyAction : AnAction {
e.presentation.isEnabledAndVisible = false
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -55,18 +54,17 @@ class OpenInBrowserAction : AnAction {
project.service<FlagToolWindow>().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.")
}

}

/**
Expand All @@ -86,4 +84,4 @@ class OpenInBrowserAction : AnAction {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -59,4 +58,4 @@ class RefreshAction : AnAction {
val project = e.project
e.presentation.isEnabledAndVisible = project != null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)

}

/**
Expand All @@ -87,4 +86,4 @@ class RunCoderefsAction : AnAction {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ class ToggleFlagAction : AnAction {
e.printStackTrace()
}
}

}
}

Expand All @@ -100,4 +99,4 @@ class ToggleFlagAction : AnAction {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<CompletionParameters>() {
override fun addCompletions(
Expand All @@ -105,7 +106,8 @@ class JavaCompletionContributor : CompletionContributor() {
}
}
)
extend(CompletionType.BASIC,
extend(
CompletionType.BASIC,
psiElement().andOr(FLAG_KEY_STRING, FLAG_KEY_STRING_DETAILS),
object : CompletionProvider<CompletionParameters>() {
override fun addCompletions(
Expand All @@ -126,7 +128,8 @@ class JavaCompletionContributor : CompletionContributor() {
}
}
)
extend(CompletionType.BASIC,
extend(
CompletionType.BASIC,
psiElement().andOr(FLAG_KEY_JSON, FLAG_KEY_JSON_DETAILS),
object : CompletionProvider<CompletionParameters>() {
override fun addCompletions(
Expand All @@ -147,6 +150,5 @@ class JavaCompletionContributor : CompletionContributor() {
}
}
)

}
}
}
Loading