Skip to content

Commit

Permalink
Reduce indentation with guard clause and minor refactoring (#191)
Browse files Browse the repository at this point in the history
* Reduce indentation with guard clause

* Refactor runCatching, fix compilation issues
  • Loading branch information
amitdash291 committed Jun 28, 2022
1 parent 8551673 commit 3070567
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ gradlew buildPlugin
```

To test your development, use task `runIde` which will automatically run an Intellij instance to test your new version of detekt plugin.
```bash
# linux & macOS
./gradlew runIde
# windows
gradlew runIde
```

## License
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Farturbosch%2Fdetekt-intellij-plugin.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Farturbosch%2Fdetekt-intellij-plugin?ref=badge_large)
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,10 @@ class AutoCorrectAction : AnAction() {
}

override fun actionPerformed(event: AnActionEvent) {
val virtualFile = event.getData(CommonDataKeys.VIRTUAL_FILE)
val project = event.getData(CommonDataKeys.PROJECT)
if (virtualFile != null && project != null) {
val psiFile = PsiManager.getInstance(project).findFile(virtualFile)
if (psiFile != null) {
runAction(project, psiFile)
}
}
val virtualFile = event.getData(CommonDataKeys.VIRTUAL_FILE) ?: return
val project = event.getData(CommonDataKeys.PROJECT) ?: return
val psiFile = PsiManager.getInstance(project).findFile(virtualFile) ?: return
runAction(project, psiFile)
}

internal fun runAction(project: Project, psiFile: PsiFile) {
Expand All @@ -56,11 +52,9 @@ class AutoCorrectAction : AnAction() {
private fun forceUpdateFile(project: Project, virtualFile: VirtualFile) {
WriteCommandAction.runWriteCommandAction(project) {
val documentManager = FileDocumentManager.getInstance()
val document = documentManager.getDocument(virtualFile)
if (document != null) {
if (documentManager.isDocumentUnsaved(document)) {
documentManager.saveDocument(document)
}
val document = documentManager.getDocument(virtualFile) ?: return@runWriteCommandAction
if (documentManager.isDocumentUnsaved(document)) {
documentManager.saveDocument(document)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,16 @@ class GitHubErrorReporting : ErrorReportSubmitter() {
.addParameter("body", formatIssueBody(additionalInfo))
.build()

runCatching {
return runCatching {
BrowserUtil.browse(uri)
ApplicationManager.getApplication()
.invokeLater { openStacktraceScratchFile(parentComponent, formatStacktrace(events)) }
}.onFailure {
consumer.consume(SubmittedReportInfo(SubmittedReportInfo.SubmissionStatus.FAILED))
return false
}.onSuccess {
consumer.consume(SubmittedReportInfo(SubmittedReportInfo.SubmissionStatus.NEW_ISSUE))
true
}.getOrElse {
consumer.consume(SubmittedReportInfo(SubmittedReportInfo.SubmissionStatus.FAILED))
false
}
return true
}

private fun openStacktraceScratchFile(parentComponent: Component, stacktrace: String) {
Expand Down

0 comments on commit 3070567

Please sign in to comment.