Skip to content

Commit

Permalink
Fix #3394: Validating Kdoc ending sequence (#5622)
Browse files Browse the repository at this point in the history
<!-- READ ME FIRST: Please fill in the explanation section below and
check off every point from the Essential Checklist! -->
## Explanation
<!--
- Explain what your PR does. If this PR fixes an existing bug, please
include
- "Fixes #bugnum:" in the explanation so that GitHub can auto-close the
issue
  - when this PR is merged.
  -->
Fix #3394
Updated the `file_content_checks` to validate against
`\\*(\\s*\\*|\\*)/` for KDoc and block comment endings. This change
ensures the script correctly detects improperly formatted endings, such
as those with multiple asterisks or unnecessary whitespace before the
closing /.

Additionally, updated the existing incorrect KDoc endings flagged by the
RegexPatternValidationCheck.kt script to conform to the correct format.
## Essential Checklist
<!-- Please tick the relevant boxes by putting an "x" in them. -->
- [x] The PR title and explanation each start with "Fix #bugnum: " (If
this PR fixes part of an issue, prefix the title with "Fix part of
#bugnum: ...".)
- [x] Any changes to
[scripts/assets](https://github.com/oppia/oppia-android/tree/develop/scripts/assets)
files have their rationale included in the PR explanation.
- [x] The PR follows the [style
guide](https://github.com/oppia/oppia-android/wiki/Coding-style-guide).
- [x] The PR does not contain any unnecessary code changes from Android
Studio
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#undo-unnecessary-changes)).
- [x] The PR is made from a branch that's **not** called "develop" and
is up-to-date with "develop".
- [x] The PR is **assigned** to the appropriate reviewers
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#clarification-regarding-assignees-and-reviewers-section)).
  • Loading branch information
manas-yu authored Jan 15, 2025
1 parent 4f5aec6 commit 164956c
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface IntentFactoryShim {
/**
* Creates a [TopicActivity] intent for [PromotedStoryViewModel] and passes necessary string
* data.
* */
*/
fun createTopicPlayStoryActivityIntent(
context: Context,
internalProfileId: Int,
Expand All @@ -27,7 +27,7 @@ interface IntentFactoryShim {

/**
* Creates a [TopicActivity] intent which opens info-tab.
* */
*/
fun createTopicActivityIntent(
context: Context,
internalProfileId: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ interface StoryFragmentScroller {
/**
* Scrolls smoothly (with animation) to the specified vertical pixel position in
* [StoryFragment].
* */
*/
fun smoothScrollToPosition(position: Int)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions scripts/assets/file_content_validation_checks.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -2607,6 +2608,37 @@ class RegexPatternValidationCheckTest {
)
}

@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<Exception>() { 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 =
Expand Down

0 comments on commit 164956c

Please sign in to comment.