diff --git a/detekt/src/main/kotlin/RepoPatternElement.kt b/detekt/src/main/kotlin/RepoPatternElement.kt index 3f400fa25693..2da17ce07737 100644 --- a/detekt/src/main/kotlin/RepoPatternElement.kt +++ b/detekt/src/main/kotlin/RepoPatternElement.kt @@ -8,6 +8,7 @@ import org.jetbrains.kotlin.psi.KtProperty import org.jetbrains.kotlin.psi.KtPropertyDelegate import org.jetbrains.kotlin.psi.KtStringTemplateEntryWithExpression import org.jetbrains.kotlin.psi.KtStringTemplateExpression +import java.net.URLEncoder class RepoPatternElement private constructor( val variableName: String, @@ -18,6 +19,12 @@ class RepoPatternElement private constructor( val pattern by lazy { rawPattern.toPattern() } + val regex101Url: String by lazy { + val encodedPattern = URLEncoder.encode(rawPattern, "UTF-8") + val encodedTests = regexTests.joinToString("\n") { URLEncoder.encode(it, "UTF-8") } + "https://regex101.com/?regex=$encodedPattern&testString=$encodedTests" + } + companion object { fun KtPropertyDelegate.asRepoPatternElement(): RepoPatternElement? { val expression = this.expression as? KtDotQualifiedExpression ?: return null diff --git a/detekt/src/main/kotlin/repo/RepoPatternRegexTest.kt b/detekt/src/main/kotlin/repo/RepoPatternRegexTest.kt index ac68ed5e4a3d..92fc5e1943dc 100644 --- a/detekt/src/main/kotlin/repo/RepoPatternRegexTest.kt +++ b/detekt/src/main/kotlin/repo/RepoPatternRegexTest.kt @@ -32,13 +32,15 @@ class RepoPatternRegexTest(config: Config) : SkyHanniRule(config) { repoPatternElement.regexTests.forEach { test -> if (!repoPatternElement.pattern.matcher(test).find()) { - delegate.reportIssue("Repo pattern `$variableName` failed regex test: `$test` pattern: `$rawPattern`.") + delegate.reportIssue("Repo pattern `$variableName` failed regex test: `$test` pattern: `$rawPattern`. " + + "[View on Regex101](${repoPatternElement.regex101Url})") } } repoPatternElement.failingRegexTests.forEach { test -> if (repoPatternElement.pattern.matcher(test).find()) { - delegate.reportIssue("Repo pattern `$variableName` passed regex test: `$test` pattern: `$rawPattern` even though it was set to fail.") + delegate.reportIssue("Repo pattern `$variableName` passed regex test: `$test` pattern: `$rawPattern` " + + "even though it was set to fail. [View on Regex101](${repoPatternElement.regex101Url})") } } }