Deal with Existing Issues
Last updated
Last updated
After initializing Trunk, you can begin scanning for issues in your repo, and decide whether to fix them up front, fix them incrementally as you code, or ignore irrelevant suggestions. This page walks through the process of fixing existing issues.
If you only want to prevent new issues from new code changes, skip to Prevent New Issues.
After initializing Trunk Code Quality, you can run linters and formatters to look for existing issues. You can run Trunk on all files in your repo with this command. This will output all issues detected by every linter enabled in your project.
There are different approaches to dealing with existing issues, such as running format
and applying automatic fixes, ignoring irrelevant issues, and sampling linters/files. This section walks you through the process to make fixing issues easier.
Some issues can be fixed automatically. You can apply fixes by running the following command.
You can also focus on the issues revealed by 1 linter at a time.
If that still produces too many issues, you can sample your files, such as 1/5 files.
You can drill down further and run only one single file.
Some recommended linters could be unnecessary for your project. You can disable and enable linters with these commands:
If there are warnings that don't apply to your project, you can ignore them by line, by file, or by class of warnings in each linter's config file.
You can tell Trunk Code Quality to ignore a line in your source code with a special comment like this:
Sometimes you may want to ignore entire files or groups of files, such as generated code. To ignore them, use the ignore
key to your .trunk/trunk.yaml
file:
You can also ignore an entire class of warnings using the config file of your linter, either at the project root or in .trunk/configs
For example, these are the ignores for Markdownlint in .trunk/configs/.markdownlint.yaml
:
You don't need to fix all the issues. Trunk Code Quality has the ability to Hold The Line, which means it only lints your git diffs; only what you changed on your branch gets linted. The pre-existing issues can be managed later.
This allows you to clean up as you go, preventing new issues and letting your team leave each file with better code quality than before.
When you've fixed the existing issues you want to fix, you can skip to Prevent New Issues directly.
If you're still overwhelmed by the results, you can fix them incrementally as you change files. See the section.
The comment should contain the name of the linter you want to ignore the following line, in this case clang-tidy
For more complex ignore commands, see .