arch

package
v0.0.0-...-094b1a8 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConfigVersion4 = ConfigVersion(4)
)

Variables

View Source
var LintersSortOrder = map[LinterID]int{
	LinterIDSyntax:   10,
	LinterIDOrphans:  20,
	LinterIDImports:  100,
	LinterIDDeepScan: 200,
}
View Source
var LintersWithPreview = map[LinterID]any{
	LinterIDSyntax:   on,
	LinterIDImports:  on,
	LinterIDDeepScan: on,
}

Functions

This section is empty.

Types

type ComponentName

type ComponentName string

ComponentName unique user-specified name of the component. Component is alias for N go packages

type Components

type Components = map[ComponentName]*SpecComponent

Components variable is alias for map[id]*component

type ConfigSettingsTagsEnum

type ConfigSettingsTagsEnum string
const (
	ConfigSettingsTagsEnumAll  ConfigSettingsTagsEnum = "All"
	ConfigSettingsTagsEnumNone ConfigSettingsTagsEnum = "None"
	ConfigSettingsTagsEnumList ConfigSettingsTagsEnum = "List"
)

type ConfigVersion

type ConfigVersion int

ConfigVersion primary arch-lint config version

type ErrorWithNotices

type ErrorWithNotices struct {
	OverallMessage string
	Notices        []Notice
	// contains filtered or unexported fields
}

func NewErrorWithNotices

func NewErrorWithNotices(overallMessage string, notices []Notice, injectNoticesToErrorText bool) *ErrorWithNotices

func (ErrorWithNotices) Error

func (en ErrorWithNotices) Error() string

type FileMatchQueryType

type FileMatchQueryType string
const (
	FileMatchQueryTypeAll             FileMatchQueryType = "all"
	FileMatchQueryTypeOnlyFiles       FileMatchQueryType = "files"
	FileMatchQueryTypeOnlyDirectories FileMatchQueryType = "directories"
)

type FileQuery

type FileQuery struct {
	Path               any          // support models.PathXXX types
	WorkingDirectory   PathRelative // fill be prepended to Path
	Type               FileMatchQueryType
	ExcludeDirectories []PathRelative
	ExcludeFiles       []PathRelative
	ExcludeRegexp      []PathRelativeRegExp
	Extensions         []string // without dot, example: [js, go, jpg]. Nil = no filter
}

type GoModule

type GoModule string

type Linter

type Linter struct {
	ID          LinterID `json:"ID"`
	Used        bool     `json:"Used"`
	Name        string   `json:"-"`
	Description string   `json:"-"`
}

type LinterDeepscanDependency

type LinterDeepscanDependency struct {
	ComponentName     ComponentName `json:"ComponentName"` // repository
	Name              string        `json:"Name"`          // micro.ViewRepository
	InjectionAST      string        `json:"InjectionAST"`  // c.provideMicroViewRepository()
	Injection         Reference     `json:"Injection"`     // internal/app/internal/container/cmd_mapping.go:15
	InjectionPath     PathRelative  `json:"-"`             // internal/app/internal/container/cmd_mapping.go:15
	SourceCodePreview []byte        `json:"-"`
}

type LinterDeepscanDetails

type LinterDeepscanDetails struct {
	Gate       LinterDeepscanGate       `json:"Gate"`
	Dependency LinterDeepscanDependency `json:"Dependency"`
	Target     LinterDeepscanTarget     `json:"Target"`
}

type LinterDeepscanGate

type LinterDeepscanGate struct {
	ComponentName ComponentName `json:"ComponentName"` // operations
	MethodName    string        `json:"MethodName"`    // NewOperation
	Definition    Reference     `json:"Definition"`    // internal/glue/code/line_count.go:54
	RelativePath  PathRelative  `json:"-"`             // internal/glue/code/line_count.go:54
}

type LinterDeepscanTarget

type LinterDeepscanTarget struct {
	Definition   Reference    `json:"Definition"`
	RelativePath PathRelative `json:"-"` // internal/app/internal/container/cmd_mapping.go:15
}

type LinterID

type LinterID string
const (
	LinterIDSyntax   LinterID = "syntax"
	LinterIDOrphans  LinterID = "orphans"
	LinterIDImports  LinterID = "imports"
	LinterIDDeepScan LinterID = "deepscan"
)

type LinterImportDetails

type LinterImportDetails struct {
	ComponentName      ComponentName                 `json:"ComponentName"`
	TargetType         LinterImportDetailsTargetType `json:"TargetType"`
	TargetName         string                        `json:"TargetName"`    // Owner of ResolvedImportName (component or vendor)
	TargetDefined      bool                          `json:"TargetDefined"` // true if Target is known component or vendor in config
	FileRelativePath   PathRelative                  `json:"FileRelativePath"`
	FileAbsolutePath   PathAbsolute                  `json:"FileAbsolutePath"`
	ResolvedImportName PathImport                    `json:"ResolvedImportName"`
	Reference          Reference                     `json:"Reference"`
}

