Skip to content

Commit 8e2040f

Browse files
committed
fix(ignored-errors): properly check if errors were modified
1 parent dd680a5 commit 8e2040f

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
### Added
55
- Option to ignore specific error for a file.
66
- Explanation for `Pipeline filtered out by workflow rules` error.
7+
- Table of ignored errors in settings.
78

89
### Changed
910
- Refactor code for getting remote URL and Gitlab API URL in `ResolveContext`.

src/main/kotlin/com/github/blarc/gitlab/template/lint/plugin/settings/ignoredErrors/IgnoredError.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,16 @@ import kotlinx.serialization.Serializable
77
class IgnoredError(
88
var filePath: String,
99
var errorMessage: String
10-
)
10+
) {
11+
override fun equals(other: Any?): Boolean {
12+
if (this === other) return true
13+
if (other?.javaClass != javaClass) return false
14+
15+
other as IgnoredError
16+
return filePath == other.filePath && errorMessage == other.errorMessage
17+
}
18+
19+
override fun hashCode(): Int {
20+
return filePath.hashCode() + errorMessage.hashCode()
21+
}
22+
}

src/main/kotlin/com/github/blarc/gitlab/template/lint/plugin/settings/ignoredErrors/IgnoredErrorsConfigurable.kt

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ import com.intellij.ui.table.TableView
1414
import com.intellij.util.ui.ListTableModel
1515
import javax.swing.ListSelectionModel
1616

17-
class IgnoredErrorsConfigurable(val project: Project) :
18-
BoundConfigurable(message("settings.ignored-errors.group.title")) {
19-
private var ignoredErrors = project.service<ProjectSettings>().ignoredErrors.toMutableMap()
17+
class IgnoredErrorsConfigurable(val project: Project) : BoundConfigurable(message("settings.ignored-errors.group.title")) {
18+
private var ignoredErrors = projectsIgnoredErrors()
2019

2120
private val tableModel = createTableModel()
2221

@@ -45,36 +44,40 @@ class IgnoredErrorsConfigurable(val project: Project) :
4544
createColumn<IgnoredError>(message("settings.ignored-error.file")) { ignoredError -> ignoredError.filePath.removePrefix("${project.basePath ?: ""}/") },
4645
createColumn(message("settings.ignored-error.message")) { ignoredError -> ignoredError.errorMessage }
4746
),
48-
ignoredErrorsList()
47+
ignoredErrors
4948
)
5049

5150
private fun removeIgnoredError() {
5251
val selectedRow = table.selectedObject ?: return
5352

54-
ignoredErrors[selectedRow.filePath]?.remove(selectedRow.errorMessage)
53+
ignoredErrors = ignoredErrors.minus(selectedRow)
5554
refreshTableModel()
5655
}
5756

5857
private fun refreshTableModel() {
59-
tableModel.items = ignoredErrorsList()
58+
tableModel.items = ignoredErrors
6059
}
6160

6261
override fun reset() {
6362
super.reset()
64-
ignoredErrors = project.service<ProjectSettings>().ignoredErrors.toMutableMap()
63+
ignoredErrors = projectsIgnoredErrors()
6564
refreshTableModel()
6665
}
6766

6867
override fun isModified(): Boolean {
69-
return super.isModified() || ignoredErrors != project.service<ProjectSettings>().ignoredErrors
68+
return ignoredErrors != projectsIgnoredErrors()
7069
}
7170

7271
override fun apply() {
7372
super.apply()
74-
project.service<ProjectSettings>().ignoredErrors = ignoredErrors
73+
project.service<ProjectSettings>().ignoredErrors = ignoredErrors.groupBy {
74+
it.filePath
75+
}.mapValues {
76+
it.value.map { ignoredError -> ignoredError.errorMessage }.toMutableSet()
77+
}.toMutableMap()
7578
}
7679

77-
private fun ignoredErrorsList() = ignoredErrors.map { mapEntry ->
80+
private fun projectsIgnoredErrors() = project.service<ProjectSettings>().ignoredErrors.map { mapEntry ->
7881
mapEntry.value.map {
7982
IgnoredError(mapEntry.key, it)
8083
}

0 commit comments

Comments
 (0)