Refactor: reduce detekt findings (unused params, throws, long methods, config)

This commit is contained in:
2026-09-27 21:54:00 +03:00
parent c6e0b0d7c8
commit a821d97ef7
13 changed files with 188 additions and 119 deletions

View File

@@ -134,7 +134,35 @@ class MarkdownRenderer(
private fun buildSanitizer(): PolicyFactory =
HtmlPolicyBuilder()
.allowElements(
.allowElements(*ALLOWED_ELEMENTS)
.allowAttributes("href")
.onElements("a")
.allowAttributes("title")
.onElements("a", "img")
.allowAttributes("src", "alt")
.onElements("img")
.allowAttributes("src", "poster", "controls", "preload", "width", "height", "loop", "muted", "playsinline")
.onElements("video")
.allowAttributes("src", "type")
.onElements("source")
.allowAttributes("src", "kind", "label", "srclang", "default")
.onElements("track")
.allowAttributes("class")
.onElements(*CLASS_ATTR_ELEMENTS)
.allowAttributes("id")
.onElements("h1", "h2", "h3", "h4", "h5", "h6")
.allowAttributes("colspan", "rowspan")
.onElements("td", "th")
.allowUrlProtocols("http", "https", "mailto")
.requireRelNofollowOnLinks()
.toFactory()
private companion object {
const val MAX_DEPTH = 5
/** Теги, разрешённые в отрендеренном HTML (allow-list санитайзера). */
val ALLOWED_ELEMENTS =
arrayOf(
"p",
"br",
"hr",
@@ -177,20 +205,11 @@ class MarkdownRenderer(
"source",
"track",
"audio",
).allowAttributes("href")
.onElements("a")
.allowAttributes("title")
.onElements("a", "img")
.allowAttributes("src", "alt")
.onElements("img")
.allowAttributes("src", "poster", "controls", "preload", "width", "height", "loop", "muted", "playsinline")
.onElements("video")
.allowAttributes("src", "type")
.onElements("source")
.allowAttributes("src", "kind", "label", "srclang", "default")
.onElements("track")
.allowAttributes("class")
.onElements(
)
/** Элементы, которым разрешён атрибут class (подсветка кода, фигуры и т.п.). */
val CLASS_ATTR_ELEMENTS =
arrayOf(
"code",
"pre",
"div",
@@ -204,16 +223,7 @@ class MarkdownRenderer(
"figcaption",
"video",
"img",
).allowAttributes("id")
.onElements("h1", "h2", "h3", "h4", "h5", "h6")
.allowAttributes("colspan", "rowspan")
.onElements("td", "th")
.allowUrlProtocols("http", "https", "mailto")
.requireRelNofollowOnLinks()
.toFactory()
private companion object {
const val MAX_DEPTH = 5
)
val MEDIA =
Regex(
pattern = "(?m)^[ \\t]*:::[ \\t]*(figure|video)[ \\t]+(\\S+)[ \\t]*(?:\\|[ \\t]*(.*?))?[ \\t]*$",