type LinterImportDetailsTargetType

type LinterImportDetailsTargetType string
const (
	LinterImportDetailsTargetTypeComponent LinterImportDetailsTargetType = "Component"
	LinterImportDetailsTargetTypeVendor    LinterImportDetailsTargetType = "Vendor"
)

type LinterNotice

type LinterNotice struct {
	Message   string              `json:"Message"`
	Reference Reference           `json:"Reference"`
	Details   LinterNoticeDetails `json:"Details"`
	Preview   string              `json:"-"`
}

type LinterNoticeDetails

type LinterNoticeDetails struct {
	LinterID LinterID `json:"LinterID"`

	// exist when LinterID = arch.LinterIDOrphans
	LinterIDSyntax *LinterSyntaxDetails `json:"LinterIDSyntax,omitempty"`

	// exist when LinterID = arch.LinterIDOrphans
	LinterIDOrphan *LinterOrphanDetails `json:"LinterIDOrphan,omitempty"`

	// exist when LinterID = arch.LinterIDComponentImports
	LinterIDImports *LinterImportDetails `json:"LinterIDImports,omitempty"`

	// exist when LinterID = arch.LinterIDDeepScan
	LinterIDDeepscan *LinterDeepscanDetails `json:"LinterIDDeepscan,omitempty"`
}

type LinterOrphanDetails

type LinterOrphanDetails struct {
	FileRelativePath PathRelative `json:"FileRelativePath"`
	FileAbsolutePath PathAbsolute `json:"FileAbsolutePath"`
}

type LinterResult

type LinterResult struct {
	Linter  Linter         `json:"Linter"`
	Notices []LinterNotice `json:"Notices"`
}

type LinterSyntaxDetails

type LinterSyntaxDetails struct {
	ComponentName ComponentName `json:"ComponentName"`
	GoPackageName string        `json:"GoPackageName"`
	GoPackagePath PathRelative  `json:"GoPackagePath"`
	SyntaxError   string        `json:"SyntaxError"`
}

type Notice

type Notice struct {
	Message     string    `json:"Message"`
	Reference   Reference `json:"Reference"`
	CodePreview string    `json:"-"`
}

type PackageDescriptor

type PackageDescriptor struct {
	PathDescriptor
	Import PathImport
}

PackageDescriptor is extension for PathDescriptor but can describe only go packages. Also, this struct contain import path for this go package

type PathAbsolute

type PathAbsolute string

PathAbsolute some absolute path (ex: "/home/user/admin/go/project/internal/app.go")

type PathAbsoluteGlob

type PathAbsoluteGlob string

PathAbsoluteGlob some absolute path with globs (ex: "/home/user/admin/go/project/internal/*/repo/**/db.go")

type PathAbsoluteRegExp

type PathAbsoluteRegExp string

PathAbsoluteRegExp some absolute path contains regexp (ex: "^.*user\/admin*_\\.go$")

type PathDescriptor

type PathDescriptor struct {
	PathRel   PathRelative // relative to (projectDirectory + workingDirectory)
	PathAbs   PathAbsolute
	IsDir     bool
	Extension string // in lowercase
}

PathDescriptor hold meta information for specific file path PathDescriptor is not synced with OS anyway and can contain old (irrelevant) information

type PathImport

type PathImport string

PathImport is absolute golang import string (ex: "github.com/goccy/go-yaml")

type PathImportGlob

type PathImportGlob string

PathImportGlob is absolute golang import string with globs (ex: "oss.terrastruct.com/d2/*/libs/**/something")

type PathRelative

type PathRelative string

PathRelative some relative to project directory path (ex: "internal/app.go")

type PathRelativeGlob

type PathRelativeGlob string

PathRelativeGlob some relative to project directory path with globs (ex: "internal/*/repo/**/db.go")

type PathRelativeRegExp

type PathRelativeRegExp string

PathRelativeRegExp some relative to project directory path contains regexp (ex: "^.*_test\\.go$")

type ProjectInfo

type ProjectInfo struct {
	Directory PathAbsolute
	Module    GoModule
}

ProjectInfo contains basic info about specific GO project

type Ref

type Ref[T any] struct {
	Value T
	Ref   Reference
}

Ref is generic structure. This struct contains any value and Reference

func NewInvalidRef

func NewInvalidRef[T any](value T) Ref[T]

func NewRef

func NewRef[T any](value T, ref Reference) Ref[T]

type RefMap

type RefMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewRefMap

func NewRefMap[K comparable, V any](size int) RefMap[K, V]

func NewRefMapFrom

func NewRefMapFrom[K comparable, V any](in map[K]Ref[V]) RefMap[K, V]

func (*RefMap[K, V]) Each

func (rf *RefMap[K, V]) Each(fn func(K, V, Reference))

