rspec/rules/S101/python/rule.adoc

65 lines
1.4 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
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
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
2020-06-30 10:16:44 +02:00
2021-02-05 10:34:25 +01:00
With default provided regular expression ``++^_?([A-Z_][a-zA-Z0-9]*|[a-z_][a-z0-9_]*)$++``:
2022-02-04 17:28:24 +01:00
[source,python]
2020-06-30 10:16:44 +02:00
----
class myClass: # Noncompliant
2020-06-30 10:16:44 +02: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
2020-06-30 10:16:44 +02:00
2022-02-04 17:28:24 +01:00
[source,python]
2020-06-30 10:16:44 +02:00
----
class MyClass:
...
class my_context_manager:
def __enter__(self):
pass
def __exit__(self, type, value, traceback):
pass
2020-06-30 10:16:44 +02:00
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
=== Parameters
.format
****
----
^_?([A-Z_][a-zA-Z0-9]{empty}*|[a-z_][a-z0-9_]{empty}*)$
----
Regular expression used to check the class names against.
****
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]