eslint-plugin-modularity 2.1.5 → 2.1.7
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/package.json +2 -3
- package/src/index.js +1 -47
- package/src/lib/eslint-plugin-modularity.js +1 -6
- package/src/oxlint.js +1 -3
- package/src/rules/ddd-anemic-domain-model.js +1 -243
- package/src/rules/ddd-value-object-immutability.js +1 -168
- package/src/rules/enforce-naming.js +1 -187
- package/src/rules/enforce-rest-conventions.js +1 -123
- package/src/rules/no-external-api-calls-in-utils.js +1 -137
- package/src/rules/no-mutable-exports.js +1 -51
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-modularity",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.7",
|
|
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,8 +58,7 @@
|
|
|
58
58
|
"node": ">=18.0.0"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"
|
|
62
|
-
"@interlace/eslint-devkit": "^1.6.1"
|
|
61
|
+
"@interlace/eslint-devkit": "^1.10.0"
|
|
63
62
|
},
|
|
64
63
|
"peerDependencies": {
|
|
65
64
|
"eslint": "^8.0.0 || ^9.0.0 || ^10.0.0"
|
package/src/index.js
CHANGED
|
@@ -1,47 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.configs = exports.plugin = exports.rules = void 0;
|
|
4
|
-
const ddd_anemic_domain_model_1 = require("./rules/ddd-anemic-domain-model");
|
|
5
|
-
const ddd_value_object_immutability_1 = require("./rules/ddd-value-object-immutability");
|
|
6
|
-
const enforce_naming_1 = require("./rules/enforce-naming");
|
|
7
|
-
const enforce_rest_conventions_1 = require("./rules/enforce-rest-conventions");
|
|
8
|
-
const no_external_api_calls_in_utils_1 = require("./rules/no-external-api-calls-in-utils");
|
|
9
|
-
const no_mutable_exports_1 = require("./rules/no-mutable-exports");
|
|
10
|
-
exports.rules = {
|
|
11
|
-
'ddd-anemic-domain-model': ddd_anemic_domain_model_1.dddAnemicDomainModel,
|
|
12
|
-
'ddd-value-object-immutability': ddd_value_object_immutability_1.dddValueObjectImmutability,
|
|
13
|
-
'enforce-naming': enforce_naming_1.enforceNaming,
|
|
14
|
-
'enforce-rest-conventions': enforce_rest_conventions_1.enforceRestConventions,
|
|
15
|
-
'no-external-api-calls-in-utils': no_external_api_calls_in_utils_1.noExternalApiCallsInUtils,
|
|
16
|
-
'no-mutable-exports': no_mutable_exports_1.noMutableExports,
|
|
17
|
-
};
|
|
18
|
-
exports.plugin = {
|
|
19
|
-
meta: {
|
|
20
|
-
name: 'eslint-plugin-modularity',
|
|
21
|
-
version: '2.1.5',
|
|
22
|
-
},
|
|
23
|
-
rules: exports.rules,
|
|
24
|
-
};
|
|
25
|
-
const recommendedRules = {
|
|
26
|
-
'modularity/ddd-anemic-domain-model': 'warn',
|
|
27
|
-
'modularity/ddd-value-object-immutability': 'error',
|
|
28
|
-
'modularity/enforce-naming': 'warn',
|
|
29
|
-
'modularity/enforce-rest-conventions': 'error',
|
|
30
|
-
'modularity/no-external-api-calls-in-utils': 'error',
|
|
31
|
-
'modularity/no-mutable-exports': 'warn',
|
|
32
|
-
};
|
|
33
|
-
exports.configs = {
|
|
34
|
-
recommended: {
|
|
35
|
-
plugins: {
|
|
36
|
-
'modularity': exports.plugin,
|
|
37
|
-
},
|
|
38
|
-
rules: recommendedRules,
|
|
39
|
-
},
|
|
40
|
-
strict: {
|
|
41
|
-
plugins: {
|
|
42
|
-
'modularity': exports.plugin,
|
|
43
|
-
},
|
|
44
|
-
rules: Object.fromEntries(Object.keys(exports.rules).map(ruleName => [`modularity/${ruleName}`, 'error'])),
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
exports.default = exports.plugin;
|
|
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.7"},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,6 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.eslintPluginModularity = eslintPluginModularity;
|
|
4
|
-
function eslintPluginModularity() {
|
|
5
|
-
return 'eslint-plugin-modularity';
|
|
6
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.eslintPluginModularity=eslintPluginModularity;function eslintPluginModularity(){return"eslint-plugin-modularity"}
|
package/src/oxlint.js
CHANGED
|
@@ -1,243 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.dddAnemicDomainModel = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
6
|
-
function isDto(className, dtoPatterns) {
|
|
7
|
-
return dtoPatterns.some(pattern => className.includes(pattern));
|
|
8
|
-
}
|
|
9
|
-
function isSimpleGetterSetter(member) {
|
|
10
|
-
if (member.value.type !== 'FunctionExpression') {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
const methodName = member.key.type === 'Identifier' ? member.key.name : '';
|
|
14
|
-
const body = member.value.body;
|
|
15
|
-
if (body.type !== 'BlockStatement' || body.body.length === 0) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
if (methodName.startsWith('get') && body.body.length === 1) {
|
|
19
|
-
const statement = body.body[0];
|
|
20
|
-
if (statement.type === 'ReturnStatement' && statement.argument) {
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
if (methodName.startsWith('set') && body.body.length === 1) {
|
|
25
|
-
const statement = body.body[0];
|
|
26
|
-
if (statement.type === 'ExpressionStatement' &&
|
|
27
|
-
statement.expression.type === 'AssignmentExpression') {
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
function isPureDelegation(member) {
|
|
34
|
-
if (member.value.type !== 'FunctionExpression') {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
const body = member.value.body;
|
|
38
|
-
if (body.type !== 'BlockStatement' || body.body.length !== 1) {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
const statement = body.body[0];
|
|
42
|
-
const builtInMethods = new Set([
|
|
43
|
-
'map', 'filter', 'reduce', 'forEach', 'find', 'findIndex', 'some', 'every',
|
|
44
|
-
'includes', 'indexOf', 'slice', 'concat', 'join', 'sort', 'reverse',
|
|
45
|
-
'push', 'pop', 'shift', 'unshift', 'splice', 'flat', 'flatMap',
|
|
46
|
-
'toString', 'valueOf', 'toJSON'
|
|
47
|
-
]);
|
|
48
|
-
if (statement.type === 'ReturnStatement' && statement.argument) {
|
|
49
|
-
const arg = statement.argument;
|
|
50
|
-
if (arg.type === 'CallExpression' && arg.callee.type === 'MemberExpression') {
|
|
51
|
-
const callee = arg.callee;
|
|
52
|
-
const methodName = callee.property.type === 'Identifier' ? callee.property.name : '';
|
|
53
|
-
if (builtInMethods.has(methodName)) {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
const object = callee.object;
|
|
57
|
-
if (object.type === 'MemberExpression' &&
|
|
58
|
-
object.object.type === 'ThisExpression') {
|
|
59
|
-
const propName = object.property.type === 'Identifier' ? object.property.name : '';
|
|
60
|
-
if (propName.includes('repository') || propName.includes('service') ||
|
|
61
|
-
propName.includes('api') || propName.includes('client') ||
|
|
62
|
-
propName.includes('dao') || propName.includes('Repository') ||
|
|
63
|
-
propName.includes('Service') || propName.includes('Api')) {
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
if (object.type === 'Identifier') {
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
if (statement.type === 'ExpressionStatement') {
|
|
74
|
-
const expr = statement.expression;
|
|
75
|
-
if (expr.type === 'CallExpression' && expr.callee.type === 'MemberExpression') {
|
|
76
|
-
const callee = expr.callee;
|
|
77
|
-
const methodName = callee.property.type === 'Identifier' ? callee.property.name : '';
|
|
78
|
-
if (builtInMethods.has(methodName)) {
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
const object = callee.object;
|
|
82
|
-
if (object.type === 'MemberExpression' &&
|
|
83
|
-
object.object.type === 'ThisExpression') {
|
|
84
|
-
const propName = object.property.type === 'Identifier' ? object.property.name : '';
|
|
85
|
-
if (propName.includes('repository') || propName.includes('service') ||
|
|
86
|
-
propName.includes('api') || propName.includes('client') ||
|
|
87
|
-
propName.includes('dao') || propName.includes('Repository') ||
|
|
88
|
-
propName.includes('Service') || propName.includes('Api')) {
|
|
89
|
-
return true;
|
|
90
|
-
}
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
function countBusinessMethods(node) {
|
|
98
|
-
let count = 0;
|
|
99
|
-
for (const member of node.body.body) {
|
|
100
|
-
if (member.type === 'MethodDefinition') {
|
|
101
|
-
const methodName = member.key.type === 'Identifier' ? member.key.name : '';
|
|
102
|
-
if (member.kind === 'get' || member.kind === 'set') {
|
|
103
|
-
continue;
|
|
104
|
-
}
|
|
105
|
-
if (methodName === 'constructor') {
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
if (isSimpleGetterSetter(member)) {
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
if (isPureDelegation(member)) {
|
|
112
|
-
continue;
|
|
113
|
-
}
|
|
114
|
-
const valueType = member.value.type;
|
|
115
|
-
if (valueType === 'FunctionExpression' || valueType === 'ArrowFunctionExpression') {
|
|
116
|
-
count++;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
else if (member.type === 'PropertyDefinition') {
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return count;
|
|
124
|
-
}
|
|
125
|
-
exports.dddAnemicDomainModel = (0, eslint_devkit_2.createRule)({
|
|
126
|
-
name: 'ddd-anemic-domain-model',
|
|
127
|
-
meta: {
|
|
128
|
-
type: 'suggestion',
|
|
129
|
-
docs: {
|
|
130
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-modularity/docs/rules/ddd-anemic-domain-model.md',
|
|
131
|
-
description: 'Detects entities with only getters/setters and no business logic',
|
|
132
|
-
},
|
|
133
|
-
messages: {
|
|
134
|
-
anemicDomainModel: (0, eslint_devkit_1.formatLLMMessage)({
|
|
135
|
-
icon: eslint_devkit_1.MessageIcons.ARCHITECTURE,
|
|
136
|
-
issueName: 'Anemic domain model',
|
|
137
|
-
description: 'Class {{className}} has no business logic (only getters/setters)',
|
|
138
|
-
severity: 'MEDIUM',
|
|
139
|
-
fix: 'Add business logic methods to create a rich domain model',
|
|
140
|
-
documentationLink: 'https://martinfowler.com/bliki/AnemicDomainModel.html',
|
|
141
|
-
}),
|
|
142
|
-
addBusinessLogic: (0, eslint_devkit_1.formatLLMMessage)({
|
|
143
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
144
|
-
issueName: 'Add Business Logic',
|
|
145
|
-
description: 'Add business logic methods',
|
|
146
|
-
severity: 'LOW',
|
|
147
|
-
fix: 'Add domain behavior methods to {{className}}',
|
|
148
|
-
documentationLink: 'https://martinfowler.com/bliki/AnemicDomainModel.html',
|
|
149
|
-
}),
|
|
150
|
-
migrateToRichModel: (0, eslint_devkit_1.formatLLMMessage)({
|
|
151
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
152
|
-
issueName: 'Migrate to Rich Model',
|
|
153
|
-
description: 'Migrate to rich domain model',
|
|
154
|
-
severity: 'LOW',
|
|
155
|
-
fix: 'Encapsulate behavior with data',
|
|
156
|
-
documentationLink: 'https://martinfowler.com/bliki/AnemicDomainModel.html',
|
|
157
|
-
}),
|
|
158
|
-
identifyAggregateRoot: (0, eslint_devkit_1.formatLLMMessage)({
|
|
159
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
160
|
-
issueName: 'Identify Aggregate Root',
|
|
161
|
-
description: 'Identify aggregate root and enforce invariants',
|
|
162
|
-
severity: 'LOW',
|
|
163
|
-
fix: 'Define aggregate boundaries and enforce invariants',
|
|
164
|
-
documentationLink: 'https://martinfowler.com/bliki/DDD_Aggregate.html',
|
|
165
|
-
}),
|
|
166
|
-
},
|
|
167
|
-
schema: [
|
|
168
|
-
{
|
|
169
|
-
type: 'object',
|
|
170
|
-
properties: {
|
|
171
|
-
minBusinessMethods: {
|
|
172
|
-
type: 'number',
|
|
173
|
-
default: 1,
|
|
174
|
-
minimum: 0,
|
|
175
|
-
description: 'Minimum business methods required',
|
|
176
|
-
},
|
|
177
|
-
ignoreDtos: {
|
|
178
|
-
type: 'boolean',
|
|
179
|
-
default: true,
|
|
180
|
-
description: 'Ignore DTOs and data transfer objects',
|
|
181
|
-
},
|
|
182
|
-
dtoPatterns: {
|
|
183
|
-
type: 'array',
|
|
184
|
-
items: { type: 'string' },
|
|
185
|
-
default: ['DTO', 'Dto', 'Data', 'Request', 'Response', 'Payload'],
|
|
186
|
-
description: 'Patterns for DTO identification',
|
|
187
|
-
},
|
|
188
|
-
},
|
|
189
|
-
additionalProperties: false,
|
|
190
|
-
},
|
|
191
|
-
],
|
|
192
|
-
},
|
|
193
|
-
defaultOptions: [
|
|
194
|
-
{
|
|
195
|
-
minBusinessMethods: 1,
|
|
196
|
-
ignoreDtos: true,
|
|
197
|
-
dtoPatterns: ['DTO', 'Dto', 'Data', 'Request', 'Response', 'Payload'],
|
|
198
|
-
},
|
|
199
|
-
],
|
|
200
|
-
create(context, [options = {}]) {
|
|
201
|
-
const { minBusinessMethods = 1, ignoreDtos = true, dtoPatterns = ['DTO', 'Dto', 'Data', 'Request', 'Response', 'Payload'], } = options || {};
|
|
202
|
-
function checkClass(node) {
|
|
203
|
-
if (!node.id) {
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
const className = node.id.name;
|
|
207
|
-
if (ignoreDtos && isDto(className, dtoPatterns)) {
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
const businessMethodCount = countBusinessMethods(node);
|
|
211
|
-
if (businessMethodCount < minBusinessMethods) {
|
|
212
|
-
context.report({
|
|
213
|
-
node,
|
|
214
|
-
messageId: 'anemicDomainModel',
|
|
215
|
-
data: {
|
|
216
|
-
className,
|
|
217
|
-
},
|
|
218
|
-
suggest: [
|
|
219
|
-
{
|
|
220
|
-
messageId: 'addBusinessLogic',
|
|
221
|
-
fix: () => null,
|
|
222
|
-
data: {
|
|
223
|
-
className,
|
|
224
|
-
},
|
|
225
|
-
},
|
|
226
|
-
{
|
|
227
|
-
messageId: 'migrateToRichModel',
|
|
228
|
-
fix: () => null,
|
|
229
|
-
},
|
|
230
|
-
{
|
|
231
|
-
messageId: 'identifyAggregateRoot',
|
|
232
|
-
fix: () => null,
|
|
233
|
-
},
|
|
234
|
-
],
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
return {
|
|
239
|
-
ClassDeclaration: checkClass,
|
|
240
|
-
ClassExpression: checkClass,
|
|
241
|
-
};
|
|
242
|
-
},
|
|
243
|
-
});
|
|
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"},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,168 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.dddValueObjectImmutability = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
6
|
-
function isValueObject(className, patterns) {
|
|
7
|
-
return patterns.some(pattern => className.includes(pattern));
|
|
8
|
-
}
|
|
9
|
-
function hasReadonlyModifier(node) {
|
|
10
|
-
return node.readonly === true;
|
|
11
|
-
}
|
|
12
|
-
function usesObjectFreeze(node) {
|
|
13
|
-
for (const member of node.body.body) {
|
|
14
|
-
if (member.type === 'MethodDefinition' && member.kind === 'constructor') {
|
|
15
|
-
const constructor = member.value;
|
|
16
|
-
if (constructor.type === 'FunctionExpression') {
|
|
17
|
-
const body = constructor.body;
|
|
18
|
-
if (body.type === 'BlockStatement') {
|
|
19
|
-
for (const statement of body.body) {
|
|
20
|
-
if (statement.type === 'ExpressionStatement' &&
|
|
21
|
-
statement.expression.type === 'CallExpression' &&
|
|
22
|
-
statement.expression.callee.type === 'MemberExpression' &&
|
|
23
|
-
statement.expression.callee.object.type === 'Identifier' &&
|
|
24
|
-
statement.expression.callee.object.name === 'Object' &&
|
|
25
|
-
statement.expression.callee.property.type === 'Identifier' &&
|
|
26
|
-
statement.expression.callee.property.name === 'freeze') {
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
exports.dddValueObjectImmutability = (0, eslint_devkit_2.createRule)({
|
|
37
|
-
name: 'ddd-value-object-immutability',
|
|
38
|
-
meta: {
|
|
39
|
-
type: 'suggestion',
|
|
40
|
-
docs: {
|
|
41
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-modularity/docs/rules/ddd-value-object-immutability.md',
|
|
42
|
-
description: 'Validates value objects are properly immutable',
|
|
43
|
-
},
|
|
44
|
-
messages: {
|
|
45
|
-
mutableValueObject: (0, eslint_devkit_1.formatLLMMessage)({
|
|
46
|
-
icon: eslint_devkit_1.MessageIcons.ARCHITECTURE,
|
|
47
|
-
issueName: 'Mutable value object',
|
|
48
|
-
description: 'Value object {{className}} has mutable properties',
|
|
49
|
-
severity: 'MEDIUM',
|
|
50
|
-
fix: 'Make properties readonly or use Object.freeze',
|
|
51
|
-
documentationLink: 'https://martinfowler.com/bliki/ValueObject.html',
|
|
52
|
-
}),
|
|
53
|
-
mutableNestedType: (0, eslint_devkit_1.formatLLMMessage)({
|
|
54
|
-
icon: eslint_devkit_1.MessageIcons.ARCHITECTURE,
|
|
55
|
-
issueName: 'Mutable nested type',
|
|
56
|
-
description: 'Value object {{className}} has mutable nested type (array/object) - use Readonly<T> or readonly arrays',
|
|
57
|
-
severity: 'MEDIUM',
|
|
58
|
-
fix: 'Use readonly arrays or Readonly<T> for nested objects',
|
|
59
|
-
documentationLink: 'https://www.typescriptlang.org/docs/handbook/utility-types.html#readonlytype',
|
|
60
|
-
}),
|
|
61
|
-
addReadonly: (0, eslint_devkit_1.formatLLMMessage)({
|
|
62
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
63
|
-
issueName: 'Add Readonly',
|
|
64
|
-
description: 'Add readonly modifier',
|
|
65
|
-
severity: 'LOW',
|
|
66
|
-
fix: 'readonly propertyName: Type',
|
|
67
|
-
documentationLink: 'https://www.typescriptlang.org/docs/handbook/2/classes.html#readonly',
|
|
68
|
-
}),
|
|
69
|
-
useObjectFreeze: (0, eslint_devkit_1.formatLLMMessage)({
|
|
70
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
71
|
-
issueName: 'Use Object.freeze',
|
|
72
|
-
description: 'Use Object.freeze in constructor',
|
|
73
|
-
severity: 'LOW',
|
|
74
|
-
fix: 'constructor() { Object.freeze(this); }',
|
|
75
|
-
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze',
|
|
76
|
-
}),
|
|
77
|
-
makeImmutable: (0, eslint_devkit_1.formatLLMMessage)({
|
|
78
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
79
|
-
issueName: 'Make Immutable',
|
|
80
|
-
description: 'Make value object fully immutable',
|
|
81
|
-
severity: 'LOW',
|
|
82
|
-
fix: 'Add readonly to all properties and freeze object',
|
|
83
|
-
documentationLink: 'https://martinfowler.com/bliki/ValueObject.html',
|
|
84
|
-
}),
|
|
85
|
-
},
|
|
86
|
-
schema: [
|
|
87
|
-
{
|
|
88
|
-
type: 'object',
|
|
89
|
-
properties: {
|
|
90
|
-
valueObjectPatterns: {
|
|
91
|
-
type: 'array',
|
|
92
|
-
items: { type: 'string' },
|
|
93
|
-
default: ['Value', 'VO', 'ValueObject'],
|
|
94
|
-
description: 'Patterns to identify value objects',
|
|
95
|
-
},
|
|
96
|
-
requireReadonly: {
|
|
97
|
-
type: 'boolean',
|
|
98
|
-
default: true,
|
|
99
|
-
description: 'Require readonly modifiers',
|
|
100
|
-
},
|
|
101
|
-
checkObjectFreeze: {
|
|
102
|
-
type: 'boolean',
|
|
103
|
-
default: true,
|
|
104
|
-
description: 'Check for Object.freeze usage',
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
additionalProperties: false,
|
|
108
|
-
},
|
|
109
|
-
],
|
|
110
|
-
},
|
|
111
|
-
defaultOptions: [
|
|
112
|
-
{
|
|
113
|
-
valueObjectPatterns: ['Value', 'VO', 'ValueObject'],
|
|
114
|
-
requireReadonly: true,
|
|
115
|
-
checkObjectFreeze: true,
|
|
116
|
-
},
|
|
117
|
-
],
|
|
118
|
-
create(context, [options = {}]) {
|
|
119
|
-
const { valueObjectPatterns = ['Value', 'VO', 'ValueObject'], requireReadonly = true, checkObjectFreeze = true, } = options || {};
|
|
120
|
-
function checkClass(node) {
|
|
121
|
-
if (!node.id) {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
const className = node.id.name;
|
|
125
|
-
if (!isValueObject(className, valueObjectPatterns)) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
if (checkObjectFreeze && usesObjectFreeze(node)) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
const mutableProperties = [];
|
|
132
|
-
for (const member of node.body.body) {
|
|
133
|
-
if (member.type === 'PropertyDefinition') {
|
|
134
|
-
if (requireReadonly && !hasReadonlyModifier(member)) {
|
|
135
|
-
mutableProperties.push(member);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
if (mutableProperties.length > 0) {
|
|
140
|
-
context.report({
|
|
141
|
-
node,
|
|
142
|
-
messageId: 'mutableValueObject',
|
|
143
|
-
data: {
|
|
144
|
-
className,
|
|
145
|
-
},
|
|
146
|
-
suggest: [
|
|
147
|
-
{
|
|
148
|
-
messageId: 'addReadonly',
|
|
149
|
-
fix: () => null,
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
messageId: 'useObjectFreeze',
|
|
153
|
-
fix: () => null,
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
messageId: 'makeImmutable',
|
|
157
|
-
fix: () => null,
|
|
158
|
-
},
|
|
159
|
-
],
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
return {
|
|
164
|
-
ClassDeclaration: checkClass,
|
|
165
|
-
ClassExpression: checkClass,
|
|
166
|
-
};
|
|
167
|
-
},
|
|
168
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.dddValueObjectImmutability=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");function isValueObject(className,patterns){return patterns.some(pattern=>className.includes(pattern))}function hasReadonlyModifier(node){return node.readonly===true}function usesObjectFreeze(node){for(const member of node.body.body){if(member.type==="MethodDefinition"&&member.kind==="constructor"){const constructor=member.value;if(constructor.type==="FunctionExpression"){const body=constructor.body;if(body.type==="BlockStatement"){for(const statement of body.body){if(statement.type==="ExpressionStatement"&&statement.expression.type==="CallExpression"&&statement.expression.callee.type==="MemberExpression"&&statement.expression.callee.object.type==="Identifier"&&statement.expression.callee.object.name==="Object"&&statement.expression.callee.property.type==="Identifier"&&statement.expression.callee.property.name==="freeze"){return true}}}}}}return false}exports.dddValueObjectImmutability=(0,eslint_devkit_2.createRule)({name:"ddd-value-object-immutability",meta:{type:"suggestion",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-modularity/docs/rules/ddd-value-object-immutability.md",description:"Validates value objects are properly immutable"},messages:{mutableValueObject:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.ARCHITECTURE,issueName:"Mutable value object",description:"Value object {{className}} has mutable properties",severity:"MEDIUM",fix:"Make properties readonly or use Object.freeze",documentationLink:"https://martinfowler.com/bliki/ValueObject.html"}),mutableNestedType:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.ARCHITECTURE,issueName:"Mutable nested type",description:"Value object {{className}} has mutable nested type (array/object) - use Readonly<T> or readonly arrays",severity:"MEDIUM",fix:"Use readonly arrays or Readonly<T> for nested objects",documentationLink:"https://www.typescriptlang.org/docs/handbook/utility-types.html#readonlytype"}),addReadonly:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Add Readonly",description:"Add readonly modifier",severity:"LOW",fix:"readonly propertyName: Type",documentationLink:"https://www.typescriptlang.org/docs/handbook/2/classes.html#readonly"}),useObjectFreeze:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use Object.freeze",description:"Use Object.freeze in constructor",severity:"LOW",fix:"constructor() { Object.freeze(this); }",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze"}),makeImmutable:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Make Immutable",description:"Make value object fully immutable",severity:"LOW",fix:"Add readonly to all properties and freeze object",documentationLink:"https://martinfowler.com/bliki/ValueObject.html"})},schema:[{type:"object",properties:{valueObjectPatterns:{type:"array",items:{type:"string"},default:["Value","VO","ValueObject"],description:"Patterns to identify value objects"},requireReadonly:{type:"boolean",default:true,description:"Require readonly modifiers"},checkObjectFreeze:{type:"boolean",default:true,description:"Check for Object.freeze usage"}},additionalProperties:false}]},defaultOptions:[{valueObjectPatterns:["Value","VO","ValueObject"],requireReadonly:true,checkObjectFreeze:true}],create(context,[options={}]){const{valueObjectPatterns=["Value","VO","ValueObject"],requireReadonly=true,checkObjectFreeze=true}=options||{};function checkClass(node){if(!node.id){return}const className=node.id.name;if(!isValueObject(className,valueObjectPatterns)){return}if(checkObjectFreeze&&usesObjectFreeze(node)){return}const mutableProperties=[];for(const member of node.body.body){if(member.type==="PropertyDefinition"){if(requireReadonly&&!hasReadonlyModifier(member)){mutableProperties.push(member)}}}if(mutableProperties.length>0){context.report({node,messageId:"mutableValueObject",data:{className},suggest:[{messageId:"addReadonly",fix:()=>null},{messageId:"useObjectFreeze",fix:()=>null},{messageId:"makeImmutable",fix:()=>null}]})}}return{ClassDeclaration:checkClass,ClassExpression:checkClass}}});
|
|
@@ -1,187 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.enforceNaming = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
6
|
-
exports.enforceNaming = (0, eslint_devkit_2.createRule)({
|
|
7
|
-
name: 'enforce-naming',
|
|
8
|
-
meta: {
|
|
9
|
-
type: 'suggestion',
|
|
10
|
-
docs: {
|
|
11
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-modularity/docs/rules/enforce-naming.md',
|
|
12
|
-
description: 'Enforce domain-specific naming conventions with business context',
|
|
13
|
-
cwe: 'CWE-216',
|
|
14
|
-
cvss: 5,
|
|
15
|
-
},
|
|
16
|
-
fixable: 'code',
|
|
17
|
-
hasSuggestions: true,
|
|
18
|
-
messages: {
|
|
19
|
-
wrongTerminology: (0, eslint_devkit_1.formatLLMMessage)({
|
|
20
|
-
icon: eslint_devkit_1.MessageIcons.QUALITY,
|
|
21
|
-
issueName: 'Domain terminology mismatch',
|
|
22
|
-
cwe: 'CWE-216',
|
|
23
|
-
description: 'Domain terminology mismatch',
|
|
24
|
-
severity: 'MEDIUM',
|
|
25
|
-
fix: 'Use "{{correctTerm}}" ({{context}}) for ubiquitous language alignment',
|
|
26
|
-
documentationLink: 'Domain glossary',
|
|
27
|
-
}),
|
|
28
|
-
useDomainTerm: (0, eslint_devkit_1.formatLLMMessage)({
|
|
29
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
30
|
-
issueName: 'Use Domain Term',
|
|
31
|
-
description: 'Replace with domain terminology',
|
|
32
|
-
severity: 'LOW',
|
|
33
|
-
fix: 'Use "{{correctTerm}}" instead',
|
|
34
|
-
documentationLink: 'https://martinfowler.com/bliki/UbiquitousLanguage.html',
|
|
35
|
-
}),
|
|
36
|
-
viewGlossary: (0, eslint_devkit_1.formatLLMMessage)({
|
|
37
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
38
|
-
issueName: 'View Glossary',
|
|
39
|
-
description: 'View domain glossary',
|
|
40
|
-
severity: 'LOW',
|
|
41
|
-
fix: 'Reference domain glossary for correct terminology',
|
|
42
|
-
documentationLink: 'https://martinfowler.com/bliki/UbiquitousLanguage.html',
|
|
43
|
-
}),
|
|
44
|
-
},
|
|
45
|
-
schema: [
|
|
46
|
-
{
|
|
47
|
-
type: 'object',
|
|
48
|
-
properties: {
|
|
49
|
-
domain: {
|
|
50
|
-
type: 'string',
|
|
51
|
-
default: 'general',
|
|
52
|
-
},
|
|
53
|
-
terms: {
|
|
54
|
-
type: 'array',
|
|
55
|
-
items: {
|
|
56
|
-
type: 'object',
|
|
57
|
-
properties: {
|
|
58
|
-
incorrect: { type: ['string', 'object'] },
|
|
59
|
-
correct: { type: 'string' },
|
|
60
|
-
context: { type: 'string' },
|
|
61
|
-
examples: {
|
|
62
|
-
type: 'array',
|
|
63
|
-
items: { type: 'string' },
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
required: ['incorrect', 'correct', 'context'],
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
glossaryUrl: {
|
|
70
|
-
type: 'string',
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
additionalProperties: false,
|
|
74
|
-
},
|
|
75
|
-
],
|
|
76
|
-
},
|
|
77
|
-
defaultOptions: [
|
|
78
|
-
{
|
|
79
|
-
domain: 'general',
|
|
80
|
-
terms: [],
|
|
81
|
-
glossaryUrl: undefined,
|
|
82
|
-
},
|
|
83
|
-
],
|
|
84
|
-
create(context) {
|
|
85
|
-
const options = context.options[0] || {};
|
|
86
|
-
const { domain = 'general', terms = [] } = options;
|
|
87
|
-
if (!terms || terms.length === 0) {
|
|
88
|
-
return {};
|
|
89
|
-
}
|
|
90
|
-
const checkIdentifier = (name) => {
|
|
91
|
-
for (const term of terms) {
|
|
92
|
-
if (typeof term.incorrect === 'string') {
|
|
93
|
-
if (name.toLowerCase().includes(term.incorrect.toLowerCase())) {
|
|
94
|
-
return term;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
else if (term.incorrect instanceof RegExp) {
|
|
98
|
-
if (term.incorrect.test(name)) {
|
|
99
|
-
return term;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return null;
|
|
104
|
-
};
|
|
105
|
-
const preserveCase = (original, replacement) => {
|
|
106
|
-
if (original === original.toUpperCase()) {
|
|
107
|
-
return replacement.toUpperCase();
|
|
108
|
-
}
|
|
109
|
-
if (original[0] === original[0].toUpperCase()) {
|
|
110
|
-
return replacement.charAt(0).toUpperCase() + replacement.slice(1);
|
|
111
|
-
}
|
|
112
|
-
return replacement.toLowerCase();
|
|
113
|
-
};
|
|
114
|
-
const generateReplacement = (name, term) => {
|
|
115
|
-
if (typeof term.incorrect === 'string') {
|
|
116
|
-
return name.replace(new RegExp(`(${term.incorrect})`, 'gi'), (match) => {
|
|
117
|
-
return preserveCase(match, term.correct);
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
return term.correct;
|
|
121
|
-
};
|
|
122
|
-
const reportViolation = (node, violatedTerm) => {
|
|
123
|
-
const replacement = generateReplacement(node.name, violatedTerm);
|
|
124
|
-
context.report({
|
|
125
|
-
node,
|
|
126
|
-
messageId: 'wrongTerminology',
|
|
127
|
-
data: {
|
|
128
|
-
incorrectTerm: node.name,
|
|
129
|
-
correctTerm: violatedTerm.correct,
|
|
130
|
-
context: violatedTerm.context || domain,
|
|
131
|
-
domain,
|
|
132
|
-
},
|
|
133
|
-
suggest: [
|
|
134
|
-
{
|
|
135
|
-
messageId: 'useDomainTerm',
|
|
136
|
-
data: { correctTerm: violatedTerm.correct },
|
|
137
|
-
fix: (fixer) => {
|
|
138
|
-
return fixer.replaceText(node, replacement);
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
|
-
],
|
|
142
|
-
});
|
|
143
|
-
};
|
|
144
|
-
return {
|
|
145
|
-
VariableDeclarator(node) {
|
|
146
|
-
if (node.id.type !== 'Identifier')
|
|
147
|
-
return;
|
|
148
|
-
const violatedTerm = checkIdentifier(node.id.name);
|
|
149
|
-
if (violatedTerm) {
|
|
150
|
-
reportViolation(node.id, violatedTerm);
|
|
151
|
-
}
|
|
152
|
-
},
|
|
153
|
-
FunctionDeclaration(node) {
|
|
154
|
-
if (!node.id)
|
|
155
|
-
return;
|
|
156
|
-
const violatedTerm = checkIdentifier(node.id.name);
|
|
157
|
-
if (violatedTerm) {
|
|
158
|
-
reportViolation(node.id, violatedTerm);
|
|
159
|
-
}
|
|
160
|
-
},
|
|
161
|
-
ClassDeclaration(node) {
|
|
162
|
-
if (!node.id)
|
|
163
|
-
return;
|
|
164
|
-
const violatedTerm = checkIdentifier(node.id.name);
|
|
165
|
-
if (violatedTerm) {
|
|
166
|
-
reportViolation(node.id, violatedTerm);
|
|
167
|
-
}
|
|
168
|
-
},
|
|
169
|
-
PropertyDefinition(node) {
|
|
170
|
-
if (node.key.type !== 'Identifier')
|
|
171
|
-
return;
|
|
172
|
-
const violatedTerm = checkIdentifier(node.key.name);
|
|
173
|
-
if (violatedTerm) {
|
|
174
|
-
reportViolation(node.key, violatedTerm);
|
|
175
|
-
}
|
|
176
|
-
},
|
|
177
|
-
MethodDefinition(node) {
|
|
178
|
-
if (node.key.type !== 'Identifier')
|
|
179
|
-
return;
|
|
180
|
-
const violatedTerm = checkIdentifier(node.key.name);
|
|
181
|
-
if (violatedTerm) {
|
|
182
|
-
reportViolation(node.key, violatedTerm);
|
|
183
|
-
}
|
|
184
|
-
},
|
|
185
|
-
};
|
|
186
|
-
},
|
|
187
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.enforceNaming=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.enforceNaming=(0,eslint_devkit_2.createRule)({name:"enforce-naming",meta:{type:"suggestion",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-modularity/docs/rules/enforce-naming.md",description:"Enforce domain-specific naming conventions with business context",cwe:"CWE-216",cvss:5},fixable:"code",hasSuggestions:true,messages:{wrongTerminology:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.QUALITY,issueName:"Domain terminology mismatch",cwe:"CWE-216",description:"Domain terminology mismatch",severity:"MEDIUM",fix:'Use "{{correctTerm}}" ({{context}}) for ubiquitous language alignment',documentationLink:"Domain glossary"}),useDomainTerm:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use Domain Term",description:"Replace with domain terminology",severity:"LOW",fix:'Use "{{correctTerm}}" instead',documentationLink:"https://martinfowler.com/bliki/UbiquitousLanguage.html"}),viewGlossary:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"View Glossary",description:"View domain glossary",severity:"LOW",fix:"Reference domain glossary for correct terminology",documentationLink:"https://martinfowler.com/bliki/UbiquitousLanguage.html"})},schema:[{type:"object",properties:{domain:{type:"string",default:"general"},terms:{type:"array",items:{type:"object",properties:{incorrect:{type:["string","object"]},correct:{type:"string"},context:{type:"string"},examples:{type:"array",items:{type:"string"}}},required:["incorrect","correct","context"]}},glossaryUrl:{type:"string"}},additionalProperties:false}]},defaultOptions:[{domain:"general",terms:[],glossaryUrl:void 0}],create(context){const options=context.options[0]||{};const{domain="general",terms=[]}=options;if(!terms||terms.length===0){return{}}const checkIdentifier=name=>{for(const term of terms){if(typeof term.incorrect==="string"){if(name.toLowerCase().includes(term.incorrect.toLowerCase())){return term}}else if(term.incorrect instanceof RegExp){if(term.incorrect.test(name)){return term}}}return null};const preserveCase=(original,replacement)=>{if(original===original.toUpperCase()){return replacement.toUpperCase()}if(original[0]===original[0].toUpperCase()){return replacement.charAt(0).toUpperCase()+replacement.slice(1)}return replacement.toLowerCase()};const generateReplacement=(name,term)=>{if(typeof term.incorrect==="string"){return name.replace(new RegExp(`(${term.incorrect})`,"gi"),match=>{return preserveCase(match,term.correct)})}return term.correct};const reportViolation=(node,violatedTerm)=>{const replacement=generateReplacement(node.name,violatedTerm);context.report({node,messageId:"wrongTerminology",data:{incorrectTerm:node.name,correctTerm:violatedTerm.correct,context:violatedTerm.context||domain,domain},suggest:[{messageId:"useDomainTerm",data:{correctTerm:violatedTerm.correct},fix:fixer=>{return fixer.replaceText(node,replacement)}}]})};return{VariableDeclarator(node){if(node.id.type!=="Identifier")return;const violatedTerm=checkIdentifier(node.id.name);if(violatedTerm){reportViolation(node.id,violatedTerm)}},FunctionDeclaration(node){if(!node.id)return;const violatedTerm=checkIdentifier(node.id.name);if(violatedTerm){reportViolation(node.id,violatedTerm)}},ClassDeclaration(node){if(!node.id)return;const violatedTerm=checkIdentifier(node.id.name);if(violatedTerm){reportViolation(node.id,violatedTerm)}},PropertyDefinition(node){if(node.key.type!=="Identifier")return;const violatedTerm=checkIdentifier(node.key.name);if(violatedTerm){reportViolation(node.key,violatedTerm)}},MethodDefinition(node){if(node.key.type!=="Identifier")return;const violatedTerm=checkIdentifier(node.key.name);if(violatedTerm){reportViolation(node.key,violatedTerm)}}}}});
|
|
@@ -1,123 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.enforceRestConventions = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
6
|
-
exports.enforceRestConventions = (0, eslint_devkit_2.createRule)({
|
|
7
|
-
name: 'enforce-rest-conventions',
|
|
8
|
-
meta: {
|
|
9
|
-
type: 'suggestion',
|
|
10
|
-
docs: {
|
|
11
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-modularity/docs/rules/enforce-rest-conventions.md',
|
|
12
|
-
description: 'Validates REST endpoint design against best practices',
|
|
13
|
-
},
|
|
14
|
-
messages: {
|
|
15
|
-
restConventionViolation: (0, eslint_devkit_1.formatLLMMessage)({
|
|
16
|
-
icon: eslint_devkit_1.MessageIcons.ARCHITECTURE,
|
|
17
|
-
issueName: 'REST convention violation',
|
|
18
|
-
description: '{{violation}}: {{details}}',
|
|
19
|
-
severity: 'MEDIUM',
|
|
20
|
-
fix: 'Follow RESTful conventions for HTTP methods, status codes, and resource naming',
|
|
21
|
-
documentationLink: 'https://restfulapi.net/',
|
|
22
|
-
}),
|
|
23
|
-
useProperHttpMethod: (0, eslint_devkit_1.formatLLMMessage)({
|
|
24
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
25
|
-
issueName: 'Use HTTP Method',
|
|
26
|
-
description: 'Use proper HTTP method',
|
|
27
|
-
severity: 'LOW',
|
|
28
|
-
fix: 'GET (read), POST (create), PUT/PATCH (update), DELETE (delete)',
|
|
29
|
-
documentationLink: 'https://restfulapi.net/http-methods/',
|
|
30
|
-
}),
|
|
31
|
-
useProperStatusCode: (0, eslint_devkit_1.formatLLMMessage)({
|
|
32
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
33
|
-
issueName: 'Use Status Code',
|
|
34
|
-
description: 'Use appropriate status code',
|
|
35
|
-
severity: 'LOW',
|
|
36
|
-
fix: '200 (OK), 201 (Created), 204 (No Content), 400 (Bad Request), 404 (Not Found)',
|
|
37
|
-
documentationLink: 'https://restfulapi.net/http-status-codes/',
|
|
38
|
-
}),
|
|
39
|
-
fixResourceNaming: (0, eslint_devkit_1.formatLLMMessage)({
|
|
40
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
41
|
-
issueName: 'Resource Naming',
|
|
42
|
-
description: 'Use plural nouns for resources',
|
|
43
|
-
severity: 'LOW',
|
|
44
|
-
fix: '/users, /orders, /products (not /user, /order)',
|
|
45
|
-
documentationLink: 'https://restfulapi.net/resource-naming/',
|
|
46
|
-
}),
|
|
47
|
-
},
|
|
48
|
-
schema: [
|
|
49
|
-
{
|
|
50
|
-
type: 'object',
|
|
51
|
-
properties: {
|
|
52
|
-
checkHttpMethods: {
|
|
53
|
-
type: 'boolean',
|
|
54
|
-
default: true,
|
|
55
|
-
description: 'Check HTTP methods',
|
|
56
|
-
},
|
|
57
|
-
checkStatusCodes: {
|
|
58
|
-
type: 'boolean',
|
|
59
|
-
default: true,
|
|
60
|
-
description: 'Check status codes',
|
|
61
|
-
},
|
|
62
|
-
checkResourceNaming: {
|
|
63
|
-
type: 'boolean',
|
|
64
|
-
default: true,
|
|
65
|
-
description: 'Check resource naming',
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
additionalProperties: false,
|
|
69
|
-
},
|
|
70
|
-
],
|
|
71
|
-
},
|
|
72
|
-
defaultOptions: [
|
|
73
|
-
{
|
|
74
|
-
checkHttpMethods: true,
|
|
75
|
-
checkStatusCodes: true,
|
|
76
|
-
checkResourceNaming: true,
|
|
77
|
-
},
|
|
78
|
-
],
|
|
79
|
-
create(context, [options = {}]) {
|
|
80
|
-
const { checkStatusCodes = true, checkResourceNaming = true, } = options || {};
|
|
81
|
-
function checkCallExpression(node) {
|
|
82
|
-
if (node.callee.type === 'MemberExpression') {
|
|
83
|
-
const property = node.callee.property;
|
|
84
|
-
if (property.type === 'Identifier') {
|
|
85
|
-
const methodName = property.name.toLowerCase();
|
|
86
|
-
const httpMethods = ['get', 'post', 'put', 'patch', 'delete', 'head', 'options'];
|
|
87
|
-
if (httpMethods.includes(methodName)) {
|
|
88
|
-
if (checkResourceNaming && node.arguments.length > 0) {
|
|
89
|
-
const pathArg = node.arguments[0];
|
|
90
|
-
if (pathArg.type === 'Literal' && typeof pathArg.value === 'string') {
|
|
91
|
-
const path = pathArg.value;
|
|
92
|
-
if (path.startsWith('/') && path.length > 1) {
|
|
93
|
-
const resource = path.split('/')[1];
|
|
94
|
-
if (!path.includes(':') && !resource.endsWith('s') && resource.length > 3) {
|
|
95
|
-
context.report({
|
|
96
|
-
node: pathArg,
|
|
97
|
-
messageId: 'restConventionViolation',
|
|
98
|
-
data: {
|
|
99
|
-
violation: 'Resource naming',
|
|
100
|
-
details: `Resource "${resource}" should be plural (e.g., /users, /orders)`,
|
|
101
|
-
},
|
|
102
|
-
suggest: [
|
|
103
|
-
{ messageId: 'fixResourceNaming', fix: () => null },
|
|
104
|
-
],
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
if (checkStatusCodes && node.callee.type === 'MemberExpression') {
|
|
114
|
-
const property = node.callee.property;
|
|
115
|
-
if (property.type === 'Identifier' && property.name === 'status') {
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return {
|
|
120
|
-
CallExpression: checkCallExpression,
|
|
121
|
-
};
|
|
122
|
-
},
|
|
123
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.enforceRestConventions=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.enforceRestConventions=(0,eslint_devkit_2.createRule)({name:"enforce-rest-conventions",meta:{type:"suggestion",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-modularity/docs/rules/enforce-rest-conventions.md",description:"Validates REST endpoint design against best practices"},messages:{restConventionViolation:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.ARCHITECTURE,issueName:"REST convention violation",description:"{{violation}}: {{details}}",severity:"MEDIUM",fix:"Follow RESTful conventions for HTTP methods, status codes, and resource naming",documentationLink:"https://restfulapi.net/"}),useProperHttpMethod:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use HTTP Method",description:"Use proper HTTP method",severity:"LOW",fix:"GET (read), POST (create), PUT/PATCH (update), DELETE (delete)",documentationLink:"https://restfulapi.net/http-methods/"}),useProperStatusCode:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use Status Code",description:"Use appropriate status code",severity:"LOW",fix:"200 (OK), 201 (Created), 204 (No Content), 400 (Bad Request), 404 (Not Found)",documentationLink:"https://restfulapi.net/http-status-codes/"}),fixResourceNaming:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Resource Naming",description:"Use plural nouns for resources",severity:"LOW",fix:"/users, /orders, /products (not /user, /order)",documentationLink:"https://restfulapi.net/resource-naming/"})},schema:[{type:"object",properties:{checkHttpMethods:{type:"boolean",default:true,description:"Check HTTP methods"},checkStatusCodes:{type:"boolean",default:true,description:"Check status codes"},checkResourceNaming:{type:"boolean",default:true,description:"Check resource naming"}},additionalProperties:false}]},defaultOptions:[{checkHttpMethods:true,checkStatusCodes:true,checkResourceNaming:true}],create(context,[options={}]){const{checkStatusCodes=true,checkResourceNaming=true}=options||{};function checkCallExpression(node){if(node.callee.type==="MemberExpression"){const property=node.callee.property;if(property.type==="Identifier"){const methodName=property.name.toLowerCase();const httpMethods=["get","post","put","patch","delete","head","options"];if(httpMethods.includes(methodName)){if(checkResourceNaming&&node.arguments.length>0){const pathArg=node.arguments[0];if(pathArg.type==="Literal"&&typeof pathArg.value==="string"){const path=pathArg.value;if(path.startsWith("/")&&path.length>1){const resource=path.split("/")[1];if(!path.includes(":")&&!resource.endsWith("s")&&resource.length>3){context.report({node:pathArg,messageId:"restConventionViolation",data:{violation:"Resource naming",details:`Resource "${resource}" should be plural (e.g., /users, /orders)`},suggest:[{messageId:"fixResourceNaming",fix:()=>null}]})}}}}}}}if(checkStatusCodes&&node.callee.type==="MemberExpression"){const property=node.callee.property;if(property.type==="Identifier"&&property.name==="status"){}}}return{CallExpression:checkCallExpression}}});
|
|
@@ -1,137 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noExternalApiCallsInUtils = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
6
|
-
function isUtilityFile(filename, patterns) {
|
|
7
|
-
return patterns.some(pattern => {
|
|
8
|
-
const regex = new RegExp(pattern.replace(/\*\*/g, '.*').replace(/\*/g, '[^/]*'));
|
|
9
|
-
return regex.test(filename);
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
function isNetworkCall(node, networkMethods) {
|
|
13
|
-
if (node.callee.type === 'Identifier') {
|
|
14
|
-
return networkMethods.includes(node.callee.name);
|
|
15
|
-
}
|
|
16
|
-
if (node.callee.type === 'MemberExpression' &&
|
|
17
|
-
node.callee.property.type === 'Identifier') {
|
|
18
|
-
const methodName = node.callee.property.name;
|
|
19
|
-
const objectName = node.callee.object.type === 'Identifier'
|
|
20
|
-
? node.callee.object.name
|
|
21
|
-
: '';
|
|
22
|
-
return networkMethods.includes(methodName) ||
|
|
23
|
-
networkMethods.includes(`${objectName}.${methodName}`);
|
|
24
|
-
}
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
exports.noExternalApiCallsInUtils = (0, eslint_devkit_2.createRule)({
|
|
28
|
-
name: 'no-external-api-calls-in-utils',
|
|
29
|
-
meta: {
|
|
30
|
-
type: 'problem',
|
|
31
|
-
docs: {
|
|
32
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-modularity/docs/rules/no-external-api-calls-in-utils.md',
|
|
33
|
-
description: 'Detects network calls in utility functions',
|
|
34
|
-
},
|
|
35
|
-
hasSuggestions: true,
|
|
36
|
-
messages: {
|
|
37
|
-
externalApiCallInUtils: (0, eslint_devkit_1.formatLLMMessage)({
|
|
38
|
-
icon: eslint_devkit_1.MessageIcons.ARCHITECTURE,
|
|
39
|
-
issueName: 'External API call in utils',
|
|
40
|
-
description: 'Network call in utility function - breaks testability',
|
|
41
|
-
severity: 'HIGH',
|
|
42
|
-
fix: 'Use dependency injection for network calls',
|
|
43
|
-
documentationLink: 'https://rules.sonarsource.com/javascript/RSPEC-1075/',
|
|
44
|
-
}),
|
|
45
|
-
useDependencyInjection: (0, eslint_devkit_1.formatLLMMessage)({
|
|
46
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
47
|
-
issueName: 'Use Dependency Injection',
|
|
48
|
-
description: 'Inject API client',
|
|
49
|
-
severity: 'LOW',
|
|
50
|
-
fix: 'function util(apiClient) { return apiClient.get(...) }',
|
|
51
|
-
documentationLink: 'https://en.wikipedia.org/wiki/Dependency_injection',
|
|
52
|
-
}),
|
|
53
|
-
extractToService: (0, eslint_devkit_1.formatLLMMessage)({
|
|
54
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
55
|
-
issueName: 'Extract to Service',
|
|
56
|
-
description: 'Extract to service layer',
|
|
57
|
-
severity: 'LOW',
|
|
58
|
-
fix: 'Create services/apiService.ts',
|
|
59
|
-
documentationLink: 'https://martinfowler.com/eaaCatalog/serviceLayer.html',
|
|
60
|
-
}),
|
|
61
|
-
passApiClient: (0, eslint_devkit_1.formatLLMMessage)({
|
|
62
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
63
|
-
issueName: 'Pass API Client',
|
|
64
|
-
description: 'Pass API client as parameter',
|
|
65
|
-
severity: 'LOW',
|
|
66
|
-
fix: 'function util(apiClient, data) { ... }',
|
|
67
|
-
documentationLink: 'https://en.wikipedia.org/wiki/Dependency_injection',
|
|
68
|
-
}),
|
|
69
|
-
},
|
|
70
|
-
schema: [
|
|
71
|
-
{
|
|
72
|
-
type: 'object',
|
|
73
|
-
properties: {
|
|
74
|
-
ignoreInTests: {
|
|
75
|
-
type: 'boolean',
|
|
76
|
-
default: true,
|
|
77
|
-
},
|
|
78
|
-
networkMethods: {
|
|
79
|
-
type: 'array',
|
|
80
|
-
items: { type: 'string' },
|
|
81
|
-
default: ['fetch', 'axios', 'request', 'http.get', 'https.get', 'get', 'post', 'put', 'delete', 'patch'],
|
|
82
|
-
},
|
|
83
|
-
utilityPatterns: {
|
|
84
|
-
type: 'array',
|
|
85
|
-
items: { type: 'string' },
|
|
86
|
-
default: ['**/utils/**', '**/helpers/**', '**/lib/**'],
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
additionalProperties: false,
|
|
90
|
-
},
|
|
91
|
-
],
|
|
92
|
-
},
|
|
93
|
-
defaultOptions: [
|
|
94
|
-
{
|
|
95
|
-
ignoreInTests: true,
|
|
96
|
-
networkMethods: ['fetch', 'axios', 'request', 'http.get', 'https.get', 'get', 'post', 'put', 'delete', 'patch'],
|
|
97
|
-
utilityPatterns: ['**/utils/**', '**/helpers/**', '**/lib/**'],
|
|
98
|
-
},
|
|
99
|
-
],
|
|
100
|
-
create(context, [options = {}]) {
|
|
101
|
-
const { ignoreInTests = true, networkMethods = ['fetch', 'axios', 'request', 'http.get', 'https.get', 'get', 'post', 'put', 'delete', 'patch'], utilityPatterns = ['**/utils/**', '**/helpers/**', '**/lib/**'], } = options || {};
|
|
102
|
-
const filename = context.filename;
|
|
103
|
-
const isTestFile = ignoreInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
104
|
-
if (isTestFile) {
|
|
105
|
-
return {};
|
|
106
|
-
}
|
|
107
|
-
const isUtility = isUtilityFile(filename, utilityPatterns);
|
|
108
|
-
if (!isUtility) {
|
|
109
|
-
return {};
|
|
110
|
-
}
|
|
111
|
-
function checkCallExpression(node) {
|
|
112
|
-
if (isNetworkCall(node, networkMethods)) {
|
|
113
|
-
context.report({
|
|
114
|
-
node,
|
|
115
|
-
messageId: 'externalApiCallInUtils',
|
|
116
|
-
suggest: [
|
|
117
|
-
{
|
|
118
|
-
messageId: 'useDependencyInjection',
|
|
119
|
-
fix: () => null,
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
messageId: 'extractToService',
|
|
123
|
-
fix: () => null,
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
messageId: 'passApiClient',
|
|
127
|
-
fix: () => null,
|
|
128
|
-
},
|
|
129
|
-
],
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return {
|
|
134
|
-
CallExpression: checkCallExpression,
|
|
135
|
-
};
|
|
136
|
-
},
|
|
137
|
-
});
|
|
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 isNetworkCall(node,networkMethods){if(node.callee.type==="Identifier"){return networkMethods.includes(node.callee.name)}if(node.callee.type==="MemberExpression"&&node.callee.property.type==="Identifier"){const methodName=node.callee.property.name;const objectName=node.callee.object.type==="Identifier"?node.callee.object.name:"";return networkMethods.includes(methodName)||networkMethods.includes(`${objectName}.${methodName}`)}return false}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:{ignoreInTests:{type:"boolean",default:true},networkMethods:{type:"array",items:{type:"string"},default:["fetch","axios","request","http.get","https.get","get","post","put","delete","patch"]},utilityPatterns:{type:"array",items:{type:"string"},default:["**/utils/**","**/helpers/**","**/lib/**"]}},additionalProperties:false}]},defaultOptions:[{ignoreInTests:true,networkMethods:["fetch","axios","request","http.get","https.get","get","post","put","delete","patch"],utilityPatterns:["**/utils/**","**/helpers/**","**/lib/**"]}],create(context,[options={}]){const{ignoreInTests=true,networkMethods=["fetch","axios","request","http.get","https.get","get","post","put","delete","patch"],utilityPatterns=["**/utils/**","**/helpers/**","**/lib/**"]}=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{}}function checkCallExpression(node){if(isNetworkCall(node,networkMethods)){context.report({node,messageId:"externalApiCallInUtils",suggest:[{messageId:"useDependencyInjection",fix:()=>null},{messageId:"extractToService",fix:()=>null},{messageId:"passApiClient",fix:()=>null}]})}}return{CallExpression:checkCallExpression}}});
|
|
@@ -1,51 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noMutableExports = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
6
|
-
exports.noMutableExports = (0, eslint_devkit_1.createRule)({
|
|
7
|
-
name: 'no-mutable-exports',
|
|
8
|
-
meta: {
|
|
9
|
-
type: 'suggestion',
|
|
10
|
-
docs: {
|
|
11
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-modularity/docs/rules/no-mutable-exports.md',
|
|
12
|
-
description: 'Disallow mutable exports (export let / export var)',
|
|
13
|
-
},
|
|
14
|
-
fixable: 'code',
|
|
15
|
-
messages: {
|
|
16
|
-
noMutableExport: (0, eslint_devkit_2.formatLLMMessage)({
|
|
17
|
-
icon: eslint_devkit_2.MessageIcons.WARNING,
|
|
18
|
-
issueName: 'Mutable Export',
|
|
19
|
-
description: 'Exporting a `{{kind}}` binding creates a live, mutable reference visible to all importers. Use `const` instead.',
|
|
20
|
-
severity: 'MEDIUM',
|
|
21
|
-
fix: 'Change `export {{kind}}` to `export const`',
|
|
22
|
-
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export',
|
|
23
|
-
}),
|
|
24
|
-
},
|
|
25
|
-
schema: [],
|
|
26
|
-
},
|
|
27
|
-
defaultOptions: [],
|
|
28
|
-
create(context) {
|
|
29
|
-
return {
|
|
30
|
-
ExportNamedDeclaration(node) {
|
|
31
|
-
const decl = node.declaration;
|
|
32
|
-
if (!decl || decl.type !== 'VariableDeclaration')
|
|
33
|
-
return;
|
|
34
|
-
if (decl.kind !== 'let' && decl.kind !== 'var')
|
|
35
|
-
return;
|
|
36
|
-
context.report({
|
|
37
|
-
node: decl,
|
|
38
|
-
messageId: 'noMutableExport',
|
|
39
|
-
data: { kind: decl.kind },
|
|
40
|
-
fix(fixer) {
|
|
41
|
-
const sourceCode = context.sourceCode;
|
|
42
|
-
const kindToken = sourceCode.getFirstToken(decl);
|
|
43
|
-
if (!kindToken)
|
|
44
|
-
return null;
|
|
45
|
-
return fixer.replaceText(kindToken, 'const');
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
},
|
|
51
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noMutableExports=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.noMutableExports=(0,eslint_devkit_1.createRule)({name:"no-mutable-exports",meta:{type:"suggestion",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-modularity/docs/rules/no-mutable-exports.md",description:"Disallow mutable exports (export let / export var)"},fixable:"code",messages:{noMutableExport:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Mutable Export",description:"Exporting a `{{kind}}` binding creates a live, mutable reference visible to all importers. Use `const` instead.",severity:"MEDIUM",fix:"Change `export {{kind}}` to `export const`",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export"})},schema:[]},defaultOptions:[],create(context){return{ExportNamedDeclaration(node){const decl=node.declaration;if(!decl||decl.type!=="VariableDeclaration")return;if(decl.kind!=="let"&&decl.kind!=="var")return;context.report({node:decl,messageId:"noMutableExport",data:{kind:decl.kind},fix(fixer){const sourceCode=context.sourceCode;const kindToken=sourceCode.getFirstToken(decl);if(!kindToken)return null;return fixer.replaceText(kindToken,"const")}})}}}});
|