Skip to content
Snippets Groups Projects

Code formatting

Closed Grégoire Kubler requested to merge feat/formatter into main
Compare and
9 files
+ 65
16
Compare changes
  • Side-by-side
  • Inline
Files
9
 
format:check_code:
 
stage: format
 
rules:
 
tags:
 
- docker
 
before_script:
 
- !reference [.retrieve_deps:apt, script]
 
- apt-get install -y git clang-format-12
 
- pip install ruff
 
script:
 
- set -x
 
- echo "Ensuring that all python files modified in previous commit are correctly formatted. If not, this job will fail."
 
- modified_files=$(git diff --name-only HEAD origin/dev) # change "dev" to $CI_DEFAULT_BRANCH when whole codebase is formatted
 
- nothing_found=true # just an alias to ease reading
 
- modified_python_files=$(echo $modified_files | grep ".py$\|.ipynb$" || true )
 
- modified_CXX_files=$(echo $modified_files | grep ".h$\|.c$\|.hpp$\|.cpp$\|.cu$" || true )
 
- >
 
if [[ -n $modified_python_files ]]; then
 
python_files_to_format=$(ruff format --check $modified_python_files)
 
python_files_to_format=$(( $python_files_to_format != "" ? $python_files_to_format : ""))
 
echo "PYTHON FILES TO FORMAT :"
 
echo "$python_files_to_format"
 
fi
 
- >
 
if [[ -n $modified_CXX_files ]]; then
 
CXX_files_to_format=$(clang-format-12 --dry-run $modified_CXX_files)
 
CXX_files_to_format=$(( $CXX_files_to_format != "" ? $CXX_files_to_format : ""))
 
echo "CXX FILES TO FORMAT :"
 
echo "$CXX_files_to_format"
 
fi
 
- >
 
if [[ "$python_files_to_format$CXX_files_to_format" != "" ]]; then
 
echo "You pushed unformatted files, setup a code formatter before pushing your code."
 
echo "For more informations about code formatting head to the dedicated wiki page :"
 
echo "https://gitlab.eclipse.org/groups/eclipse/aidge/-/wikis/code-quality-:-formatting-&-linting"
 
exit
 
else
 
echo "No files to format, congratulations!"
 
fi
Loading