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許可獲得許可。有關詳細信息,請參見許可證文件。