Skip to content

Commit

Permalink
[UseDataClass] Do not report on inner classes (#4344)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aksi0m committed Dec 1, 2021
1 parent 6f41282 commit 5e34645
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
7 changes: 4 additions & 3 deletions README.md
Expand Up @@ -21,7 +21,7 @@ It operates on the abstract syntax tree provided by the Kotlin compiler.
- Complexity reports based on lines of code, cyclomatic complexity and amount of code smells
- Highly configurable rule sets
- Suppression of findings with Kotlin's `@Suppress` and Java's `@SuppressWarnings` annotations
- Specification of quality gates which will break your build
- Specification of quality gates which will break your build
- Code Smell baseline and suppression for legacy projects
- [Gradle plugin](#with-gradle) for code analysis via Gradle builds
- [SonarQube integration](https://github.com/detekt/sonar-kotlin)
Expand Down Expand Up @@ -160,7 +160,7 @@ If you contributed to detekt but your name is not in the list, please feel free
- [Paul Merlin](https://github.com/eskatos) - Gradle build improvements
- [Konstantin Aksenov](https://github.com/vacxe) - Coding improvement
- [Matthew Haughton](https://github.com/3flex) - Added type resolution, Dependency updates, Coding + Documentation improvements
- [Janusz Bagiński](https://github.com/jbaginski) - Fixed line number reporting for MaxLineLengthRule
- [Janusz Bagiński](https://github.com/jbaginski) - Fixed line number reporting for MaxLineLengthRule
- [Mike Kobit](https://github.com/mkobit) - Gradle build improvements
- [Philipp Hofmann](https://github.com/philipphofmann) - Readme improvements
- [Olivier PEREZ](https://github.com/olivierperez) - Fixed Typo in Readme
Expand Down Expand Up @@ -238,10 +238,11 @@ If you contributed to detekt but your name is not in the list, please feel free
- [Lukasz Osowicki](https://github.com/lukaszosowicki) - New rule: OutdatedDocumentation
- [Luan Nico](https://github.com/luanpotter) - Bug fix for the UselessCallOnNotNull rule
- [Tasha Ramesh](https://github.com/drinkthestars) - Docs around configuring for Compose
- [Renato Turic](https://github.com/Aksi0m) - Rule fix: UseDataClass for inner class

### Mentions

[![androidweekly](https://img.shields.io/badge/androidweekly.net-259-orange.svg?style=flat-square)](http://androidweekly.net/issues/issue-259)
[![androidweekly](https://img.shields.io/badge/androidweekly.net-259-orange.svg?style=flat-square)](http://androidweekly.net/issues/issue-259)
[![androidweekly](https://img.shields.io/badge/androidweekly.cn-154-orange.svg?style=flat-square)](http://androidweekly.cn/android-dev-wekly-issue-154/)

As mentioned in...
Expand Down
Expand Up @@ -124,7 +124,8 @@ class UseDataClass(config: Config = Config.empty) : Rule(config) {
klass.isAnnotation() ||
klass.isSealed() ||
klass.isInline() ||
klass.isValue()
klass.isValue() ||
klass.isInner()

private fun hasOnlyPrivateConstructors(klass: KtClass): Boolean {
val primaryConstructor = klass.primaryConstructor
Expand Down
Expand Up @@ -370,5 +370,14 @@ class UseDataClassSpec : Spek({
"""
assertThat(subject.compileAndLint(code)).hasSize(1)
}

it("does not report inner classes") {
val code = """
class Outer {
inner class Inner(val x: Int)
}
""".trimIndent()
assertThat(subject.compileAndLint(code)).isEmpty()
}
}
})

0 comments on commit 5e34645

Please sign in to comment.