Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
blablatdinov committed Jun 22, 2024
1 parent 71961b5 commit 17af567
Showing 1 changed file with 52 additions and 43 deletions.
95 changes: 52 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@

This is a simple Python script designed to filter coding violations (likely identified by a static analyzer) for only the lines that have been changed in a Git repository.

This tool works with any linter or static code analyzer, including but not limited to:

- Flake8
- pylint
- mypy
- eslint
- rubocop
- stylelint

## Prerequisites:

- Python 3.9 or higher
Expand All @@ -29,7 +38,47 @@ Run the script:
flake8 script.py | ondivi
```

## Description
```
$ ondivi --help
Usage: ondivi [OPTIONS]
Ondivi (Only diff violations).
Python script filtering coding violations, identified by static analysis,
only for changed lines in a Git repo. Usage example:
flake8 script.py | ondivi
Options:
--baseline TEXT Commit or branch which will contain legacy code. Program
filter out violations on baseline (default: "master")
--format TEXT Template for parsing linter messages. The template should include the following named parts:
{filename} The name of the file with the error/warning
{line_num} The line number with the error/warning (integer)
Example usage:
--format "{filename}:{line_num:d}{other}"
In this example, the linter message
"src/app_types/listable.py:23:1: UP035 Import from collections.abc instead: Sequence"
will be recognized and parsed into the following components:
- filename: "src/app_types/listable.py"
- line_num: 23
- other: :1: UP035 Import from collections.abc instead: Sequence"
Ensure that the template matches the format of the messages generated by your linter.
(default: "{filename}:{line_num:d}{other}")
--only-violations Show only violations
--help Show this message and exit.
```

## How it works

The script parses the Git diff output to identify the changed lines in each file.

It then filters the given coding violations to include only those violations that correspond to the changed lines.

[flakeheaven](https://github.com/flakeheaven/flakeheaven) and [flakehell](https://github.com/flakehell/flakehell)
are not supported because they rely on internal flake8 API, which can lead to compatibility issues as flake8
evolves. In contrast, ondivi uses only the text output of violations and the state of Git repository, making
it more robust and easier to maintain.

Flake8 on file:

Expand Down Expand Up @@ -62,55 +111,15 @@ Example of changes:
+ greet(User('Bob', '23'))
```

By git diff we see, that append 2 new lines (12 and 16)
By git diff we see, that two new lines were appended (12 and 16):

Ondivi filter out violations and show only one for 12's line
Ondivi filters out violations and shows only one for line 12:

```bash
$ flake8 script.py | ondivi
file.py:12:80: E501 line too long (119 > 79 characters)
```

```bash
ondivi --help
```

```
Usage: ondivi [OPTIONS]
Ondivi (Only diff violations).
Python script filtering coding violations, identified by static analysis,
only for changed lines in a Git repo. Usage example:
flake8 script.py | ondivi
Options:
--baseline TEXT Commit or branch which will contain legacy code. Program
filter out violations on baseline (default: "master")
--format TEXT Template for parsing linter messages. The template should include the following named parts:
{filename} The name of the file with the error/warning
{line_num} The line number with the error/warning (integer)
Example usage:
--format "{filename}:{line_num:d}{other}"
In this example, the linter message
"src/app_types/listable.py:23:1: UP035 Import from collections.abc instead: Sequence"
will be recognized and parsed into the following components:
- filename: "src/app_types/listable.py"
- line_num: 23
- other: :1: UP035 Import from collections.abc instead: Sequence"
Ensure that the template matches the format of the messages generated by your linter.
(default: "{filename}:{line_num:d}{other}")
--only-violations Show only violations
--help Show this message and exit.
```

## How it Works

The script parses the Git diff output to identify the changed lines in each file.

It then filters the given coding violations to include only those violations that correspond to the changed lines.

## License

This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.

0 comments on commit 17af567

Please sign in to comment.