Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Quick-Fix incorrectly applied in kotlin #401

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ private LintFix quickFixIssueLog(UCallExpression logCall) {
throw new IllegalStateException("android.util.Log overloads should have 2 or 3 arguments");
}

String logCallSource = logCall.asSourceString();
String logCallSource = logCall.getUastParent().asSourceString();
LintFix.GroupBuilder fixGrouper = fix().group();
fixGrouper.add(
fix().replace().text(logCallSource).shortenNames().reformat(true).with(fixSource1).build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,34 @@ class WrongTimberUsageDetectorTest {
|- Log.d("TAG", "msg");
|+ Timber.d("msg");
|""".trimMargin())

lint()
.files(
kt("""
|package foo
|import android.util.Log
|class Example {
| fun log() {
| Log.d("TAG", "msg")
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_LOG)
.run()
.expect("""
|src/foo/Example.kt:5: Warning: Using 'Log' instead of 'Timber' [LogNotTimber]
| Log.d("TAG", "msg")
| ~~~~~~~~~~~~~~~~~~~
|0 errors, 1 warnings""".trimMargin())
.expectFixDiffs("""
|Fix for src/foo/Example.kt line 5: Replace with Timber.tag("TAG").d("msg"):
|@@ -5 +5
|- Log.d("TAG", "msg")
|+ Timber.tag("TAG").d("msg")
|Fix for src/foo/Example.kt line 5: Replace with Timber.d("msg"):
|@@ -5 +5
|- Log.d("TAG", "msg")
|+ Timber.d("msg")""".trimMargin())
}

@Test fun usingAndroidLogWithThreeArguments() {
Expand Down Expand Up @@ -82,6 +110,25 @@ class WrongTimberUsageDetectorTest {
|- Log.d("TAG", "msg", new Exception());
|+ Timber.d(new Exception(), "msg");
|""".trimMargin())

lint()
.files(
kt("""
|package foo
|import android.util.Log
|class Example {
| fun log() {
| Log.d("TAG", "msg", Exception())
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_LOG)
.run()
.expect("""
|src/foo/Example.kt:5: Warning: Using 'Log' instead of 'Timber' [LogNotTimber]
| Log.d("TAG", "msg", Exception())
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|0 errors, 1 warnings""".trimMargin())
}

@Test fun usingFullyQualifiedAndroidLogWithTwoArguments() {
Expand Down Expand Up @@ -112,6 +159,34 @@ class WrongTimberUsageDetectorTest {
|- android.util.Log.d("TAG", "msg");
|+ Timber.d("msg");
|""".trimMargin())

lint()
.files(
kt("""
|package foo
|class Example {
| fun log() {
| android.util.Log.d("TAG", "msg")
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_LOG)
.run()
.expect("""
|src/foo/Example.kt:4: Warning: Using 'Log' instead of 'Timber' [LogNotTimber]
| android.util.Log.d("TAG", "msg")
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|0 errors, 1 warnings""".trimMargin())
.expectFixDiffs("""
|Fix for src/foo/Example.kt line 4: Replace with Timber.tag("TAG").d("msg"):
|@@ -4 +4
|- android.util.Log.d("TAG", "msg")
|+ Timber.tag("TAG").d("msg")
|Fix for src/foo/Example.kt line 4: Replace with Timber.d("msg"):
|@@ -4 +4
|- android.util.Log.d("TAG", "msg")
|+ Timber.d("msg")
|""".trimMargin())
}

@Test fun usingFullyQualifiedAndroidLogWithThreeArguments() {
Expand Down Expand Up @@ -142,6 +217,24 @@ class WrongTimberUsageDetectorTest {
|- android.util.Log.d("TAG", "msg", new Exception());
|+ Timber.d(new Exception(), "msg");
|""".trimMargin())

lint()
.files(
kt("""
|package foo
|class Example {
| fun log() {
| android.util.Log.d("TAG", "msg", Exception());
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_LOG)
.run()
.expect("""
|src/foo/Example.kt:4: Warning: Using 'Log' instead of 'Timber' [LogNotTimber]
| android.util.Log.d("TAG", "msg", Exception());
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|0 errors, 1 warnings""".trimMargin())
}

@Test fun innerStringFormat() {
Expand Down