Skip to content

Create Cop to enforce the use of namespaced classes

Fabio Pitino requested to merge enforce-namespaced-classes into master

What does this MR do?

Related to #212156 (closed)

A healthy application is divided into macro and sub components that represent the domains at play. As GitLab code becomes broad with so many features and components it's hard to see what domains are at play.

We should expect any class to be defined inside a module/namespace that represents the domain where it operates.

The lack of namespaces today makes large parts of the codebase to have a flat structure:

  • class names from different domains may be confused because X may mean something in one domain and something else in another domain
  • it's hard to understand which group is responsible for the direction of the codebase (domain experts)
  • it's extremely hard to understand the interactions between components
  • etc.

This MR introduces a cop that flags class declarations that are not nested.

It's considered a first step towards defining better boundaries in the codebase.

This current implementation has a limitation. Compact class declarations like class MyDomain::MyClass are considered valid because we can't statically know if MyDomain is a class or a module. However if MyDomain is a class and it's indeed non nested, it will be flagged. Once it's fixed and all nested classes reorganized, the cop will be able to flag invalid declarations.

Screenshots (strongly suggested)

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team

Merge request reports