Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Melevir/flake8-functions-names
An extension for flake8 that validates functions names, decomposition and conformity with annotations.
https://github.com/Melevir/flake8-functions-names
code-style contract flake8 flake8-plugin styleguide
Last synced: 3 months ago
JSON representation
An extension for flake8 that validates functions names, decomposition and conformity with annotations.
- Host: GitHub
- URL: https://github.com/Melevir/flake8-functions-names
- Owner: Melevir
- License: mit
- Created: 2021-03-20T18:46:11.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-13T11:34:19.000Z (over 1 year ago)
- Last Synced: 2024-07-09T06:40:09.483Z (4 months ago)
- Topics: code-style, contract, flake8, flake8-plugin, styleguide
- Language: Python
- Homepage:
- Size: 43 KB
- Stars: 27
- Watchers: 2
- Forks: 9
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-flake8-extensions - flake8-functions-names - Validate functions names, decomposition and conformity with annotations. (Naming)
README
# flake8-functions-names
[![PyPI version](https://badge.fury.io/py/flake8-functions-names.svg)](https://badge.fury.io/py/flake8-functions-names)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/flake8-functions-names)An extension for flake8 that validates functions names, decomposition and
conformity with annotations. The plugin also has some validations
of [deal](https://github.com/life4/deal) contracts.This plugin helps to provide better naming for functions.
The validations are based on my articles:- [Python functions naming: an algorithm](https://melevir.medium.com/python-functions-naming-the-algorithm-74320a18278d)
- [Python functions naming: 10 tips](https://melevir.medium.com/python-functions-naming-tips-376f12549f9)`deal`-related validations are enabled only if `deal` is installed.
They are disabled otherwise.## Installation
```terminal
pip install flake8-functions-names
```## Example
```python
def is_user_banned(user: User) -> str:
return 'is_banned' if user.id in BANNED_USERS else 'not_banned'def save_user(user: User) -> None:
user.save()
```Usage:
```terminal
$ flake8 test.py
text.py:1:35: FNE001 Name of the function says that it should return bool-like, but it returns str
text.py:4:4: FNE003 Name of the function uses "save", but not uses "to"
```Tested on Python 3.8+ and flake8 3.9+.
## Error codes
| Error code | Description |
|:----------:|:----------------------------------------:|
| FNE001 | Name of the function says that it should return `bool-like`[^1], but it returns *actual_type* |
| FNE002 | The method has a `@property` decorator, but has a verb in it's name (*verb*) |
| FNE003 | Name of the function uses `save`, but not uses `to` |
| FNE004 | Name of the function uses `load`, but not uses `from` |
| FNE005 | Return type of the function is `bool-like`[^1], but the name doesn't show it |
| FNE006 | Name of function says, that it works with data, so it should be pure, but it has no `@deal.pure()` |
| FNE007 | `and` is not recommended in functions names |
| FNE008 | Name of functions ends with it's first argument name |[^1]: bool-like return types: bool, TypeGuard