depslint

package module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2022 License: MIT Imports: 12 Imported by: 0

README

depslint

This tool is a linter that checks dependencies based on import statements.
This will help you practice things like clean architecture.

Installation

go install github.com/ogugu9/depslint/cmd/depslint@latest

Usage

First, create .depslint.puml like below.

@startuml "clean arachitecture"
[adapter] --> [usecase]
[usecase] --> [entity]
@enduml

Then, execute like below.

go vet -vettool=$(which depslint) -depslint.root=`pwd` ./...

Example

Here is example for .depslint.puml.

@startuml "layer"
[aa] --> [bb]
[cc] --> [bb]
@enduml

And then target go file is below.

package bb

import (
	"log"

	"github.com/ogugu9/a/aa"
	//lint:ignore depslint
	"github.com/ogugu9/a/cc"
	"go.uber.org/zap"
)

func BBB() {
	aa.AAA()
	cc.CCC()
	log.Println("AAA")
	logger, _ := zap.NewDevelopment()
	logger.Info("AAA")
}

The result will be like...

go vet -vettool=$(which depslint) -depslint.root=`pwd` ./...
# github.com/ogugu9/a/bb
bb/bb.go:6:2: dependency violation: github.com/ogugu9/a/bb -> github.com/ogugu9/a/aa

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name: "depslint",
	Doc:  doc,
	Run:  run,
	Requires: []*analysis.Analyzer{
		inspect.Analyzer,
	},
}

Analyzer is ...

Functions

func CheckImport

func CheckImport(pass *analysis.Pass, n *ast.ImportSpec, rules []DependencyRule)

func GetRootPkgName

func GetRootPkgName(rootPath string) (string, error)

func IsDisabledLint

func IsDisabledLint(n *ast.ImportSpec) bool

Types

type DependencyRule

type DependencyRule struct {
	From string
	To   string
}

func ParsePuml

func ParsePuml(rootPkg, path string) []DependencyRule

func ParseRule

func ParseRule(rootPkg, lineTxt string) *DependencyRule

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL