- Tue 07 February 2023
- misc
- Januar Harianto
- #linting, #error-checking, #devEx, #automation
See Trunk in action in the eeharvest
package repository
Use Trunk to check and monitor code prior to pushing it to production, allowing you to catch issues quickly. It works like a local CI or pre-commit hook for linting and formatting, but is instantenous. Best of all, it doesn't force collaborators to install anything, and they may appreciate you for it.
With trunk you can replace:
- linters: e.g.
flake8
,pylint
,eslint
,stylelint
,shellcheck
,markdownlint
- formatters: e.g.
black
,prettier
,isort
,shfmt
- issue detection: e.g.
bandit
,safety
,mypy
- ErrorLens: in-line error reporting - installing this will result in "double" error reporting
All of the above are configured, installed and managed for you by Trunk, and
editable in a .trunk.yaml
file.
Lint
Trunk can lint your files as you type and shows you the errors inline:
Format
Enable automatic formatting on save - using black
, prettier
, or other
formatters of choice:
Trunk is available for free in most circumstances.
Check
When used in VS Code, Trunk can consolidate all issues in a "Check" sidebar:
Other functionality
Trunk works with continuous integration workflows, accepts custom linters and parsers, and has a robust CLI interface which allows developlers to allow teammates to use its features without installing anything (if Trunk is commited directly into the repo). Check out the documentation here.
In most cases, a local install of Trunk is sufficient for routine linting and error checks. It's just so convenient.
Installation
VS Code (recommended)
Install via VS Code extensions. For every new project, you will be asked if you want to initialise Trunk.
Bash
If you use other editors, you can install Trunk via the command line:
curl https://get.trunk.io -fsSL | bash
Then, initialise trunk for a project by running the following command in the root folder:
trunk init
Use trunk check
to run all linters, or trunk fmt
to run all formatters. More
information ca be found in the documentation
here.