From f5457ec98007def178bba124800352fa8ad4d2f4 Mon Sep 17 00:00:00 2001 From: manas-yu Date: Thu, 26 Dec 2024 19:47:20 +0530 Subject: [PATCH 1/4] adding cases to regex --- .../app/player/audio/LanguageInterface.kt | 2 +- .../android/app/shim/IntentFactoryShim.kt | 4 +- .../app/story/StoryFragmentScroller.kt | 2 +- .../domain/hintsandsolution/HintHandler.kt | 2 +- .../exceptions/ExceptionsController.kt | 2 +- .../file_content_validation_checks.textproto | 4 +- .../regex/RegexPatternValidationCheckTest.kt | 51 ++++++++++--------- 7 files changed, 34 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/player/audio/LanguageInterface.kt b/app/src/main/java/org/oppia/android/app/player/audio/LanguageInterface.kt index ad3265ebdca..769b990f4d9 100644 --- a/app/src/main/java/org/oppia/android/app/player/audio/LanguageInterface.kt +++ b/app/src/main/java/org/oppia/android/app/player/audio/LanguageInterface.kt @@ -11,7 +11,7 @@ interface LanguageInterface { /** * Returns whether the user is actively seeking a new audio position, that is, dragging the * knob to a new position in the audio track. - * */ + */ fun getUserIsSeeking(): Boolean /** Returns the position of the knob on the audio track. */ diff --git a/app/src/main/java/org/oppia/android/app/shim/IntentFactoryShim.kt b/app/src/main/java/org/oppia/android/app/shim/IntentFactoryShim.kt index 0a8994ce081..208942cb9bb 100644 --- a/app/src/main/java/org/oppia/android/app/shim/IntentFactoryShim.kt +++ b/app/src/main/java/org/oppia/android/app/shim/IntentFactoryShim.kt @@ -16,7 +16,7 @@ interface IntentFactoryShim { /** * Creates a [TopicActivity] intent for [PromotedStoryViewModel] and passes necessary string * data. - * */ + */ fun createTopicPlayStoryActivityIntent( context: Context, internalProfileId: Int, @@ -27,7 +27,7 @@ interface IntentFactoryShim { /** * Creates a [TopicActivity] intent which opens info-tab. - * */ + */ fun createTopicActivityIntent( context: Context, internalProfileId: Int, diff --git a/app/src/main/java/org/oppia/android/app/story/StoryFragmentScroller.kt b/app/src/main/java/org/oppia/android/app/story/StoryFragmentScroller.kt index cb3ee1cf989..50c900d1f68 100644 --- a/app/src/main/java/org/oppia/android/app/story/StoryFragmentScroller.kt +++ b/app/src/main/java/org/oppia/android/app/story/StoryFragmentScroller.kt @@ -4,6 +4,6 @@ interface StoryFragmentScroller { /** * Scrolls smoothly (with animation) to the specified vertical pixel position in * [StoryFragment]. - * */ + */ fun smoothScrollToPosition(position: Int) } diff --git a/domain/src/main/java/org/oppia/android/domain/hintsandsolution/HintHandler.kt b/domain/src/main/java/org/oppia/android/domain/hintsandsolution/HintHandler.kt index e836f381541..35ca867e6a3 100644 --- a/domain/src/main/java/org/oppia/android/domain/hintsandsolution/HintHandler.kt +++ b/domain/src/main/java/org/oppia/android/domain/hintsandsolution/HintHandler.kt @@ -35,7 +35,7 @@ interface HintHandler { * @param trackedWrongAnswerCount the count of wrong answers saved in the checkpoint * @param helpIndex the cached state of hints/solution from the checkpoint * @param state the restored pending state - * */ + */ suspend fun resumeHintsForSavedState( trackedWrongAnswerCount: Int, helpIndex: HelpIndex, diff --git a/domain/src/main/java/org/oppia/android/domain/oppialogger/exceptions/ExceptionsController.kt b/domain/src/main/java/org/oppia/android/domain/oppialogger/exceptions/ExceptionsController.kt index 16e8640a1c9..f0912590b25 100644 --- a/domain/src/main/java/org/oppia/android/domain/oppialogger/exceptions/ExceptionsController.kt +++ b/domain/src/main/java/org/oppia/android/domain/oppialogger/exceptions/ExceptionsController.kt @@ -113,7 +113,7 @@ class ExceptionsController @Inject constructor( * At first, it checks if the size of the store isn't exceeding [exceptionLogStorageCacheSize]. * If the limit is exceeded then the least recent exception is removed from the [exceptionLogStore]. * After this, the [exceptionLog] is added to the store. - * */ + */ private fun cacheExceptionLog(exceptionLog: ExceptionLog) { exceptionLogStore.storeDataAsync(true) { oppiaExceptionLogs -> val storeSize = oppiaExceptionLogs.exceptionLogList.size diff --git a/scripts/assets/file_content_validation_checks.textproto b/scripts/assets/file_content_validation_checks.textproto index fe0d7d9aba9..788ffc0e86c 100644 --- a/scripts/assets/file_content_validation_checks.textproto +++ b/scripts/assets/file_content_validation_checks.textproto @@ -503,8 +503,8 @@ file_content_checks { } file_content_checks { file_path_regex: ".+?\\.kt$" - prohibited_content_regex: "\\*\\*/" - failure_message: "Badly formatted KDoc or block comment. KDocs and block comments should only end with \"*/\"." + prohibited_content_regex: "\\*(\\s*\\*|\\*)/" + failure_message: "Badly formatted KDoc or block comment. KDocs and block comments should only end with \"*/\". Multiple asterisks or whitespace between asterisks are not allowed." exempted_file_name: "scripts/src/javatests/org/oppia/android/scripts/regex/RegexPatternValidationCheckTest.kt" } file_content_checks { diff --git a/scripts/src/javatests/org/oppia/android/scripts/regex/RegexPatternValidationCheckTest.kt b/scripts/src/javatests/org/oppia/android/scripts/regex/RegexPatternValidationCheckTest.kt index 5f47d4b81e1..7f6924c12bd 100644 --- a/scripts/src/javatests/org/oppia/android/scripts/regex/RegexPatternValidationCheckTest.kt +++ b/scripts/src/javatests/org/oppia/android/scripts/regex/RegexPatternValidationCheckTest.kt @@ -2566,23 +2566,23 @@ class RegexPatternValidationCheckTest { fun testFileContent_multipleCommentTypesWithExtraCharactersBeforeEnd_fileContentIsNotCorrect() { val prohibitedContent = """ - /** Content here.*/ - /** Content here. **/ - /** Correct KDoc. */ - - /* - * Incorrect block comment. - **/ - /* - * Correct block comment. - */ - /** - * Incorrect KDoc comment. - **/ - /** - * Correct KDoc comment. - */ - """.trimIndent() + /** Content here.*/ + /** Content here. **/ + /** Correct KDoc. */ + + /* + * Incorrect block comment. + **/ + /* + * Correct block comment. + */ + /** + * Incorrect KDoc comment. + * */ + /** + * Correct KDoc comment. + */ + """.trimIndent() tempFolder.newFolder("testfiles", "app", "src", "main", "java", "org", "oppia", "android") val stringFilePath = "app/src/main/java/org/oppia/android/TestPresenter.kt" tempFolder.newFile("testfiles/$stringFilePath").writeText(prohibitedContent) @@ -2596,14 +2596,15 @@ class RegexPatternValidationCheckTest { assertThat(outContent.toString().trim()) .isEqualTo( """ - $stringFilePath:1: $badSingleLineKdocShouldHaveSpacesBeforeEnding - $stringFilePath:2: $badSingleLineKdocShouldHaveSpacesBeforeEnding - $stringFilePath:2: $badKdocOrBlockCommentShouldEndWithCorrectEnding - $stringFilePath:7: $badKdocOrBlockCommentShouldEndWithCorrectEnding - $stringFilePath:13: $badKdocOrBlockCommentShouldEndWithCorrectEnding - $stringFilePath:2: $badSingleLineKdocShouldEndWithPunctuation - $wikiReferenceNote - """.trimIndent() + $stringFilePath:1: $badSingleLineKdocShouldHaveSpacesBeforeEnding + $stringFilePath:2: $badSingleLineKdocShouldHaveSpacesBeforeEnding + $stringFilePath:2: $badKdocOrBlockCommentShouldEndWithCorrectEnding + $stringFilePath:7: $badKdocOrBlockCommentShouldEndWithCorrectEnding + $stringFilePath:13: $badKdocOrBlockCommentShouldEndWithCorrectEnding + $stringFilePath:12: $badKdocOrBlockCommentShouldEndWithCorrectEnding + $stringFilePath:2: $badSingleLineKdocShouldEndWithPunctuation + $wikiReferenceNote + """.trimIndent() ) } From ee7d3d311f000d955ff2e42eaa74323ebdf82702 Mon Sep 17 00:00:00 2001 From: manas-yu Date: Thu, 26 Dec 2024 19:48:36 +0530 Subject: [PATCH 2/4] formatting --- .../android/scripts/regex/RegexPatternValidationCheckTest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/src/javatests/org/oppia/android/scripts/regex/RegexPatternValidationCheckTest.kt b/scripts/src/javatests/org/oppia/android/scripts/regex/RegexPatternValidationCheckTest.kt index 7f6924c12bd..519c645e0a3 100644 --- a/scripts/src/javatests/org/oppia/android/scripts/regex/RegexPatternValidationCheckTest.kt +++ b/scripts/src/javatests/org/oppia/android/scripts/regex/RegexPatternValidationCheckTest.kt @@ -2582,7 +2582,7 @@ class RegexPatternValidationCheckTest { /** * Correct KDoc comment. */ - """.trimIndent() + """.trimIndent() tempFolder.newFolder("testfiles", "app", "src", "main", "java", "org", "oppia", "android") val stringFilePath = "app/src/main/java/org/oppia/android/TestPresenter.kt" tempFolder.newFile("testfiles/$stringFilePath").writeText(prohibitedContent) @@ -2604,7 +2604,7 @@ class RegexPatternValidationCheckTest { $stringFilePath:12: $badKdocOrBlockCommentShouldEndWithCorrectEnding $stringFilePath:2: $badSingleLineKdocShouldEndWithPunctuation $wikiReferenceNote - """.trimIndent() + """.trimIndent() ) } From 6e8d5fd8771bd7817127261c6f46b7a002498cd1 Mon Sep 17 00:00:00 2001 From: manas-yu Date: Thu, 26 Dec 2024 20:51:35 +0530 Subject: [PATCH 3/4] test fix --- .../regex/RegexPatternValidationCheckTest.kt | 79 +++++++++++++------ 1 file changed, 55 insertions(+), 24 deletions(-) diff --git a/scripts/src/javatests/org/oppia/android/scripts/regex/RegexPatternValidationCheckTest.kt b/scripts/src/javatests/org/oppia/android/scripts/regex/RegexPatternValidationCheckTest.kt index 519c645e0a3..6e4fec07570 100644 --- a/scripts/src/javatests/org/oppia/android/scripts/regex/RegexPatternValidationCheckTest.kt +++ b/scripts/src/javatests/org/oppia/android/scripts/regex/RegexPatternValidationCheckTest.kt @@ -206,7 +206,8 @@ class RegexPatternValidationCheckTest { "Badly formatted KDoc. Single-line KDocs should always end with exactly one space before the" + " final \"*/\"." private val badKdocOrBlockCommentShouldEndWithCorrectEnding = - "Badly formatted KDoc or block comment. KDocs and block comments should only end with \"*/\"." + "Badly formatted KDoc or block comment. KDocs and block comments should only" + + " end with \"*/\". Multiple asterisks or whitespace between asterisks are not allowed." private val badKdocParamsAndPropertiesShouldHaveNameFollowing = "Badly formatted KDoc param or property at-clause: the name of the parameter or property" + " should immediately follow the at-clause without any additional linking with brackets." @@ -2566,22 +2567,22 @@ class RegexPatternValidationCheckTest { fun testFileContent_multipleCommentTypesWithExtraCharactersBeforeEnd_fileContentIsNotCorrect() { val prohibitedContent = """ - /** Content here.*/ - /** Content here. **/ - /** Correct KDoc. */ + /** Content here.*/ + /** Content here. **/ + /** Correct KDoc. */ - /* - * Incorrect block comment. - **/ - /* - * Correct block comment. - */ - /** - * Incorrect KDoc comment. - * */ - /** - * Correct KDoc comment. - */ + /* + * Incorrect block comment. + **/ + /* + * Correct block comment. + */ + /** + * Incorrect KDoc comment. + **/ + /** + * Correct KDoc comment. + */ """.trimIndent() tempFolder.newFolder("testfiles", "app", "src", "main", "java", "org", "oppia", "android") val stringFilePath = "app/src/main/java/org/oppia/android/TestPresenter.kt" @@ -2596,18 +2597,48 @@ class RegexPatternValidationCheckTest { assertThat(outContent.toString().trim()) .isEqualTo( """ - $stringFilePath:1: $badSingleLineKdocShouldHaveSpacesBeforeEnding - $stringFilePath:2: $badSingleLineKdocShouldHaveSpacesBeforeEnding - $stringFilePath:2: $badKdocOrBlockCommentShouldEndWithCorrectEnding - $stringFilePath:7: $badKdocOrBlockCommentShouldEndWithCorrectEnding - $stringFilePath:13: $badKdocOrBlockCommentShouldEndWithCorrectEnding - $stringFilePath:12: $badKdocOrBlockCommentShouldEndWithCorrectEnding - $stringFilePath:2: $badSingleLineKdocShouldEndWithPunctuation - $wikiReferenceNote + $stringFilePath:1: $badSingleLineKdocShouldHaveSpacesBeforeEnding + $stringFilePath:2: $badSingleLineKdocShouldHaveSpacesBeforeEnding + $stringFilePath:2: $badKdocOrBlockCommentShouldEndWithCorrectEnding + $stringFilePath:7: $badKdocOrBlockCommentShouldEndWithCorrectEnding + $stringFilePath:13: $badKdocOrBlockCommentShouldEndWithCorrectEnding + $stringFilePath:2: $badSingleLineKdocShouldEndWithPunctuation + $wikiReferenceNote """.trimIndent() ) } + @Test + fun testFileContent_kdocWithInvalidEndingSequences_failsValidation() { + val prohibitedContent = + """ + /** + * Incorrect KDoc comment. + * */ + /** + * Incorrect KDoc comment. + **/ + /** + * Correct KDoc comment. + */ + """.trimIndent() + tempFolder.newFolder("testfiles", "app", "src", "main", "java", "org", "oppia", "android") + val stringFilePath = "app/src/main/java/org/oppia/android/TestPresenter.kt" + tempFolder.newFile("testfiles/$stringFilePath").writeText(prohibitedContent) + + val exception = assertThrows() { runScript() } + + assertThat(exception).hasMessageThat().contains(REGEX_CHECK_FAILED_OUTPUT_INDICATOR) + assertThat(outContent.toString().trim()) + .isEqualTo( + """ + $stringFilePath:3: $badKdocOrBlockCommentShouldEndWithCorrectEnding + $stringFilePath:6: $badKdocOrBlockCommentShouldEndWithCorrectEnding + $wikiReferenceNote + """.trimIndent() + ) + } + @Test fun testFileContent_singleLineKdocWithExtraSpacesBeforeEnd_fileContentIsNotCorrect() { val prohibitedContent = From cc871af3775ee475ec2df6a03d32d56f4c0daa09 Mon Sep 17 00:00:00 2001 From: manas-yu Date: Thu, 26 Dec 2024 20:52:35 +0530 Subject: [PATCH 4/4] formatting --- .../android/scripts/regex/RegexPatternValidationCheckTest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/src/javatests/org/oppia/android/scripts/regex/RegexPatternValidationCheckTest.kt b/scripts/src/javatests/org/oppia/android/scripts/regex/RegexPatternValidationCheckTest.kt index 6e4fec07570..60b415c68db 100644 --- a/scripts/src/javatests/org/oppia/android/scripts/regex/RegexPatternValidationCheckTest.kt +++ b/scripts/src/javatests/org/oppia/android/scripts/regex/RegexPatternValidationCheckTest.kt @@ -2621,7 +2621,7 @@ class RegexPatternValidationCheckTest { /** * Correct KDoc comment. */ - """.trimIndent() + """.trimIndent() tempFolder.newFolder("testfiles", "app", "src", "main", "java", "org", "oppia", "android") val stringFilePath = "app/src/main/java/org/oppia/android/TestPresenter.kt" tempFolder.newFile("testfiles/$stringFilePath").writeText(prohibitedContent) @@ -2635,7 +2635,7 @@ class RegexPatternValidationCheckTest { $stringFilePath:3: $badKdocOrBlockCommentShouldEndWithCorrectEnding $stringFilePath:6: $badKdocOrBlockCommentShouldEndWithCorrectEnding $wikiReferenceNote - """.trimIndent() + """.trimIndent() ) }