func (*RefMap[K, V]) Get

func (rf *RefMap[K, V]) Get(key K) (V, Reference, bool)

func (*RefMap[K, V]) Has

func (rf *RefMap[K, V]) Has(key K) bool

func (*RefMap[K, V]) Len

func (rf *RefMap[K, V]) Len() int

func (*RefMap[K, V]) Set

func (rf *RefMap[K, V]) Set(key K, val V, ref Reference)

type RefSlice

type RefSlice[T comparable] []Ref[T]

func (RefSlice[T]) Contains

func (rs RefSlice[T]) Contains(ref Ref[T]) bool

func (RefSlice[T]) Values

func (rs RefSlice[T]) Values() []T

type Reference

type Reference struct {
	File   PathAbsolute `json:"File"`
	Line   int          `json:"Line"`
	Column int          `json:"Column"`
	XPath  string       `json:"-"`
	Valid  bool         `json:"Valid"`
}

Reference contains pointer to specific file/line/column in file system It can be used in errors / notices / linter warnings / etc

func NewFileReference

func NewFileReference(file PathAbsolute) Reference

func NewInvalidReference

func NewInvalidReference() Reference

func NewReference

func NewReference(file PathAbsolute, line int, column int, xpath string) Reference

type ReferencedError

type ReferencedError struct {
	// contains filtered or unexported fields
}

func NewReferencedError

func NewReferencedError(err error, ref Reference) ReferencedError

func (ReferencedError) Error

func (re ReferencedError) Error() string

func (ReferencedError) Reference

func (re ReferencedError) Reference() Reference

type Spec

type Spec struct {
	Project          ProjectInfo
	WorkingDirectory Ref[PathRelative]
	Components       Components
	Vendors          Vendors
	Orphans          []SpecOrphan
}

Spec fully describes project configuration and all linter rules is primary (main) structure for working with in all other code Spec is indivisible struct, and it parts shouldn't be used separately

type SpecComponent

type SpecComponent struct {
	Name                Ref[ComponentName]
	DefinitionComponent Reference // $.components.<NAME>
	DefinitionDeps      Reference // $.deps.<NAME>
	DeepScan            Ref[bool]
	StrictMode          Ref[bool]
	AllowAllProjectDeps Ref[bool]
	AllowAllVendorDeps  Ref[bool]
	AllowAllTags        Ref[bool]
	AllowedTags         RefSlice[StructTag]
	MayDependOn         RefSlice[ComponentName]
	CanUse              RefSlice[VendorName]
	MatchPatterns       RefSlice[PathRelativeGlob] // $.components.X.in
	MatchedFiles        []PathDescriptor           // all files matched by component "in" query
	MatchedPackages     []PackageDescriptor        // all packages matched by component "in" query
	OwnedFiles          []PathDescriptor           // unique subset of MatchedFiles, belongs to this component (every file will belong only to single component)
	OwnedPackages       []PackageDescriptor        // unique subset of MatchedPackages, belongs to this component (every package will belong only to single component)
}

SpecComponent fully describe one project component and it rules. Component is alias for N go packages

type SpecOrphan

type SpecOrphan struct {
	File PathDescriptor
}

SpecOrphan describes project file that is not mapped to any component

type SpecVendor

type SpecVendor struct {
	Name         Ref[VendorName]
	Definition   Reference // $.vendors.<NAME>
	OwnedImports RefSlice[PathImportGlob]
}

SpecVendor fully describe one vendor and its settings.

type StructTag

type StructTag string

StructTag used in go source code for struct annotations (ex: "json", "db")

type TerminalColorEnv

type TerminalColorEnv string
const (

	// TerminalColorEnvBlackAndWhite only basic text (black/white) without any formatting
	TerminalColorEnvBlackAndWhite TerminalColorEnv = "ASCII"

	// TerminalColorEnvColored mode affect all output and printing.
	// this mode will try to turn on colors (if terminal/emulator/std env is support it)
	TerminalColorEnvColored TerminalColorEnv = "Colored"
)

func DetectColorProfile

func DetectColorProfile(useColors bool) TerminalColorEnv

type UsedContext

type UsedContext int
const (
	// UsedContextDefault should be used by default, except rare cased described in UsedContextCLI
	UsedContextDefault UsedContext = 0

	// UsedContextCLI Marks that SDK used from CLI program
	// this affects small details, e.g. validation errors will not be pasted into error,
	// but will be formatted separately in stdout.
	//
	// DO NOT USE anywhere, except go-arch-lint CLI program, or analog
	UsedContextCLI UsedContext = 1
)

type VendorName

type VendorName string

VendorName unique user-specified name of the vendor library. Vendor is alias for N specific imports (ex: [github.com/hello/world, go.example.com/my/package])

type Vendors

type Vendors = map[VendorName]*SpecVendor

Vendors variable is alias for map[id]*vendor

Jump to

Keyboard shortcuts

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