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 #5329: Add color formatting to static check messages #5540

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
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
8 changes: 5 additions & 3 deletions scripts/buf_lint_check.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

source scripts/formatting.sh

jar_file_path=$?
config_file_path=$?
os_type=$?
Expand All @@ -15,11 +17,11 @@ lint_protobuf_files() {
status=$?

if [ "$status" = 0 ] ; then
echo "Protobuf lint check completed successfully"
echo_success "Protobuf lint check completed successfully"
exit 0
else
echo "********************************"
echo "Protobuf lint check issues found. Please fix them before pushing your code."
echo_error "Protobuf lint check issues found. Please fix them before pushing your code."
echo "********************************"
exit 1
fi
Expand Down Expand Up @@ -57,7 +59,7 @@ check_os_type() {
elif [[ "$OSTYPE" == "darwin"* ]]; then
os_type="Darwin"
else
echo "Protobuf lint check not available on $OSTYPE"
echo_error "Protobuf lint check not available on $OSTYPE"
exit 0
fi
}
Expand Down
6 changes: 4 additions & 2 deletions scripts/buildifier_lint_check.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

source scripts/formatting.sh

echo "********************************"
echo "Checking Bazel file formatting"
echo "********************************"
Expand All @@ -19,12 +21,12 @@ $buildifier_file_path --lint=warn --mode=check --warnings=-native-android,+out-o
status=$?

if [ "$status" = 0 ] ; then
echo "Buildifier lint check completed successfully"
echo_success "Buildifier lint check completed successfully"
exit 0
else
# Assume any lint output or non-zero exit code is a failure.
echo "********************************"
echo "Buildifier issue found."
echo_error "Buildifier issue found."
echo "Please fix the above issues."
echo "********************************"
exit 1
Expand Down
6 changes: 4 additions & 2 deletions scripts/checkstyle_lint_check.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

source scripts/formatting.sh

echo "********************************"
echo "Checking Java file formatting"
echo "********************************"
Expand All @@ -23,11 +25,11 @@ echo $lint_results
if [ "$lint_command_result" -ne 0 ] || [ -z "$lint_results" ] || [[ ${lint_results} == *"[WARN]"* ]]; then
# Assume any lint output or non-zero exit code is a failure.
echo "********************************"
echo "Checkstyle issue found."
echo_error "Checkstyle issue found."
echo "Please fix the above issues."
echo "********************************"
exit 1
else
echo "Checkstyle lint check completed successfully"
echo_success "Checkstyle lint check completed successfully"
exit 0
fi
10 changes: 6 additions & 4 deletions scripts/feature_flags_check.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

source scripts/formatting.sh

echo "********************************"
echo "Running feature flag checks"
echo "********************************"
Expand Down Expand Up @@ -120,24 +122,24 @@ function perform_checks_on_feature_flags() {
in_array=$(item_in_array "$element" "${imported_classes[@]}")
if [[ $in_array -ne 1 ]]; then
failed_checks=$((failed_checks + 1))
echo "$element is not imported in the constructor argument in $file_path at line $imports_line_number"
echo_error "$element is not imported in the constructor argument in $file_path at line $imports_line_number"
fi
done

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

if [[ $failed_checks -eq 0 ]]; then
echo "Feature flag checks completed successfully"
echo_success "Feature flag checks completed successfully"
exit 0
else
echo "********************************"
echo "Feature flag issues found."
echo_error "Feature flag issues found."
echo "Please fix the above issues."
echo "********************************"
exit 1
Expand Down
19 changes: 19 additions & 0 deletions scripts/formatting.sh
theMr17 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m'

function echo_error() {
echo -e "${RED}$1${NC}"
}

function echo_success() {
echo -e "${GREEN}$1${NC}"
}

function echo_warning() {
echo -e "${YELLOW}$1${NC}"
}

8 changes: 5 additions & 3 deletions scripts/ktlint_lint_check.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

source scripts/formatting.sh

echo "********************************"
echo "Checking code formatting"
echo "********************************"
Expand All @@ -19,15 +21,15 @@ java -jar $jar_file_path --android app/src/**/*.kt data/src/**/*.kt domain/src/*
status=$?

if [ "$status" = 0 ] ; then
echo "Lint completed successfully."
echo_success "Lint completed successfully."
exit 0
else
echo "********************************"
echo "Ktlint issue found."
echo_error "Ktlint issue found."
echo "Please fix the above issues.
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
command to fix the most common issues."
echo "Please note, there might be a possibility where the above command will not fix the issue.
echo_warning "Please note, there might be a possibility where the above command will not fix the issue.
In that case, you will have to fix it yourself."
echo "********************************"
exit 1
Expand Down
4 changes: 3 additions & 1 deletion scripts/pre-push.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#!/bin/bash

source scripts/formatting.sh

# This script will run the pre-push checks in the given order
# - ktlint
# - checkstyle
# - buf
# - (others in the future)

if bash scripts/ktlint_lint_check.sh && bash scripts/checkstyle_lint_check.sh && bash scripts/buf_lint_check.sh ; then
echo "All checks passed successfully"
echo_success "All checks passed successfully"
exit 0
else
exit 1
Expand Down
Loading