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

Show finding at declaration name instead of the whole declaration #5003

Merged
merged 1 commit into from Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -79,7 +79,7 @@ class MatchingDeclarationName(config: Config = Config.empty) : Rule(config) {
val declarationName = declaration.name
val filename = file.fileNameWithoutSuffix()
if (declarationName != filename && hasNoMatchingTypeAlias(filename)) {
val entity = Entity.from(declaration).copy(ktElement = file)
val entity = Entity.atName(declaration).copy(ktElement = file)
report(
CodeSmell(
issue,
Expand Down
Expand Up @@ -132,7 +132,7 @@ class MatchingDeclarationNameSpec {
fun `should not pass for object declaration`() {
val ktFile = compileContentForTest("object O", filename = "Objects.kt")
val findings = MatchingDeclarationName().lint(ktFile)
assertThat(findings).hasSourceLocation(1, 1)
assertThat(findings).hasSourceLocation(1, 8)
}

@Test
Expand All @@ -142,14 +142,14 @@ class MatchingDeclarationNameSpec {
filename = "Objects.kt"
)
val findings = MatchingDeclarationName().lint(ktFile)
assertThat(findings).hasSourceLocation(1, 1)
assertThat(findings).hasSourceLocation(1, 45)
}

@Test
fun `should not pass for class declaration`() {
val ktFile = compileContentForTest("class C", filename = "Classes.kt")
val findings = MatchingDeclarationName().lint(ktFile)
assertThat(findings).hasSourceLocation(1, 1)
assertThat(findings).hasSourceLocation(1, 7)
}

@Test
Expand All @@ -163,14 +163,14 @@ class MatchingDeclarationNameSpec {
filename = "ClassUtils.kt"
)
val findings = MatchingDeclarationName().lint(ktFile)
assertThat(findings).hasSourceLocation(1, 1)
assertThat(findings).hasSourceLocation(1, 7)
}

@Test
fun `should not pass for interface declaration`() {
val ktFile = compileContentForTest("interface I", filename = "Not_I.kt")
val findings = MatchingDeclarationName().lint(ktFile)
assertThat(findings).hasSourceLocation(1, 1)
assertThat(findings).hasSourceLocation(1, 11)
}

@Test
Expand All @@ -184,7 +184,7 @@ class MatchingDeclarationNameSpec {
filename = "E.kt"
)
val findings = MatchingDeclarationName().lint(ktFile)
assertThat(findings).hasSourceLocation(1, 1)
assertThat(findings).hasSourceLocation(1, 12)
}

@Test
Expand All @@ -211,7 +211,7 @@ class MatchingDeclarationNameSpec {
val findings = MatchingDeclarationName(
TestConfig("mustBeFirst" to "false")
).lint(ktFile)
assertThat(findings).hasSourceLocation(3, 1)
assertThat(findings).hasSourceLocation(3, 7)
}
}
}