Skip to content

Commit

Permalink
Merge pull request #9 from vinted/feature/ignore_recorded_violations
Browse files Browse the repository at this point in the history
Add option to ignore recorded violations
  • Loading branch information
oleg-vinted authored Aug 1, 2023
2 parents 3f281fe + 90574a8 commit e07458f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- Experimental mode to ignore recorded violations (#9)

## [0.0.4] - 2023-07-21

### Added
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pluginGroup = com.vinted.packwerkintellij
pluginName = packwerk-intellij
pluginRepositoryUrl = https://github.com/vinted/packwerk-intellij
# SemVer format -> https://semver.org
pluginVersion = 0.0.4
pluginVersion = 0.0.5

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 223
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ class PackwerkSettingsConfigurable(private val project: Project) : BoundConfigur
private var packwerkPath: String = ""
private var enabled = true
private var lintUnsavedFiles = false
private var ignoreRecordedViolations = false

override fun createPanel(): DialogPanel = panel {
val settings = project.service<PackwerkSettingsState>()
packwerkPath = settings.packwerkPath
enabled = settings.enabled
lintUnsavedFiles = settings.lintUnsavedFiles
ignoreRecordedViolations = settings.ignoreRecordedViolations

row("Packwerk path:") {
textField()
Expand All @@ -41,11 +43,20 @@ class PackwerkSettingsConfigurable(private val project: Project) : BoundConfigur
"which is currently only supported by Packs and not Packwerk."
)
}
row {
checkBox("Experimental: Ignore recorded violations")
.bindSelected(::ignoreRecordedViolations)
.comment(
"Show violations in the editor even if they're recorded in package_todo.yml. " +
"Warning: not widely supported."
)
}

onApply {
settings.packwerkPath = packwerkPath
settings.enabled = enabled
settings.lintUnsavedFiles = lintUnsavedFiles
settings.ignoreRecordedViolations = ignoreRecordedViolations
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class PackwerkSettingsState : PersistentStateComponent<PackwerkSettingsState> {
var packwerkPath: String = "bin/packwerk"
var enabled = true
var lintUnsavedFiles = false
var ignoreRecordedViolations = false

override fun getState(): PackwerkSettingsState {
return this
Expand All @@ -20,5 +21,6 @@ class PackwerkSettingsState : PersistentStateComponent<PackwerkSettingsState> {
this.packwerkPath = state.packwerkPath
this.enabled = state.enabled
this.lintUnsavedFiles = state.lintUnsavedFiles
this.ignoreRecordedViolations = state.ignoreRecordedViolations
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ internal class PackwerkAnnotator : ExternalAnnotator<PackwerkAnnotator.State, Pa
var file: PsiFile,
var packwerkPath: String,
var fileText: String?,
var ignoreRecordedViolations: Boolean,
)

internal class Results(var problems: List<Problem>)
internal class Problem(var line: Int, var column: Int, var explanation: String)

Expand All @@ -59,24 +61,33 @@ internal class PackwerkAnnotator : ExternalAnnotator<PackwerkAnnotator.State, Pa
null
}

return State(file, settings.packwerkPath, fileText)
return State(file, settings.packwerkPath, fileText, settings.ignoreRecordedViolations)
}

override fun doAnnotate(collectedInfo: State): Results? {
val root: VirtualFile = getRootForFile(collectedInfo.file) ?: return null
val relativePath = VfsUtilCore.getRelativePath(collectedInfo.file.virtualFile, root) ?: return null

val cmdParams = ArrayList<String>()

val useStdin = collectedInfo.fileText != null
val packwerkSubcommand = if (useStdin) {
"check-contents"
if (useStdin) {
cmdParams.push("check-contents")
} else {
"check"
cmdParams.push("check")
}

if (collectedInfo.ignoreRecordedViolations) {
cmdParams.push("--ignore-recorded-violations")
}

cmdParams.push("--")
cmdParams.push(relativePath)

val cmd = GeneralCommandLine(collectedInfo.packwerkPath)
.withWorkDirectory(root.path)
.withCharset(Charset.forName("UTF-8"))
.withParameters(packwerkSubcommand, relativePath)
.withParameters(cmdParams)

val process: Process
try {
Expand Down Expand Up @@ -137,7 +148,9 @@ internal class PackwerkAnnotator : ExternalAnnotator<PackwerkAnnotator.State, Pa
el = el.parent
}

if (el == null) { el = file }
if (el == null) {
el = file
}

holder
.newAnnotation(HighlightSeverity.ERROR, problem.explanation)
Expand All @@ -146,7 +159,7 @@ internal class PackwerkAnnotator : ExternalAnnotator<PackwerkAnnotator.State, Pa
}
}

private fun getRootForFile(file: PsiFile) : VirtualFile? {
private fun getRootForFile(file: PsiFile): VirtualFile? {
val application = ApplicationManager.getApplication()
var root: VirtualFile? = null

Expand Down

0 comments on commit e07458f

Please sign in to comment.