Detecting Duplication and Beyond: Building Custom Linters in Go

By Divya Rani

Elevator Pitch

In this talk, we’ll explore how to build custom linters in Go that detect code duplication and complexity using the “go/analysis” package. By the end of this talk, you’ll be able to create your own custom linters to help ensure clean and maintainable code in your projects.

Description

The talk will start by introducing the go/analysis package, which provides a powerful framework for building custom linters. We’ll then dive into the steps for creating a custom linter for code duplication and complexity, including:

  • Setting up the analysis package, and defining our custom linter rules.
  • Parsing and analyzing the Go code using the go/analysis package.
  • Implementing logic to detect code duplication and complexity issues.
  • Adding output formatting for clearer, more actionable results.

We will also look into the best practices for building effective custom linters. By the end of the talk, you’ll be able to create custom linters and easily integrate them into your Go development workflow (using golangci-lint or go vet).

Notes

To deliver this talk effectively, a strong background in Go, in-depth knowledge of the “go/analysis” package, and experience in static program analysis are necessary. I have been working with Golang for the past 3+ years and have experience creating custom linters for internal organization use cases. I have a keen interest in static and dynamic program analysis, which has led me to undertake several research projects and publish papers in the same domain.

Just to note: For the Audience to fully engage with the talk, some familiarity with Go would be helpful.