flake8-simple-var


Nameflake8-simple-var JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/blablatdinov/flake8-simple-var
Summaryflake8 plugin for checking variable names contain only one word
upload_time2025-08-11 19:21:49
maintainerNone
docs_urlNone
authorAlmaz Ilaletdinov
requires_python<4.0,>=3.9
licenseMIT
keywords flake8 linting variable-names code-quality python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <!---
The MIT License (MIT)

Copyright (c) 2025 Almaz Ilaletdinov <a.ilaletdinov@yandex.ru>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
OR OTHER DEALINGS IN THE SOFTWARE.
--->

# flake8-simple-var

[![test](https://github.com/blablatdinov/flake8-simple-var/actions/workflows/test.yml/badge.svg)](https://github.com/blablatdinov/flake8-simple-var/actions/workflows/test.yml)
[![codecov](https://codecov.io/gh/blablatdinov/flake8-simple-var/branch/master/graph/badge.svg)](https://codecov.io/gh/blablatdinov/flake8-simple-var)
[![Python Version](https://img.shields.io/pypi/pyversions/flake8-simple-var.svg)](https://pypi.org/project/flake8-simple-var/)
[![wemake-python-styleguide](https://img.shields.io/badge/style-wemake-000000.svg)](https://github.com/wemake-services/wemake-python-styleguide)

## 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`:

```bash
pip install flake8-simple-var
```

## Usage

After installing the plugin, flake8 will automatically use it when you run the following command:

```bash
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:

```python
# 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:

```python
# 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:

1. **Large scope**: When you need compound names, it usually means your scope (method, class, module) is too large
2. **Complexity**: Simple nouns become ambiguous because there are too many variables in the same scope
3. **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

[MIT](https://github.com/blablatdinov/flake8-simple-var/blob/master/LICENSE)

## Credits

This project was generated with [`wemake-python-package`](https://github.com/wemake-services/wemake-python-package). Current template version is: [9899cb192f754a566da703614227e6d63227b933](https://github.com/wemake-services/wemake-python-package/tree/9899cb192f754a566da703614227e6d63227b933). See what is [updated](https://github.com/wemake-services/wemake-python-package/compare/9899cb192f754a566da703614227e6d63227b933...master) since then.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/blablatdinov/flake8-simple-var",
    "name": "flake8-simple-var",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": "flake8, linting, variable-names, code-quality, python",
    "author": "Almaz Ilaletdinov",
    "author_email": "a.ilaletdinov@yandex.ru",
    "download_url": "https://files.pythonhosted.org/packages/c5/22/a1ee373617ab0886f576d208f780de5656aadf4a1abb256d4b093b1eda16/flake8_simple_var-0.1.0.tar.gz",
    "platform": null,
    "description": "<!---\nThe MIT License (MIT)\n\nCopyright (c) 2025 Almaz Ilaletdinov <a.ilaletdinov@yandex.ru>\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\nDAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\nOTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE\nOR OTHER DEALINGS IN THE SOFTWARE.\n--->\n\n# flake8-simple-var\n\n[![test](https://github.com/blablatdinov/flake8-simple-var/actions/workflows/test.yml/badge.svg)](https://github.com/blablatdinov/flake8-simple-var/actions/workflows/test.yml)\n[![codecov](https://codecov.io/gh/blablatdinov/flake8-simple-var/branch/master/graph/badge.svg)](https://codecov.io/gh/blablatdinov/flake8-simple-var)\n[![Python Version](https://img.shields.io/pypi/pyversions/flake8-simple-var.svg)](https://pypi.org/project/flake8-simple-var/)\n[![wemake-python-styleguide](https://img.shields.io/badge/style-wemake-000000.svg)](https://github.com/wemake-services/wemake-python-styleguide)\n\n## Background\n\nThis 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.\n\nWhen 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.\n\nThis approach promotes cleaner, more maintainable code by encouraging smaller, more focused scopes.\n\n## Installation\n\nTo install `flake8-simple-var`, you can use `pip`:\n\n```bash\npip install flake8-simple-var\n```\n\n## Usage\n\nAfter installing the plugin, flake8 will automatically use it when you run the following command:\n\n```bash\nflake8 your_project_directory\n```\n\nThe 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.\n\n## Rules\n\nThe plugin checks the following types of variable names:\n\n- **SVN100**: Variable names should contain only one word\n- **SVN200**: Function argument names should contain only one word\n- **SVN300**: Exception handler variable names should contain only one word\n- **SVN400**: With statement variable names should contain only one word\n\n### What is considered a compound name:\n\n- `textLength` (camelCase)\n- `table_name` (snake_case)\n- `current-user-email` (kebab-case)\n- `USER_NAME` (UPPER_CASE with multiple words)\n\n### What is considered valid:\n\n- `x`, `name`, `value`, `count` (single words)\n- `_private_var` (private variables starting with `_` are ignored)\n- `__very_private` (dunder names are ignored)\n\n## Examples\n\n### \u274c Invalid variable names:\n\n```python\n# These will trigger SVN errors\ntextLength = 10\nuserName = \"john\"\ntable_name = \"users\"\ncurrent_user_email = \"test@example.com\"\nfile_path = \"/tmp/file.txt\"\n\ndef process_data(user_name, file_path):\n    return user_name + file_path\n\nfor item_name in items:\n    print(item_name)\n\ntry:\n    pass\nexcept ValueError as error_message:\n    print(error_message)\n\nwith open('file.txt') as file_handle:\n    content = file_handle.read()\n```\n\n### \u2705 Valid variable names:\n\n```python\n# These are valid single-word names\nx = 1\nname = \"test\"\nvalue = 42\ncount = 10\nuser = \"john\"\ntable = \"users\"\nemail = \"test@example.com\"\nfile = \"/tmp/file.txt\"\n\ndef process_data(user, file):\n    return user + file\n\nfor item in items:\n    print(item)\n\ntry:\n    pass\nexcept ValueError as error:\n    print(error)\n\nwith open('file.txt') as file:\n    content = file.read()\n```\n\n## Philosophy\n\nThe principle behind this plugin is inspired by the idea that compound variable names often indicate:\n\n1. **Large scope**: When you need compound names, it usually means your scope (method, class, module) is too large\n2. **Complexity**: Simple nouns become ambiguous because there are too many variables in the same scope\n3. **Poor design**: If you can't find unique single-word names for your variables, consider refactoring\n\nThe goal is to encourage:\n- Smaller, more focused methods and classes\n- Better variable naming through context\n- Cleaner, more readable code\n\n## License\n\n[MIT](https://github.com/blablatdinov/flake8-simple-var/blob/master/LICENSE)\n\n## Credits\n\nThis project was generated with [`wemake-python-package`](https://github.com/wemake-services/wemake-python-package). Current template version is: [9899cb192f754a566da703614227e6d63227b933](https://github.com/wemake-services/wemake-python-package/tree/9899cb192f754a566da703614227e6d63227b933). See what is [updated](https://github.com/wemake-services/wemake-python-package/compare/9899cb192f754a566da703614227e6d63227b933...master) since then.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "flake8 plugin for checking variable names contain only one word",
    "version": "0.1.0",
    "project_urls": {
        "Homepage": "https://github.com/blablatdinov/flake8-simple-var",
        "Repository": "https://github.com/blablatdinov/flake8-simple-var"
    },
    "split_keywords": [
        "flake8",
        " linting",
        " variable-names",
        " code-quality",
        " python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d3d8d020003ba2f2aede162125a84f4cd5fec0786f413aaaa69c5e7dad57c1be",
                "md5": "a6228345468329cf58611c15e69213bb",
                "sha256": "b58fa4c4c0385a6c04d9fe816251f038cc39db07e0a97a0cee5bf9dadf1556af"
            },
            "downloads": -1,
            "filename": "flake8_simple_var-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a6228345468329cf58611c15e69213bb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 8333,
            "upload_time": "2025-08-11T19:21:48",
            "upload_time_iso_8601": "2025-08-11T19:21:48.146891Z",
            "url": "https://files.pythonhosted.org/packages/d3/d8/d020003ba2f2aede162125a84f4cd5fec0786f413aaaa69c5e7dad57c1be/flake8_simple_var-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c522a1ee373617ab0886f576d208f780de5656aadf4a1abb256d4b093b1eda16",
                "md5": "12d9ad8b948534aa9c4725c821e57305",
                "sha256": "d38f6447e285a56fce46dfa21d3dc816ba8de1b2faeb37b62289af2c8cbfffce"
            },
            "downloads": -1,
            "filename": "flake8_simple_var-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "12d9ad8b948534aa9c4725c821e57305",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 5300,
            "upload_time": "2025-08-11T19:21:49",
            "upload_time_iso_8601": "2025-08-11T19:21:49.373867Z",
            "url": "https://files.pythonhosted.org/packages/c5/22/a1ee373617ab0886f576d208f780de5656aadf4a1abb256d4b093b1eda16/flake8_simple_var-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-11 19:21:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "blablatdinov",
    "github_project": "flake8-simple-var",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "flake8-simple-var"
}
        
Elapsed time: 0.73282s