Skip to content

Commit 1fc92c9

Browse files
authored
Improve ValidateLocalizedMessages (#2552)
- When there is not an = in a line, fail (it previously passed) - Add line numbers to errors so you can quickly jump to them when run through the IDE
1 parent 2a3bf8a commit 1fc92c9

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

buildSrc/src/main/kotlin/software/aws/toolkits/gradle/resources/ValidateMessages.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import org.gradle.language.base.plugins.LifecycleBasePlugin.VERIFICATION_GROUP
1414
import java.time.Instant
1515

1616
open class ValidateMessages : DefaultTask() {
17+
private companion object {
18+
const val COPYRIGHT_HEADER_LINES = 2
19+
}
1720
@InputFiles
1821
val paths: ConfigurableFileCollection = project.objects.fileCollection()
1922

@@ -35,18 +38,20 @@ open class ValidateMessages : DefaultTask() {
3538
fileLines
3639
// filter out blank lines and comments
3740
.filter { it.isNotBlank() && it.trim().firstOrNull() != '#' }
38-
.mapNotNull {
41+
.mapIndexed { lineNumber, it ->
3942
if (it.contains("=")) {
4043
it
4144
} else {
42-
logger.warn(""""$filePath contains invalid message missing a '=': "$it"""")
45+
logger.error(""""$filePath:${lineNumber + COPYRIGHT_HEADER_LINES} contains invalid message missing a '=': "$it"""")
46+
hasError = true
4347
null
4448
}
4549
}
50+
.filterNotNull()
4651
.map { it.split("=").first() }
47-
.reduce { item1, item2 ->
52+
.reduceIndexed { lineNumber, item1, item2 ->
4853
if (item1 > item2) {
49-
logger.error("""$filePath is not sorted:"$item1" > "$item2"""")
54+
logger.error("""$filePath:${lineNumber + COPYRIGHT_HEADER_LINES} is not sorted:"$item1" > "$item2"""")
5055
hasError = true
5156
}
5257

0 commit comments

Comments
 (0)