Skip to content

Commit ec5a4f0

Browse files
Fix #5329: Add color formatting to static check messages (#5540)
<!-- READ ME FIRST: Please fill in the explanation section below and check off every point from the Essential Checklist! --> ## Explanation Fixes #5329 This PR implements color-coded messages for static checks to improve experience. Error messages are displayed in red for failing checks, while warnings are shown in yellow. Successful checks are indicated with green messages. <!-- - 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. --> ## 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)). ## For UI-specific PRs only <!-- Delete these section if this PR does not include UI-related changes. --> If your PR includes UI-related changes, then: - Add screenshots for portrait/landscape for both a tablet & phone of the before & after UI changes - For the screenshots above, include both English and pseudo-localized (RTL) screenshots (see [RTL guide](https://github.com/oppia/oppia-android/wiki/RTL-Guidelines)) - Add a video showing the full UX flow with a screen reader enabled (see [accessibility guide](https://github.com/oppia/oppia-android/wiki/Accessibility-A11y-Guide)) - For PRs introducing new UI elements or color changes, both light and dark mode screenshots must be included - Add a screenshot demonstrating that you ran affected Espresso tests locally & that they're passing --------- Co-authored-by: Adhiambo Peres <[email protected]>
1 parent f7e4651 commit ec5a4f0

File tree

7 files changed

+57
-15
lines changed

7 files changed

+57
-15
lines changed

scripts/buf_lint_check.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

