googleapis / googleapis/api-linter

How to integrate a custom rule into the linter?

Open
#1,485 10 comments 0 reactions 0 assignees View on GitHub
priority: p3 type: question
Dominant language
Go
Stars
765
Forks
181
Avg merge
2d 12h
Merged PRs (30d)
3

Description

While adopting AIPs in my organization, and relying on `api-linter` to perform the validations, we have pretty quickly hit the need of writing our own custom rules, that would extend the behavior of the linter.

This page describes how one [might adopt AIPs on their orgs](https://google.aip.dev/adopting), but I found no reference on this repository, nor on the [documentation page](https://linter.aip.dev/) on what the advised approach is, or the steps to be taken.

Our current workaround is to fork this repository and maintain our own copy of the linter, but that has an embedded operational cost of distributing the binary, keeping it in sync with the upstream remote, etc.

Let's say I'd like to write the simple rule as follows:

```
var myCustomRule = &lint.MessageRule{
Name: lint.NewRuleName("custom", "9001", "message-naming"),
LintMessage: func(m *desc.MessageDescriptor) []lint.Problem {
if !strings.HasPrefix(m.GetName(), "MyCompany") {
return []lint.Problem{{
Message: "Message names must start with 'MyCompany'",
Descriptor: m,
}}
}
return nil
},
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.