forked from hannibal002/SkyHanni
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'refs/heads/beta' into data-watcher
# Conflicts: # src/main/java/at/hannibal2/skyhanni/api/DataWatcherAPI.kt # src/main/java/at/hannibal2/skyhanni/events/DataWatcherUpdatedEvent.kt
- Loading branch information
Showing
449 changed files
with
7,265 additions
and
4,507 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package at.hannibal2.skyhanni.detektrules | ||
|
||
import org.jetbrains.kotlin.psi.KtCallExpression | ||
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression | ||
import org.jetbrains.kotlin.psi.KtEscapeStringTemplateEntry | ||
import org.jetbrains.kotlin.psi.KtLiteralStringTemplateEntry | ||
import org.jetbrains.kotlin.psi.KtProperty | ||
import org.jetbrains.kotlin.psi.KtPropertyDelegate | ||
import org.jetbrains.kotlin.psi.KtStringTemplateEntryWithExpression | ||
import org.jetbrains.kotlin.psi.KtStringTemplateExpression | ||
|
||
class RepoPatternElement private constructor( | ||
val variableName: String, | ||
val rawPattern: String, | ||
val regexTests: List<String>, | ||
val failingRegexTests: List<String>, | ||
) { | ||
|
||
val pattern by lazy { rawPattern.toPattern() } | ||
|
||
companion object { | ||
fun KtPropertyDelegate.asRepoPatternElement(): RepoPatternElement? { | ||
val expression = this.expression as? KtDotQualifiedExpression ?: return null | ||
val callExpression = expression.selectorExpression as? KtCallExpression ?: return null | ||
if (callExpression.valueArguments.size != 2) return null | ||
|
||
val patternArg = callExpression.valueArguments[1].getArgumentExpression() ?: return null | ||
|
||
// We only want to match on plain strings, not string templates | ||
if (patternArg !is KtStringTemplateExpression) return null | ||
if (patternArg.entries.any { it is KtStringTemplateEntryWithExpression }) return null | ||
|
||
val rawPattern = patternArg.entries.joinToString("") { entry -> | ||
when (entry) { | ||
is KtLiteralStringTemplateEntry -> entry.text | ||
is KtEscapeStringTemplateEntry -> entry.unescapedValue | ||
else -> "" // Skip any other types of entries | ||
} | ||
}.removeSurrounding("\"").replace("\n", "") | ||
|
||
val parent = parent as? KtProperty ?: return null | ||
val variableName = parent.name ?: "unknownPattern" | ||
|
||
val (regexTests, failingRegexTests) = findRegexTestInKDoc(parent) | ||
return RepoPatternElement(variableName, rawPattern, regexTests, failingRegexTests) | ||
} | ||
|
||
private fun findRegexTestInKDoc(property: KtProperty): Pair<List<String>, List<String>> { | ||
val kDoc = property.docComment ?: return listOf<String>() to listOf() | ||
|
||
val regexTests = mutableListOf<String>() | ||
val failingRegexTests = mutableListOf<String>() | ||
|
||
kDoc.getDefaultSection().getContent().lines().forEach { line -> | ||
if (line.contains("REGEX-TEST: ")) { | ||
regexTests.add(line.substringAfter("REGEX-TEST: ")) | ||
} | ||
if (line.contains("REGEX-FAIL: ")) { | ||
failingRegexTests.add(line.substringAfter("REGEX-FAIL: ")) | ||
} | ||
} | ||
return regexTests to failingRegexTests | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package at.hannibal2.skyhanni.detektrules | ||
|
||
import io.gitlab.arturbosch.detekt.api.CodeSmell | ||
import io.gitlab.arturbosch.detekt.api.Config | ||
import io.gitlab.arturbosch.detekt.api.Entity | ||
import io.gitlab.arturbosch.detekt.api.Rule | ||
import org.jetbrains.kotlin.com.intellij.psi.PsiElement | ||
|
||
abstract class SkyHanniRule(config: Config) : Rule(config) { | ||
|
||
protected fun PsiElement.reportIssue(message: String) { | ||
report(CodeSmell(issue, Entity.from(this), message)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.