Create Cop to enforce the use of namespaced classes
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
-
Changelog entry -
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
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