-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
Style Checker and Pre-commit hook CI #9132
Conversation
👋 Hello lucasssvaz, we appreciate your contribution to this project! Click to see more instructions ...
Review and merge process you can expect ...
|
d559c29
to
15df680
Compare
64b00c3
to
c69ca14
Compare
958bba1
to
c69ca14
Compare
c69ca14
to
bfcfd52
Compare
@VojtechBartoska We'll also need to add the bot to the list of signed users of CLAassistant as described in here: |
Arduino also enforces markdown formatting and linting for their documentation. It wouldn't make much sense to follow Arduino standards for our documentation but we can add our own formatting and linting rules. @pedrominatel Do we have any specific rule set that we should follow (or that you would like us to follow) ? |
a3bb162
to
7bb7270
Compare
67fa719
to
f09bd1c
Compare
aec760a
to
bffb8dc
Compare
* Add Config * Add Cache and remove pre-commit action * [pre-commit.ci lite] apply automatic fixes * Remove freeze * Fix * Update action * Use latest stable Python 3 version * Improve caching * Improve cache tag * Improve bot message * Fix flake and make Vale manual * Add filter --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Co-authored-by: Rodrigo Garcia <[email protected]>
* Add Config * Add Cache and remove pre-commit action * [pre-commit.ci lite] apply automatic fixes * Remove freeze * Fix * Update action * Use latest stable Python 3 version * Improve caching * Improve cache tag * Improve bot message * Fix flake and make Vale manual * Add filter --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Co-authored-by: Rodrigo Garcia <[email protected]>
Description of Change
This PR aims to add pre-commit hooks into the CI by using pre-commit.ci lite. It adds all necessary files to make
clang-format
,black
,flake8
,prettier
andcodespell
follow the default Arduino styling. This PR also adds a.editorconfig
file to help with default Arduino indentation for different file types andvale
with the default Espressif settings.The default Arduino styles were taken from: https://github.com/arduino/tooling-project-assets
This PR requires adding the pre-commit.ci lite bot to the repository and is easily extendable for future hooks (like Markdown linting)
As decided in the meeting this should only be merged after refactoring the code base (possibly after all open PRs have been resolved).
Tested locally and on my fork (lucasssvaz#2).
Description of each Hook
clang-format
(C/C++ Formatter)This hook will format the C, C++ and sketch files according to the Arduino default styling (LLVM style based). Shouldn't cause any problem as it will only reformat the code to follow the specs.
black
(Python Formatter)Black will format Python files to it's default configuration. The only changes Arduino does to the default config is
line-length=120
. This will also fix most errors pointed out byflake8
. Shouldn't cause any problem by itself as it is only a formatter. Note that it doesn't change long comment lines automatically.flake8
(Python Linter)The aim of this hook is to enforce Python styling and good practices. It uses error codes generated by itself and
pycodestyle
for pointing out what should be changed. Arduino ignores error W503 and sets the maximum complexity score to 10.Note that
black
can't fix all errors pointed byflake8
.bare expect
andtoo complex
are such examples. This should cause the need for some manual edits depending on how the code was written.prettier
(YAML Formatter)This hook uses
prettier
to format only YAML files. It doesn't have configuration options as Arduino uses the default options for formatting. Won't cause any problems by itself.codespell
(Spell Checker)Checks for common spelling mistakes and automatically converts
EN_GB
toEN_US
. It is configured to be run manually as it sometimes can detect false positives (During my local testing, out of ~200 spelling mistakes detected, 4 were false positives). For example swapping a variablefinalY
tofinally
. This won't be run by the CI and can be run locally usingpre-commit run codespell --hook-stage manual
.vale
(Prose Linter)Checks for mistakes and improvements in natural language (english). Used in documentation files with the default Espressif configuration. Can't auto fix files.
Related links
Closes #7975.