ondivi
Version 0.6.0

这是一个简单的Python脚本,旨在仅针对GIT存储库中更改的线进行过滤编码违规(可能由静态分析器识别)。
该工具可与任何Linter或静态代码分析仪一起使用,包括但不限于:
pip install ondivi确保您位于GIT存储库的根目录中。
运行脚本:
flake8 script.py | ondivi
# with ruff:
ruff check file.py --output-format=concise | ondivi或者:
flake8 script.py > violations.txt
ondivi --fromfile=violations.txt $ 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")
--fromfile TEXT Path to file with violations. Expected "utf-8" encoding
--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.
脚本解析git diff输出以识别每个文件中更改的行。
然后,它过滤给定的编码违规行为,仅包括与更改线相对应的违规行为。
Flakeheaven和Flakehell不受支持,因为它们依赖于内部Flake8 API,这可能会导致随着Flake8的发展而导致兼容性问题。相比之下,Ondivi仅使用违规的文本输出和GIT存储库状态,使其更稳定和更易于维护。
flake8文件:
$ flake8 file.py
file.py:3:1: E302 expected 2 blank lines, found 1
file.py:9:1: E302 expected 2 blank lines, found 1
file.py:10:121: E501 line too long (123 > 120 characters)
file.py:14:1: E305 expected 2 blank lines after class or function definition, found 1更改的示例:
from dataclasses import dataclass
@dataclass
class User(object):
name: str
age: int
def greet(user: User):
print('Long string in initial commit ################################################################################')
print(f'Hello, {user.name}!')
+ print('Long string in new commit ################################################################################')
if __name__ == '__main__':
greet(User(345, 23))
+ greet(User('Bob', '23'))通过git diff,我们看到了两条新行(12和16):
Ondivi滤除了违规行为,仅显示第12行的一项:
$ flake8 script.py | ondivi
file.py:12:80: E501 line too long (119 > 79 characters)该项目已根据MIT许可获得许可。有关详细信息,请参见许可证文件。