mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
trying the android linter for code inspection
This commit is contained in:
10
.idea/libraries/android_lint.xml
generated
Normal file
10
.idea/libraries/android_lint.xml
generated
Normal file
@@ -0,0 +1,10 @@
|
||||
<component name="libraryTable">
|
||||
<library name="android-lint">
|
||||
<CLASSES>
|
||||
<root url="file://$PROJECT_DIR$/lib/android-lint" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
<jarDirectory url="file://$PROJECT_DIR$/lib/android-lint" recursive="false" />
|
||||
</library>
|
||||
</component>
|
||||
@@ -16,5 +16,6 @@
|
||||
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
||||
<orderEntry type="library" name="jetbrains.kotlin.reflect" level="project" />
|
||||
<orderEntry type="library" name="jetbrains.kotlin.test" level="project" />
|
||||
<orderEntry type="library" name="android-lint" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -24,5 +24,6 @@
|
||||
<orderEntry type="library" name="badlogicgames.gdx.backend.lwjgl3" level="project" />
|
||||
<orderEntry type="library" name="jetbrains.kotlin.reflect" level="project" />
|
||||
<orderEntry type="library" name="jetbrains.kotlin.test" level="project" />
|
||||
<orderEntry type="library" name="android-lint" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
BIN
lib/android-lint/common-31.0.1.jar
LFS
Normal file
BIN
lib/android-lint/common-31.0.1.jar
LFS
Normal file
Binary file not shown.
BIN
lib/android-lint/guava-31.0.1-jre.jar
LFS
Normal file
BIN
lib/android-lint/guava-31.0.1-jre.jar
LFS
Normal file
Binary file not shown.
BIN
lib/android-lint/intellij-core-31.0.1.jar
LFS
Normal file
BIN
lib/android-lint/intellij-core-31.0.1.jar
LFS
Normal file
Binary file not shown.
BIN
lib/android-lint/kotlin-compiler-31.0.1.jar
LFS
Normal file
BIN
lib/android-lint/kotlin-compiler-31.0.1.jar
LFS
Normal file
Binary file not shown.
BIN
lib/android-lint/kxml2-2.3.0.jar
LFS
Normal file
BIN
lib/android-lint/kxml2-2.3.0.jar
LFS
Normal file
Binary file not shown.
BIN
lib/android-lint/layoutlib-api-31.0.1.jar
LFS
Normal file
BIN
lib/android-lint/layoutlib-api-31.0.1.jar
LFS
Normal file
Binary file not shown.
127
lib/android-lint/lint-31.0.1.pom
Normal file
127
lib/android-lint/lint-31.0.1.pom
Normal file
@@ -0,0 +1,127 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.android.tools.lint</groupId>
|
||||
<artifactId>lint</artifactId>
|
||||
<version>31.0.1</version>
|
||||
<name>com.android.tools.lint.lint</name>
|
||||
<description>Lint tools. Both a Command line tool and a library to add lint features to other tools</description>
|
||||
<url>http://tools.android.com/</url>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>The Apache Software License, Version 2.0</name>
|
||||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||
<distribution>repo</distribution>
|
||||
</license>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer>
|
||||
<name>The Android Open Source Project</name>
|
||||
</developer>
|
||||
</developers>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.android.tools.lint</groupId>
|
||||
<artifactId>lint-api</artifactId>
|
||||
<version>31.0.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.android.tools.lint</groupId>
|
||||
<artifactId>lint-checks</artifactId>
|
||||
<version>31.0.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.android.tools.external.com-intellij</groupId>
|
||||
<artifactId>intellij-core</artifactId>
|
||||
<version>31.0.1</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.android.tools.external.com-intellij</groupId>
|
||||
<artifactId>kotlin-compiler</artifactId>
|
||||
<version>31.0.1</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.android.tools.external.org-jetbrains</groupId>
|
||||
<artifactId>uast</artifactId>
|
||||
<version>31.0.1</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.android.tools.analytics-library</groupId>
|
||||
<artifactId>protos</artifactId>
|
||||
<version>31.0.1</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.android.tools.analytics-library</groupId>
|
||||
<artifactId>shared</artifactId>
|
||||
<version>31.0.1</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.android.tools.analytics-library</groupId>
|
||||
<artifactId>tracker</artifactId>
|
||||
<version>31.0.1</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.android.tools.build</groupId>
|
||||
<artifactId>manifest-merger</artifactId>
|
||||
<version>31.0.1</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.android.tools</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
<version>31.0.1</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.android.tools.layoutlib</groupId>
|
||||
<artifactId>layoutlib-api</artifactId>
|
||||
<version>31.0.1</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.android.tools</groupId>
|
||||
<artifactId>sdk-common</artifactId>
|
||||
<version>31.0.1</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.android.tools</groupId>
|
||||
<artifactId>sdklib</artifactId>
|
||||
<version>31.0.1</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>31.0.1-jre</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sf.kxml</groupId>
|
||||
<artifactId>kxml2</artifactId>
|
||||
<version>2.3.0</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-reflect</artifactId>
|
||||
<version>1.7.10</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-jdk8</artifactId>
|
||||
<version>1.7.10</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
BIN
lib/android-lint/lint-api-31.0.1.jar
LFS
Normal file
BIN
lib/android-lint/lint-api-31.0.1.jar
LFS
Normal file
Binary file not shown.
BIN
lib/android-lint/lint-checks-31.0.1.jar
LFS
Normal file
BIN
lib/android-lint/lint-checks-31.0.1.jar
LFS
Normal file
Binary file not shown.
BIN
lib/android-lint/manifest-merger-31.0.1.jar
LFS
Normal file
BIN
lib/android-lint/manifest-merger-31.0.1.jar
LFS
Normal file
Binary file not shown.
BIN
lib/android-lint/protos-31.0.1.jar
LFS
Normal file
BIN
lib/android-lint/protos-31.0.1.jar
LFS
Normal file
Binary file not shown.
BIN
lib/android-lint/sdk-common-31.0.1.jar
LFS
Normal file
BIN
lib/android-lint/sdk-common-31.0.1.jar
LFS
Normal file
Binary file not shown.
BIN
lib/android-lint/sdklib-31.0.1.jar
LFS
Normal file
BIN
lib/android-lint/sdklib-31.0.1.jar
LFS
Normal file
Binary file not shown.
BIN
lib/android-lint/shared-31.0.1.jar
LFS
Normal file
BIN
lib/android-lint/shared-31.0.1.jar
LFS
Normal file
Binary file not shown.
BIN
lib/android-lint/tracker-31.0.1.jar
LFS
Normal file
BIN
lib/android-lint/tracker-31.0.1.jar
LFS
Normal file
Binary file not shown.
BIN
lib/android-lint/uast-31.0.1.jar
LFS
Normal file
BIN
lib/android-lint/uast-31.0.1.jar
LFS
Normal file
Binary file not shown.
97
src/net/torvald/terrarum/UnserialisableTypeIssueRegistry.kt
Normal file
97
src/net/torvald/terrarum/UnserialisableTypeIssueRegistry.kt
Normal file
@@ -0,0 +1,97 @@
|
||||
package net.torvald.terrarum
|
||||
|
||||
import com.android.tools.lint.client.api.IssueRegistry
|
||||
import com.android.tools.lint.client.api.UElementHandler
|
||||
import com.android.tools.lint.detector.api.*
|
||||
import net.torvald.random.HQRNG
|
||||
import net.torvald.terrarum.gameactors.Actor
|
||||
import net.torvald.terrarum.gameitems.GameItem
|
||||
import net.torvald.terrarum.gameworld.BlockLayer
|
||||
import net.torvald.terrarum.gameworld.WorldTime
|
||||
import net.torvald.terrarum.savegame.ByteArray64
|
||||
import net.torvald.terrarum.utils.*
|
||||
import org.jetbrains.uast.UClass
|
||||
import org.jetbrains.uast.UField
|
||||
import org.jetbrains.uast.util.classSetOf
|
||||
import org.jetbrains.uast.util.isInstanceOf
|
||||
import java.math.BigInteger
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* https://medium.com/@vanniktech/writing-your-first-lint-check-39ad0e90b9e6
|
||||
* https://medium.com/mobile-app-development-publication/making-custom-lint-for-kotlin-code-8a6c203bf474
|
||||
* https://github.com/googlesamples/android-custom-lint-rules
|
||||
* https://googlesamples.github.io/android-custom-lint-rules/api-guide.html
|
||||
*
|
||||
* Created by minjaesong on 2023-05-22.
|
||||
*/
|
||||
class UnserialisableTypeIssueRegistry : IssueRegistry() {
|
||||
override val issues = listOf(ISSUE_SAVEGAME_UNSERIALISABLE_TYPE_USED_WITHOUT_TRANSIENT)
|
||||
}
|
||||
|
||||
val ISSUE_SAVEGAME_UNSERIALISABLE_TYPE_USED_WITHOUT_TRANSIENT = Issue.create("TerrarumNonTransientUnserialisableType",
|
||||
"Unserialisable Type Used Without Care",
|
||||
"Unserialisable type is used on the potentially serialised class without @Transient annotation",
|
||||
Category.CORRECTNESS,
|
||||
9,
|
||||
Severity.ERROR,
|
||||
Implementation(TerrarumNonTransientUnserialisableType::class.java, EnumSet.of(Scope.JAVA_FILE))
|
||||
)
|
||||
|
||||
class TerrarumNonTransientUnserialisableType : Detector(), Detector.UastScanner {
|
||||
override fun getApplicablePsiTypes() = listOf(UClass::class.java)
|
||||
override fun createUastHandler(context: JavaContext) = TerrarumNonTransientUnserialisableTypeHandler(context)
|
||||
|
||||
class TerrarumNonTransientUnserialisableTypeHandler(private val context: JavaContext) : UElementHandler() {
|
||||
override fun visitClass(clazz: UClass) {
|
||||
/*if (clazz.name?.isDefinedCamelCase() == false) {
|
||||
context.report(ISSUE_SAVEGAME_UNSERIALISABLE_TYPE_USED_WITHOUT_TRANSIENT, clazz,
|
||||
context.getNameLocation(clazz),
|
||||
"Not named in defined camel case.")
|
||||
}*/
|
||||
}
|
||||
|
||||
override fun visitField(node: UField) {
|
||||
if (node.uastParent.isInstanceOf(classSetOf(Actor::class.java, GameItem::class.java)) &&
|
||||
!node.hasAnnotation("Transient") &&
|
||||
!node.isInstanceOf(classSetOf(
|
||||
// primitives
|
||||
String::class.java,
|
||||
Array<String>::class.java,
|
||||
Boolean::class.java,
|
||||
Byte::class.java,
|
||||
ByteArray::class.java,
|
||||
ByteArray64::class.java,
|
||||
Short::class.java,
|
||||
ShortArray::class.java,
|
||||
Int::class.java,
|
||||
IntArray::class.java,
|
||||
Long::class.java,
|
||||
LongArray::class.java,
|
||||
Float::class.java,
|
||||
FloatArray::class.java,
|
||||
Double::class.java,
|
||||
DoubleArray::class.java,
|
||||
// has serialiser on net.torvald.terrarum.serialise.Common
|
||||
BigInteger::class.java,
|
||||
ZipCodedStr::class.java,
|
||||
BlockLayer::class.java,
|
||||
WorldTime::class.java,
|
||||
HashArray::class.java,
|
||||
HashedWirings::class.java,
|
||||
HashedWiringGraph::class.java,
|
||||
WiringGraphMap::class.java,
|
||||
UUID::class.java,
|
||||
HQRNG::class.java,
|
||||
))) {
|
||||
|
||||
context.report(
|
||||
ISSUE_SAVEGAME_UNSERIALISABLE_TYPE_USED_WITHOUT_TRANSIENT,
|
||||
node,
|
||||
context.getNameLocation(node),
|
||||
"Unserialisable type is used on the potentially serialised class without @Transient annotation"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user