Here I have the content to give the presentation about how to create your first linter.
The goal of this presentation is to create a linter, and run:
- standalone
- inside golangci-lint
To start the slides, inside the ./slides/ folder, run:
npm startExample on how the AST looks like for a small .go file
cd astexample && make tExercise to implement uber style guideline Prefix Unerxported Globals with _.
| Bad | Good |
|---|---|
// foo.go
const (
defaultPort = 8080
defaultUser = "user"
)
// bar.go
func Bar() {
defaultPort := 9090
...
fmt.Println("Default port", defaultPort)
// We will not see a compile error if the first line of
// Bar() is deleted.
} |
// foo.go
const (
_defaultPort = 8080
_defaultUser = "user"
) |
To implement: analyzer.go
Small web app to run custom plugin linters.