Skip to content

Commit 5185145

Browse files
committed
chore: switch to ruff for lint and format
This switches Bleach to ruff for linting and formatting. This simplifies the problem we had with flake8 and gets us off of black which currently has a security issue.
1 parent 3037720 commit 5185145

8 files changed

Lines changed: 14 additions & 40 deletions

File tree

MANIFEST.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ include LICENSE
66
include Makefile
77
include README.rst
88
include requirements-dev.txt
9-
include requirements-flake8.txt
109
include SECURITY.md
1110
include tox.ini
1211

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ test: ## Run tests
1414
docs: ## Build docs
1515
tox -e py310-docs
1616

17+
.PHONY: format
18+
format: ## Format Python files
19+
tox exec -e py310-lint -- ruff format --target-version=py310 --exclude=_vendor setup.py bleach/ tests/ tests_website/
20+
1721
.PHONY: lint
1822
lint: ## Lint files
19-
tox exec -e py310-format-check -- black --target-version=py310 --exclude=_vendor setup.py bleach/ tests/ tests_website/
2023
tox -e py310-lint
21-
tox -e py310-format-check
2224

2325
.PHONY: vendorverify
2426
vendorverify: ## Verify vendored files

bleach/linkifier.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ def build_url_re(tlds=TLDS, protocols=html5lib_shim.allowed_protocols):
4848
(?:[/?][^\s\{{\}}\|\\\^`<>"]*)?
4949
# /path/zz (excluding "unsafe" chars from RFC 3986,
5050
# except for # and ~, which happen in practice)
51-
""".format(
52-
"|".join(sorted(protocols)), "|".join(sorted(tlds))
53-
),
51+
""".format("|".join(sorted(protocols)), "|".join(sorted(tlds))),
5452
re.IGNORECASE | re.VERBOSE | re.UNICODE,
5553
)
5654

@@ -81,9 +79,7 @@ def build_email_re(tlds=TLDS):
8179
|^"([\001-\010\013\014\016-\037!#-\[\]-\177]
8280
|\\[\001-\011\013\014\016-\177])*" # quoted-string
8381
)@(?:[A-Z0-9](?:[A-Z0-9-]{{0,61}}[A-Z0-9])?\.)+(?:{0})) # domain
84-
""".format(
85-
"|".join(tlds)
86-
),
82+
""".format("|".join(tlds)),
8783
re.IGNORECASE | re.MULTILINE | re.VERBOSE,
8884
)
8985

requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
-e .
22

3-
black==24.4.2; implementation_name == 'cpython'
43
build==1.2.1
54
mypy==1.10.1; implementation_name =='cpython'
65
pytest==8.2.2
6+
ruff==0.15.6; implementation_name == 'cpython'
77
setuptools==80.7.1
88
tox==4.16.0
99
tox-gh-actions==3.2.0

requirements-flake8.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

setup.cfg

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
[flake8]
2-
exclude =
3-
.git/,
4-
.tox/,
5-
bleach/_vendor/*
6-
ignore =
7-
# E203: whitespace before ":"; doesn't work with black
8-
E203,
9-
# E501: line too long
10-
E501,
11-
# E731: do not assign a lambda expression, use a def
12-
E731,
13-
# W503: line break before opertor; this doesn't work with black
14-
W503
15-
max-line-length = 88
16-
171
[tool:pytest]
182
filterwarnings =
193
error

tests/test_clean.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,11 +416,14 @@ def test_poster_attribute():
416416

417417
def test_attributes_callable():
418418
"""Verify attributes can take a callable"""
419-
ATTRS = lambda tag, name, val: name == "title"
419+
420+
def attrs_fun(tag, name, val):
421+
return name == "title"
422+
420423
TAGS = {"a"}
421424

422425
text = '<a href="/foo" title="blah">example</a>'
423-
assert clean(text, tags=TAGS, attributes=ATTRS) == '<a title="blah">example</a>'
426+
assert clean(text, tags=TAGS, attributes=attrs_fun) == '<a title="blah">example</a>'
424427

425428

426429
def test_attributes_wildcard():

tox.ini

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ envlist =
66
py{310,311,312,313,314,py3}-tinycss2
77
py{310,311,312,313,314}-build-no-lang
88
py310-docs
9-
py310-format-check
109
py310-lint
1110
py310-vendorverify
1211

@@ -93,10 +92,10 @@ commands =
9392

9493
[testenv:py310-lint]
9594
changedir = {toxinidir}
96-
deps = -rrequirements-flake8.txt
9795
platform = linux
9896
commands =
99-
flake8 setup.py tests/ bleach/ tests_website/
97+
ruff format --check --target-version=py310 --exclude=_vendor setup.py bleach/ tests/ tests_website/
98+
ruff check --target-version=py310 --exclude=_vendor setup.py bleach/ tests/ tests_website/
10099

101100
[testenv:py310-vendorverify]
102101
allowlist_externals = {toxinidir}/scripts/vendor_verify.sh
@@ -106,13 +105,6 @@ platform = linux
106105
commands =
107106
{toxinidir}/scripts/vendor_verify.sh
108107

109-
[testenv:py310-format-check]
110-
changedir = {toxinidir}
111-
deps = -rrequirements-dev.txt
112-
platform = linux
113-
commands =
114-
black --target-version=py310 --check --diff --exclude=_vendor setup.py bleach/ tests/ tests_website/
115-
116108
[testenv:py310-docs]
117109
changedir = docs
118110
deps = -rrequirements-dev.txt

0 commit comments

Comments
 (0)