Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
242318f
space checking fix
just-d-aa Nov 23, 2020
02164db
logs for SimplificationsFunctionDetector
just-d-aa Nov 23, 2020
6a762ab
debug SimplificationsFunctionDetector
just-d-aa Nov 23, 2020
54f7749
simplification for functions fixed
just-d-aa Nov 23, 2020
dee4c54
add lines count check
just-d-aa Nov 23, 2020
9db4668
debug
just-d-aa Nov 23, 2020
af10e50
change SimplificationsFunctionDetector message
just-d-aa Nov 23, 2020
8ef0ca0
LambdaDetector fixed
just-d-aa Nov 23, 2020
1fc1548
lambda correction
just-d-aa Nov 23, 2020
cdf0c42
change SimplificationsControlInstructionsDetector logic
just-d-aa Nov 23, 2020
41361c8
change MainActivity and change SimplificationsControlInstructionsDete…
just-d-aa Nov 23, 2020
af6fc41
change AbbreviationDetector
just-d-aa Nov 23, 2020
ab7efc8
refactoring
just-d-aa Nov 23, 2020
309b245
fix AbbreviationDetector
just-d-aa Nov 25, 2020
7e331a4
debug for AbbreviationDetector
just-d-aa Nov 25, 2020
7ad166c
new check for AbbreviationDetector
just-d-aa Nov 25, 2020
50b2436
change MaxFunctionLengthDetector
just-d-aa Nov 25, 2020
74c6aea
testing new space detector
just-d-aa Nov 25, 2020
6cfad00
prepare for pull request
just-d-aa Nov 25, 2020
b759c35
debug AbbreviationDetector for POST request
just-d-aa Nov 25, 2020
a3ba698
fix AbbreviationDetector error with retrofit
just-d-aa Nov 25, 2020
81d4576
prepare for pull request
just-d-aa Nov 25, 2020
265d781
add lint-report.html
just-d-aa Nov 25, 2020
0d9acca
debug lint-message
just-d-aa Nov 25, 2020
611e1cf
fixed NullPointerException for lint
just-d-aa Nov 25, 2020
dbbb364
fix space detector parent call
just-d-aa Nov 25, 2020
a0c1b73
fix max fun length detector and Abbreviation Detector
just-d-aa Nov 25, 2020
10e492d
fix TODO error
just-d-aa Nov 25, 2020
b41af2d
add "?" symbol to function declaration
just-d-aa Nov 25, 2020
8a4f521
comments correction
just-d-aa Nov 26, 2020
1ed3d38
refactoring
just-d-aa Nov 26, 2020
c0894d4
add layout check for constructors
just-d-aa Nov 26, 2020
9ad10d2
fix empty branch underline
just-d-aa Nov 26, 2020
4483f3c
add dialog checking
just-d-aa Nov 26, 2020
6916584
change NameResourceLayoutDetector logic
just-d-aa Nov 27, 2020
0c12a50
change space detector log
just-d-aa Nov 27, 2020
c2ca056
comments correction
just-d-aa Nov 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 52 additions & 13 deletions app/src/main/java/com/example/lint/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,40 +1,44 @@
package com.example.lint

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity


