Skip to content

✨(firmware_mod): Add pre-commit hooks for code quality and formatting#1914

Open
mdeweerd wants to merge 9 commits intoEliasKotlyar:betafrom
mdeweerd:qual/precommit
Open

✨(firmware_mod): Add pre-commit hooks for code quality and formatting#1914
mdeweerd wants to merge 9 commits intoEliasKotlyar:betafrom
mdeweerd:qual/precommit

Conversation

@mdeweerd
Copy link

  • Add pre-commit hooks for code quality and formatting
  • Include hooks for Markdown, YAML, JSON, shell scripts, and text files
  • Configure hooks for various tools like mdformat, pre-commit-hooks, prettier, yamllint, codespell, beautysh, and shellcheck
  • Set up manual stages for some hooks to avoid changing files too much yet
  • Exclude specific files and directories from certain hooks
  • Apply multiple fixes identified by tools

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces pre-commit hooks infrastructure to enforce code quality and formatting standards across the firmware modification codebase. The changes include configuration files for automated code quality checks and apply numerous fixes identified by various linting tools.

Key changes:

  • Added comprehensive pre-commit configuration with hooks for Markdown, YAML, JSON, and shell scripts
  • Set up GitHub Actions workflow for automated pre-commit checks on pull requests
  • Applied multiple automated fixes including spelling corrections, proper quoting in shell scripts, and security improvements

Reviewed changes

Copilot reviewed 44 out of 50 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
.pre-commit-config.yaml Configures pre-commit hooks for mdformat, prettier, yamllint, codespell, beautysh, and shellcheck
.github/workflows/pre-commit.yml Sets up CI workflow to run pre-commit checks automatically
pyproject.toml Adds codespell and yamlfix tool configurations
.gitignore Excludes node_modules generated by tools
Shell scripts (multiple) Adds shellcheck directives, fixes quoting issues, improves variable expansions, and replaces deprecated operators
Documentation files Corrects spelling errors (seperators→separators, trough→through, informations→information, etc.)
HTML files Fixes HTML attribute typos (allign→align)
Python files Corrects shebang positioning
Various files Removes trailing whitespace and ensures proper end-of-file markers

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +230 to +231
{ [ "$send_telegram" = true ] && { [ "$telegram_alert_type" = video+image ] || [ "$telegram_alert_type" = video ]; }; } ||
{ [ "$send_matrix" = true ] && { [ "$matrix_alert_type" = video+image ] || [ "$matrix_alert_type" = video ]; }; } ||
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of parentheses in the test condition for lines 230-231 creates a complex conditional structure. While the syntax is corrected with proper braces and semicolons, this creates deeply nested conditionals that may be hard to read. Consider extracting these conditions into separate boolean variables for better readability.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 44 out of 50 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +230 to +231
{ [ "$send_telegram" = true ] && { [ "$telegram_alert_type" = video+image ] || [ "$telegram_alert_type" = video ]; }; } ||
{ [ "$send_matrix" = true ] && { [ "$matrix_alert_type" = video+image ] || [ "$matrix_alert_type" = video ]; }; } ||
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 230-231 use complex nested braces for conditional logic that is hard to read and potentially error-prone. The original code using parentheses with the '-o' operator was clearer. The current transformation changes semantics: the original condition was "(A && (B || C)) || D", but the new version appears to be "{ A && { B || C; }; } || D" which has different shell evaluation behavior.

Suggested change
{ [ "$send_telegram" = true ] && { [ "$telegram_alert_type" = video+image ] || [ "$telegram_alert_type" = video ]; }; } ||
{ [ "$send_matrix" = true ] && { [ "$matrix_alert_type" = video+image ] || [ "$matrix_alert_type" = video ]; }; } ||
{ [ "$send_telegram" = true ] && [ "$telegram_alert_type" = "video+image" ]; } ||
{ [ "$send_telegram" = true ] && [ "$telegram_alert_type" = "video" ]; } ||
{ [ "$send_matrix" = true ] && [ "$matrix_alert_type" = "video+image" ]; } ||
{ [ "$send_matrix" = true ] && [ "$matrix_alert_type" = "video" ]; } ||

