diff --git a/detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/tooling/ParsingStrategy.kt b/detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/tooling/ParsingStrategy.kt index 405cf2f89f8..032167f7aeb 100644 --- a/detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/tooling/ParsingStrategy.kt +++ b/detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/tooling/ParsingStrategy.kt @@ -11,14 +11,13 @@ typealias ParsingStrategy = (settings: ProcessingSettings) -> List fun contentToKtFile(content: String, path: Path): ParsingStrategy = { settings -> require(path.isRegularFile()) { "Given sub path ($path) should be a regular file!" } listOf( - KtCompiler(settings.environment).createKtFile(content, settings.spec.projectSpec.basePath, path) + KtCompiler(settings.environment).createKtFile(content, path) ) } val inputPathsToKtFiles: ParsingStrategy = { settings -> val compiler = KtCompiler(settings.environment) - val basePath = settings.spec.projectSpec.basePath settings.spec.projectSpec.inputPaths.map { path -> - compiler.compile(basePath, path) + compiler.compile(path) } } diff --git a/detekt-generator/src/main/kotlin/io/gitlab/arturbosch/detekt/generator/Generator.kt b/detekt-generator/src/main/kotlin/io/gitlab/arturbosch/detekt/generator/Generator.kt index 68e775e9cfe..5ea1d7295f0 100644 --- a/detekt-generator/src/main/kotlin/io/gitlab/arturbosch/detekt/generator/Generator.kt +++ b/detekt-generator/src/main/kotlin/io/gitlab/arturbosch/detekt/generator/Generator.kt @@ -59,5 +59,5 @@ private fun parseAll(parser: KtCompiler, root: Path): Collection = Files.walk(root) .asSequence() .filter { it.extension == "kt" } - .map { parser.compile(root, it) } + .map { parser.compile(it) } .toList() diff --git a/detekt-parser/src/main/kotlin/io/github/detekt/parser/KtCompiler.kt b/detekt-parser/src/main/kotlin/io/github/detekt/parser/KtCompiler.kt index 2925bb13944..2ac8fed801b 100644 --- a/detekt-parser/src/main/kotlin/io/github/detekt/parser/KtCompiler.kt +++ b/detekt-parser/src/main/kotlin/io/github/detekt/parser/KtCompiler.kt @@ -19,12 +19,12 @@ open class KtCompiler( protected val psiFileFactory = KtPsiFactory(environment.project, markGenerated = false) - fun compile(basePath: Path, path: Path): KtFile { + fun compile(path: Path): KtFile { require(path.isRegularFile()) { "Given path '$path' should be a regular file!" } - return createKtFile(path.readText(), basePath, path) + return createKtFile(path.readText(), path) } - fun createKtFile(@Language("kotlin") content: String, basePath: Path, path: Path): KtFile { + fun createKtFile(@Language("kotlin") content: String, path: Path): KtFile { val psiFile = psiFileFactory.createPhysicalFile(path.name, StringUtilRt.convertLineSeparators(content)) return psiFile.apply { diff --git a/detekt-parser/src/test/kotlin/io/github/detekt/parser/KtCompilerSpec.kt b/detekt-parser/src/test/kotlin/io/github/detekt/parser/KtCompilerSpec.kt index 836041d6229..24f164bbd98 100644 --- a/detekt-parser/src/test/kotlin/io/github/detekt/parser/KtCompilerSpec.kt +++ b/detekt-parser/src/test/kotlin/io/github/detekt/parser/KtCompilerSpec.kt @@ -19,14 +19,14 @@ class KtCompilerSpec { @Test fun `Kotlin file with LF line separators has extra user data`() { - val ktFile = ktCompiler.compile(path, path.resolve("DefaultLf.kt")) + val ktFile = ktCompiler.compile(path.resolve("DefaultLf.kt")) assertThat(ktFile.lineSeparator).isEqualTo("\n") } @Test fun `Kotlin file with CRLF line separators has extra user data`() { - val ktFile = ktCompiler.compile(path, path.resolve("DefaultCrLf.kt")) + val ktFile = ktCompiler.compile(path.resolve("DefaultCrLf.kt")) assertThat(ktFile.lineSeparator).isEqualTo("\r\n") } @@ -34,21 +34,21 @@ class KtCompilerSpec { @Test fun `throws an exception for an invalid path`() { assertThatIllegalArgumentException() - .isThrownBy { ktCompiler.compile(path, path) } + .isThrownBy { ktCompiler.compile(path) } .withMessage("Given path '$path' should be a regular file!") } @Test fun `throws an exception for an non existent path`() { assertThatIllegalArgumentException() - .isThrownBy { ktCompiler.compile(Path(""), Path("nonExistent")) } + .isThrownBy { ktCompiler.compile(Path("nonExistent")) } .withMessage("Given path 'nonExistent' should be a regular file!") } @Test fun `parses with errors for non kotlin files`() { val cssPath = resourceAsPath("css") - val ktFile = ktCompiler.compile(cssPath, cssPath.resolve("test.css")) + val ktFile = ktCompiler.compile(cssPath.resolve("test.css")) val errors = mutableListOf() ktFile.accept(object : KtTreeVisitorVoid() { diff --git a/detekt-test-utils/src/main/kotlin/io/github/detekt/test/utils/CompileExtensions.kt b/detekt-test-utils/src/main/kotlin/io/github/detekt/test/utils/CompileExtensions.kt index 5d2cf48e4b3..0d01e8e1a80 100644 --- a/detekt-test-utils/src/main/kotlin/io/github/detekt/test/utils/CompileExtensions.kt +++ b/detekt-test-utils/src/main/kotlin/io/github/detekt/test/utils/CompileExtensions.kt @@ -27,10 +27,10 @@ fun compileContentForTest( basePath: Path = Path("/").absolute(), path: Path = basePath.resolve("Test.kt"), ): KtFile { - return KtTestCompiler.createKtFile(content, basePath, path) + return KtTestCompiler.createKtFile(content, path) } /** * Use this method if you test a kt file/class in the test resources. */ -fun compileForTest(path: Path) = KtTestCompiler.compile(resourceAsPath("/"), path) +fun compileForTest(path: Path) = KtTestCompiler.compile(path)