flake8 plugin for checking variable names contain only one word
Project description
flake8-simple-var
Background
This flake8 plugin enforces the principle that variable names should contain only one word. The idea is based on the concept that compound variable names (like textLength, table_name, or current-user-email) often indicate that the scope is too large and complex, making simple nouns ambiguous.
When you need compound names, it usually means your scope is too big and complex. An ideal method should deal with up to five variables, and an ideal class should encapsulate up to five properties. If we have five variables, we should be able to find five unique single-word nouns to name them.
This approach promotes cleaner, more maintainable code by encouraging smaller, more focused scopes.
Installation
To install flake8-simple-var, you can use pip:
pip install flake8-simple-var
Usage
After installing the plugin, flake8 will automatically use it when you run the following command:
flake8 your_project_directory
The plugin will check variable names to ensure they contain only one word. If a variable name contains multiple words (camelCase, snake_case, kebab-case, etc.), an error will be reported.
Rules
The plugin checks the following types of variable names:
- SVN100: Variable names should contain only one word
- SVN200: Function argument names should contain only one word
- SVN300: Exception handler variable names should contain only one word
- SVN400: With statement variable names should contain only one word
What is considered a compound name:
textLength(camelCase)table_name(snake_case)current-user-email(kebab-case)USER_NAME(UPPER_CASE with multiple words)
What is considered valid:
x,name,value,count(single words)_private_var(private variables starting with_are ignored)__very_private(dunder names are ignored)
Examples
❌ Invalid variable names:
# These will trigger SVN errors
textLength = 10
userName = "john"
table_name = "users"
current_user_email = "test@example.com"
file_path = "/tmp/file.txt"
def process_data(user_name, file_path):
return user_name + file_path
for item_name in items:
print(item_name)
try:
pass
except ValueError as error_message:
print(error_message)
with open('file.txt') as file_handle:
content = file_handle.read()
✅ Valid variable names:
# These are valid single-word names
x = 1
name = "test"
value = 42
count = 10
user = "john"
table = "users"
email = "test@example.com"
file = "/tmp/file.txt"
def process_data(user, file):
return user + file
for item in items:
print(item)
try:
pass
except ValueError as error:
print(error)
with open('file.txt') as file:
content = file.read()
Philosophy
The principle behind this plugin is inspired by the idea that compound variable names often indicate:
- Large scope: When you need compound names, it usually means your scope (method, class, module) is too large
- Complexity: Simple nouns become ambiguous because there are too many variables in the same scope
- Poor design: If you can't find unique single-word names for your variables, consider refactoring
The goal is to encourage:
- Smaller, more focused methods and classes
- Better variable naming through context
- Cleaner, more readable code
License
Credits
This project was generated with wemake-python-package. Current template version is: 9899cb192f754a566da703614227e6d63227b933. See what is updated since then.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flake8_simple_var-0.1.0.tar.gz.
File metadata
- Download URL: flake8_simple_var-0.1.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.0 Darwin/24.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d38f6447e285a56fce46dfa21d3dc816ba8de1b2faeb37b62289af2c8cbfffce
|
|
| MD5 |
12d9ad8b948534aa9c4725c821e57305
|
|
| BLAKE2b-256 |
c522a1ee373617ab0886f576d208f780de5656aadf4a1abb256d4b093b1eda16
|
File details
Details for the file flake8_simple_var-0.1.0-py3-none-any.whl.
File metadata
- Download URL: flake8_simple_var-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.0 Darwin/24.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b58fa4c4c0385a6c04d9fe816251f038cc39db07e0a97a0cee5bf9dadf1556af
|
|
| MD5 |
a6228345468329cf58611c15e69213bb
|
|
| BLAKE2b-256 |
d3d8d020003ba2f2aede162125a84f4cd5fec0786f413aaaa69c5e7dad57c1be
|