eslint-plugin-clean-architecture v0.1.0
eslint-plugin-clean-architecture
Enforce layering your code following Jason Taylor's Clean Architecture.

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-architectureUsage
// .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 layerFolder structure
plugin:clean-architecture/strict
layered-code
| presentation
| infrastructure
| application
| domainplugin:clean-architecture/strictWithNumbers
layered-code
| 1-presentation
| 1-infrastructure
| 2-application
| 3-domainNote that the presentation layer is prefixed with "0-" for looseWithNumbers but "1-" for strictWithNumbers.
plugin:clean-architecture/loose
layered-code
| presentation
| infrastructure
| application
| domainplugin:clean-architecture/looseWithNumbers
layered-code
| 0-presentation
| 1-infrastructure
| 2-application
| 3-domainNote 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.