Skip to content

Latest commit

 

History

History
56 lines (34 loc) · 4.21 KB

linters.md

File metadata and controls

56 lines (34 loc) · 4.21 KB

Linting the datadog-agent repository

Welcome to the Datadog Agent linters documentation! Linters are tools that check our source code for errors, bugs, and stylistic inconsistencies. They're essential for maintaining code quality and consistency.

Here are the linters used on the datadog-agent repository depending on the language:

Go

For Go, we're using golangci-lint, a Go linters aggregator. Its configuration is defined in the .golangci.yml file.

The linters key defines the list of linters we're using: https://github.com/DataDog/datadog-agent/blob/dffd3262934a5540b9bf8e4bd3a743732637ef37/.golangci.yml#L65-L79

To run the linters locally, run deva linter.go.

Tip

In your code, you can ignore linter issues on a line by prepending it with the nolint directive, for example, //nolint:linter_name. Example here and here.

Python

For Python, we're using (see invoke task):

  • ruff, a style linter and a code formatter.
  • vulture, to find unused code.

Their configuration is defined in both the setup.cfg and the pyproject.toml files.

To run the linters locally, run deva linter.python.

Tip

In your code, you can ignore linter issues on a line by prepending it with # noqa: error_code. Example here and here.

Troubleshooting

Go

Q: I get a lot of errors locally that I don't get in the CI, why ?

A: This could have several causes:

  • Your tool versions are not aligned with ours:
  • You're testing OS specific code; running locally, the linters only get the results for your local OS.
  • You didn't run deva tidy in the repository, making some dependencies in the remote env outdated compared to your local env.

About the new-from-rev golangci-lint parameter

Introducing the revive linter in the codebase caused hundreds of errors to appear in the CI. As such, the new-from-rev parameter was added to only display linter issues from changes made after the commit that enabled revive. See the Golang documentation for more information.

In a scenario where you have a legacy file hello.go with 100 linter issues, the new-from-rev parameter removes them all. But if you rename the file to hello_world.go, or move it to another folder, all the linter issues reappear. See issue 4349 in the golangci repo for more information.

This case added technical debt so we removed it and used the the nolint directive instead.