ddd

module
v1.50.1 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2023 License: MIT

README

ddd Linter

The ddd Go linter checks that Domain Driven Design layers are applied properly. Main purpose is to avoid muddy code and to make it easier to keep the code clean and separated. For example, a file in the domain package must not directly import a file from any of the other layers.

You may read up on ddd code separation. Generally, as a rule of thumb, when the linter complains you may want to put and interface in the domain package and put an implementation it in the package you got the complaint from.

NOTE: when you check out the source code, the compiler will complain about the imports in testdata packages. This is necessary to make the tests pass and hence is accepted. DO NOT FIX!

Install

Standalone Linter

Just get the most current binary from the releases page or run:

go install gitlab.com/doertydoerk/ddd/cmd@latest

golangci-lint Plugin

To use ddd as a golangci-lint plugin, perform the following steps from the project root:

  1. go mod tidy

  2. make plugin

  3. make golangci-lint

As part of step 2 the new golangci-lint executable is copied into your $GOPATH/bin directory. Any older version will be overwritten. So, in you golangci.yml you need to specify the path to the plugin.

Notice that step 3 is to build golangci-lint from the source, which is also a 'unneeded dependency' to ddd. This is important to keep the dependencies of ddd and golangci-lint in sync. Check the articles linked below for more information.

golangci.yml example config:

linters-settings:
  custom:
    ddd:
      path: <$GOPTH>/bin/ddd.so
      description: A linter to enforce Domain Driven Design layers are applied properly.
      original-url: gitlab.com/doertydoerk/ddd

With that done you can further configure ddd in the .golangci.yml file as any other linter.

Read here how to use ddd as a custom plugin for golangci-lint.

Run

Standalone Linter

ddd ./...

To skip all *_test.go file do:

ddd -test=false ./...

Release

To release a new version to the Gitlab releases page, run: To release a new version to the Gitlab releases page, run:

VERSION=[release] make release

Configuration

These are the default rules which are applied when no config file is provided.

Package Can import from
domain domain
application domain, application
infrastructure domain, infrasstructure
interfaces domain, interfaces, application

You can alter these rules by providing a .ddd.yml file in the root of the project you want to run the linter on. The file should look like this:

layers:
  domain:
    - domain
  interfaces:
    - domain
    - interfaces
    - application
  application:
    - domain
    - application
  infrastructure:
    - domain
    - infrastructure

To Do

  • fully integrate into golangci-lint. When done this will be integral part of golangci-lint.

There are a few issues listed already. If you encounter a bug feel free to open a new issue. Or even better, fix it yourself and open a merge request 😉.

Miscellaneous

This linter is based on the following links/tutorials:

Directories

Path Synopsis
cmd
ddd
pkg
This must be package main.
This must be package main.

Jump to

Keyboard shortcuts

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