class MainActivity : AppCompatActivity() {

companion object {

const val SS_S_SFDAS = 2
private const val SSS = 2
}

val some = 2

private const val EXTRA_PHOTO = "photo"

fun createIntent(context: Context, photo: String): Intent {
return Intent(context, MainActivity ::class.java).putExtra(EXTRA_PHOTO, photo)
}
fun spme () {
String ?.toString()
}


fun createLauncher() {
createActivityLauncher()
}

val SSs = 2

fun spme() {
String?.toString()
private fun createActivityLauncher(): String {
return "createLauncher()"
}

override fun onCreate(savedInstanceState: Bundle?) {


super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)


val cTX: Context = this
String.toString()
String
.toString()
String::class.java


val list = listOf<String>()
Expand All @@ -44,10 +48,37 @@ class MainActivity : AppCompatActivity() {
}
}

private fun SSsome() {
private fun getTabName(position: Int): String {
return when (position) {
0 -> getString(R.string.app_name)
else -> getString(R.string.app_name)
}
}



private fun SSsome(): Int {
val s = 2
val list = listOf("")
list.forEach { line ->
val some = line
}

val s3 = 1
return when (s) {
s3 -> { 0 }

0, 2 -> {
val some = 2
1
}
else -> 2
}

}



class SomeClass() {
val soURL = 2
}
Expand All @@ -61,6 +92,14 @@ class MainActivity : AppCompatActivity() {
}
}

object Auth : Screen()

open class Screen() {}

fun some(): String {
return "S"
}

protected val s2: String = ""


Expand Down
1 change: 1 addition & 0 deletions checks/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ lintOptions {
textReport true
absolutePaths false
ignoreTestSources true
abortOnError false
}

dependencies {
Expand Down
15 changes: 8 additions & 7 deletions checks/src/main/java/com/omegar/lint/checks/LintIssueRegistry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.omegar.lint.checks.detector.code_guidelines.kotlin_rules.exception.Ex
import com.omegar.lint.checks.detector.code_guidelines.kotlin_style.elements_formating.annotation.AnnotationDetector
import com.omegar.lint.checks.detector.code_guidelines.kotlin_style.elements_formating.lambda.LambdaDetector
import com.omegar.lint.checks.detector.code_guidelines.kotlin_style.name.`class`.NameFileSufixDetector
import com.omegar.lint.checks.detector.code_guidelines.kotlin_style.name.abbreviation.AbbreviationDetector
import com.omegar.lint.checks.detector.code_guidelines.kotlin_style.name.field.CompanionObjectFieldsDetector
import com.omegar.lint.checks.detector.code_guidelines.kotlin_style.order.file_class_interface.ComponentPositionDetector
import com.omegar.lint.checks.detector.code_guidelines.kotlin_style.order.function_params.PositionArgumentDetector
Expand All @@ -29,10 +30,10 @@ import com.omegar.lint.checks.detector.project_guidelines.file_name.`class`.Name
import com.omegar.lint.checks.detector.project_guidelines.file_name.resource.layout.NameResourceLayoutDetector

class LintIssueRegistry : IssueRegistry() {
override val issues: List<Issue>
get() = listOf(
override val issues: List<Issue>
get() = listOf(
NameFileUpperCamelCaseDetector.ISSUE,
// AbbreviationDetector.ISSUE, TODO underline const values, need to fix
AbbreviationDetector.ISSUE,// TODO need testing
PositionArgumentDetector.ISSUE,
MaxFunctionsArgumentsDetector.ISSUE,
ExceptionCatchDetector.ISSUE,
Expand All @@ -53,13 +54,13 @@ class LintIssueRegistry : IssueRegistry() {
AttributesPositionXmlDetector.ISSUE,
// MaxClassInPackageDetector.ISSUE, TODO this working only for classes which user has visited after rebuild, need to fix, and count all classes
// MaxPackageCountDetector.ISSUE, TODO this working only for classes which user has visited after rebuild, need to fix, and count all classes
SimplificationsControlInstructionsDetector.ISSUE,
SimplificationsControlInstructionsDetector.ISSUE, // TODO need testing
IntentExtraParametersDetector.ISSUE,
ArgumentsBundleKeyPrefixDetector.ISSUE,
LambdaDetector.ISSUE,
NameResourceLayoutDetector.ISSUE
)

override val api: Int
get() = CURRENT_API
}
override val api: Int
get() = CURRENT_API
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ class ArgumentsBundleKeyPrefixDetector : Detector(), Detector.UastScanner {
/** Issue describing the problem and pointing to the detector implementation */
@JvmField
val ISSUE: Issue = Issue.create(
// ID: used in @SuppressLint warnings etc
id = "OMEGA_USE_KEY_PREFIX_FOR_FRAGMENT_IN_ARGUMENTS_BUNDLE_PARAMS",
// Title -- shown in the IDE's preference dialog, as category headers in the
// Analysis results window, etc
briefDescription = "Use KEY prefix for Fragment in Arguments Bundle param.",
// Full explanation of the issue; you can use some markdown markup such as
// `monospace`, *italic*, and **bold**.
explanation = """
// ID: used in @SuppressLint warnings etc
id = "OMEGA_USE_KEY_PREFIX_FOR_FRAGMENT_IN_ARGUMENTS_BUNDLE_PARAMS",
// Title -- shown in the IDE's preference dialog, as category headers in the
// Analysis results window, etc
briefDescription = "Use KEY prefix for Fragment in Arguments Bundle param.",
// Full explanation of the issue; you can use some markdown markup such as
// `monospace`, *italic*, and **bold**.
explanation = """
Use EXTRA prefix for intent arguments
http://wiki.omega-r.club/dev-android-code#rec228392168
""",
category = Category.CORRECTNESS,
priority = 7,
severity = Severity.WARNING,
implementation = Implementation(
ArgumentsBundleKeyPrefixDetector::class.java,
Scope.JAVA_FILE_SCOPE
)
)
category = Category.CORRECTNESS,
priority = 7,
severity = Severity.WARNING,
implementation = Implementation(
ArgumentsBundleKeyPrefixDetector::class.java,
Scope.JAVA_FILE_SCOPE
)
)

val KEY_PREFIX_REGEX = Regex("""^KEY_""")
val PUT_PARCELABLE_METHOD_REGEX = Regex("""^putParcelable$""")
Expand All @@ -51,7 +51,12 @@ class ArgumentsBundleKeyPrefixDetector : Detector(), Detector.UastScanner {
val firstParam = node.valueArguments.firstOrNull() ?: return
val extraParam = firstParam.asRenderString()
if (!extraParam.contains(ArgumentsBundleKeyPrefixDetector.Companion.KEY_PREFIX_REGEX)) {
context.report(ArgumentsBundleKeyPrefixDetector.Companion.ISSUE, node, context.getLocation(firstParam), ArgumentsBundleKeyPrefixDetector.Companion.ISSUE.getExplanation(TextFormat.TEXT))
context.report(
ArgumentsBundleKeyPrefixDetector.Companion.ISSUE,
node,
context.getLocation(firstParam),
ArgumentsBundleKeyPrefixDetector.Companion.ISSUE.getExplanation(TextFormat.TEXT)
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import org.jetbrains.uast.UCallExpression
import org.jetbrains.uast.UElement

class IntentExtraParametersDetector : Detector(), Detector.UastScanner {
companion object {
/** Issue describing the problem and pointing to the detector implementation */
@JvmField
val ISSUE: Issue = Issue.create(
companion object {
/** Issue describing the problem and pointing to the detector implementation */
@JvmField
val ISSUE: Issue = Issue.create(
// ID: used in @SuppressLint warnings etc
id = "OMEGA_USE_EXTRA_PREFIX_FOR_INTENT_PARAMS",
// Title -- shown in the IDE's preference dialog, as category headers in the
Expand All @@ -30,28 +30,28 @@ class IntentExtraParametersDetector : Detector(), Detector.UastScanner {
)
)

val EXTRA_PREFIX_REGEX = Regex("""^EXTRA_""")
val PUT_EXTRA_METHOD_REGEX = Regex("""^putExtra$""")
}
val EXTRA_PREFIX_REGEX = Regex("""^EXTRA_""")
val PUT_EXTRA_METHOD_REGEX = Regex("""^putExtra$""")
}

override fun getApplicableUastTypes(): List<Class<out UElement?>>? {
return listOf(UCallExpression::class.java)
}
override fun getApplicableUastTypes(): List<Class<out UElement?>>? {
return listOf(UCallExpression::class.java)
}

override fun createUastHandler(context: JavaContext): UElementHandler? {
return object : UElementHandler() {
override fun visitCallExpression(node: UCallExpression) {
val name = node.methodName ?: return
override fun createUastHandler(context: JavaContext): UElementHandler? {
return object : UElementHandler() {
override fun visitCallExpression(node: UCallExpression) {
val name = node.methodName ?: return

if(name.matches(PUT_EXTRA_METHOD_REGEX)) {
val firstParam = node.valueArguments.firstOrNull() ?: return
val extraParam = firstParam.asRenderString()
if(!extraParam.contains(EXTRA_PREFIX_REGEX)) {
context.report(ISSUE, node, context.getLocation(firstParam), ISSUE.getExplanation(TextFormat.TEXT))
}
}
}
}
}
if (name.matches(PUT_EXTRA_METHOD_REGEX)) {
val firstParam = node.valueArguments.firstOrNull() ?: return
val extraParam = firstParam.asRenderString()
if (!extraParam.contains(EXTRA_PREFIX_REGEX)) {
context.report(ISSUE, node, context.getLocation(firstParam), ISSUE.getExplanation(TextFormat.TEXT))
}
}
}
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ class ExceptionCatchDetector : Detector(), Detector.UastScanner {
@JvmField
val ISSUE: Issue = Issue.create(

id = "OMEGA_NOT_IGNORE_EXCEPTIONS",
briefDescription = "Catch body is empty, it not match the coding convention",
explanation = """
id = "OMEGA_NOT_IGNORE_EXCEPTIONS",
briefDescription = "Catch body is empty, it not match the coding convention",
explanation = """
Catch body is empty. Add exception handling.
http://wiki.omega-r.club/dev-android-code#rec226449864
""",
category = Category.CORRECTNESS,
priority = 7,
severity = Severity.WARNING,
implementation = Implementation(
ExceptionCatchDetector::class.java,
Scope.JAVA_FILE_SCOPE
)
)
category = Category.CORRECTNESS,
priority = 7,
severity = Severity.WARNING,
implementation = Implementation(
ExceptionCatchDetector::class.java,
Scope.JAVA_FILE_SCOPE
)
)

private val EMPTY_BODY_REGEX = Regex("""\{\s*}""")

Expand All @@ -47,22 +47,22 @@ class ExceptionCatchDetector : Detector(), Detector.UastScanner {
val string = body.asRenderString()
if (string.matches(EMPTY_BODY_REGEX)) {
context.report(
ISSUE,
body,
context.getNameLocation(body),
ISSUE.getExplanation(TextFormat.TEXT)
)
ISSUE,
body,
context.getNameLocation(body),
ISSUE.getExplanation(TextFormat.TEXT)
)
}
val parameters = node.parameters
parameters.forEach {
if (it.type.canonicalText == GENERALIZED_EXCEPTION_VAL) {
if (!string.contains(THROW_VAL)) {
context.report(
ISSUE,
body,
context.getNameLocation(it),
GENERALIZED_EXCEPTION_MESSAGE
)
ISSUE,
body,
context.getNameLocation(it),
GENERALIZED_EXCEPTION_MESSAGE
)
}
}
}
Expand Down
Loading