Do you use linter to enforce layer/architecture boundaries?

Hi all,

Does anyone use a linter that also takes regex as parameters and checks to see if layer/architecture boundaries are not being stepped over ?

For example code in the database layer should not depend on code in the presentation layer directly, but instead only depend on bussiness logic layer ?

Is there such a tool that monitors code dependencies when compiling/linting ?

I’m not aware of such a tool, but you can hack it with go list and grep.

Complain if pkg/db imports pkg/preso:

if ( go list -f '{{range .Imports}}{{.}}{{"\n"}}{{end}}' example.com/pkg/db \
  | grep -q example.com/pkg/preso ) ; then
  echo forbidden dependency
  exit 1
fi
exit 0

Totally untested of course, etc

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.