rspec/rules/S1845/python/rule.adoc

30 lines
944 B
Plaintext
Raw Normal View History

2021-01-27 13:42:22 +01:00
Looking at the set of methods and fields in a ``++class++`` and finding two that differ only by capitalization is confusing to users of the class.
2020-06-30 12:47:33 +02:00
2021-02-02 15:02:10 +01:00
2020-06-30 12:47:33 +02:00
This situation may simply indicate poor naming. Method names should be action-oriented, and thus contain a verb, which is unlikely in the case where both a method and a field have the same name (with or without capitalization differences). However, renaming a public method could be disruptive to callers. Therefore renaming the member is the recommended action.
== Noncompliant Code Example
----
class SomeClass:
lookUp = false
def lookup(): # Non-compliant; method name differs from field name only by capitalization
pass
----
== Compliant Solution
----
class SomeClass:
lookUp = false
def getLookUp():
pass
----
ifdef::rspecator-view[]
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::rspecator-view[]