Code Maintainability
Rules that identify code patterns leading to confusion, technical debt, or unexpected behavior. Focus areas: useless code, deprecated APIs, and code organization.
Incorrect (Python - duplicate if condition):
if a:
print('1')
elif a:
print('2')Correct (Python - distinct conditions):
if a:
print('1')
elif b:
print('2')Incorrect (Python - identical if/else branches):
if a:
print('1')
else:
print('1')Correct (Python - different branches or simplified):
print('1')Incorrect (Python - unused inner function):
def A():
def B():
print('never used')
return NoneCorrect (Python - inner function called or returned):
def A():
def B():
print('used')
return B()Incorrect (Python - function reference without call):
if example.is_positive:
do_something()Correct (Python - function called with parentheses):
if example.is_positive():
do_something()Incorrect (Django - duplicate URL paths):
urlpatterns = [
path('path/to/view', views.example_view),
path('path/to/view', views.other_view),
]Correct (Django - unique URL paths):
urlpatterns = [
path('path/to/view1', views.example_view),
path('path/to/view2', views.other_view),
]Incorrect (Flask - deprecated APIs):
from flask import json_available
blueprint = request.moduleCorrect (Flask - modern alternatives):
from flask import Flask, request
app = Flask(__name__)