LogoLogo
SlackLogin
  • Overview
    • Welcome
  • Setup & Configuration
    • Connecting to Trunk
    • Managing Your Organization
      • GitHub App Permissions
  • Integration with Slack
  • Flaky Tests (Beta)
    • Overview
    • Get Started
      • Test Frameworks
        • Android
        • Bazel
        • Behave
        • cargo-nextest
        • Cypress
        • Dart Test
        • Go
        • GoogleTest
        • Gradle
        • Jasmine
        • Jest
        • Karma
        • Kotest
        • Maven
        • minitest
        • Mocha
        • Nightwatch
        • NUnit
        • Pest
        • PHPUnit
        • Playwright
        • Pytest
        • Robot Framework
        • RSpec
          • RSpec (Manual Uploads)
        • Swift Testing
        • Vitest
        • XCTest
        • Other Test Frameworks
      • CI Providers
        • Azure DevOps Pipelines
        • BitBucket Pipelines
        • Buildkite
        • CircleCI
        • Drone CI
        • GitHub Actions
        • GitLab
        • Jenkins
        • Semaphore CI
        • TeamCity
        • Travis CI
        • Other CI Providers
    • Dashboard
    • Flaky Test Detection
    • Quarantining
    • PR Comments
    • Ticketing Integrations
      • Jira Integration
      • Linear Integration
      • Other Ticketing Platforms
    • Webhooks
      • Slack Integration
      • Microsoft Teams Integration
      • GitHub Issues Integration
      • Linear Integration
    • Uploader CLI Reference
  • Merge Queue
    • Overview
    • How does it work?
    • Setup
      • Quick Start
      • Settings
      • Integration for Slack
    • Concepts and Optimizations
      • Predictive Testing
      • Optimistic Merging
      • Pending Failure Depth
      • Anti-Flake Protection
      • Batching
      • Parallel Queues
        • Bazel
        • Nx
        • API
      • FAQ
    • Priority
    • Managing Merge Queue
      • Using the Merge UI
      • Metrics
      • Command Line
    • Webhooks
    • Reference
  • Code Quality
    • Overview
    • Why Metalinters?
      • How does it work?
      • Why Code Quality?
    • Setup & Installation
      • Initialize Trunk
      • Local Linting
      • Linting in CI
      • Nightly Report (Deprecated)
      • OpenAI Codex Support
    • IDE Integration
      • VSCode
      • Neovim
      • GitHub Codespaces
    • Linters
      • Supported Linters
        • Actionlint
        • Ansible-lint
        • Autopep8
        • Bandit
        • Biome
        • Black
        • Brakeman
        • buf
        • Buildifier
        • cfnlint
        • Checkov
        • circleci
        • ClangFormat
        • clang-tidy
        • Clippy
        • cmake-format
        • codespell
        • cspell
        • cue-fmt
        • dart
        • deno
        • Detekt
        • djlint
        • dotenv-linter
        • dotnet-format
        • dustilock
        • ESLint
        • Flake8
        • git-diff-check
        • Gitleaks
        • Gofmt
        • gofumpt
        • goimports
        • gokart
        • golangci-lint
        • golines
        • google-java-format
        • graphql-schema-linter
        • hadolint
        • haml-lint
        • isort
        • iwyu
        • ktlint
        • kube-linter
        • markdown-link-check
        • markdown-table-prettify
        • Markdownlint
        • markdownlint-cli2
        • mypy
        • nancy
        • nixpkgs-fmt
        • opa
        • OSV-Scanner
        • Oxipng
        • perlcritic
        • perltidy
        • php-cs-fixer
        • phpstan
        • pmd
        • pragma-once
        • pre-commit-hooks
        • Prettier
        • prisma
        • psscriptanalyzer
        • Pylint
        • pyright
        • regal
        • remark-lint
        • renovate
        • rome
        • rubocop
        • Ruff
        • rufo
        • rustfmt
        • scalafmt
        • semgrep
        • ShellCheck
        • shfmt
        • sort-package-json
        • sourcery
        • sql-formatter
        • SQLFluff
        • sqlfmt
        • squawk
        • standardrb
        • stringslint
        • stylelint
        • stylua
        • SVGO
        • swiftformat
        • swiftlint
        • taplo
        • Terraform
        • terragrunt
        • terrascan
        • TFLint
        • tfsec
        • tofu
        • Trivy
        • Trufflehog
        • txtpbfmt
        • vale
        • Yamllint
        • yapf
      • Run Linters
      • Manage Linters
      • Configure Linters
      • Ignoring Issues and Files
      • Custom Linters
      • Shared Configs
      • Upgrades
    • Debugging
    • Licensing
  • CLI & API References
    • CLI Reference
      • Install
      • Getting Started
        • Code Quality
        • Merge Queue
        • Flaky Tests
        • Tools
        • Actions
          • Git Hooks
        • Announce
      • Compatibility
      • Caching
      • Commands Reference
        • Code Quality
        • Actions
        • Merge
      • Configuration
        • Plugins
          • Share Config Between Codebases
          • Exporting Linter Configs
        • Runtimes
        • Tools
        • Lint
          • Definitions
          • Commands
          • Output
          • Output Parsing
          • Files and Caching
          • Dependencies
          • Auto-Enable
        • Actions
          • Notifications
          • Logging and Troubleshooting
        • Merge
        • Telemetry
        • Per User Overrides
    • API Reference
      • Flaky Tests
      • Merge Queue
      • Webhooks Reference
  • Pricing & Security
    • Security
  • Billing
  • Community & Support
  • Links
    • Open App
    • Slack Community
    • Changelog
    • Feature Requests
