Package: arduino-hooks
Arduino HooksThis project providespre-commithooks forarduinocommand line tooling.
This is an un-official project.Currently, this includes:arduino-lint- Linter for checking arduino projects for problems and conformance to conventions.arduino-cli- Limited tocompilecalls for verifying arduino code can be compiled.This project usesCliPy-Hooks, to handle most of the cross-platform, sub-process nastiness.Getting StartedTo configure pre-commit seetheir official docsfor instructions.To use any of the arduino hooks below you must have the respective executables installed andon path.
If you are running in an environment where putting this on path is difficult, you may pass an--install-dirargument to define the absolute path to the arduino executable.The hooked tools do not work with individual source files as is done with most pre-commit hooks, as these tools work against complete arduino projects.
By default, the hooks will treat the root directory as the project root, as is typical in arduino repositories.
In cases where this is not true, you can pass a--project-dirargument with the project root path to the hook.Due to limitations inargparse, it ishighlysuggested that you pass all arguments with values using--key=valuerather than--key value.Arduino LintSample.pre-commit-config.yaml:-repo:https://github.com/creatingnull/arduino-hooksrev:v0.2.0hooks:-id:arduino-lintYou can find instructions on how to installarduino-lintand pre-compiled binaries in theofficial docs.For convenience this hook recognises the following arguments:--fail-on-warnflag that will fail on any warning returned by arduino lint.
Similar result tocompliance=strictbut even stricter.You also may pass in supportedarduino-cliargumentswhich will be handed through to the executable.-repo:https://github.com/creatingnull/arduino-hooksrev:v0.2.0hooks:-id:arduino-lint-args:["--install-dir=/opt/arduino/","--fail-on-warn","--project-dir=src/"]Arduino CLISample.pre-commit-config.yaml:-repo:https://github.com/creatingnull/arduino-hooksrev:v0.2.0hooks:-id:arduino-cliargs:["--fqbn=arduino:avr:nano"]You can find instructions on how to installarduino-cliand pre-compiled binaries in theofficial docsMust provide the full qualified board name for the target microcontroller, this parameter should be passed in""quotes due to yaml restrictions on:use.
You'll also need to have previously installed thecorefor this target and anylibsrequired by your project.As a Github ActionYou can add these hooks to your existing pre-commit workflow by adding a step to install the required dependencies.See the following example step added to aubuntu-latestpre-commit workflow:-name:Install Dependanciesrun:|curl -fsSL https://raw.githubusercontent.com/arduino/arduino-lint/main/etc/install.sh | shcurl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | shbin/arduino-cli core install arduino:avrbin/arduino-cli lib install NullPacketCommsecho "${PWD}/bin/" >> $GITHUB_PATHThe process followed is to:Install arduino-cli if usedInstall arduino-lint if usedInstall required cores for the arduino-cli hook(s)Install required 3rd party libs for the arduino-cli hook(s)Put arduino tooling on pathFor more information you can check outthis projectimplementing these hooks in a github workflow.DonationsI just do this stuff for fun in my spare time, but feel free to:LicenseThe source of this repo uses the MIT open-source license, for details on the current licensing seeLICENSEor click the badge above.