mirror of
https://github.com/twentyhq/twenty
synced 2026-04-21 13:37:22 +00:00
## Summary Moves the custom ESLint rules from `tools/eslint-rules` to `packages/twenty-eslint-rules` for better organization within the monorepo packages structure. ## Changes - Move `eslint-rules` from `tools/` to `packages/twenty-eslint-rules` - Use `loadWorkspaceRules` from `@nx/eslint-plugin` to load custom rules - Update all ESLint configs to use the `twenty/` rule prefix instead of `@nx/workspace-` - Update `project.json`, `jest.config.mjs` with new paths - Update `package.json` workspaces and `nx.json` cache inputs - Update Dockerfile reference ## Technical Details The custom ESLint rules are now loaded using Nx's `loadWorkspaceRules` utility which: - Handles TypeScript transpilation automatically - Allows loading workspace rules from any directory - Provides a cleaner approach than the previous `@nx/workspace-` convention ## Testing - Verified all 17 custom ESLint rules load correctly from the new location - Verified linting works on dependent packages (twenty-front, twenty-server, etc.)
86 lines
2.9 KiB
TypeScript
86 lines
2.9 KiB
TypeScript
import { ESLintUtils, TSESTree } from '@typescript-eslint/utils';
|
|
|
|
export const RULE_NAME = 'inject-workspace-repository';
|
|
|
|
export const rule = ESLintUtils.RuleCreator(() => __filename)({
|
|
name: RULE_NAME,
|
|
meta: {
|
|
type: 'problem',
|
|
docs: {
|
|
description:
|
|
'Ensure class names and file names follow the required pattern when using @InjectWorkspaceRepository.',
|
|
recommended: 'recommended',
|
|
},
|
|
schema: [],
|
|
messages: {
|
|
invalidClassName: "Class name should end with 'WorkspaceService'.",
|
|
invalidFileName: "File name should end with '.workspace-service.ts'.",
|
|
},
|
|
},
|
|
defaultOptions: [],
|
|
create: (context) => {
|
|
return {
|
|
MethodDefinition: (node: TSESTree.MethodDefinition) => {
|
|
const filename = context.filename;
|
|
|
|
// Only check files that end with '.workspace-service.ts' or '.service.ts'
|
|
if (
|
|
!filename.endsWith('.workspace-service.ts') &&
|
|
!filename.endsWith('.service.ts')
|
|
) {
|
|
return;
|
|
}
|
|
|
|
if (node.kind === 'constructor') {
|
|
const hasInjectWorkspaceRepositoryDecoratorOrWorkspaceService =
|
|
node.value.params.some((param) => {
|
|
if (param.type === TSESTree.AST_NODE_TYPES.TSParameterProperty) {
|
|
const hasDecorator = param.decorators?.some((decorator) => {
|
|
return (
|
|
decorator.expression.type ===
|
|
TSESTree.AST_NODE_TYPES.CallExpression &&
|
|
(decorator.expression.callee as TSESTree.Identifier)
|
|
.name === 'InjectWorkspaceRepository'
|
|
);
|
|
});
|
|
const hasWorkspaceServiceType =
|
|
param.parameter.typeAnnotation?.typeAnnotation &&
|
|
param.parameter.typeAnnotation.typeAnnotation.type ===
|
|
TSESTree.AST_NODE_TYPES.TSTypeReference &&
|
|
(
|
|
param.parameter.typeAnnotation.typeAnnotation
|
|
.typeName as TSESTree.Identifier
|
|
).name.endsWith('WorkspaceService');
|
|
|
|
return hasDecorator || hasWorkspaceServiceType;
|
|
}
|
|
|
|
return false;
|
|
});
|
|
|
|
if (hasInjectWorkspaceRepositoryDecoratorOrWorkspaceService) {
|
|
const className = (node.parent.parent as TSESTree.ClassDeclaration)
|
|
.id?.name;
|
|
const filename = context.filename;
|
|
|
|
if (!className?.endsWith('WorkspaceService')) {
|
|
context.report({
|
|
node: node.parent,
|
|
messageId: 'invalidClassName',
|
|
});
|
|
}
|
|
|
|
if (!filename.endsWith('.workspace-service.ts')) {
|
|
context.report({
|
|
node: node.parent,
|
|
messageId: 'invalidFileName',
|
|
});
|
|
}
|
|
}
|
|
}
|
|
},
|
|
};
|
|
},
|
|
});
|
|
|
|
export default rule;
|