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

Move PathFilters from detekt-api to detekt-utils #6866

Merged
merged 3 commits into from May 6, 2024
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
1 change: 1 addition & 0 deletions detekt-cli/build.gradle.kts
Expand Up @@ -22,6 +22,7 @@ val pluginsJarFiles by configurations.resolvable("pluginsJarFiles") {
dependencies {
implementation(libs.jcommander)
implementation(projects.detektTooling)
implementation(projects.detektUtils)
implementation(libs.kotlin.compilerEmbeddable) {
version {
strictly(libs.versions.kotlin.get())
Expand Down
Expand Up @@ -2,9 +2,9 @@ package io.gitlab.arturbosch.detekt.cli

import io.github.detekt.tooling.api.spec.ProcessingSpec
import io.github.detekt.tooling.api.spec.RulesSpec
import io.github.detekt.utils.PathFilters
import io.gitlab.arturbosch.detekt.api.Rule
import io.gitlab.arturbosch.detekt.api.RuleSet
import io.gitlab.arturbosch.detekt.api.internal.PathFilters
import java.nio.file.Path
import kotlin.io.path.ExperimentalPathApi
import kotlin.io.path.absolute
Expand Down

This file was deleted.

@@ -1,8 +1,8 @@
package io.gitlab.arturbosch.detekt.core.util

import io.github.detekt.psi.absolutePath
import io.github.detekt.utils.PathFilters
import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.api.internal.PathFilters
import org.jetbrains.kotlin.psi.KtFile
import java.nio.file.Path
import kotlin.io.path.Path
Expand Down
@@ -1,4 +1,4 @@
package io.gitlab.arturbosch.detekt.api.internal
package io.github.detekt.utils

import java.nio.file.Path
import java.nio.file.PathMatcher
Expand Down
@@ -1,4 +1,4 @@
package io.gitlab.arturbosch.detekt.api.internal
package io.github.detekt.utils

import java.nio.file.FileSystem
import java.nio.file.FileSystems
Expand All @@ -9,7 +9,7 @@ import java.nio.file.PathMatcher
* We only support the "glob:" syntax to stay os independently.
* Internally a globbing pattern is transformed to a regex respecting the Windows file system.
*/
fun pathMatcher(pattern: String): PathMatcher {
internal fun pathMatcher(pattern: String): PathMatcher {
val result = when (pattern.substringBefore(":")) {
"glob" -> pattern
"regex" -> throw IllegalArgumentException(USE_GLOB_MSG)
Expand Down
@@ -0,0 +1,42 @@
package io.github.detekt.utils

import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import kotlin.io.path.Path

class PathFiltersSpec {

@Test
fun `returns an empty path filter when includes are empty and excludes are empty`() {
val pathFilter = PathFilters.of(emptyList(), emptyList())
assertThat(pathFilter).isNull()
}

@Test
fun `parses includes correctly`() {
val pathFilter = PathFilters.of(listOf("**/one/**", "**/two/**"), emptyList())
assertThat(pathFilter).isNotNull
assertThat(pathFilter?.isIgnored(Path("/one/path"))).isFalse
assertThat(pathFilter?.isIgnored(Path("/two/path"))).isFalse
assertThat(pathFilter?.isIgnored(Path("/three/path"))).isTrue
}

@Test
fun `parses excludes correctly`() {
val pathFilter = PathFilters.of(emptyList(), listOf("**/one/**", "**/two/**"))
assertThat(pathFilter).isNotNull
assertThat(pathFilter?.isIgnored(Path("/one/path"))).isTrue
assertThat(pathFilter?.isIgnored(Path("/two/path"))).isTrue
assertThat(pathFilter?.isIgnored(Path("/three/path"))).isFalse
}

@Test
fun `parses both includes and excludes correctly`() {
val pathFilter = PathFilters.of(listOf("**/one/**"), listOf("**/two/**"))
assertThat(pathFilter).isNotNull
assertThat(pathFilter?.isIgnored(Path("/one/path"))).isFalse
assertThat(pathFilter?.isIgnored(Path("/two/path"))).isTrue
assertThat(pathFilter?.isIgnored(Path("/three/path"))).isTrue
assertThat(pathFilter?.isIgnored(Path("/one/two/three/path"))).isTrue
}
}
@@ -1,4 +1,4 @@
package io.gitlab.arturbosch.detekt.api.internal
package io.github.detekt.utils

import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatThrownBy
Expand Down