twentyhq / twenty

Building a modern alternative to Salesforce, powered by the community.
https://twenty.com
GNU Affero General Public License v3.0
15.59k stars 1.65k forks source link

feat: add eslint rule for enforcing WorkspaceService naming convention #6309

Closed magrinj closed 1 month ago

magrinj commented 1 month ago

Introduces a custom ESLint rule to enforce naming conventions for files and classes that use the @InjectWorkspaceRepository decorator or include services ending with WorkspaceService in their constructors.

greptile-apps[bot] commented 1 month ago

To add an ESLint rule for enforcing the WorkspaceService naming convention:

  1. Create a custom ESLint rule: Add a new file for the custom rule, e.g., workspace-service-naming.js in your ESLint rules directory.
module.exports = {
  meta: {
    type: 'suggestion',
    docs: {
      description: 'Enforce WorkspaceService naming convention',
      category: 'Best Practices',
      recommended: true
    },
    schema: []
  },
  create(context) {
    return {
      ClassDeclaration(node) {
        if (node.id.name === 'WorkspaceService') {
          context.report({
            node,
            message: 'Class name should follow WorkspaceService naming convention.'
          });
        }
      }
    };
  }
};
  1. Update ESLint configuration: Add the new rule to your .eslintrc.js file.
module.exports = {
  // ... other configurations
  rules: {
    'workspace-service-naming': 'error'
  }
};
  1. Reference WorkspaceService: Ensure the rule checks the WorkspaceService class in /packages/twenty-server/src/engine/modules/workspace/services/workspace.service.ts.

  2. Validate DTOs: Optionally, extend the rule to check DTOs in /packages/twenty-server/src/engine/modules/workspace/dtos if needed.

References

/packages/twenty-server/src/engine/modules/workspace/services /packages/twenty-server/src/engine/modules/workspace/dtos /packages/twenty-server/src/engine/modules/workspace

#### About Greptile This response provides a starting point for your research, not a precise solution. Help us improve! Please leave a ๐Ÿ‘ if this is helpful and ๐Ÿ‘Ž if it is irrelevant. [Ask Greptile](https://app.greptile.com/chat/github/twentyhq/twenty/main) ยท [Edit Issue Bot Settings](https://app.greptile.com/apps/github)