Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #5075: Revert "Fix #5072 : Remove condition of hex color for drawables from regex" #5081

Closed
wants to merge 5 commits into from
Closed
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
11 changes: 11 additions & 0 deletions scripts/assets/file_content_validation_checks.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,17 @@ file_content_checks {
prohibited_content_regex: "@color/(?!component_color_).+|\"#\\p{XDigit}+\""
failure_message: "Only colors from component_colors.xml may be used in layouts."
}
file_content_checks {
file_path_regex: "app/src/main/res/drawable.*?/.+?\\.xml"
prohibited_content_regex: "@color/(?!component_color_).+|\"#\\p{XDigit}+\""
failure_message: "Only colors from component_colors.xml may be used in drawables except vector assets."
exempted_file_patterns: "app/src/main/res/drawable.*?/(ic_|lesson_thumbnail_graphic_).+?\\.xml"
exempted_file_patterns: "app/src/main/res/drawable/full_oppia_logo.xml"
exempted_file_patterns: "app/src/main/res/drawable/rounded_white_background_with_shadow.xml"
exempted_file_patterns: "app/src/main/res/drawable/profile_image_shadow.xml"
exempted_file_patterns: "app/src/main/res/drawable/selected_region_background.xml"
exempted_file_patterns: "app/src/main/res/drawable/splash_page.xml"
}
file_content_checks {
file_path_regex: "app/src/main/java/org/oppia/android/app.?/.+(ActivityPresenter|FragmentPresenter|ViewPresenter|Activity|Fragment|View)\\.kt"
prohibited_content_regex: "R.color.(?!component_color_).+"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ class RegexPatternValidationCheckTest {
"Only colors from color_defs.xml may be used in color_palette.xml."
private val doesNotReferenceColorFromComponentColorInLayouts =
"Only colors from component_colors.xml may be used in layouts."
private val doesNotReferenceColorFromComponentColorInDrawables =
"Only colors from component_colors.xml may be used in drawables except vector assets."
private val doesNotReferenceColorFromComponentColorInKotlinFiles =
"Only colors from component_colors.xml may be used in Kotlin Files (Activities, Fragments, " +
"Views and Presenters)."
Expand Down Expand Up @@ -2343,7 +2345,35 @@ class RegexPatternValidationCheckTest {
)
}

// TODO(#5075): Add test for drawables file that checks color uses only component colors
@Test
fun testFileContent_xmlDrawables_includesNonColorComponentReferences_fileContentIsNotCorrect() {
val prohibitedContent =
"""
android:color="@color/component_color_shared_primary_text_color"
android:color="@color/color_defs_shared_primary_text_color"
android:color="@color/color_palette_primary_text_color"
android:color="#003933"
""".trimIndent()
tempFolder.newFolder("testfiles", "app", "src", "main", "res", "drawable")
val stringFilePath = "app/src/main/res/drawable/test_layout.xml"
tempFolder.newFile("testfiles/$stringFilePath").writeText(prohibitedContent)

val exception = assertThrows(Exception::class) {
runScript()
}

// Verify that all patterns are properly detected & prohibited.
assertThat(exception).hasMessageThat().contains(REGEX_CHECK_FAILED_OUTPUT_INDICATOR)
assertThat(outContent.toString().trim())
.isEqualTo(
"""
$stringFilePath:2: $doesNotReferenceColorFromComponentColorInDrawables
$stringFilePath:3: $doesNotReferenceColorFromComponentColorInDrawables
$stringFilePath:4: $doesNotReferenceColorFromComponentColorInDrawables
$wikiReferenceNote
""".trimIndent()
)
}

@Test
fun testFileContent_kotlinFiles_includesNonColorComponentReferences_fileContentIsNotCorrect() {
Expand Down