eslint-plugin-clean-architecture
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

eslint-plugin-clean-architecture

Enforce layering your code following Jason Taylor's Clean Architecture.

Taylor, J. 2020. Clean Architecture Diagram

There are four configurations available:

  • plugin:clean-architecture/strict
  • plugin:clean-architecture/strictWithNumbers
  • plugin:clean-architecture/loose
  • plugin:clean-architecture/looseWithNumbers

Strict configurations follow Jason Taylor's clean architecture exactly as he presented it.

Numbered configurations prefix each layer with "1-", "2-", etc. This helps organise the layers visually to match the way they are stacked logically.

Loose configurations allow the presentation layer to reference the infrastructure layer. This is handy for bootstrapping your dependencies, factories, etc.

Installation

npm i -D eslint-plugin-clean-architecture

Usage

// .eslintrc.js

module.exports = {
  extends: ["plugin:clean-architecture/strict"],
};

You will only be able to import code from layer X to layer Y if layer X depends on layer Y. Any other layer-to-layer import will yield a linting error.

For example:

// application/business-logic.js

import { apiMethod } from "../presentation/api";
// error: Do not import presentation code into the application layer

Folder structure

plugin:clean-architecture/strict

layered-code
| presentation
| infrastructure
| application
| domain

plugin:clean-architecture/strictWithNumbers

layered-code
| 1-presentation
| 1-infrastructure
| 2-application
| 3-domain

Note that the presentation layer is prefixed with "0-" for looseWithNumbers but "1-" for strictWithNumbers.

plugin:clean-architecture/loose

layered-code
| presentation
| infrastructure
| application
| domain

plugin:clean-architecture/looseWithNumbers

layered-code
| 0-presentation
| 1-infrastructure
| 2-application
| 3-domain

Note that the presentation layer is prefixed with "0-" for looseWithNumbers but "1-" for strictWithNumbers.

EslintPluginBuilder

This plugin is built on top of my eslint plugin builder for layered architectures. You can use that library to enforce lint rules for any layer names you like, in case you're not a fan of clean architecture.

Package Sidebar

Install

npm i eslint-plugin-clean-architecture

Weekly Downloads

1

Version

0.1.0

License

MIT

Unpacked Size

9.28 kB

Total Files

6

Last publish

Collaborators

  • joshuahull