2020-12-21 15:38:52 +01:00
Shared coding conventions allow teams to collaborate effectively. This rule allows to check that all class names match a provided regular expression.
2021-02-02 15:02:10 +01:00
2020-12-21 15:38:52 +01:00
The default regular expression is based on PEP-8 standard. It allows "CapWords" convention and "snake_case" in lowercase. The "snake_case" convention is accepted by PEP-8 when the class is primarily used as a callable (ex: decorator, context manager, etc...). However the "CapWords" convention is recommended in every case.
2020-06-30 10:16:44 +02:00
== Noncompliant Code Example
2021-02-05 10:34:25 +01:00
With default provided regular expression ``++^_?([A-Z_][a-zA-Z0-9]*|[a-z_][a-z0-9_]*)$++``:
2020-06-30 14:49:38 +02:00
2020-06-30 10:16:44 +02:00
----
2020-12-21 15:38:52 +01:00
class myClass: # Noncompliant
2020-06-30 10:16:44 +02:00
...
2020-12-21 15:38:52 +01:00
class my_CONTEXT_manager: # Noncompliant
def __enter__(self):
pass
def __exit__(self, type, value, traceback):
pass
2020-06-30 10:16:44 +02:00
----
== Compliant Solution
----
class MyClass:
...
2020-12-21 15:38:52 +01:00
class my_context_manager:
def __enter__(self):
pass
def __exit__(self, type, value, traceback):
pass
2020-06-30 10:16:44 +02:00
----
2021-06-02 20:44:38 +02:00
ifdef::rspecator-view[]
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::rspecator-view[]