Skip to content

Commit ab60539

Browse files
Lint code with ruff
1 parent 2d5ff34 commit ab60539

21 files changed

+106
-37
lines changed

.github/workflows/lint.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Lint
2+
3+
on: [push, pull_request, workflow_dispatch]
4+
5+
permissions: {}
6+
7+
env:
8+
FORCE_COLOR: 1
9+
RUFF_OUTPUT_FORMAT: github
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
lint:
17+
runs-on: ubuntu-latest
18+
timeout-minutes: 10
19+
20+
steps:
21+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
22+
with:
23+
persist-credentials: false
24+
- uses: j178/prek-action@0bb87d7f00b0c99306c8bcb8b8beba1eb581c037 # v1.1.1

.pre-commit-config.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: a27a2e47c7751b639d2b5badf0ef6ff11fee893f # frozen: v0.15.4
4+
hooks:
5+
- id: ruff
6+
exclude: ^corp-
7+
- id: ruff-format
8+
exclude: ^corp-
9+
10+
11+
- repo: https://github.com/pre-commit/pre-commit-hooks
12+
rev: 3e8a8703264a2f4a69428a0aa4dcb512790b2c8c # frozen: v6.0.0
13+
hooks:
14+
- id: check-case-conflict
15+
- id: check-merge-conflict
16+
- id: end-of-file-fixer
17+
exclude: ^corp-
18+
- id: end-of-file-fixer
19+
exclude: ^corp-
20+
- id: trailing-whitespace
21+
exclude: ^corp-

.ruff.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[lint]
2+
ignore = [
3+
"E722", # bare except
4+
"F841", # unused variable
5+
]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Components that are hosted in this repository:
2828

2929
Components that are hosted elsewhere:
3030

31-
* [Project configuration](https://github.com/google/oss-fuzz/tree/master/projects/python3-libraries):
31+
* [Project configuration](https://github.com/google/oss-fuzz/tree/master/projects/python3-libraries):
3232
This component controls the OSS-Fuzz project definition, maintainers.
3333
* [Fuzzer image configuration](https://github.com/google/oss-fuzz/tree/master/projects/python3-libraries):
3434
`Dockerfile` and `build.sh` describe how the fuzzer

ast.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import ast
22
import warnings
33

4-
warnings.filterwarnings('ignore')
4+
warnings.filterwarnings("ignore")
5+
56

67
def FuzzerRunOne(FuzzerInput):
78
# Python documentation states:
8-
#
9+
#
910
# 'It is possible to crash the Python interpreter with a sufficiently
1011
# large/complex string due to stack depth limitations in Python’s AST
1112
# compiler.'

configparser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import configparser
22

3+
34
def FuzzerRunOne(FuzzerInput):
45
parser = configparser.ConfigParser(allow_no_value=True, strict=False)
56
try:
67
parser.read_string(FuzzerInput.decode("utf-8", "replace"))
78
list(parser.items())
89
except configparser.Error:
910
return
10-

csv.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import csv
22

3+
34
def FuzzerRunOne(FuzzerInput):
45
lines = FuzzerInput.decode("utf-8", "replace").splitlines()
56
try:
6-
reader = csv.reader(lines, delimiter=',')
7+
reader = csv.reader(lines, delimiter=",")
78
for row in reader:
89
pass
910
except csv.Error:

decode.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
def FuzzerRunOne(FuzzerInput):
2-
l = int(len(FuzzerInput)/2)
3-
A = FuzzerInput[:l]
4-
B = FuzzerInput[l:].decode("utf-8", "replace").strip()
2+
half = int(len(FuzzerInput) / 2)
3+
A = FuzzerInput[:half]
4+
B = FuzzerInput[half:].decode("utf-8", "replace").strip()
55
try:
66
A.decode(B)
77
except SystemError:

difflib.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import difflib
22

3+
34
def FuzzerRunOne(FuzzerInput):
45
# SequenceMatcher is quadratic time worst case (see Lib/difflib.py).
56
# Cap input size to avoid timeouts on large inputs.
67
if not (0 < len(FuzzerInput) < 4096):
78
return
8-
l = int(len(FuzzerInput)/2)
9-
A = FuzzerInput[:l].decode("utf-8", "replace").splitlines()
10-
B = FuzzerInput[l:].decode("utf-8", "replace").splitlines()
9+
half = int(len(FuzzerInput) / 2)
10+
A = FuzzerInput[:half].decode("utf-8", "replace").splitlines()
11+
B = FuzzerInput[half:].decode("utf-8", "replace").splitlines()
1112
for x in difflib.unified_diff(A, B):
1213
pass
1314
for x in difflib.context_diff(A, B):
1415
pass
1516
difflib.HtmlDiff().make_file(A, B)
16-
17-

email.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
from email.parser import BytesParser, Parser
2-
from email.policy import default, HTTP
1+
from email.parser import Parser
2+
from email.policy import HTTP
3+
34

45
def FuzzerRunOne(FuzzerInput):
56
try:
67
Parser(policy=HTTP).parsestr(FuzzerInput.decode("utf-8", "replace"))
7-
# #Parser(policy=default).parsestr(FuzzerInput.decode("utf-8", "replace"))
88
except SystemError:
99
raise
1010
except:
1111
pass
12-

0 commit comments

Comments
 (0)