Skip to content

Proposal: Custom Linter#190

Open
GaballaGit wants to merge 4 commits into
mainfrom
proposal/custom-linter
Open

Proposal: Custom Linter#190
GaballaGit wants to merge 4 commits into
mainfrom
proposal/custom-linter

Conversation

@GaballaGit
Copy link
Copy Markdown
Member

Hello, I was messing around with go/ast and had an idea we could make a custom linter for our project.

Why?

A custom linter can be useful for our projects to enforce architectural rules, for example here in this proposal I am enforcing the rule of no dbmodel imports in the api handlers. I think this will help future contributors follow architectural rules that they may not be aware off by getting caught in the ci first and reading about it possibly. The ci will fail if merged, which means it is currently working as intended.

It's pretty messy right now in the proposal state, but I want to put the idea out there for you all. Feel free to leave thoughts/comments/questions about it, Ill answer them.

@GaballaGit GaballaGit force-pushed the proposal/custom-linter branch from 5178ee3 to 246f818 Compare May 22, 2026 11:54
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 22, 2026

godoc reference preview ready ✨
Go Documentation

@TheJolman
Copy link
Copy Markdown
Collaborator

Sounds cool, ima take a look. If it's not too hard to implement maintain would be a good addition

@GaballaGit
Copy link
Copy Markdown
Member Author

Let me summarize the changes I made today:

I moved the linter logic into internal and made it take a struct lintRule.

What is lint rule? In the same directory there is a file: linterRules.go that contains a struct lintrule. This struct defines where the linter goes, what files it should skip, and bad imports. Thats all for now, but it can be easily expanded upon later if we want to check for functions and such.

After the struct is defined, there is a function below that creates a list of rules to lint through. Once main receives this list, it goes through and lints all the rules.

Comment thread internal/linter/linter.go

func Lint(rule lintRule) {

os.Chdir(rule.path)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line might cause issues. I am thinking what if it goes to internal/api/etc and then tries to change to internal/cli/etc from there? Haven't confirmed if this is the case yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants