website refactor
This commit is contained in:
41
apps/api/eslint-rules/controller-location.js
Normal file
41
apps/api/eslint-rules/controller-location.js
Normal file
@@ -0,0 +1,41 @@
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: 'problem',
|
||||
docs: {
|
||||
description: 'Enforce controller location in apps/api',
|
||||
category: 'Architecture',
|
||||
recommended: true,
|
||||
},
|
||||
fixable: null,
|
||||
schema: [],
|
||||
messages: {
|
||||
invalidLocation: 'Controllers must be located in "src/domain/<feature>/" or "src/features/". Found: {{location}}',
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
return {
|
||||
ClassDeclaration(node) {
|
||||
const isController = node.decorators && node.decorators.some(d =>
|
||||
d.expression.type === 'CallExpression' &&
|
||||
d.expression.callee.name === 'Controller'
|
||||
);
|
||||
|
||||
if (isController) {
|
||||
const filename = context.getFilename();
|
||||
const isValidLocation = /apps\/api\/src\/(domain\/[^/]+\/|features\/)/.test(filename);
|
||||
|
||||
if (!isValidLocation) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'invalidLocation',
|
||||
data: {
|
||||
location: filename,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user