# flake8-staged-diff
Run flake8 but report the findings only on staged files (identified with `git diff --staged`)
This tool is primarily meant to be integrated through [pre-commit](https://pre-commit.com/) but it also offers a CLI.
## How it works?
This tool runs first `git diff -U0 --staged --` and identify the files and lines that were modified,
it then runs flake8 on the entire files and simply filters out all the findings that are not coming
from the modified code.
If no files is staged in git, it will return immediately
## Pre-commit integration
An example `.pre-commit-config.yaml`:
```yaml
repos:
- repo: https://github.com/bagerard/flake8-staged-diff
rev: '' # Use the sha / tag you want to point at
hooks:
- id: flake8-staged-diff
```
> **_NOTE:_** This will only affect local usage of pre-commit, typically through `git commit`.
> When it runs for instance in a Github pipeline through `pre-commit run -a`, there will be **no staged files**
> and the tool will simply pass.
## CLI Usage
Interface is the same as flake8, e.g.
flake8-staged-diff file1.py file2.py --select=E501
## Rationale
This tool allows to introduce some flake8 rules in large/legacy codebases only on the code that is updated or inserted.
We use this at work for enforcing type annotations on modified code using the following config
```yaml
- repo: https://github.com/bagerard/flake8-staged-diff
rev: '' # Use the sha / tag you want to point at
hooks:
- id: flake8-staged-diff
args:
- "--select=AN"
additional_dependencies:
- flake8-annotations
```
## Consideration
Use this consciously, not every flake8's rule is a good candidate for this tool, in fact sometimes a modified line can introduce errors in other part of the file but since those part of the file aren't in the diff, they wouldn't appear through this tool. Make sure to review pre-commit / Flake8's maintainer comment made [here](https://github.com/pre-commit/pre-commit/issues/1279#issuecomment-573444321).
Raw data
{
"_id": null,
"home_page": "https://github.com/bagerard/flake8-staged-diff",
"name": "flake8-staged-diff",
"maintainer": "Bastien Gerard",
"docs_url": null,
"requires_python": "",
"maintainer_email": "bast.gerard@gmail.com",
"keywords": "flake8 diff linter pre-commit",
"author": "",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/4d/5f/d99b1a74d4d8ef8bb1e5a7662eb00173b8436c1b6236e987fd2a84741c28/flake8-staged-diff-0.3.0.tar.gz",
"platform": null,
"description": "# flake8-staged-diff\n\nRun flake8 but report the findings only on staged files (identified with `git diff --staged`)\nThis tool is primarily meant to be integrated through [pre-commit](https://pre-commit.com/) but it also offers a CLI.\n\n## How it works?\n\nThis tool runs first `git diff -U0 --staged --` and identify the files and lines that were modified,\nit then runs flake8 on the entire files and simply filters out all the findings that are not coming\nfrom the modified code.\n\nIf no files is staged in git, it will return immediately\n\n## Pre-commit integration\n\nAn example `.pre-commit-config.yaml`:\n\n```yaml\nrepos:\n - repo: https://github.com/bagerard/flake8-staged-diff\n rev: '' # Use the sha / tag you want to point at\n hooks:\n - id: flake8-staged-diff\n```\n\n> **_NOTE:_** This will only affect local usage of pre-commit, typically through `git commit`.\n> When it runs for instance in a Github pipeline through `pre-commit run -a`, there will be **no staged files**\n> and the tool will simply pass.\n\n## CLI Usage\n\nInterface is the same as flake8, e.g.\n\n flake8-staged-diff file1.py file2.py --select=E501\n\n## Rationale\n\nThis tool allows to introduce some flake8 rules in large/legacy codebases only on the code that is updated or inserted. \n\nWe use this at work for enforcing type annotations on modified code using the following config\n\n```yaml\n - repo: https://github.com/bagerard/flake8-staged-diff\n rev: '' # Use the sha / tag you want to point at\n hooks:\n - id: flake8-staged-diff\n args:\n - \"--select=AN\"\n additional_dependencies:\n - flake8-annotations\n```\n\n## Consideration\n\nUse this consciously, not every flake8's rule is a good candidate for this tool, in fact sometimes a modified line can introduce errors in other part of the file but since those part of the file aren't in the diff, they wouldn't appear through this tool. Make sure to review pre-commit / Flake8's maintainer comment made [here](https://github.com/pre-commit/pre-commit/issues/1279#issuecomment-573444321).\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "flake8 wrapper to run only on modified/staged code",
"version": "0.3.0",
"project_urls": {
"Homepage": "https://github.com/bagerard/flake8-staged-diff"
},
"split_keywords": [
"flake8",
"diff",
"linter",
"pre-commit"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "cb6865c1e9210e51cdb4a87766b8eda943a08e4771a65149ea17447e4f38ea1e",
"md5": "40293f224bf730d3ead5f00edefdf231",
"sha256": "90f58e400f74ddfcd73a1f4f037ffae0e7516d922b03334eac8ac90e2077bbc4"
},
"downloads": -1,
"filename": "flake8_staged_diff-0.3.0-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "40293f224bf730d3ead5f00edefdf231",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 4730,
"upload_time": "2023-07-29T22:05:02",
"upload_time_iso_8601": "2023-07-29T22:05:02.375923Z",
"url": "https://files.pythonhosted.org/packages/cb/68/65c1e9210e51cdb4a87766b8eda943a08e4771a65149ea17447e4f38ea1e/flake8_staged_diff-0.3.0-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4d5fd99b1a74d4d8ef8bb1e5a7662eb00173b8436c1b6236e987fd2a84741c28",
"md5": "70c82e869f8e171c883363b832413771",
"sha256": "035dc628315d06bb61438149f600f7b380afae46ddc85fa3b6db6e3896a35d71"
},
"downloads": -1,
"filename": "flake8-staged-diff-0.3.0.tar.gz",
"has_sig": false,
"md5_digest": "70c82e869f8e171c883363b832413771",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4216,
"upload_time": "2023-07-29T22:05:04",
"upload_time_iso_8601": "2023-07-29T22:05:04.103193Z",
"url": "https://files.pythonhosted.org/packages/4d/5f/d99b1a74d4d8ef8bb1e5a7662eb00173b8436c1b6236e987fd2a84741c28/flake8-staged-diff-0.3.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-29 22:05:04",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "bagerard",
"github_project": "flake8-staged-diff",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "flake8-staged-diff"
}