flake8-expression-complexity


Nameflake8-expression-complexity JSON
Version 0.0.11 PyPI version JSON
download
home_pagehttps://github.com/best-doctor/flake8-expression-complexity
SummaryA flake8 extension that checks expressions complexity
upload_time2022-03-19 07:13:04
maintainer
docs_urlNone
authorIlya Lebedev
requires_python>=3.7
licenseMIT
keywords flake8
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # flake8-expression-complexity

[![Build Status](https://github.com/best-doctor/flake8-expression-complexity/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/best-doctor/flake8-expression-complexity/actions/workflows/build.yml)
[![Maintainability](https://api.codeclimate.com/v1/badges/f85c1fd2ad4af63d93b6/maintainability)](https://codeclimate.com/github/best-doctor/flake8-expression-complexity/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/f85c1fd2ad4af63d93b6/test_coverage)](https://codeclimate.com/github/best-doctor/flake8-expression-complexity/test_coverage)
[![PyPI version](https://badge.fury.io/py/flake8-expression-complexity.svg?)](https://badge.fury.io/py/flake8-expression-complexity)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/flake8-expression-complexity)

An extension for flake8 that validates expression complexity.

Splits code into expression and scores each according to how much one is complicated.
Fires an error on each expression more complex than theshold.

Default complexity is 7, can be configured via `--max-expression-complexity` option.

Since Django ORM queries can produce long and readable expressions,
checker can skip them. To enable this behaviour,
use `--ignore-django-orm-queries-complexity` option.

## Installation

```terminal
pip install flake8-expression-complexity
```

## Example

```python
if (
    (user and user.is_authorized)
    and user.subscriptions.filter(start_date__lt=today, end_date__gt=today).exists()
    and (
        user.total_credits_added
        - Check.objects.filter(user=user).aggregate(Sum('price'))['check__sum']
    )
    and UserAction.objects.filter(user=user).last().datetime > today - datetime.timedelta(days=10)
):
    ...
```

Usage:

```terminal
$ flake8 --max-expression-complexity=3 test.py
text.py:2:5: ECE001 Expression is too complex (7.0 > 3)
```

## Error codes

| Error code |                     Description   |
|:----------:|:---------------------------------:|
|   ECE001   | Expression is too complex (X > Y) |

## Contributing

We would love you to contribute to our project. It's simple:

1. Create an issue with bug you found or proposal you have.
   Wait for approve from maintainer.
1. Create a pull request. Make sure all checks are green.
1. Fix review comments if any.
1. Be awesome.

Here are useful tips:

- You can run all checks and tests with `make check`.
  Please do it before TravisCI does.
- We use [BestDoctor python styleguide](https://github.com/best-doctor/guides/blob/master/guides/en/python_styleguide.md).
- We respect [Django CoC](https://www.djangoproject.com/conduct/).
  Make soft, not bullshit.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/best-doctor/flake8-expression-complexity",
    "name": "flake8-expression-complexity",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "flake8",
    "author": "Ilya Lebedev",
    "author_email": "melevir@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/19/71/5bfb69acbfd319add958c70b60e68aee8914d4a5e243b87f4fcda249cf7b/flake8_expression_complexity-0.0.11.tar.gz",
    "platform": null,
    "description": "# flake8-expression-complexity\n\n[![Build Status](https://github.com/best-doctor/flake8-expression-complexity/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/best-doctor/flake8-expression-complexity/actions/workflows/build.yml)\n[![Maintainability](https://api.codeclimate.com/v1/badges/f85c1fd2ad4af63d93b6/maintainability)](https://codeclimate.com/github/best-doctor/flake8-expression-complexity/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/f85c1fd2ad4af63d93b6/test_coverage)](https://codeclimate.com/github/best-doctor/flake8-expression-complexity/test_coverage)\n[![PyPI version](https://badge.fury.io/py/flake8-expression-complexity.svg?)](https://badge.fury.io/py/flake8-expression-complexity)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/flake8-expression-complexity)\n\nAn extension for flake8 that validates expression complexity.\n\nSplits code into expression and scores each according to how much one is complicated.\nFires an error on each expression more complex than theshold.\n\nDefault complexity is 7, can be configured via `--max-expression-complexity` option.\n\nSince Django ORM queries can produce long and readable expressions,\nchecker can skip them. To enable this behaviour,\nuse `--ignore-django-orm-queries-complexity` option.\n\n## Installation\n\n```terminal\npip install flake8-expression-complexity\n```\n\n## Example\n\n```python\nif (\n    (user and user.is_authorized)\n    and user.subscriptions.filter(start_date__lt=today, end_date__gt=today).exists()\n    and (\n        user.total_credits_added\n        - Check.objects.filter(user=user).aggregate(Sum('price'))['check__sum']\n    )\n    and UserAction.objects.filter(user=user).last().datetime > today - datetime.timedelta(days=10)\n):\n    ...\n```\n\nUsage:\n\n```terminal\n$ flake8 --max-expression-complexity=3 test.py\ntext.py:2:5: ECE001 Expression is too complex (7.0 > 3)\n```\n\n## Error codes\n\n| Error code |                     Description   |\n|:----------:|:---------------------------------:|\n|   ECE001   | Expression is too complex (X > Y) |\n\n## Contributing\n\nWe would love you to contribute to our project. It's simple:\n\n1. Create an issue with bug you found or proposal you have.\n   Wait for approve from maintainer.\n1. Create a pull request. Make sure all checks are green.\n1. Fix review comments if any.\n1. Be awesome.\n\nHere are useful tips:\n\n- You can run all checks and tests with `make check`.\n  Please do it before TravisCI does.\n- We use [BestDoctor python styleguide](https://github.com/best-doctor/guides/blob/master/guides/en/python_styleguide.md).\n- We respect [Django CoC](https://www.djangoproject.com/conduct/).\n  Make soft, not bullshit.\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A flake8 extension that checks expressions complexity",
    "version": "0.0.11",
    "split_keywords": [
        "flake8"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "b806a6ba0bb47ad3c44bcf7e96a90eb7",
                "sha256": "b56bac37f7dd5d3d102a7111c89f6579c2cbd897b868147794c9ed12aadc627c"
            },
            "downloads": -1,
            "filename": "flake8_expression_complexity-0.0.11-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b806a6ba0bb47ad3c44bcf7e96a90eb7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 8235,
            "upload_time": "2022-03-19T07:13:03",
            "upload_time_iso_8601": "2022-03-19T07:13:03.128527Z",
            "url": "https://files.pythonhosted.org/packages/bc/20/6707c990610d45a3a961345ad5fdabf096cac5a1ce8571581f5787453574/flake8_expression_complexity-0.0.11-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "f621be803c47473db0f1cfc0bd6599fe",
                "sha256": "4dd8909fecbc20f53814cdcef9d0b04f61532764278d9b6e8026686812e96631"
            },
            "downloads": -1,
            "filename": "flake8_expression_complexity-0.0.11.tar.gz",
            "has_sig": false,
            "md5_digest": "f621be803c47473db0f1cfc0bd6599fe",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 7097,
            "upload_time": "2022-03-19T07:13:04",
            "upload_time_iso_8601": "2022-03-19T07:13:04.985206Z",
            "url": "https://files.pythonhosted.org/packages/19/71/5bfb69acbfd319add958c70b60e68aee8914d4a5e243b87f4fcda249cf7b/flake8_expression_complexity-0.0.11.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-03-19 07:13:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "best-doctor",
    "github_project": "flake8-expression-complexity",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "flake8-expression-complexity"
}
        
Elapsed time: 0.01657s