Showing 4,191 of 4,191 total issues
Either merge this branch with the identical one on line "694" or change one of the implementations. Open
return _fmt_retval(self._match_type_dict['substitution'])
- Read upRead up
- Exclude checks
Having two branches in the same if
structure with the same implementation is at best duplicate code, and at worst a coding error. If
the same logic is truly needed for both instances, then they should be combined.
Noncompliant Code Example
if 0 <= a < 10: do_the_thing() elif 10 <= a < 20: do_the_other_thing() elif 20 <= a < 50: do_the_thing() # Noncompliant; duplicates first condition else: do_the_rest() b = 4 if a > 12 else 4
Compliant Solution
if (0 <= a < 10) or (20 <= a < 50): do_the_thing() elif 10 <= a < 20: do_the_other_thing() else: do_the_rest() b = 4
or
if 0 <= a < 10: do_the_thing() elif 10 <= a < 20: do_the_other_thing() elif 20 <= a < 50: do_the_third_thing() else: do_the_rest() b = 8 if a > 12 else 4
Refactor this function to reduce its Cognitive Complexity from 122 to the 15 allowed. Open
def sim_type(
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
Method "__init__" has 10 parameters, which is greater than the 7 authorized. Open
self,
max_offset: int = 5,
max_distance: int = 0,
tokenizer: Optional[_Tokenizer] = None,
token_matcher: Optional[Callable[[str, str], bool]] = None,
- Read upRead up
- Exclude checks
A long parameter list can indicate that a new structure should be created to wrap the numerous parameters or that the function is doing too many things.
Noncompliant Code Example
With a maximum number of 4 parameters:
def do_something(param1, param2, param3, param4, param5): ...
Compliant Solution
def do_something(param1, param2, param3, param4): ...
Rename field "corpus" Open
self.corpus = [] # type: List[List[List[str]]]
- Read upRead up
- Exclude checks
It's confusing to have a class member with the same name (case differences aside) as its enclosing class. This is particularly so when you consider the common practice of naming a class instance for the class itself.
Best practice dictates that any field or member with the same name as the enclosing class be renamed to be more descriptive of the particular aspect of the class it represents or holds.
Noncompliant Code Example
class Foo: foo = '' def getFoo(self): ... foo = Foo() foo.getFoo() # what does this return?
Compliant Solution
class Foo: name = '' def getName(self): ... foo = Foo() foo.getName()
Refactor this function to reduce its Cognitive Complexity from 22 to the 15 allowed. Open
def corpus_importer(
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
Consider using enumerate instead of iterating with range and len Open
for j in range(len(nums)):
- Read upRead up
- Exclude checks
Emitted when code that iterates with range and len is encountered. Such code can be simplified by using the enumerate builtin.
Wrong hanging indentation before block (add 4 spaces). Open
self._tp == other[0]
- Read upRead up
- Exclude checks
TODO self._tp == other[0] ^ |
Wrong hanging indentation before block (add 4 spaces). Open
and word[-1] == word[-2]
- Read upRead up
- Exclude checks
TODO and word[-1] == word[-2] ^ |
Method could be a function Open
def stem(self, word: str) -> str:
- Read upRead up
- Exclude checks
Used when a method doesn't use its bound instance, and so could be written as a function.
Wrong hanging indentation before block (add 4 spaces). Open
'bb',
- Read upRead up
- Exclude checks
TODO 'bb', ^ |
Merge this if statement with the enclosing one. Open
if ca_ratio >= self._char_approx_min:
- Read upRead up
- Exclude checks
Merging collapsible if
statements increases the code's readability.
Noncompliant Code Example
if condition1: if condition2: # ...
Compliant Solution
if condition1 and condition2: # ...
Merge this if statement with the enclosing one. Open
if not ying[0].isdigit():
- Read upRead up
- Exclude checks
Merging collapsible if
statements increases the code's readability.
Noncompliant Code Example
if condition1: if condition2: # ...
Compliant Solution
if condition1 and condition2: # ...
Refactor this function to reduce its Cognitive Complexity from 21 to the 15 allowed. Open
def ipa_to_feature_dicts(ipa: str) -> List[Dict[str, str]]:
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
Wrong hanging indentation before block (add 4 spaces). Open
metric: Optional[Callable[[str, str], float]] = None,
- Read upRead up
- Exclude checks
TODO metric: Optional[Callable[[str, str], float]] = None, ^ |
Wrong hanging indentation before block (add 4 spaces). Open
self._tp == other['tp']
- Read upRead up
- Exclude checks
TODO self._tp == other['tp'] ^ |
Wrong hanging indentation before block (add 4 spaces). Open
and self._fp == other['fp']
- Read upRead up
- Exclude checks
TODO and self._fp == other['fp'] ^ |
Wrong hanging indentation before block (add 4 spaces). Open
and self._fn == other['fn']
- Read upRead up
- Exclude checks
TODO and self._fn == other['fn'] ^ |
Wrong hanging indentation before block (add 4 spaces). Open
'erede',
- Read upRead up
- Exclude checks
TODO 'erede', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
'heder',
- Read upRead up
- Exclude checks
TODO 'heder', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
len(word[r1_start:]) >= 1
- Read upRead up
- Exclude checks
TODO len(word[r1_start:]) >= 1 ^ |