Skip to content

Commit 4c8706b

Browse files
authored
fix template lint exception (#248)
1 parent f801b7a commit 4c8706b

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/main/kotlin/com/emberjs/hbs/linter/ember-template-lint/TemplateLintResultParser.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import com.intellij.lang.annotation.HighlightSeverity
22
import com.intellij.lang.javascript.linter.JSLinterError
33
import com.intellij.openapi.diagnostic.Logger
44
import com.intellij.openapi.util.text.StringUtil
5-
import org.codehaus.jettison.json.JSONObject
5+
import kotlinx.serialization.json.*
66
import java.io.IOException
77
import java.util.*
88

@@ -19,13 +19,13 @@ class TemplateLintResultParser {
1919
private const val SEVERITY = "severity"
2020
private const val MESSAGE = "message"
2121

22-
private fun parseItem(map: JSONObject): JSLinterError {
23-
val line = map.getInt(LINE)
24-
val column = map.getInt(COLUMN)
25-
val rule = map.getString(RULE)
26-
val text = map.getString(MESSAGE)
22+
private fun parseItem(map: JsonObject): JSLinterError {
23+
val line = map[LINE]!!.jsonPrimitive.int
24+
val column = map[COLUMN]!!.jsonPrimitive.int
25+
val rule = map[RULE]!!.jsonPrimitive.content
26+
val text = map[MESSAGE]!!.jsonPrimitive.content
2727

28-
val highlightSeverity = when (map.getInt(SEVERITY)) {
28+
val highlightSeverity = when (map[SEVERITY]!!.jsonPrimitive.int) {
2929
WARNING_SEVERITY -> HighlightSeverity.WARNING
3030
ERROR_SEVERITY -> HighlightSeverity.ERROR
3131
else -> null
@@ -43,14 +43,14 @@ class TemplateLintResultParser {
4343

4444
val errorList: ArrayList<JSLinterError> = ArrayList()
4545
try {
46-
val obj = JSONObject(stdout)
46+
val obj = Json.parseToJsonElement(stdout!!).jsonObject
4747

48-
val issues = obj.getJSONArray(obj.keys().next() as String)
49-
for (i in 0 until issues.length()) {
50-
val issue = issues.getJSONObject(i)
48+
val issues = obj.values.flatMap { map -> map.jsonArray }
49+
for (i in 0 until issues.size) {
50+
val issue = issues[i].jsonObject
5151

5252
// we skip fatal errors
53-
if (issue.has("fatal") && issue.getBoolean("fatal")) continue
53+
if (issue.containsKey("fatal") && issue["fatal"]?.jsonPrimitive?.boolean == true) continue
5454

5555
errorList.add(parseItem(issue))
5656
}
@@ -59,7 +59,7 @@ class TemplateLintResultParser {
5959
} catch (ioException: IOException) {
6060
return null
6161
} catch (exception: Exception) {
62-
LOG.warn("TemplateLint result parsing error")
62+
LOG.warn("TemplateLint result parsing error: $exception")
6363
throw Exception("TemplateLint result parsing error", exception)
6464
}
6565
}

0 commit comments

Comments
 (0)