Skip to content

Commit

Permalink
review notes
Browse files Browse the repository at this point in the history
  • Loading branch information
nulls committed Nov 22, 2023
1 parent 1a86bb5 commit 6211a81
Showing 1 changed file with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,7 @@ abstract class DiktatBaseMojo : AbstractMojo() {
* @throws MojoExecutionException if an exception in __KtLint__ has been thrown
*/
override fun execute() {
val configFile = resolveConfig()
if (!configFile.isRegularFile()) {
throw MojoExecutionException("Configuration file $diktatConfigFile doesn't exist")
}
val configFile = resolveConfig() ?: throw MojoExecutionException("Configuration file $diktatConfigFile doesn't exist")
log.info("Running diKTat plugin with configuration file $configFile and inputs $inputs" +
if (excludes.isNotEmpty()) " and excluding $excludes" else ""
)
Expand Down Expand Up @@ -149,19 +146,17 @@ abstract class DiktatBaseMojo : AbstractMojo() {
* If [diktatConfigFile] is absolute, it's path is used. If [diktatConfigFile] is relative, this method looks for it in all maven parent projects.
* This way config file can be placed in parent module directory and used in all child modules too.
*
* @return a configuration file. File by this path might not exist.
* @return a configuration file. File by this path exists.
*/
private fun resolveConfig(): Path {
private fun resolveConfig(): Path? {
val file = Paths.get(diktatConfigFile)
if (file.isAbsolute) {
return file
}

return generateSequence(mavenProject) { it.parent }
.map { it.basedir.toPath().resolve(diktatConfigFile) }
.run {
firstOrNull { it.isRegularFile() } ?: file
}
.firstOrNull { it.isRegularFile() }

Check warning on line 159 in diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/DiktatBaseMojo.kt

View check run for this annotation

Codecov / codecov/patch

diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/DiktatBaseMojo.kt#L159

Added line #L159 was not covered by tests
}

private fun files(): List<Path> {
Expand All @@ -182,8 +177,9 @@ abstract class DiktatBaseMojo : AbstractMojo() {
excludedFiles: List<File>,
): Sequence<File> = walk()
.filter { file ->

Check warning on line 179 in diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/DiktatBaseMojo.kt

View check run for this annotation

Codecov / codecov/patch

diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/DiktatBaseMojo.kt#L178-L179

Added lines #L178 - L179 were not covered by tests
file.isDirectory || file.toPath().isKotlinCodeOrScript()
file.isFile && file.toPath().isKotlinCodeOrScript()
}
.filterNot { file ->

Check warning on line 182 in diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/DiktatBaseMojo.kt

View check run for this annotation

Codecov / codecov/patch

diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/DiktatBaseMojo.kt#L182

Added line #L182 was not covered by tests
file in excludedFiles || excludedDirs.any { file.startsWith(it) }
}

Check warning on line 184 in diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/DiktatBaseMojo.kt

View check run for this annotation

Codecov / codecov/patch

diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/DiktatBaseMojo.kt#L184

Added line #L184 was not covered by tests
.filter { it.isFile }
.filterNot { file -> file in excludedFiles || excludedDirs.any { file.startsWith(it) } }
}

0 comments on commit 6211a81

Please sign in to comment.