eslint-plugin-modularity 2.1.8 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
<a href="https://opensource.org/licenses/MIT" target="_blank"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="Package License" /></a>
|
|
17
17
|
<a href="https://app.codecov.io/gh/ofri-peretz/eslint/components?components%5B0%5D=eslint-plugin-modularity" target="_blank"><img src="https://codecov.io/gh/ofri-peretz/eslint/graph/badge.svg?component=eslint-plugin-modularity" alt="Codecov" /></a>
|
|
18
18
|
<a href="https://github.com/ofri-peretz/eslint" target="_blank"><img src="https://img.shields.io/badge/Since-Dec_2025-blue?logo=rocket&logoColor=white" alt="Since Dec 2025" /></a>
|
|
19
|
+
<a href="https://scorecard.dev/viewer/?uri=github.com/ofri-peretz/eslint" target="_blank"><img src="https://api.securityscorecards.dev/projects/github.com/ofri-peretz/eslint/badge" alt="OpenSSF Scorecard" /></a>
|
|
19
20
|
</p>
|
|
20
21
|
|
|
21
22
|
> ⭐ If this plugin caught a real bug for you, [**star the repo**](https://github.com/ofri-peretz/eslint) — it's the signal that keeps these rules maintained.
|
|
@@ -28,6 +29,45 @@ This plugin provides Modularity rules — module boundaries, circular dependency
|
|
|
28
29
|
|
|
29
30
|
**Interlace** fosters **strength through integration**. Instead of stacking isolated rules, we **interlace** security directly into your workflow to create a resilient fabric of code. We believe tools should **guide rather than gatekeep**, providing educational feedback that strengthens the developer with every interaction.
|
|
30
31
|
|
|
32
|
+
<!-- AUTO-GENERATED:DOCTRINE:START - Do not edit manually -->
|
|
33
|
+
|
|
34
|
+
## Why these rules are quiet
|
|
35
|
+
|
|
36
|
+
**Noise creates apathy, and apathy is not a security posture.** A linter that reports
|
|
37
|
+
a thousand things a week gets switched off in a month, and the real finding goes with
|
|
38
|
+
it. So every rule here is built to be worth reading: we would rather miss a finding
|
|
39
|
+
than spend your attention on one that was never real.
|
|
40
|
+
|
|
41
|
+
That is a trade, and it is made deliberately. It costs recall, and we measure what it
|
|
42
|
+
costs rather than assuming it is free.
|
|
43
|
+
|
|
44
|
+
## How the rules decide
|
|
45
|
+
|
|
46
|
+
**Evidence, not names.** A rule fires on what the code *does*, resolved through the
|
|
47
|
+
AST and ESLint's own scope analysis — not on an identifier that happens to contain
|
|
48
|
+
`query`, a method called `setItem`, or a file whose path contains `key`. Every one of
|
|
49
|
+
those was a real false positive in this ecosystem, found by reading our own output on
|
|
50
|
+
open-source projects and fixed with a test that fails on the unfixed rule.
|
|
51
|
+
|
|
52
|
+
Where a rule has known false-positive shapes, its page carries a **Not a finding**
|
|
53
|
+
section: what it deliberately stays quiet on, and what to check first when it fires
|
|
54
|
+
and you disagree.
|
|
55
|
+
|
|
56
|
+
## What you get
|
|
57
|
+
|
|
58
|
+
The rules below. Security rules carry a CWE mapping and, where one is assigned, a
|
|
59
|
+
CVSS score; every rule carries a fix on its message — in prose for a human and as
|
|
60
|
+
structured JSON for an agent. Install it, enable
|
|
61
|
+
`recommended`, and read the findings. If one of them is wrong,
|
|
62
|
+
[open an issue](https://github.com/ofri-peretz/eslint/issues) — a false positive is a
|
|
63
|
+
bug here, not a tuning exercise for you.
|
|
64
|
+
|
|
65
|
+
How that is measured, on which projects, and where it falls short:
|
|
66
|
+
[benchmark methodology](https://github.com/ofri-peretz/eslint/blob/main/BENCHMARK-METHODOLOGY.md)
|
|
67
|
+
and [results](https://github.com/ofri-peretz/eslint/blob/main/BENCHMARK-RESULTS.md).
|
|
68
|
+
|
|
69
|
+
<!-- AUTO-GENERATED:DOCTRINE:END -->
|
|
70
|
+
|
|
31
71
|
## Getting Started
|
|
32
72
|
|
|
33
73
|
- To check out the [guide](https://eslint.interlace.tools/docs/quality/plugin-modularity?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-modularity), visit [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-modularity). 📚
|
|
@@ -169,12 +209,12 @@ See the [ESLint Version Support Policy](../../docs/ESLINT_VERSION_SUPPORT.md)
|
|
|
169
209
|
<!-- AUTO-GENERATED:RULES_TABLE:START - Do not edit manually -->
|
|
170
210
|
| Rule | CWE | OWASP | CVSS | Description | 🧠 | 💼 | ⚠️ | 🔧 | 💡 | 🚫 |
|
|
171
211
|
| :--- | :---: | :---: | :---: | :--- | :---: | :---: | :---: | :---: | :---: | :---: |
|
|
172
|
-
| [ddd-anemic-domain-model](https://eslint.interlace.tools/docs/quality/plugin-modularity/rules/ddd-anemic-domain-model?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-modularity) | | | | Detects entities with only getters/setters and no business logic, enforcing the Rich Domain Model over the… | 🟢 | |
|
|
173
|
-
| [ddd-value-object-immutability](https://eslint.interlace.tools/docs/quality/plugin-modularity/rules/ddd-value-object-immutability?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-modularity) | | | | ESLint Rule: ddd-value-object-immutability with LLM-optimized suggestions and auto-fix capabilities. | 🟢 |
|
|
174
|
-
| [enforce-naming](https://eslint.interlace.tools/docs/quality/plugin-modularity/rules/enforce-naming?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-modularity) | | | | Enforce domain-specific naming conventions with business context | 🟢 | |
|
|
175
|
-
| [enforce-rest-conventions](https://eslint.interlace.tools/docs/quality/plugin-modularity/rules/enforce-rest-conventions?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-modularity) | | | | ESLint Rule: enforce-rest-conventions with LLM-optimized suggestions and auto-fix capabilities. | 🟢 |
|
|
176
|
-
| [no-external-api-calls-in-utils](https://eslint.interlace.tools/docs/quality/plugin-modularity/rules/no-external-api-calls-in-utils?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-modularity) | | | | ESLint Rule: no-external-api-calls-in-utils with LLM-optimized suggestions and auto-fix capabilities. | 🟢 |
|
|
177
|
-
| [no-mutable-exports](https://eslint.interlace.tools/docs/quality/plugin-modularity/rules/no-mutable-exports?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-modularity) | | | | Disallow mutable let/var declarations on exported bindings | 🟢 | |
|
|
212
|
+
| [ddd-anemic-domain-model](https://eslint.interlace.tools/docs/quality/plugin-modularity/rules/ddd-anemic-domain-model?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-modularity) | | | | Detects entities with only getters/setters and no business logic, enforcing the Rich Domain Model over the… | 🟢 | | ⚠️ | | 💡 | |
|
|
213
|
+
| [ddd-value-object-immutability](https://eslint.interlace.tools/docs/quality/plugin-modularity/rules/ddd-value-object-immutability?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-modularity) | | | | ESLint Rule: ddd-value-object-immutability with LLM-optimized suggestions and auto-fix capabilities. | 🟢 | 💼 | | | 💡 | |
|
|
214
|
+
| [enforce-naming](https://eslint.interlace.tools/docs/quality/plugin-modularity/rules/enforce-naming?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-modularity) | | | | Enforce domain-specific naming conventions with business context | 🟢 | | ⚠️ | | 💡 | |
|
|
215
|
+
| [enforce-rest-conventions](https://eslint.interlace.tools/docs/quality/plugin-modularity/rules/enforce-rest-conventions?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-modularity) | | | | ESLint Rule: enforce-rest-conventions with LLM-optimized suggestions and auto-fix capabilities. | 🟢 | 💼 | | | 💡 | |
|
|
216
|
+
| [no-external-api-calls-in-utils](https://eslint.interlace.tools/docs/quality/plugin-modularity/rules/no-external-api-calls-in-utils?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-modularity) | | | | ESLint Rule: no-external-api-calls-in-utils with LLM-optimized suggestions and auto-fix capabilities. | 🟢 | 💼 | | | 💡 | |
|
|
217
|
+
| [no-mutable-exports](https://eslint.interlace.tools/docs/quality/plugin-modularity/rules/no-mutable-exports?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-modularity) | | | | Disallow mutable let/var declarations on exported bindings | 🟢 | | ⚠️ | | | |
|
|
178
218
|
<!-- AUTO-GENERATED:RULES_TABLE:END -->
|
|
179
219
|
## 🔗 Related ESLint Plugins
|
|
180
220
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-modularity",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "ESLint plugin for module architecture — enforces DDD value objects and anemic-model checks, naming, REST conventions, and utility isolation.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"node": ">=18.0.0"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@interlace/eslint-devkit": "^1.
|
|
61
|
+
"@interlace/eslint-devkit": "^1.17.0"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
64
|
"eslint": "^8.40.0 || ^9.0.0 || ^10.0.0"
|
package/src/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.configs=exports.plugin=exports.rules=void 0;exports.rules={get"ddd-anemic-domain-model"(){return require("./rules/ddd-anemic-domain-model").dddAnemicDomainModel},get"ddd-value-object-immutability"(){return require("./rules/ddd-value-object-immutability").dddValueObjectImmutability},get"enforce-naming"(){return require("./rules/enforce-naming").enforceNaming},get"enforce-rest-conventions"(){return require("./rules/enforce-rest-conventions").enforceRestConventions},get"no-external-api-calls-in-utils"(){return require("./rules/no-external-api-calls-in-utils").noExternalApiCallsInUtils},get"no-mutable-exports"(){return require("./rules/no-mutable-exports").noMutableExports}};exports.plugin={meta:{name:"eslint-plugin-modularity",version:"2.
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.configs=exports.plugin=exports.rules=void 0;exports.rules={get"ddd-anemic-domain-model"(){return require("./rules/ddd-anemic-domain-model").dddAnemicDomainModel},get"ddd-value-object-immutability"(){return require("./rules/ddd-value-object-immutability").dddValueObjectImmutability},get"enforce-naming"(){return require("./rules/enforce-naming").enforceNaming},get"enforce-rest-conventions"(){return require("./rules/enforce-rest-conventions").enforceRestConventions},get"no-external-api-calls-in-utils"(){return require("./rules/no-external-api-calls-in-utils").noExternalApiCallsInUtils},get"no-mutable-exports"(){return require("./rules/no-mutable-exports").noMutableExports}};exports.plugin={meta:{name:"eslint-plugin-modularity",version:"2.2.0"},rules:exports.rules};const recommendedRules={"modularity/ddd-anemic-domain-model":"warn","modularity/ddd-value-object-immutability":"error","modularity/enforce-naming":"warn","modularity/enforce-rest-conventions":"error","modularity/no-external-api-calls-in-utils":"error","modularity/no-mutable-exports":"warn"};exports.configs={recommended:{plugins:{"modularity":exports.plugin},rules:recommendedRules},strict:{plugins:{"modularity":exports.plugin},rules:Object.fromEntries(Object.keys(exports.rules).map(ruleName=>[`modularity/${ruleName}`,"error"]))}};exports.default=exports.plugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.dddAnemicDomainModel=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");function isDto(className,dtoPatterns){return dtoPatterns.some(pattern=>className.includes(pattern))}function isSimpleGetterSetter(member){if(member.value.type!=="FunctionExpression"){return false}const methodName=member.key.type==="Identifier"?member.key.name:"";const body=member.value.body;if(body.type!=="BlockStatement"||body.body.length===0){return false}if(methodName.startsWith("get")&&body.body.length===1){const statement=body.body[0];if(statement.type==="ReturnStatement"&&statement.argument){return true}}if(methodName.startsWith("set")&&body.body.length===1){const statement=body.body[0];if(statement.type==="ExpressionStatement"&&statement.expression.type==="AssignmentExpression"){return true}}return false}function isPureDelegation(member){if(member.value.type!=="FunctionExpression"){return false}const body=member.value.body;if(body.type!=="BlockStatement"||body.body.length!==1){return false}const statement=body.body[0];const builtInMethods=new Set(["map","filter","reduce","forEach","find","findIndex","some","every","includes","indexOf","slice","concat","join","sort","reverse","push","pop","shift","unshift","splice","flat","flatMap","toString","valueOf","toJSON"]);if(statement.type==="ReturnStatement"&&statement.argument){const arg=statement.argument;if(arg.type==="CallExpression"&&arg.callee.type==="MemberExpression"){const callee=arg.callee;const methodName=callee.property.type==="Identifier"?callee.property.name:"";if(builtInMethods.has(methodName)){return false}const object=callee.object;if(object.type==="MemberExpression"&&object.object.type==="ThisExpression"){const propName=object.property.type==="Identifier"?object.property.name:"";if(propName.includes("repository")||propName.includes("service")||propName.includes("api")||propName.includes("client")||propName.includes("dao")||propName.includes("Repository")||propName.includes("Service")||propName.includes("Api")){return true}return false}if(object.type==="Identifier"){return true}}}if(statement.type==="ExpressionStatement"){const expr=statement.expression;if(expr.type==="CallExpression"&&expr.callee.type==="MemberExpression"){const callee=expr.callee;const methodName=callee.property.type==="Identifier"?callee.property.name:"";if(builtInMethods.has(methodName)){return false}const object=callee.object;if(object.type==="MemberExpression"&&object.object.type==="ThisExpression"){const propName=object.property.type==="Identifier"?object.property.name:"";if(propName.includes("repository")||propName.includes("service")||propName.includes("api")||propName.includes("client")||propName.includes("dao")||propName.includes("Repository")||propName.includes("Service")||propName.includes("Api")){return true}return false}}}return false}function countBusinessMethods(node){let count=0;for(const member of node.body.body){if(member.type==="MethodDefinition"){const methodName=member.key.type==="Identifier"?member.key.name:"";if(member.kind==="get"||member.kind==="set"){continue}if(methodName==="constructor"){continue}if(isSimpleGetterSetter(member)){continue}if(isPureDelegation(member)){continue}const valueType=member.value.type;if(valueType==="FunctionExpression"||valueType==="ArrowFunctionExpression"){count++}}else if(member.type==="PropertyDefinition"){continue}}return count}exports.dddAnemicDomainModel=(0,eslint_devkit_2.createRule)({name:"ddd-anemic-domain-model",meta:{type:"suggestion",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-modularity/docs/rules/ddd-anemic-domain-model.md",description:"Detects entities with only getters/setters and no business logic"},hasSuggestions:true,messages:{anemicDomainModel:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.ARCHITECTURE,issueName:"Anemic domain model",description:"Class {{className}} has no business logic (only getters/setters)",severity:"MEDIUM",fix:"Add business logic methods to create a rich domain model",documentationLink:"https://martinfowler.com/bliki/AnemicDomainModel.html"}),addBusinessLogic:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Add Business Logic",description:"Add business logic methods",severity:"LOW",fix:"Add domain behavior methods to {{className}}",documentationLink:"https://martinfowler.com/bliki/AnemicDomainModel.html"}),migrateToRichModel:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Migrate to Rich Model",description:"Migrate to rich domain model",severity:"LOW",fix:"Encapsulate behavior with data",documentationLink:"https://martinfowler.com/bliki/AnemicDomainModel.html"}),identifyAggregateRoot:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Identify Aggregate Root",description:"Identify aggregate root and enforce invariants",severity:"LOW",fix:"Define aggregate boundaries and enforce invariants",documentationLink:"https://martinfowler.com/bliki/DDD_Aggregate.html"})},schema:[{type:"object",properties:{minBusinessMethods:{type:"number",default:1,minimum:0,description:"Minimum business methods required"},ignoreDtos:{type:"boolean",default:true,description:"Ignore DTOs and data transfer objects"},dtoPatterns:{type:"array",items:{type:"string"},default:["DTO","Dto","Data","Request","Response","Payload"],description:"Patterns for DTO identification"}},additionalProperties:false}]},defaultOptions:[{minBusinessMethods:1,ignoreDtos:true,dtoPatterns:["DTO","Dto","Data","Request","Response","Payload"]}],create(context,[options={}]){const{minBusinessMethods=1,ignoreDtos=true,dtoPatterns=["DTO","Dto","Data","Request","Response","Payload"]}=options||{};function checkClass(node){if(!node.id){return}const className=node.id.name;if(ignoreDtos&&isDto(className,dtoPatterns)){return}const businessMethodCount=countBusinessMethods(node);if(businessMethodCount<minBusinessMethods){context.report({node,messageId:"anemicDomainModel",data:{className},suggest:[{messageId:"addBusinessLogic",fix:()=>null,data:{className}},{messageId:"migrateToRichModel",fix:()=>null},{messageId:"identifyAggregateRoot",fix:()=>null}]})}}return{ClassDeclaration:checkClass,ClassExpression:checkClass}}});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.dddAnemicDomainModel=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");function isDto(className,dtoPatterns){return dtoPatterns.some(pattern=>className.includes(pattern))}function isSimpleGetterSetter(member){if(member.value.type!=="FunctionExpression"){return false}const methodName=member.key.type==="Identifier"?member.key.name:"";const body=member.value.body;if(body.type!=="BlockStatement"||body.body.length===0){return false}if(methodName.startsWith("get")&&body.body.length===1){const statement=body.body[0];if(statement.type==="ReturnStatement"&&statement.argument){return true}}if(methodName.startsWith("set")&&body.body.length===1){const statement=body.body[0];if(statement.type==="ExpressionStatement"&&statement.expression.type==="AssignmentExpression"){return true}}return false}function isPureDelegation(member){if(member.value.type!=="FunctionExpression"){return false}const body=member.value.body;if(body.type!=="BlockStatement"||body.body.length!==1){return false}const statement=body.body[0];const builtInMethods=new Set(["map","filter","reduce","forEach","find","findIndex","some","every","includes","indexOf","slice","concat","join","sort","reverse","push","pop","shift","unshift","splice","flat","flatMap","toString","valueOf","toJSON"]);if(statement.type==="ReturnStatement"&&statement.argument){const arg=statement.argument;if(arg.type==="CallExpression"&&arg.callee.type==="MemberExpression"){const callee=arg.callee;const methodName=callee.property.type==="Identifier"?callee.property.name:"";if(builtInMethods.has(methodName)){return false}const object=callee.object;if(object.type==="MemberExpression"&&object.object.type==="ThisExpression"){const propName=object.property.type==="Identifier"?object.property.name:"";if(propName.includes("repository")||propName.includes("service")||propName.includes("api")||propName.includes("client")||propName.includes("dao")||propName.includes("Repository")||propName.includes("Service")||propName.includes("Api")){return true}return false}if(object.type==="Identifier"){return true}}}if(statement.type==="ExpressionStatement"){const expr=statement.expression;if(expr.type==="CallExpression"&&expr.callee.type==="MemberExpression"){const callee=expr.callee;const methodName=callee.property.type==="Identifier"?callee.property.name:"";if(builtInMethods.has(methodName)){return false}const object=callee.object;if(object.type==="MemberExpression"&&object.object.type==="ThisExpression"){const propName=object.property.type==="Identifier"?object.property.name:"";if(propName.includes("repository")||propName.includes("service")||propName.includes("api")||propName.includes("client")||propName.includes("dao")||propName.includes("Repository")||propName.includes("Service")||propName.includes("Api")){return true}return false}}}return false}function countBusinessMethods(node){let count=0;for(const member of node.body.body){if(member.type==="MethodDefinition"){const methodName=member.key.type==="Identifier"?member.key.name:"";if(member.kind==="get"||member.kind==="set"){continue}if(methodName==="constructor"){continue}if(isSimpleGetterSetter(member)){continue}if(isPureDelegation(member)){continue}const valueType=member.value.type;if(valueType==="FunctionExpression"||valueType==="ArrowFunctionExpression"){count++}}else if(member.type==="PropertyDefinition"){continue}}return count}const DEFAULT_DOMAIN_PATHS=["domain","domains","entities","entity","aggregate","aggregates","model","models"];function isDomainFile(filename,segments){if(segments.length===0)return true;return filename.replace(/\\/g,"/").split("/").some(part=>segments.includes(part))}exports.dddAnemicDomainModel=(0,eslint_devkit_2.createRule)({name:"ddd-anemic-domain-model",meta:{type:"suggestion",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-modularity/docs/rules/ddd-anemic-domain-model.md",description:"Detects entities with only getters/setters and no business logic"},hasSuggestions:true,messages:{anemicDomainModel:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.ARCHITECTURE,issueName:"Anemic domain model",description:"Class {{className}} has no business logic (only getters/setters)",severity:"MEDIUM",fix:"Add business logic methods to create a rich domain model",documentationLink:"https://martinfowler.com/bliki/AnemicDomainModel.html"}),addBusinessLogic:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Add Business Logic",description:"Add business logic methods",severity:"LOW",fix:"Add domain behavior methods to {{className}}",documentationLink:"https://martinfowler.com/bliki/AnemicDomainModel.html"}),migrateToRichModel:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Migrate to Rich Model",description:"Migrate to rich domain model",severity:"LOW",fix:"Encapsulate behavior with data",documentationLink:"https://martinfowler.com/bliki/AnemicDomainModel.html"}),identifyAggregateRoot:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Identify Aggregate Root",description:"Identify aggregate root and enforce invariants",severity:"LOW",fix:"Define aggregate boundaries and enforce invariants",documentationLink:"https://martinfowler.com/bliki/DDD_Aggregate.html"})},schema:[{type:"object",properties:{minBusinessMethods:{type:"number",default:1,minimum:0,description:"Minimum business methods required"},ignoreDtos:{type:"boolean",default:true,description:"Ignore DTOs and data transfer objects"},domainPaths:{type:"array",items:{type:"string"},description:"Directory segments holding domain code. Empty checks everywhere."},dtoPatterns:{type:"array",items:{type:"string"},default:["DTO","Dto","Data","Request","Response","Payload"],description:"Patterns for DTO identification"}},additionalProperties:false}]},defaultOptions:[{minBusinessMethods:1,ignoreDtos:true,dtoPatterns:["DTO","Dto","Data","Request","Response","Payload"],domainPaths:DEFAULT_DOMAIN_PATHS}],create(context,[options={}]){const{minBusinessMethods=1,ignoreDtos=true,dtoPatterns=["DTO","Dto","Data","Request","Response","Payload"],domainPaths=DEFAULT_DOMAIN_PATHS}=options||{};const inDomain=isDomainFile(context.filename,domainPaths);function checkClass(node){if(!inDomain){return}if(!node.id){return}const className=node.id.name;if(ignoreDtos&&isDto(className,dtoPatterns)){return}const businessMethodCount=countBusinessMethods(node);if(businessMethodCount<minBusinessMethods){context.report({node,messageId:"anemicDomainModel",data:{className},suggest:[{messageId:"addBusinessLogic",fix:()=>null,data:{className}},{messageId:"migrateToRichModel",fix:()=>null},{messageId:"identifyAggregateRoot",fix:()=>null}]})}}return{ClassDeclaration:checkClass,ClassExpression:checkClass}}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noExternalApiCallsInUtils=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");function isUtilityFile(filename,patterns){return patterns.some(pattern=>{const regex=new RegExp(pattern.replace(/\*\*/g,".*").replace(/\*/g,"[^/]*"));return regex.test(filename)})}function
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noExternalApiCallsInUtils=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");const DEFAULT_HTTP_MODULES=["axios","got","ky","node-fetch","undici","superagent","request","phin","needle","http","https","http2","node:http","node:https","node:http2"];const DEFAULT_NETWORK_METHODS=["get","post","put","patch","delete","head","options","request","fetch","all","stream"];const DEFAULT_UTILITY_PATTERNS=["**/utils/**","**/helpers/**","**/lib/**"];const GLOBAL_CLIENTS=new Set(["fetch"]);const GLOBAL_CLIENT_HOSTS=new Set(["window","globalThis","global","self"]);const AMBIGUOUS_MODULE_NAMES=new Set(["request","got"]);function isUtilityFile(filename,patterns){return patterns.some(pattern=>{const regex=new RegExp(pattern.replace(/\*\*/g,".*").replace(/\*/g,"[^/]*"));return regex.test(filename)})}function rootName(node){let current=node;while(current.type==="MemberExpression"){current=current.object}return current.type==="Identifier"?current.name:null}function requiredModule(node){if(node.type==="CallExpression"&&node.callee.type==="Identifier"&&node.callee.name==="require"&&node.arguments[0]?.type==="Literal"&&typeof node.arguments[0].value==="string"){return node.arguments[0].value}return null}exports.noExternalApiCallsInUtils=(0,eslint_devkit_2.createRule)({name:"no-external-api-calls-in-utils",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-modularity/docs/rules/no-external-api-calls-in-utils.md",description:"Detects network calls in utility functions"},hasSuggestions:true,messages:{externalApiCallInUtils:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.ARCHITECTURE,issueName:"External API call in utils",description:"Network call in utility function - breaks testability",severity:"HIGH",fix:"Use dependency injection for network calls",documentationLink:"https://rules.sonarsource.com/javascript/RSPEC-1075/"}),useDependencyInjection:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use Dependency Injection",description:"Inject API client",severity:"LOW",fix:"function util(apiClient) { return apiClient.get(...) }",documentationLink:"https://en.wikipedia.org/wiki/Dependency_injection"}),extractToService:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Extract to Service",description:"Extract to service layer",severity:"LOW",fix:"Create services/apiService.ts",documentationLink:"https://martinfowler.com/eaaCatalog/serviceLayer.html"}),passApiClient:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Pass API Client",description:"Pass API client as parameter",severity:"LOW",fix:"function util(apiClient, data) { ... }",documentationLink:"https://en.wikipedia.org/wiki/Dependency_injection"})},schema:[{type:"object",properties:{httpModules:{type:"array",items:{type:"string"},default:DEFAULT_HTTP_MODULES},ignoreInTests:{type:"boolean",default:true},networkMethods:{description:'HTTP method names to flag. A bare name ("get") applies only when the receiver resolves to a known HTTP client. A dotted entry ("httpClient.get") is an exact object.method escape hatch that bypasses client resolution entirely \u2014 use it for an in-house client this rule cannot trace.',type:"array",items:{type:"string"},default:DEFAULT_NETWORK_METHODS},utilityPatterns:{type:"array",items:{type:"string"},default:DEFAULT_UTILITY_PATTERNS}},additionalProperties:false}]},defaultOptions:[{httpModules:DEFAULT_HTTP_MODULES,ignoreInTests:true,networkMethods:DEFAULT_NETWORK_METHODS,utilityPatterns:DEFAULT_UTILITY_PATTERNS}],create(context,[options={}]){const{httpModules=DEFAULT_HTTP_MODULES,ignoreInTests=true,networkMethods=DEFAULT_NETWORK_METHODS,utilityPatterns=DEFAULT_UTILITY_PATTERNS}=options||{};const filename=context.filename;const isTestFile=ignoreInTests&&/\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);if(isTestFile){return{}}const isUtility=isUtilityFile(filename,utilityPatterns);if(!isUtility){return{}}const modules=new Set(httpModules);const methods=new Set(networkMethods);const explicitPairs=new Set(networkMethods.filter(method=>method.includes(".")));const clients=new Set(GLOBAL_CLIENTS);for(const source of modules){const bare=source.replace(/^node:/,"");if(/^[A-Za-z_$][\w$]*$/.test(bare)&&!AMBIGUOUS_MODULE_NAMES.has(bare)){clients.add(bare)}}const aliases=[];const calls=[];function trackBinding(id){if(id.type==="Identifier"){clients.add(id.name)}else if(id.type==="ObjectPattern"){for(const property of id.properties){if(property.type==="Property"&&property.value.type==="Identifier"){clients.add(property.value.name)}}}}function isNetworkCall(node){const callee=node.callee;if(callee.type==="Identifier"){return clients.has(callee.name)}if(callee.type!=="MemberExpression"||callee.computed||callee.property.type!=="Identifier"){return false}const method=callee.property.name;const root=rootName(callee.object);if(root===null){return false}if(explicitPairs.has(`${root}.${method}`)){return true}if(GLOBAL_CLIENT_HOSTS.has(root)){return GLOBAL_CLIENTS.has(method)}return clients.has(root)&&methods.has(method)}return{ImportDeclaration(node){if(node.importKind==="type"||!modules.has(node.source.value)){return}for(const specifier of node.specifiers){if(specifier.type!=="ImportSpecifier"||specifier.importKind!=="type"){clients.add(specifier.local.name)}}},VariableDeclarator(node){if(!node.init){return}const source=requiredModule(node.init);if(source!==null){if(modules.has(source)){trackBinding(node.id)}return}const root=rootName(node.init.type==="CallExpression"?node.init.callee:node.init);if(root!==null&&node.id.type==="Identifier"){aliases.push([node.id.name,root])}},CallExpression(node){calls.push(node)},"Program:exit"(){let changed=true;while(changed){changed=false;for(const[local,root]of aliases){if(clients.has(root)&&!clients.has(local)){clients.add(local);changed=true}}}for(const node of calls){if(!isNetworkCall(node)){continue}context.report({node,messageId:"externalApiCallInUtils",suggest:[{messageId:"useDependencyInjection",fix:()=>null},{messageId:"extractToService",fix:()=>null},{messageId:"passApiClient",fix:()=>null}]})}}}}});
|