From 7ac8d6848ab597b992b4e828e913b4cf5f793917 Mon Sep 17 00:00:00 2001 From: Ludwig Fritsch Date: Mon, 13 Nov 2023 14:30:53 +0100 Subject: [PATCH 01/12] Add default value for tabWidth #3336 --- .../codecharta/parser/rawtextparser/ParserDialog.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt index fee269bfa0..a7bf5a0275 100644 --- a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt +++ b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt @@ -35,7 +35,7 @@ class ParserDialog { ) val tabWidth: BigDecimal = - KInquirer.promptInputNumber(message = "What is the tab width used (estimated if not provided)?") + KInquirer.promptInputNumber(message = "What is the tab width used (estimated if not provided)?", default="") val maxIndentationLevel: BigDecimal = KInquirer.promptInputNumber(message = "What is the maximum Indentation Level?", default = "10", hint = "10") From d05fe202c8283bae96c4019b47efca51d3b8f638 Mon Sep 17 00:00:00 2001 From: Ludwig Fritsch Date: Mon, 13 Nov 2023 20:30:40 +0100 Subject: [PATCH 02/12] Provide hint for tabWidth #3336 --- .../codecharta/parser/rawtextparser/ParserDialog.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt index a7bf5a0275..fd27ad7a8c 100644 --- a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt +++ b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt @@ -35,7 +35,7 @@ class ParserDialog { ) val tabWidth: BigDecimal = - KInquirer.promptInputNumber(message = "What is the tab width used (estimated if not provided)?", default="") + KInquirer.promptInputNumber(message = "What is the tab width used (estimated if kept at 0)?", default="0", hint="0") val maxIndentationLevel: BigDecimal = KInquirer.promptInputNumber(message = "What is the maximum Indentation Level?", default = "10", hint = "10") From 5a3ee9b96653feab0a32264ca18c25a38154893a Mon Sep 17 00:00:00 2001 From: Ludwig Fritsch Date: Mon, 13 Nov 2023 21:10:18 +0100 Subject: [PATCH 03/12] Add missing spaces around '=' #3336 --- .../codecharta/parser/rawtextparser/ParserDialog.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt index fd27ad7a8c..e7116cecc2 100644 --- a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt +++ b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt @@ -35,7 +35,7 @@ class ParserDialog { ) val tabWidth: BigDecimal = - KInquirer.promptInputNumber(message = "What is the tab width used (estimated if kept at 0)?", default="0", hint="0") + KInquirer.promptInputNumber(message = "What is the tab width used (estimated if kept at 0)?", default = "0", hint = "0") val maxIndentationLevel: BigDecimal = KInquirer.promptInputNumber(message = "What is the maximum Indentation Level?", default = "10", hint = "10") From cb3f4b87373ec3619421839f0c30977c42f48e63 Mon Sep 17 00:00:00 2001 From: Ludwig Fritsch Date: Tue, 14 Nov 2023 09:48:52 +0100 Subject: [PATCH 04/12] Set default value for tabwidth to unknown #3336 --- .../codecharta/parser/rawtextparser/ParserDialog.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt index e7116cecc2..cb363777b3 100644 --- a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt +++ b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt @@ -6,6 +6,7 @@ import com.github.kinquirer.components.promptInput import com.github.kinquirer.components.promptInputNumber import de.maibornwolff.codecharta.tools.interactiveparser.ParserDialogInterface import java.math.BigDecimal +import java.math.BigInteger import java.nio.file.Paths class ParserDialog { @@ -34,8 +35,8 @@ class ParserDialog { hint = "metric1, metric2, metric3 (leave empty for all metrics)" ) - val tabWidth: BigDecimal = - KInquirer.promptInputNumber(message = "What is the tab width used (estimated if kept at 0)?", default = "0", hint = "0") + val tabWidth: Int = + KInquirer.promptInput(message = "What is the tab width used (estimated if unknown)?", default = "unknown", hint = "unknown").toIntOrNull() ?: 0 val maxIndentationLevel: BigDecimal = KInquirer.promptInputNumber(message = "What is the maximum Indentation Level?", default = "10", hint = "10") From 6443872190875232ffff7fa024cc13c0f298d310 Mon Sep 17 00:00:00 2001 From: Ludwig Fritsch Date: Tue, 14 Nov 2023 10:00:33 +0100 Subject: [PATCH 05/12] Remove unused import #3336 --- .../maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt index cb363777b3..a776bffd45 100644 --- a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt +++ b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt @@ -6,7 +6,6 @@ import com.github.kinquirer.components.promptInput import com.github.kinquirer.components.promptInputNumber import de.maibornwolff.codecharta.tools.interactiveparser.ParserDialogInterface import java.math.BigDecimal -import java.math.BigInteger import java.nio.file.Paths class ParserDialog { From 0a9fcf7e73a7f8202147b7e8ebb456ac061fbde4 Mon Sep 17 00:00:00 2001 From: Ludwig Fritsch Date: Tue, 14 Nov 2023 11:39:44 +0100 Subject: [PATCH 06/12] Add tests for invalid tabwidth-input #3336 --- .../parser/rawtextparser/ParserDialog.kt | 7 +- .../rawtextparser/ParserDialogTest.kt | 86 ++++++++++++++++--- 2 files changed, 77 insertions(+), 16 deletions(-) diff --git a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt index a776bffd45..ea24e2ef81 100644 --- a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt +++ b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt @@ -34,8 +34,9 @@ class ParserDialog { hint = "metric1, metric2, metric3 (leave empty for all metrics)" ) - val tabWidth: Int = - KInquirer.promptInput(message = "What is the tab width used (estimated if unknown)?", default = "unknown", hint = "unknown").toIntOrNull() ?: 0 + val tabWidth: String = + KInquirer.promptInput(message = "What is the tab width used (estimated if unknown)?", default = "unknown", hint = "unknown") + val tabWidthValue = tabWidth.toIntOrNull() ?: 0 val maxIndentationLevel: BigDecimal = KInquirer.promptInputNumber(message = "What is the maximum Indentation Level?", default = "10", hint = "10") @@ -54,7 +55,7 @@ class ParserDialog { if (isCompressed) null else "--not-compressed", "--verbose=$verbose", "--metrics=$metrics", - "--tab-width=$tabWidth", + "--tab-width=$tabWidthValue", "--max-indentation-level=$maxIndentationLevel", "--exclude=$exclude", "--file-extensions=$fileExtensions", diff --git a/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/ParserDialogTest.kt b/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/ParserDialogTest.kt index 2be10a16f4..bdbb87eeb1 100644 --- a/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/ParserDialogTest.kt +++ b/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/ParserDialogTest.kt @@ -13,6 +13,9 @@ import org.assertj.core.api.Assertions import org.junit.jupiter.api.AfterAll import org.junit.jupiter.api.Test import org.junit.jupiter.api.TestInstance +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.Arguments +import org.junit.jupiter.params.provider.MethodSource import picocli.CommandLine import java.io.File import java.math.BigDecimal @@ -25,6 +28,42 @@ class ParserDialogTest { unmockkAll() } + companion object { + @JvmStatic + fun provideInvalidTabWidth(): List { + return listOf( + Arguments.of("unknown"), + Arguments.of("string-value"), + Arguments.of("12."), + Arguments.of("12.0")) + } + } + + private fun setupMockedInquirer( + fileName: String, + outputFileName: String, + metrics: String, + tabWidth: String, + exclude: String, + fileExtensions: String, + maxIndentLvl: BigDecimal, + isCompressed: Boolean, + verbose: Boolean, + withoutDefaultExcludes: Boolean + ) { + mockkStatic("com.github.kinquirer.components.InputKt") + every { + KInquirer.promptInput(any(), any(), any()) + } returns fileName andThen outputFileName andThen metrics andThen tabWidth andThen exclude andThen fileExtensions + every { + KInquirer.promptInputNumber(any(), any(), any()) + } returns maxIndentLvl + mockkStatic("com.github.kinquirer.components.ConfirmKt") + every { + KInquirer.promptConfirm(any(), any()) + } returns isCompressed andThen verbose andThen withoutDefaultExcludes + } + @Test fun `should output correct arguments that can be parsed`() { val fileName = "test.txt" @@ -32,33 +71,54 @@ class ParserDialogTest { val isCompressed = false val verbose = false val metrics = "metric1" - val tabWidth = BigDecimal(0) + val tabWidth = "5" + val tabWidthValue = 5 val maxIndentLvl = BigDecimal(10) val exclude = "file1" val fileExtensions = "" val withoutDefaultExcludes = false - mockkStatic("com.github.kinquirer.components.InputKt") - every { - KInquirer.promptInput(any(), any(), any()) - } returns fileName andThen outputFileName andThen metrics andThen exclude andThen fileExtensions - every { - KInquirer.promptInputNumber(any(), any(), any()) - } returns tabWidth andThen maxIndentLvl - mockkStatic("com.github.kinquirer.components.ConfirmKt") - every { - KInquirer.promptConfirm(any(), any()) - } returns isCompressed andThen verbose andThen withoutDefaultExcludes + setupMockedInquirer(fileName, outputFileName, metrics, tabWidth, exclude, fileExtensions, maxIndentLvl, isCompressed, verbose, withoutDefaultExcludes) val parserArguments = ParserDialog.collectParserArgs() + val commandLine = CommandLine(RawTextParser()) + val parseResult = commandLine.parseArgs(*parserArguments.toTypedArray()) + Assertions.assertThat(parseResult.matchedOption("output-file").getValue().equals(outputFileName)) + Assertions.assertThat(parseResult.matchedOption("not-compressed").getValue()).isEqualTo(isCompressed) + Assertions.assertThat(parseResult.matchedOption("metrics").getValue>()).isEqualTo(listOf(metrics)) + Assertions.assertThat(parseResult.matchedOption("max-indentation-level").getValue()).isEqualTo(maxIndentLvl.toInt()) + Assertions.assertThat(parseResult.matchedOption("tab-width").getValue()).isEqualTo(tabWidthValue) + Assertions.assertThat(parseResult.matchedOption("file-extensions").getValue>()).isEqualTo(arrayOf(fileExtensions)) + Assertions.assertThat(parseResult.matchedOption("without-default-excludes").getValue()).isEqualTo(withoutDefaultExcludes) + Assertions.assertThat(parseResult.matchedOption("verbose").getValue()).isEqualTo(withoutDefaultExcludes) + Assertions.assertThat(parseResult.matchedOption("exclude").getValue>()).isEqualTo(arrayOf(exclude)) + Assertions.assertThat(parseResult.matchedPositional(0).getValue().name).isEqualTo(fileName) + } + @ParameterizedTest + @MethodSource("provideInvalidTabWidth") + fun `should set non-integer tab-width to 0`(invalidTabWidth: String) { + val fileName = "test.txt" + val outputFileName = "test.cc.json" + val isCompressed = false + val verbose = false + val metrics = "metric1" + val tabWidthValue = 0 + val maxIndentLvl = BigDecimal(10) + val exclude = "file1" + val fileExtensions = "" + val withoutDefaultExcludes = false + + setupMockedInquirer(fileName, outputFileName, metrics, invalidTabWidth, exclude, fileExtensions, maxIndentLvl, isCompressed, verbose, withoutDefaultExcludes) + + val parserArguments = ParserDialog.collectParserArgs() val commandLine = CommandLine(RawTextParser()) val parseResult = commandLine.parseArgs(*parserArguments.toTypedArray()) Assertions.assertThat(parseResult.matchedOption("output-file").getValue().equals(outputFileName)) Assertions.assertThat(parseResult.matchedOption("not-compressed").getValue()).isEqualTo(isCompressed) Assertions.assertThat(parseResult.matchedOption("metrics").getValue>()).isEqualTo(listOf(metrics)) Assertions.assertThat(parseResult.matchedOption("max-indentation-level").getValue()).isEqualTo(maxIndentLvl.toInt()) - Assertions.assertThat(parseResult.matchedOption("tab-width").getValue()).isEqualTo(tabWidth.toInt()) + Assertions.assertThat(parseResult.matchedOption("tab-width").getValue()).isEqualTo(tabWidthValue) Assertions.assertThat(parseResult.matchedOption("file-extensions").getValue>()).isEqualTo(arrayOf(fileExtensions)) Assertions.assertThat(parseResult.matchedOption("without-default-excludes").getValue()).isEqualTo(withoutDefaultExcludes) Assertions.assertThat(parseResult.matchedOption("verbose").getValue()).isEqualTo(withoutDefaultExcludes) From e8a0d888621f920e96affb91a77801a13bd9d8c0 Mon Sep 17 00:00:00 2001 From: Ludwig Fritsch Date: Tue, 14 Nov 2023 13:58:45 +0100 Subject: [PATCH 07/12] Add changelog entry tabwidth estimation #3336 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 639c59048a..5e8e231447 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/) ### Fixed 🐞 - Fix an issue with web demo on Safari showing a white screen and not loading [#3396](https://github.com/MaibornWolff/codecharta/pull/3396) +- Allow user to skip the value for tabwidth when configuring the rawtextparser and estimate its value [#3404](https://github.com/MaibornWolff/codecharta/pull/3404) ### Chore 👨‍💻 👩‍💻 From ce7fc001a34d4e2fa784003bebc8805194dde5da Mon Sep 17 00:00:00 2001 From: Ludwig Fritsch Date: Wed, 15 Nov 2023 09:36:35 +0100 Subject: [PATCH 08/12] Handle negative integer values for tabwidth #3336 --- .../parser/rawtextparser/metrics/IndentationCounter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/metrics/IndentationCounter.kt b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/metrics/IndentationCounter.kt index 13fe04adce..ff8498f1b1 100644 --- a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/metrics/IndentationCounter.kt +++ b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/metrics/IndentationCounter.kt @@ -72,7 +72,7 @@ class IndentationCounter( } override fun getValue(): FileMetrics { - if (tabWidth == 0) { + if (tabWidth <= 0) { guessTabWidth() } correctMismatchingIndents(tabWidth) From df261a4416088f66c61a079b0a1dbeb6fe2118bb Mon Sep 17 00:00:00 2001 From: Ludwig Fritsch Date: Thu, 16 Nov 2023 14:53:45 +0100 Subject: [PATCH 09/12] Clarify changelog entry #3336 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e8e231447..f8c0792796 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/) ### Fixed 🐞 - Fix an issue with web demo on Safari showing a white screen and not loading [#3396](https://github.com/MaibornWolff/codecharta/pull/3396) -- Allow user to skip the value for tabwidth when configuring the rawtextparser and estimate its value [#3404](https://github.com/MaibornWolff/codecharta/pull/3404) +- Fix the ability for users to skip the value for tab-width when configuring the rawtextparser and estimate its value [#3404](https://github.com/MaibornWolff/codecharta/pull/3404) ### Chore 👨‍💻 👩‍💻 From 5d2161b9e1198b4c5e2f5f4faedf997729d5ad5c Mon Sep 17 00:00:00 2001 From: Ludwig Fritsch Date: Thu, 16 Nov 2023 16:59:02 +0100 Subject: [PATCH 10/12] Set default tab-width empty #3336 --- .../codecharta/parser/rawtextparser/ParserDialog.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt index ea24e2ef81..0ca28f7bb5 100644 --- a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt +++ b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt @@ -35,7 +35,7 @@ class ParserDialog { ) val tabWidth: String = - KInquirer.promptInput(message = "What is the tab width used (estimated if unknown)?", default = "unknown", hint = "unknown") + KInquirer.promptInput(message = "What is the tab width used (estimated if empty)?", default = "") val tabWidthValue = tabWidth.toIntOrNull() ?: 0 val maxIndentationLevel: BigDecimal = KInquirer.promptInputNumber(message = "What is the maximum Indentation Level?", default = "10", hint = "10") From 7728a47a85bf72d067ea4b936f81a07a957c2a80 Mon Sep 17 00:00:00 2001 From: Ludwig Fritsch Date: Thu, 16 Nov 2023 17:00:08 +0100 Subject: [PATCH 11/12] Adjust test cases for tab-width #3336 --- .../maibornwolff/codecharta/rawtextparser/ParserDialogTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/ParserDialogTest.kt b/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/ParserDialogTest.kt index bdbb87eeb1..7995a7d5a3 100644 --- a/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/ParserDialogTest.kt +++ b/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/ParserDialogTest.kt @@ -32,8 +32,8 @@ class ParserDialogTest { @JvmStatic fun provideInvalidTabWidth(): List { return listOf( - Arguments.of("unknown"), Arguments.of("string-value"), + Arguments.of(""), Arguments.of("12."), Arguments.of("12.0")) } From b0b0433803e894edff105b2c2f711d8f5bd6b795 Mon Sep 17 00:00:00 2001 From: Ludwig Fritsch Date: Thu, 16 Nov 2023 17:11:40 +0100 Subject: [PATCH 12/12] Clarify question for tab-width #3336 --- .../codecharta/parser/rawtextparser/ParserDialog.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt index 0ca28f7bb5..81d9446b5d 100644 --- a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt +++ b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt @@ -35,7 +35,7 @@ class ParserDialog { ) val tabWidth: String = - KInquirer.promptInput(message = "What is the tab width used (estimated if empty)?", default = "") + KInquirer.promptInput(message = "How many spaces represent one indentation level when using spaces for indentation (estimated if empty)?", default = "") val tabWidthValue = tabWidth.toIntOrNull() ?: 0 val maxIndentationLevel: BigDecimal = KInquirer.promptInputNumber(message = "What is the maximum Indentation Level?", default = "10", hint = "10")