3+
source scripts/formatting.sh
4+
35
jar_file_path=$?
46
config_file_path=$?
57
os_type=$?
@@ -15,11 +17,11 @@ lint_protobuf_files() {
1517
status=$?
1618

1719
if [ "$status" = 0 ] ; then
18-
echo "Protobuf lint check completed successfully"
20+
echo_success "Protobuf lint check completed successfully"
1921
exit 0
2022
else
2123
echo "********************************"
22-
echo "Protobuf lint check issues found. Please fix them before pushing your code."
24+
echo_error "Protobuf lint check issues found. Please fix them before pushing your code."
2325
echo "********************************"
2426
exit 1
2527
fi
@@ -57,7 +59,7 @@ check_os_type() {
5759
elif [[ "$OSTYPE" == "darwin"* ]]; then
5860
os_type="Darwin"
5961
else
60-
echo "Protobuf lint check not available on $OSTYPE"
62+
echo_error "Protobuf lint check not available on $OSTYPE"
6163
exit 0
6264
fi
6365
}

scripts/buildifier_lint_check.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

3+
source scripts/formatting.sh
4+
35
echo "********************************"
46
echo "Checking Bazel file formatting"
57
echo "********************************"
@@ -19,12 +21,12 @@ $buildifier_file_path --lint=warn --mode=check --warnings=-native-android,+out-o
1921
status=$?
2022

2123
if [ "$status" = 0 ] ; then
22-
echo "Buildifier lint check completed successfully"
24+
echo_success "Buildifier lint check completed successfully"
2325
exit 0
2426
else
2527
# Assume any lint output or non-zero exit code is a failure.
2628
echo "********************************"
27-
echo "Buildifier issue found."
29+
echo_error "Buildifier issue found."
2830
echo "Please fix the above issues."
2931
echo "********************************"
3032
exit 1

scripts/checkstyle_lint_check.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

3+
source scripts/formatting.sh
4+
35
echo "********************************"
46
echo "Checking Java file formatting"
57
echo "********************************"
@@ -23,11 +25,11 @@ echo $lint_results
2325
if [ "$lint_command_result" -ne 0 ] || [ -z "$lint_results" ] || [[ ${lint_results} == *"[WARN]"* ]]; then
2426
# Assume any lint output or non-zero exit code is a failure.
2527
echo "********************************"
26-
echo "Checkstyle issue found."
28+
echo_error "Checkstyle issue found."
2729
echo "Please fix the above issues."
2830
echo "********************************"
2931
exit 1
3032
else
31-
echo "Checkstyle lint check completed successfully"
33+
echo_success "Checkstyle lint check completed successfully"
3234
exit 0
3335
fi

scripts/feature_flags_check.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

3+
source scripts/formatting.sh
4+
35
echo "********************************"
46
echo "Running feature flag checks"
57
echo "********************************"
@@ -120,24 +122,24 @@ function perform_checks_on_feature_flags() {
120122
in_array=$(item_in_array "$element" "${imported_classes[@]}")
121123
if [[ $in_array -ne 1 ]]; then
122124
failed_checks=$((failed_checks + 1))
123-
echo "$element is not imported in the constructor argument in $file_path at line $imports_line_number"
125+
echo_error "$element is not imported in the constructor argument in $file_path at line $imports_line_number"
124126
fi
125127
done
126128

127129
for element in "${feature_flags[@]}"; do
128130
in_array=$(item_in_array "$element" "${flags_added_to_map[@]}")
129131
if [[ $in_array -ne 1 ]]; then
130132
failed_checks=$((failed_checks + 1))
131-
echo "$element is not added to the logging map in $file_path at line $flags_map_line_number"
133+
echo_error "$element is not added to the logging map in $file_path at line $flags_map_line_number"
132134
fi
133135
done
134136

135137
if [[ $failed_checks -eq 0 ]]; then
136-
echo "Feature flag checks completed successfully"
138+
echo_success "Feature flag checks completed successfully"
137139
exit 0
138140
else
139141
echo "********************************"
140-
echo "Feature flag issues found."
142+
echo_error "Feature flag issues found."
141143
echo "Please fix the above issues."
142144
echo "********************************"
143145
exit 1

scripts/formatting.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
#Defines color codes for output formatting
4+
5+
# Red color for error messages
6+
RED='\033[0;31m'
7+
8+
# Green color for success messages
9+
GREEN='\033[0;32m'
10+
11+
# Yellow color for warnings messages
12+
YELLOW='\033[0;33m'
13+
14+
# No color, used to reset the color after each message
15+
NC='\033[0m'
16+
17+
# Function to print an error message in red
18+
function echo_error() {
19+
echo -e "${RED}$1${NC}"
20+
}
21+
22+
# Function to print a success message in green
23+
function echo_success() {
24+
echo -e "${GREEN}$1${NC}"
25+
}
26+
27+
# Function to print a warning message in yellow
28+
function echo_warning() {
29+
echo -e "${YELLOW}$1${NC}"
30+
}

scripts/ktlint_lint_check.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

3+
source scripts/formatting.sh
4+
35
echo "********************************"
46
echo "Checking code formatting"
57
echo "********************************"
@@ -19,15 +21,15 @@ java -jar $jar_file_path --android app/src/**/*.kt data/src/**/*.kt domain/src/*
1921
status=$?
2022

2123
if [ "$status" = 0 ] ; then
22-
echo "Lint completed successfully."
24+
echo_success "Lint completed successfully."
2325
exit 0
2426
else
2527
echo "********************************"
26-
echo "Ktlint issue found."
28+
echo_error "Ktlint issue found."
2729
echo "Please fix the above issues.
2830
You can also use the java -jar $jar_file_path -F --android domain/src/**/*.kt utility/src/**/*.kt data/src/**/*.kt app/src/**/*.kt testing/src/**/*.kt scripts/src/**/*.kt instrumentation/src/**/*.kt
2931
command to fix the most common issues."
30-
echo "Please note, there might be a possibility where the above command will not fix the issue.
32+
echo_warning "Please note, there might be a possibility where the above command will not fix the issue.
3133
In that case, you will have to fix it yourself."
3234
echo "********************************"
3335
exit 1

scripts/pre-push.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
#!/bin/bash
22

3+
source scripts/formatting.sh
4+
35
# This script will run the pre-push checks in the given order
46
# - ktlint
57
# - checkstyle
68
# - buf
79
# - (others in the future)
810

911
if bash scripts/ktlint_lint_check.sh && bash scripts/checkstyle_lint_check.sh && bash scripts/buf_lint_check.sh ; then
10-
echo "All checks passed successfully"
12+
echo_success "All checks passed successfully"
1113
exit 0
1214
else
1315
exit 1

0 commit comments

Comments
 (0)