diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 304689aa..d5bee4f3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -152,3 +152,12 @@ repos: language: system types: [text] files: \.(xacro|urdf|sdf|xml|launch)$ + + - repo: local + hooks: + - id: check-line-length-under-100 + name: Check line length + description: Ensure no line is longer than 100 characters. + entry: bash -c 'if (( $(awk "{ if (length > 100) print }" $1 | wc -l) > 0 )); then echo "Line too long in file $1"; exit 1; fi' + language: system + files: . diff --git a/extras/lint_local/lint_local.sh b/extras/lint_local/lint_local.sh index 87142020..c5725414 100755 --- a/extras/lint_local/lint_local.sh +++ b/extras/lint_local/lint_local.sh @@ -44,7 +44,7 @@ done # Check if Python 3 is installed before checking Python packages if ! command -v python3 &>/dev/null; then - echo -e "\033[31mPython is not installed. Install it to proceed with Python package checks.\033[0m" + echo -e "\033[31mPython is not installed. Install to proceed.\033[0m" else echo "Checking Python dependencies to run lints..." @@ -69,11 +69,17 @@ if [ "$all_dependencies_installed" = true ]; then find . -iname '*.cpp' -o -iname '*.h' | xargs clang-format -i echo -e "\033[32m[3/6] ========= Linting XML files ===========\033[0m" - find . \( -iname '*.urdf' -o -iname '*.sdf' -o -iname '*.xacro' -o -iname '*.xml' -o -iname '*.launch' \) -print0 | xargs -0 xmllint --noout + find . \( -iname '*.urdf' -o -iname '*.sdf' -o -iname '*.xacro' \ + -o -iname '*.xml' -o -iname '*.launch' \) -print0 | xargs -0 xmllint --noout echo -e "\033[32m[4/6] ========= Running ShellCheck ===========\033[0m" # shellcheck disable=SC2038 - find . -iname '*.sh' | xargs shellcheck + find . -iname '*.sh' | while read -r file; do + awk '{ if (length($0) > 100) \ + printf "\033[31mError in file %s: Line %d is %d characters long \ + (should be under 100):\n%s\n\033[0m", \ + FILENAME, NR, length($0), $0 }' "$file" + done echo -e "\033[32m[5/6] ========= Linting YAML files ===========\033[0m" find . \( -iname '*.yml' -o -iname '*.yaml' \) -print0 | xargs -0 yamllint @@ -84,5 +90,6 @@ if [ "$all_dependencies_installed" = true ]; then # shellcheck disable=SC2028 echo "\033[32mAll linting processes completed. Awesome!\033[0m" else - echo -e "\033[31mNot all dependencies are installed. Please install the missing packages before proceeding.\033[0m" + echo -e "\033[31mNot all dependencies are installed. \ + Please install the missing packages before proceeding.\033[0m" fi diff --git a/extras/ros-jazzy-gz-harmonic-install.sh b/extras/ros-jazzy-gz-harmonic-install.sh index 61c146fd..78feb62f 100644 --- a/extras/ros-jazzy-gz-harmonic-install.sh +++ b/extras/ros-jazzy-gz-harmonic-install.sh @@ -32,6 +32,8 @@ sudo apt install -y \ echo "Installation complete!" sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg +# shellcheck disable=SC1091 +# shellcheck disable=SC2086 echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2-testing/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list >/dev/null sudo wget https://packages.osrfoundation.org/gazebo.gpg -O /usr/share/keyrings/pkgs-osrf-archive-keyring.gpg echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/pkgs-osrf-archive-keyring.gpg] http://packages.osrfoundation.org/gazebo/ubuntu-stable $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/gazebo-stable.list >/dev/null