Copilot uses AI. Check for mistakes.
Comment on lines +230 to +231
{ [ "$send_telegram" = true ] && { [ "$telegram_alert_type" = video+image ] || [ "$telegram_alert_type" = video ]; }; } ||
{ [ "$send_matrix" = true ] && { [ "$matrix_alert_type" = video+image ] || [ "$matrix_alert_type" = video ]; }; } ||
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The string comparisons on lines 230-231 are missing quotes around the values 'video+image' and 'video', while similar comparisons elsewhere in the file (lines 51, 361, 388) have these values properly quoted. This inconsistency could lead to word splitting issues or unexpected behavior.

Suggested change
{ [ "$send_telegram" = true ] && { [ "$telegram_alert_type" = video+image ] || [ "$telegram_alert_type" = video ]; }; } ||
{ [ "$send_matrix" = true ] && { [ "$matrix_alert_type" = video+image ] || [ "$matrix_alert_type" = video ]; }; } ||
{ [ "$send_telegram" = true ] && { [ "$telegram_alert_type" = "video+image" ] || [ "$telegram_alert_type" = "video" ]; }; } ||
{ [ "$send_matrix" = true ] && { [ "$matrix_alert_type" = "video+image" ] || [ "$matrix_alert_type" = "video" ]; }; } ||

Copilot uses AI. Check for mistakes.
VER="Need upgrade to have VERSION file"
fi
MQTT_COMMAND="/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -p "$PORT" -u "$USER" -P "$PASS" -t"
MQTT_COMMAND="/system/sdcard/bin/mosquitto_pub.bin -h \"$HOST\" -p \"$PORT\" -u \"$USER\" -P \"$PASS\" -t"
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MQTT_COMMAND variable on line 30 contains quoted variables that will be evaluated when MQTT_COMMAND is expanded. This could lead to unexpected behavior if HOST, PORT, USER, or PASS contain special characters. The previous version without escaped quotes was likely safer. When MQTT_COMMAND is used later with shellcheck disable=2086, the double quoting may cause issues.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@jmtatsch
Copy link
Collaborator

@mdeweerd can you do the PR against the beta branch please?

@mdeweerd mdeweerd changed the base branch from master to beta December 23, 2025 14:54
- Add pre-commit hooks for code quality and formatting
- Include hooks for Markdown, YAML, JSON, shell scripts, and text files
- Configure hooks for various tools like mdformat, pre-commit-hooks, prettier, yamllint, codespell, beautysh, and shellcheck
- Set up manual stages for some hooks to avoid changing files too much yet
- Exclude specific files and directories from certain hooks
- Apply multiple fixes identified by tools
Added shellcheck directives to improve code quality and maintainability. This includes:
- Adding source directives for included files
- Disabling specific shellcheck warnings where appropriate
- Using proper quoting for variables and command substitutions
- Replace 'shellscript source' comments with 'shellcheck source' directives in multiple scripts
- Fix potential issues with file path handling in getFonts function
- Fix shellcheck notices
- Replace `-o` with `||` for better readability and consistency
- Add shellcheck directives for better code quality
- Improve variable handling with `${var:?}` to prevent errors
- Update conditional statements for better readability
Update the skip pattern in the codespell configuration to ensure consistent formatting. Also fix a typo in the quote_representation parameter.
- Added error code 2143 to shellcheck args to ignore specific warnings
- Fixed variable quoting in merge_config.sh for better shell compatibility
- Improved comparison operator in merge_config.sh
Changed comparison operators from '==' to '=' in light sensor conditions to follow shell script best practices. This change improves code consistency and readability without altering functionality.
The motor control command was missing quotes around the expression, which could cause issues with negative values. Added quotes to ensure proper command execution.
@mdeweerd
Copy link
Author

Changed ;-).

@jmtatsch
Copy link
Collaborator

@mdeweerd have you tested functionality on device?

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 44 out of 50 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +124 to +128
if [ "$LIGHT_SENSOR" == 'hw' ]
then
# shellcheck disable=2086
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -p "$PORT" -u "$USER" -P "$PASS" -t "${TOPIC}"/brightness ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "$(ldr status)"
elif [ $LIGHT_SENSOR == 'virtual' ]
elif [ "$LIGHT_SENSOR" == 'virtual' ]
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent comparison operator usage. In this file, the double equals operator (==) is still used for string comparison, but in mqtt-status-interval.sh the same comparisons were changed to use the single equals operator (=). For POSIX shell compatibility and consistency across the codebase, these should also be changed to use the single equals operator (=).

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants