Skip to content

Commit

Permalink
Merge branch 'refs/heads/beta' into data-watcher
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/at/hannibal2/skyhanni/api/DataWatcherAPI.kt
#	src/main/java/at/hannibal2/skyhanni/events/DataWatcherUpdatedEvent.kt
  • Loading branch information
CalMWolfs committed Dec 5, 2024
2 parents b8cf5e6 + 0da7414 commit ab0eea7
Show file tree
Hide file tree
Showing 449 changed files with 7,265 additions and 4,507 deletions.
26 changes: 8 additions & 18 deletions .github/workflows/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ jobs:
detekt:
name: Run detekt
runs-on: ubuntu-latest
concurrency:
group: detekt-${{ github.event.pull_request.number }}
cancel-in-progress: true
permissions:
contents: read
pull-requests: write
Expand All @@ -40,7 +43,7 @@ jobs:
fi
- name: Add label if detekt fails
if: failure()
if: ${{ failure() && steps.check_sarif.outputs.exists == 'true' }}
uses: actions-ecosystem/action-add-labels@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -67,6 +70,9 @@ jobs:
detekt_comment:
name: Comment detekt failures on PR
runs-on: ubuntu-latest
concurrency:
group: detekt-comment-${{ github.event.pull_request.number }}
cancel-in-progress: true
needs: detekt
if: ${{ needs.detekt.outputs.sarif_exists == 'true' && failure() }}
permissions:
Expand All @@ -92,24 +98,8 @@ jobs:
GITHUB_REPOSITORY: ${{ github.repository }}
run: |
node .github/scripts/process_detekt_output.js
- name: Check if this is the latest workflow run
id: check_latest
run: |
PR_LATEST_SHA=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}" \
| jq -r '.head.sha')
echo "Latest commit SHA from PR: $PR_LATEST_SHA"
echo "Current workflow SHA: ${{ github.event.pull_request.head.sha }}"
# Compare the SHAs and set a result variable
if [[ "${PR_LATEST_SHA}" == "${{ github.event.pull_request.head.sha }}" ]]; then
echo "is_latest=true" >> $GITHUB_ENV
else
echo "is_latest=false" >> $GITHUB_ENV
fi
- name: Add comment to PR
if: env.is_latest == 'true'
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
24 changes: 4 additions & 20 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ jobs:
verify-changelog:
if: github.event.pull_request.state == 'open' && '511310721' == github.repository_id && github.event.pull_request.draft == false
runs-on: ubuntu-latest

concurrency:
group: verify-changelog-${{ github.event.pull_request.number }}
cancel-in-progress: true
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down Expand Up @@ -42,26 +44,8 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
labels: 'Wrong Title/Changelog'

- name: Check if this is the latest workflow run
if: failure()
id: check_latest
run: |
PR_LATEST_SHA=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}" \
| jq -r '.head.sha')
echo "Latest commit SHA from PR: $PR_LATEST_SHA"
echo "Current workflow SHA: ${{ github.event.pull_request.head.sha }}"
# Compare the SHAs and set a result variable
if [[ "${PR_LATEST_SHA}" == "${{ github.event.pull_request.head.sha }}" ]]; then
echo "is_latest=true" >> $GITHUB_ENV
else
echo "is_latest=false" >> $GITHUB_ENV
fi
- name: Add comment to PR if changelog verification fails
if: ${{ failure() && env.is_latest == 'true' }}
if: failure()
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
4 changes: 2 additions & 2 deletions .idea/dictionaries/default_user.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .live-plugins/regexr/plugin.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ val logger =
Logger.getInstance("SkyHanni")

val regexTestPrefix = "REGEX-TEST: "
val regexTestFailPrefix = "REGEX-FAIL: "

class RegexInfo(
val regex: KtValueArgument,
Expand Down Expand Up @@ -50,7 +51,7 @@ class RegexInfo(
}

fun getExamples(): List<String> {
val examples = commentText?.filter { it.startsWith(regexTestPrefix) }
val examples = commentText?.filter { it.startsWith(regexTestPrefix) || it.startsWith(regexTestFailPrefix) }
?.map { it.substring(regexTestPrefix.length) }
if (examples == null) return listOf()
return examples
Expand Down
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ format like "- #821" to illustrate the dependency.
- **There are valid reasons to deviate from the norm**
- If you have such a case, either use `@Supress("rule_name")`, or re-build the `baseline.xml` file, using `./gradlew detektBaselineMain`.
After running detektBaselineMain, you should find a file called `baseline-main.xml` in the `version/1.8.9` folder, rename the file to
`baseline.xml` replacing the old one. You also should copy the new contents of this file to the [main baseline file](detekt/baseline.xml)
`baseline.xml` replacing the old one.
- Do not copy features from other mods. Exceptions:
- Mods that are paid to use.
- Mods that have reached their end of life. (Rip SBA, Dulkir and Soopy).
Expand Down Expand Up @@ -145,6 +145,7 @@ format like "- #821" to illustrate the dependency.
- Do not use `MinecraftForge.EVENT_BUS.post(event)`, use `event.post()` instead.
- Do not use `toRegex()` or `toPattern()`, use `RepoPattern` instead.
- See [RepoPattern.kt](https://github.com/hannibal002/SkyHanni/blob/beta/src/main/java/at/hannibal2/skyhanni/utils/repopatterns/RepoPattern.kt)
- All repo patterns must be accompanied by a regex test. Look at other patterns for examples.
for more information and usages.
- The pattern variables are named in the scheme `variableNamePattern`
- Please use Regex instead of String comparison when it is likely Hypixel will change the message in the future.
Expand Down
4 changes: 3 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ dependencies {
implementation("net.hypixel:mod-api:0.3.1")

// getting clock offset
shadowImpl("commons-net:commons-net:3.8.0")
shadowImpl("commons-net:commons-net:3.11.1")

detektPlugins("org.notenoughupdates:detektrules:1.0.0")
detektPlugins(project(":detekt"))
Expand Down Expand Up @@ -312,6 +312,7 @@ tasks.withType(JavaCompile::class) {

tasks.withType(org.gradle.jvm.tasks.Jar::class) {
archiveBaseName.set("SkyHanni")
archiveAppendix.set("mc${target.minecraftVersion.versionName}")
duplicatesStrategy = DuplicatesStrategy.EXCLUDE // Why do we have this here? This only *hides* errors.
manifest.attributes.run {
this["Main-Class"] = "SkyHanniInstallerFrame"
Expand Down Expand Up @@ -384,6 +385,7 @@ preprocess {

blossom {
replaceToken("@MOD_VERSION@", version)
replaceToken("@MC_VERSION@", target.minecraftVersion.versionName)
}

val sourcesJar by tasks.creating(Jar::class) {
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ repositories {

dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib")
implementation("com.github.SkyHanniStudios:SkyHanniChangelogBuilder:1.0.1")
implementation("com.github.SkyHanniStudios:SkyHanniChangelogBuilder:1.0.2")
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ abstract class ChangelogVerification : DefaultTask() {

@TaskAction
fun scanChangelog() {
if (prBodyLines.contains("exclude_from_changelog")) {
if (prBodyLines.let { it.contains("exclude_from_changelog") || it.contains("ignore_from_changelog") }) {
println("PR is excluded from changelog verification")
return
}
Expand Down
6 changes: 5 additions & 1 deletion detekt/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ FormattingRules:
CustomAnnotationSpacing:
active: true

UseRepoRules:
RepoRules:
SkullTexturesUseRepo:
active: true
RepoPatternRegexTest:
active: true
RepoPatternUnnamedGroup:
active: true

ImportRules:
CustomImportOrdering:
Expand Down
65 changes: 65 additions & 0 deletions detekt/src/main/kotlin/RepoPatternElement.kt
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
}
}
}
14 changes: 14 additions & 0 deletions detekt/src/main/kotlin/SkyHanniRule.kt
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))
}
}
12 changes: 3 additions & 9 deletions detekt/src/main/kotlin/formatting/CustomAnnotationSpacing.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package at.hannibal2.skyhanni.detektrules.formatting

import at.hannibal2.skyhanni.detektrules.PreprocessingPattern.Companion.containsPreprocessingPattern
import at.hannibal2.skyhanni.detektrules.SkyHanniRule
import io.gitlab.arturbosch.detekt.api.CodeSmell
import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.api.Debt
import io.gitlab.arturbosch.detekt.api.Entity
import io.gitlab.arturbosch.detekt.api.Issue
import io.gitlab.arturbosch.detekt.api.Rule
import io.gitlab.arturbosch.detekt.api.Severity
import org.jetbrains.kotlin.com.intellij.psi.PsiComment
import org.jetbrains.kotlin.com.intellij.psi.PsiWhiteSpace
Expand All @@ -18,7 +18,7 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings
* This rule enforces the default spacing rules for annotations but allows preprocessed comments to be between
* an annotation and the annotated construct.
*/
class CustomAnnotationSpacing(config: Config) : Rule(config) {
class CustomAnnotationSpacing(config: Config) : SkyHanniRule(config) {
override val issue = Issue(
"CustomAnnotationSpacing",
Severity.Style,
Expand All @@ -38,13 +38,7 @@ class CustomAnnotationSpacing(config: Config) : Rule(config) {
}

if (hasInvalidSpacing) {
report(
CodeSmell(
issue,
Entity.from(annotationEntry),
"Annotations should occur immediately before the annotated construct"
)
)
annotationEntry.reportIssue("Annotations should occur immediately before the annotated construct.")
}
super.visitAnnotationEntry(annotationEntry)
}
Expand Down
12 changes: 3 additions & 9 deletions detekt/src/main/kotlin/formatting/CustomCommentSpacing.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package at.hannibal2.skyhanni.detektrules.formatting

import at.hannibal2.skyhanni.detektrules.PreprocessingPattern.Companion.containsPreprocessingPattern
import at.hannibal2.skyhanni.detektrules.SkyHanniRule
import io.gitlab.arturbosch.detekt.api.CodeSmell
import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.api.Debt
import io.gitlab.arturbosch.detekt.api.Entity
import io.gitlab.arturbosch.detekt.api.Issue
import io.gitlab.arturbosch.detekt.api.Rule
import io.gitlab.arturbosch.detekt.api.Severity
import org.jetbrains.kotlin.com.intellij.psi.PsiComment

/**
* This rule enforces the default spacing rules for comments but ignores preprocessed comments.
*/
class CustomCommentSpacing(config: Config) : Rule(config) {
class CustomCommentSpacing(config: Config) : SkyHanniRule(config) {
override val issue = Issue(
"CustomCommentSpacing",
Severity.Style,
Expand All @@ -24,13 +24,7 @@ class CustomCommentSpacing(config: Config) : Rule(config) {
override fun visitComment(comment: PsiComment) {
if (comment.text.containsPreprocessingPattern()) return
if (!commentRegex.matches(comment.text)) {
report(
CodeSmell(
issue,
Entity.from(comment),
"Expected space after opening comment."
)
)
comment.reportIssue("Expected space after opening comment.")
}

// Fallback to super (ostensibly a no-check)
Expand Down
12 changes: 3 additions & 9 deletions detekt/src/main/kotlin/grammar/AvoidBritishSpelling.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package at.hannibal2.skyhanni.detektrules.grammar

import at.hannibal2.skyhanni.detektrules.SkyHanniRule
import io.gitlab.arturbosch.detekt.api.CodeSmell
import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.api.Debt
import io.gitlab.arturbosch.detekt.api.Entity
import io.gitlab.arturbosch.detekt.api.Issue
import io.gitlab.arturbosch.detekt.api.Rule
import io.gitlab.arturbosch.detekt.api.Severity
import org.jetbrains.kotlin.psi.KtStringTemplateExpression

/**
* This rule reports all usages of the british spelling over the american spelling in the codebase,
* this will ignore any type annotations, i.e., `@ConfigEditorColour` will not be reported.
*/
class AvoidBritishSpelling(config: Config) : Rule(config) {
class AvoidBritishSpelling(config: Config) : SkyHanniRule(config) {
override val issue = Issue(
"AvoidBritishSpelling",
Severity.Style,
Expand All @@ -32,13 +32,7 @@ class AvoidBritishSpelling(config: Config) : Rule(config) {

for (word in scannedWords) {
if (text.contains(word.key, ignoreCase = true)) {
report(
CodeSmell(
issue,
Entity.from(expression),
"Avoid using the word '${word.key}' in code, '${word.value}' is preferred instead.",
),
)
expression.reportIssue("Avoid using the word '${word.key}' in code, '${word.value}' is preferred instead.")
}
}
super.visitStringTemplateExpression(expression)
Expand Down
Loading

0 comments on commit ab0eea7

Please sign in to comment.