Skip to content
Open
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
6 changes: 3 additions & 3 deletions .github/workflows/gradle-pr-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
os: [windows-latest]
java: [ 8, 11 ]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -20,7 +20,7 @@ jobs:
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with release Kotlin version
run: ./gradlew clean build ktlint
run: ./gradlew --stacktrace clean build ktlint
- name: Upload artifacts
uses: actions/upload-artifact@v2
if: failure()
Expand All @@ -29,4 +29,4 @@ jobs:
path: '**/build/**/dependency-verification-report.html'
if-no-files-found: warn
- name: Build with dev Kotlin version
run: ./gradlew -PkotlinDev clean build ktlint
run: ./gradlew --stacktrace -PkotlinDev clean build ktlint
26 changes: 21 additions & 5 deletions ktlint/src/main/kotlin/com/pinterest/ktlint/internal/FileUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import java.io.File
import java.nio.file.FileSystem
import java.nio.file.FileVisitResult
import java.nio.file.Files
import java.nio.file.InvalidPathException
import java.nio.file.Path
import java.nio.file.Paths
import java.nio.file.SimpleFileVisitor
Expand All @@ -23,28 +24,43 @@ internal fun FileSystem.fileSequence(
): Sequence<Path> {
checkGlobsContainAbsolutePath(globs)

val pathMatchers = if (globs.isEmpty()) {
val result = mutableListOf<Path>()

val (existingFiles, actualGlobs) = globs.partition {
try {
Files.isRegularFile(rootDir.resolve(it))
} catch (e: InvalidPathException) {
false
}
}
existingFiles.mapTo(result) { rootDir.resolve(it) }

// Return early and don't traverse the file system if all the input globs are absolute paths
if (result.isNotEmpty() && actualGlobs.isEmpty()) {
return result.asSequence()
}

val pathMatchers = if (actualGlobs.isEmpty()) {
setOf(
getPathMatcher("glob:**$globSeparator*.kt"),
getPathMatcher("glob:**$globSeparator*.kts")
)
} else {
globs
actualGlobs
.filterNot { it.startsWith("!") }
.map {
getPathMatcher(it.toGlob(rootDir))
}
}

val negatedPathMatchers = if (globs.isEmpty()) {
val negatedPathMatchers = if (actualGlobs.isEmpty()) {
emptySet()
} else {
globs
actualGlobs
.filter { it.startsWith("!") }
.map { getPathMatcher(it.removePrefix("!").toGlob(rootDir)) }
}

val result = mutableListOf<Path>()
Files.walkFileTree(
rootDir,
object : SimpleFileVisitor<Path>() {
Expand Down