eslint-plugin-clean-architecture
Version:
Enforce layering your code following Jason Taylor's Clean Architecture.
2 lines (1 loc) • 1.8 kB
JavaScript
;class o{withLayer(t){const r={};return r[t]=[],new l(r)}}class l{constructor(t){this.layerMap=t}withLayer(t,r){if(this.layerMap.hasOwnProperty(t))throw new Error(`Cannot add layer "${t}" as it has already been added`);const a=r??[];for(let e of a)if(!this.layerMap.hasOwnProperty(e))throw new Error(`Layer "${t}" cannot depend on layer "${e}" as layer "${e}" has not been added to the builder`);const c=this.layerMap;return c[t]=a,this}build(t){const r=[];for(let a in this.layerMap){const c=this.layerMap[a],e=[];for(let n in this.layerMap)a!==n&&(c.includes(n)||e.push({group:[n],message:`Do not import ${n} code into the ${a} layer`}));r.push({files:[`**/${a}/**`],rules:{"no-restricted-imports":["error",{patterns:e}]}})}return{plugins:[t],rules:{"no-restricted-imports":"off"},overrides:r}}}const s=(i,t)=>i&&t?new o().withLayer("3-domain").withLayer("2-application",["3-domain"]).withLayer("1-infrastructure",["3-domain","2-application"]).withLayer("0-presentation",["3-domain","2-application","1-infrastructure"]).build("clean-architecture"):i?new o().withLayer("3-domain").withLayer("2-application",["3-domain"]).withLayer("1-infrastructure",["3-domain","2-application"]).withLayer("1-presentation",["3-domain","2-application"]).build("clean-architecture"):t?new o().withLayer("domain").withLayer("application",["domain"]).withLayer("infrastructure",["domain","application"]).withLayer("presentation",["domain","application","infrastructure"]).build("clean-architecture"):new o().withLayer("domain").withLayer("application",["domain"]).withLayer("infrastructure",["domain","application"]).withLayer("presentation",["domain","application"]).build("clean-architecture"),p={configs:{strict:s(!1,!1),strictWithNumbers:s(!0,!1),loose:s(!1,!0),looseWithNumbers:s(!0,!0)}};module.exports=p;