On this page
  • Running for the First Time
  • Hold-the-line
  • Running for the First Time
  • Fixing Existing Issues
  • Hold-the-line
Edit on GitHub
  1. Code Quality
  2. Setup & Installation

Local Linting

Last updated 1 month ago

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 linting locally and fixing existing issues.

Running for the First Time

After initializing Trunk Code Quality, you can run all tools on all files 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.

Hold-the-line

You don't need to fix all issues upfront. Trunk lets you fix linter errors incrementally with hold-the-line.

Learn more about .

Issues in PRs

You can reproduce issues discovered in CI by running trunk check and addressing issues.

If trunk check continues to identify new Code Quality issues on your PR, first try merging the latest changes from your base branch. Trunk will rebase your changes on top of the current HEAD in main to ensure it catches all issues before merging.

If this continues to fail, then run git checkout refs/pull/<PR number>/merge && trunk check. This is a reference to the merge commit GitHub creates.

Hold-the-line

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 linting locally and fixing existing issues.

If you only want to prevent new issues from new code changes, skip to Linting in CI.

Running for the First Time

After initializing Trunk Code Quality, you can run all tools on all files 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.

trunk check --all

Trunk is Git aware

Fixing Existing Issues

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.

Hold-the-line

You don't need to fix all issues upfront. Trunk lets you fix linter errors incrementally with hold-the-line.

Running Formatters and Applying Fixes

Some issues can be fixed automatically. You can apply fixes by running the following command.

trunk check --all --fix

Overwhelmed by Existing Issues?

You can also focus on the issues revealed by 1 linter at a time.

trunk check --all --filter=<linter>

If that still produces too many issues, you can sample your files, such as 1/5 files.

trunk check --all --filter=<linter> --sample=5

You can drill down further and run only one single file.

trunk check --all --filter=<linter> --sample=5 <dir/filename>

Disabling Linters

Some recommended linters could be unnecessary for your project. You can disable and enable linters with these commands:

trunk check enable <linter>
trunk check disable <linter>

Ignore Issues

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:

struct FooBar {
  // trunk-ignore(clang-tidy)
  void *ptr = NULL;
};

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:

lint:
  ignore:
    - linters: [ALL]
      paths:
        # Ignore generated files
        - src/generated/**

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:

# Prettier friendly markdownlint config (all formatting rules disabled)
extends: markdownlint/style/prettier
MD024: false
MD033: false
MD034: false

Issues in PRs

You can reproduce issues discovered in CI by running trunk check and addressing issues.

If trunk check continues to identify new Code Quality issues on your PR, first try merging the latest changes from your base branch. Trunk will rebase your changes on top of the current HEAD in main to ensure it catches all issues before merging.

If this continues to fail, then run git checkout refs/pull/<PR number>/merge && trunk check. This is a reference to the merge commit GitHub creates.

Hold-the-line

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 Linting in CI directly.

When you run trunk check without specifying --all, it will only run on files you've modified according to git. Remember to if you're using something other than main or master.

Learn more about .

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 .

hold-the-line
specify a base branch
hold-the-line
hold-the-line
Ignoring Issues