@@ -68,6 +68,13 @@ import slack.cli.skipBuildAndCacheDirs
6868public class LintBaselineMergerCli : CliktCommand (DESCRIPTION ) {
6969 private companion object {
7070 const val DESCRIPTION = " Merges multiple lint baselines into one"
71+ private val LEVEL_NAMES =
72+ Level .entries.joinToString(
73+ separator = " , " ,
74+ prefix = " [" ,
75+ postfix = " ]" ,
76+ transform = Level ::name
77+ )
7178 }
7279
7380 @AutoService(CommandFactory ::class )
@@ -90,19 +97,13 @@ public class LintBaselineMergerCli : CliktCommand(DESCRIPTION) {
9097 " -m" ,
9198 help =
9299 " Template for messages with each issue. This message can optionally " +
93- " contain '{id}' in it to be replaced with the issue ID."
100+ " contain '{id}' in it to be replaced with the issue ID and '{message}' " +
101+ " for the original message."
94102 )
95- .default(" Lint issue {id }" )
103+ .default(" {message }" )
96104
97105 private val level by
98- option(
99- " --level" ,
100- " -l" ,
101- help =
102- " Priority level. Defaults to Error. Options are ${
103- Level .entries.joinToString(separator = " , " , prefix = " [" , postfix = " ]" , transform = Level ::name)
104- } "
105- )
106+ option(" --level" , " -l" , help = " Priority level. Defaults to Error. Options are $LEVEL_NAMES " )
106107 .enum<Level >()
107108 .default(Level .Error )
108109
@@ -120,13 +121,6 @@ public class LintBaselineMergerCli : CliktCommand(DESCRIPTION) {
120121 val issues = parseIssues()
121122
122123 if (verbose) println (" Merging ${issues.size} issues" )
123- val idsToLocations =
124- issues.entries
125- .groupBy { (issue, _) -> issue.id }
126- .mapValues { (_, entries) ->
127- entries.map { (issue, projectPath) -> issue.toLocation(projectPath) }
128- }
129- .toSortedMap()
130124
131125 if (verbose) println (" Gathering rules" )
132126 val rules =
@@ -155,20 +149,30 @@ public class LintBaselineMergerCli : CliktCommand(DESCRIPTION) {
155149 Run (
156150 tool = Tool (ToolComponent (name = " lint" , rules = rules)),
157151 results =
158- buildList {
159- for ((id, locations) in idsToLocations) {
160- add(
161- Result (
162- ruleID = id,
163- level = level,
164- ruleIndex = ruleIndices.getValue(id),
165- locations =
166- locations.sortedBy { it.physicalLocation?.artifactLocation?.uri },
167- message = Message (text = messageTemplate.replace(" {id}" , id))
168- )
152+ issues.keys
153+ .sortedWith(
154+ compareBy(
155+ { it.id },
156+ { it.location.file },
157+ { it.location.line },
158+ { it.location.column }
159+ )
160+ )
161+ .map { key -> key to issues.getValue(key) }
162+ .map { (issue, projectPath) ->
163+ val id = issue.id
164+ Result (
165+ ruleID = id,
166+ level = level,
167+ ruleIndex = ruleIndices.getValue(id),
168+ locations = listOf (issue.toLocation(projectPath)),
169+ message =
170+ Message (
171+ text =
172+ messageTemplate.replace(" {id}" , id).replace(" {message}" , issue.message)
173+ )
169174 )
170175 }
171- }
172176 )
173177 )
174178 )
0 commit comments