Giter VIP home page Giter VIP logo

flake8-functions-names's Introduction

flake8-functions-names

PyPI version PyPI - Python Version

An extension for flake8 that validates functions names, decomposition and conformity with annotations. The plugin also has some validations of deal contracts.

This plugin helps to provide better naming for functions. The validations are based on my articles:

deal-related validations are enabled only if deal is installed. They are disabled otherwise.

Installation

pip install flake8-functions-names

Example

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:

$ 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-like1, 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-like1, 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

Footnotes

  1. bool-like return types: bool, TypeGuard 2

flake8-functions-names's People

Contributors

melevir avatar ryan-thom avatar thewchan avatar ember91 avatar sobolevn avatar sutyrin avatar gost-serb avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.