Skip to content

Commit 543307d

Browse files
Merge pull request #11 from Omega-R/develop
Develop
2 parents 92c3564 + c2ca056 commit 543307d

26 files changed

Lines changed: 990 additions & 877 deletions

File tree

app/src/main/java/com/example/lint/MainActivity.kt

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,44 @@
11
package com.example.lint
22

3+
import android.annotation.SuppressLint
34
import android.content.Context
4-
import android.content.Intent
55
import android.os.Bundle
66
import androidx.appcompat.app.AppCompatActivity
77

8-
98
class MainActivity : AppCompatActivity() {
109

1110
companion object {
1211

13-
const val SS_S_SFDAS = 2
12+
private const val SSS = 2
13+
}
1414

15-
val some = 2
1615

17-
private const val EXTRA_PHOTO = "photo"
1816

19-
fun createIntent(context: Context, photo: String): Intent {
20-
return Intent(context, MainActivity ::class.java).putExtra(EXTRA_PHOTO, photo)
21-
}
17+
fun spme () {
18+
String ?.toString()
19+
}
20+
21+
22+
fun createLauncher() {
23+
createActivityLauncher()
2224
}
2325

24-
val SSs = 2
2526

26-
fun spme() {
27-
String?.toString()
27+
private fun createActivityLauncher(): String {
28+
return "createLauncher()"
2829
}
2930

3031
override fun onCreate(savedInstanceState: Bundle?) {
3132

33+
3234
super.onCreate(savedInstanceState)
3335
setContentView(R.layout.activity_main)
3436

3537

3638
val cTX: Context = this
37-
String.toString()
39+
String
40+
.toString()
41+
String::class.java
3842

3943

4044
val list = listOf<String>()
@@ -44,10 +48,37 @@ class MainActivity : AppCompatActivity() {
4448
}
4549
}
4650

47-
private fun SSsome() {
51+
private fun getTabName(position: Int): String {
52+
return when (position) {
53+
0 -> getString(R.string.app_name)
54+
else -> getString(R.string.app_name)
55+
}
56+
}
57+
58+
59+
60+
private fun SSsome(): Int {
61+
val s = 2
62+
val list = listOf("")
63+
list.forEach { line ->
64+
val some = line
65+
}
66+
67+
val s3 = 1
68+
return when (s) {
69+
s3 -> { 0 }
70+
71+
0, 2 -> {
72+
val some = 2
73+
1
74+
}
75+
else -> 2
76+
}
4877

4978
}
5079

80+
81+
5182
class SomeClass() {
5283
val soURL = 2
5384
}
@@ -61,6 +92,14 @@ class MainActivity : AppCompatActivity() {
6192
}
6293
}
6394

95+
object Auth : Screen()
96+
97+
open class Screen() {}
98+
99+
fun some(): String {
100+
return "S"
101+
}
102+
64103
protected val s2: String = ""
65104

66105

checks/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ lintOptions {
88
textReport true
99
absolutePaths false
1010
ignoreTestSources true
11+
abortOnError false
1112
}
1213

1314
dependencies {

checks/src/main/java/com/omegar/lint/checks/LintIssueRegistry.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.omegar.lint.checks.detector.code_guidelines.kotlin_rules.exception.Ex
99
import com.omegar.lint.checks.detector.code_guidelines.kotlin_style.elements_formating.annotation.AnnotationDetector
1010
import com.omegar.lint.checks.detector.code_guidelines.kotlin_style.elements_formating.lambda.LambdaDetector
1111
import com.omegar.lint.checks.detector.code_guidelines.kotlin_style.name.`class`.NameFileSufixDetector
12+
import com.omegar.lint.checks.detector.code_guidelines.kotlin_style.name.abbreviation.AbbreviationDetector
1213
import com.omegar.lint.checks.detector.code_guidelines.kotlin_style.name.field.CompanionObjectFieldsDetector
1314
import com.omegar.lint.checks.detector.code_guidelines.kotlin_style.order.file_class_interface.ComponentPositionDetector
1415
import com.omegar.lint.checks.detector.code_guidelines.kotlin_style.order.function_params.PositionArgumentDetector
@@ -29,10 +30,10 @@ import com.omegar.lint.checks.detector.project_guidelines.file_name.`class`.Name
2930
import com.omegar.lint.checks.detector.project_guidelines.file_name.resource.layout.NameResourceLayoutDetector
3031

3132
class LintIssueRegistry : IssueRegistry() {
32-
override val issues: List<Issue>
33-
get() = listOf(
33+
override val issues: List<Issue>
34+
get() = listOf(
3435
NameFileUpperCamelCaseDetector.ISSUE,
35-
// AbbreviationDetector.ISSUE, TODO underline const values, need to fix
36+
AbbreviationDetector.ISSUE,// TODO need testing
3637
PositionArgumentDetector.ISSUE,
3738
MaxFunctionsArgumentsDetector.ISSUE,
3839
ExceptionCatchDetector.ISSUE,
@@ -53,13 +54,13 @@ class LintIssueRegistry : IssueRegistry() {
5354
AttributesPositionXmlDetector.ISSUE,
5455
// MaxClassInPackageDetector.ISSUE, TODO this working only for classes which user has visited after rebuild, need to fix, and count all classes
5556
// MaxPackageCountDetector.ISSUE, TODO this working only for classes which user has visited after rebuild, need to fix, and count all classes
56-
SimplificationsControlInstructionsDetector.ISSUE,
57+
SimplificationsControlInstructionsDetector.ISSUE, // TODO need testing
5758
IntentExtraParametersDetector.ISSUE,
5859
ArgumentsBundleKeyPrefixDetector.ISSUE,
5960
LambdaDetector.ISSUE,
6061
NameResourceLayoutDetector.ISSUE
6162
)
6263

63-
override val api: Int
64-
get() = CURRENT_API
65-
}
64+
override val api: Int
65+
get() = CURRENT_API
66+
}

checks/src/main/java/com/omegar/lint/checks/detector/code_guidelines/general_recommendations/parameter_passing/argument_bundle_for_fragments_creation/ArgumentsBundleKeyPrefixDetector.kt

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,25 @@ class ArgumentsBundleKeyPrefixDetector : Detector(), Detector.UastScanner {
1111
/** Issue describing the problem and pointing to the detector implementation */
1212
@JvmField
1313
val ISSUE: Issue = Issue.create(
14-
// ID: used in @SuppressLint warnings etc
15-
id = "OMEGA_USE_KEY_PREFIX_FOR_FRAGMENT_IN_ARGUMENTS_BUNDLE_PARAMS",
16-
// Title -- shown in the IDE's preference dialog, as category headers in the
17-
// Analysis results window, etc
18-
briefDescription = "Use KEY prefix for Fragment in Arguments Bundle param.",
19-
// Full explanation of the issue; you can use some markdown markup such as
20-
// `monospace`, *italic*, and **bold**.
21-
explanation = """
14+
// ID: used in @SuppressLint warnings etc
15+
id = "OMEGA_USE_KEY_PREFIX_FOR_FRAGMENT_IN_ARGUMENTS_BUNDLE_PARAMS",
16+
// Title -- shown in the IDE's preference dialog, as category headers in the
17+
// Analysis results window, etc
18+
briefDescription = "Use KEY prefix for Fragment in Arguments Bundle param.",
19+
// Full explanation of the issue; you can use some markdown markup such as
20+
// `monospace`, *italic*, and **bold**.
21+
explanation = """
2222
Use EXTRA prefix for intent arguments
2323
http://wiki.omega-r.club/dev-android-code#rec228392168
2424
""",
25-
category = Category.CORRECTNESS,
26-
priority = 7,
27-
severity = Severity.WARNING,
28-
implementation = Implementation(
29-
ArgumentsBundleKeyPrefixDetector::class.java,
30-
Scope.JAVA_FILE_SCOPE
31-
)
32-
)
25+
category = Category.CORRECTNESS,
26+
priority = 7,
27+
severity = Severity.WARNING,
28+
implementation = Implementation(
29+
ArgumentsBundleKeyPrefixDetector::class.java,
30+
Scope.JAVA_FILE_SCOPE
31+
)
32+
)
3333

3434
val KEY_PREFIX_REGEX = Regex("""^KEY_""")
3535
val PUT_PARCELABLE_METHOD_REGEX = Regex("""^putParcelable$""")
@@ -51,7 +51,12 @@ class ArgumentsBundleKeyPrefixDetector : Detector(), Detector.UastScanner {
5151
val firstParam = node.valueArguments.firstOrNull() ?: return
5252
val extraParam = firstParam.asRenderString()
5353
if (!extraParam.contains(ArgumentsBundleKeyPrefixDetector.Companion.KEY_PREFIX_REGEX)) {
54-
context.report(ArgumentsBundleKeyPrefixDetector.Companion.ISSUE, node, context.getLocation(firstParam), ArgumentsBundleKeyPrefixDetector.Companion.ISSUE.getExplanation(TextFormat.TEXT))
54+
context.report(
55+
ArgumentsBundleKeyPrefixDetector.Companion.ISSUE,
56+
node,
57+
context.getLocation(firstParam),
58+
ArgumentsBundleKeyPrefixDetector.Companion.ISSUE.getExplanation(TextFormat.TEXT)
59+
)
5560
}
5661
}
5762
}

checks/src/main/java/com/omegar/lint/checks/detector/code_guidelines/general_recommendations/parameter_passing/intent_creation/IntentExtraParametersDetector.kt

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import org.jetbrains.uast.UCallExpression
66
import org.jetbrains.uast.UElement
77

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

33-
val EXTRA_PREFIX_REGEX = Regex("""^EXTRA_""")
34-
val PUT_EXTRA_METHOD_REGEX = Regex("""^putExtra$""")
35-
}
33+
val EXTRA_PREFIX_REGEX = Regex("""^EXTRA_""")
34+
val PUT_EXTRA_METHOD_REGEX = Regex("""^putExtra$""")
35+
}
3636

37-
override fun getApplicableUastTypes(): List<Class<out UElement?>>? {
38-
return listOf(UCallExpression::class.java)
39-
}
37+
override fun getApplicableUastTypes(): List<Class<out UElement?>>? {
38+
return listOf(UCallExpression::class.java)
39+
}
4040

41-
override fun createUastHandler(context: JavaContext): UElementHandler? {
42-
return object : UElementHandler() {
43-
override fun visitCallExpression(node: UCallExpression) {
44-
val name = node.methodName ?: return
41+
override fun createUastHandler(context: JavaContext): UElementHandler? {
42+
return object : UElementHandler() {
43+
override fun visitCallExpression(node: UCallExpression) {
44+
val name = node.methodName ?: return
4545

46-
if(name.matches(PUT_EXTRA_METHOD_REGEX)) {
47-
val firstParam = node.valueArguments.firstOrNull() ?: return
48-
val extraParam = firstParam.asRenderString()
49-
if(!extraParam.contains(EXTRA_PREFIX_REGEX)) {
50-
context.report(ISSUE, node, context.getLocation(firstParam), ISSUE.getExplanation(TextFormat.TEXT))
51-
}
52-
}
53-
}
54-
}
55-
}
46+
if (name.matches(PUT_EXTRA_METHOD_REGEX)) {
47+
val firstParam = node.valueArguments.firstOrNull() ?: return
48+
val extraParam = firstParam.asRenderString()
49+
if (!extraParam.contains(EXTRA_PREFIX_REGEX)) {
50+
context.report(ISSUE, node, context.getLocation(firstParam), ISSUE.getExplanation(TextFormat.TEXT))
51+
}
52+
}
53+
}
54+
}
55+
}
5656
}
5757

checks/src/main/java/com/omegar/lint/checks/detector/code_guidelines/kotlin_rules/exception/ExceptionCatchDetector.kt

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ class ExceptionCatchDetector : Detector(), Detector.UastScanner {
1212
@JvmField
1313
val ISSUE: Issue = Issue.create(
1414

15-
id = "OMEGA_NOT_IGNORE_EXCEPTIONS",
16-
briefDescription = "Catch body is empty, it not match the coding convention",
17-
explanation = """
15+
id = "OMEGA_NOT_IGNORE_EXCEPTIONS",
16+
briefDescription = "Catch body is empty, it not match the coding convention",
17+
explanation = """
1818
Catch body is empty. Add exception handling.
1919
http://wiki.omega-r.club/dev-android-code#rec226449864
2020
""",
21-
category = Category.CORRECTNESS,
22-
priority = 7,
23-
severity = Severity.WARNING,
24-
implementation = Implementation(
25-
ExceptionCatchDetector::class.java,
26-
Scope.JAVA_FILE_SCOPE
27-
)
28-
)
21+
category = Category.CORRECTNESS,
22+
priority = 7,
23+
severity = Severity.WARNING,
24+
implementation = Implementation(
25+
ExceptionCatchDetector::class.java,
26+
Scope.JAVA_FILE_SCOPE
27+
)
28+
)
2929

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

@@ -47,22 +47,22 @@ class ExceptionCatchDetector : Detector(), Detector.UastScanner {
4747
val string = body.asRenderString()
4848
if (string.matches(EMPTY_BODY_REGEX)) {
4949
context.report(
50-
ISSUE,
51-
body,
52-
context.getNameLocation(body),
53-
ISSUE.getExplanation(TextFormat.TEXT)
54-
)
50+
ISSUE,
51+
body,
52+
context.getNameLocation(body),
53+
ISSUE.getExplanation(TextFormat.TEXT)
54+
)
5555
}
5656
val parameters = node.parameters
5757
parameters.forEach {
5858
if (it.type.canonicalText == GENERALIZED_EXCEPTION_VAL) {
5959
if (!string.contains(THROW_VAL)) {
6060
context.report(
61-
ISSUE,
62-
body,
63-
context.getNameLocation(it),
64-
GENERALIZED_EXCEPTION_MESSAGE
65-
)
61+
ISSUE,
62+
body,
63+
context.getNameLocation(it),
64+
GENERALIZED_EXCEPTION_MESSAGE
65+
)
6666
}
6767
}
6868
}

0 commit comments

Comments
 (0)