Skip to content

Commit 7762458

Browse files
authored
🔧 Use ruff-format (#107)
1 parent 950908b commit 7762458

File tree

14 files changed

+128
-123
lines changed

14 files changed

+128
-123
lines changed

‎.github/workflows/tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ jobs:
4848
- name: Upload to Codecov
4949
uses: codecov/codecov-action@v3
5050
with:
51+
token: ${{ secrets.CODECOV_TOKEN }}
5152
name: mdit-py-plugins-pytests
5253
flags: pytests
5354
file: ./coverage.xml

‎.pre-commit-config.yaml

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,22 @@ exclude: >
1212
repos:
1313

1414
- repo: https://github.com/pre-commit/pre-commit-hooks
15-
rev: v4.5.0
15+
rev: v4.6.0
1616
hooks:
1717
- id: check-json
1818
- id: check-yaml
1919
- id: end-of-file-fixer
2020
- id: trailing-whitespace
2121

22-
- repo: https://github.com/PyCQA/isort
23-
rev: 5.13.2
24-
hooks:
25-
- id: isort
26-
27-
- repo: https://github.com/psf/black
28-
rev: 23.12.1
29-
hooks:
30-
- id: black
31-
3222
- repo: https://github.com/astral-sh/ruff-pre-commit
33-
rev: v0.1.13
23+
rev: v0.4.4
3424
hooks:
35-
- id: ruff
25+
- id: ruff
26+
args: [--fix]
27+
- id: ruff-format
3628

3729
- repo: https://github.com/pre-commit/mirrors-mypy
38-
rev: v1.8.0
30+
rev: v1.10.0
3931
hooks:
4032
- id: mypy
4133
additional_dependencies: [markdown-it-py~=3.0]

‎mdit_py_plugins/admon/index.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from contextlib import suppress
66
import re
7-
from typing import TYPE_CHECKING, Callable, List, Sequence, Tuple
7+
from typing import TYPE_CHECKING, Callable, Sequence
88

99
from markdown_it import MarkdownIt
1010
from markdown_it.rules_block import StateBlock
@@ -17,7 +17,7 @@
1717
from markdown_it.utils import EnvType, OptionsDict
1818

1919

20-
def _get_multiple_tags(params: str) -> Tuple[List[str], str]:
20+
def _get_multiple_tags(params: str) -> tuple[list[str], str]:
2121
"""Check for multiple tags when the title is double quoted."""
2222
re_tags = re.compile(r'^\s*(?P<tokens>[^"]+)\s+"(?P<title>.*)"\S*$')
2323
match = re_tags.match(params)
@@ -27,7 +27,7 @@ def _get_multiple_tags(params: str) -> Tuple[List[str], str]:
2727
raise ValueError("No match found for parameters")
2828

2929

30-
def _get_tag(_params: str) -> Tuple[List[str], str]:
30+
def _get_tag(_params: str) -> tuple[list[str], str]:
3131
"""Separate the tag name from the admonition title."""
3232
params = _params.strip()
3333
if not params:
@@ -212,7 +212,7 @@ def renderDefault(
212212
_options: OptionsDict,
213213
env: EnvType,
214214
) -> str:
215-
return self.renderToken(tokens, idx, _options, env) # type: ignore
215+
return self.renderToken(tokens, idx, _options, env) # type: ignore[attr-defined,no-any-return]
216216

217217
render = render or renderDefault
218218

‎mdit_py_plugins/amsmath/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"""An extension to capture amsmath latex environments."""
2+
23
from __future__ import annotations
34

45
import re
5-
from typing import TYPE_CHECKING, Callable, Optional, Sequence
6+
from typing import TYPE_CHECKING, Callable, Sequence
67

78
from markdown_it import MarkdownIt
89
from markdown_it.common.utils import escapeHtml
@@ -57,7 +58,7 @@
5758

5859

5960
def amsmath_plugin(
60-
md: MarkdownIt, *, renderer: Optional[Callable[[str], str]] = None
61+
md: MarkdownIt, *, renderer: Callable[[str], str] | None = None
6162
) -> None:
6263
"""Parses TeX math equations, without any surrounding delimiters,
6364
only for top-level `amsmath <https://ctan.org/pkg/amsmath>`__ environments:

‎mdit_py_plugins/attrs/index.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def _span_rule(state: StateInline, silent: bool) -> bool:
140140
state.pos = labelStart
141141
state.posMax = labelEnd
142142
token = state.push("span_open", "span", 1)
143-
token.attrs = attrs # type: ignore
143+
token.attrs = attrs # type: ignore[assignment]
144144
state.md.inline.tokenize(state)
145145
token = state.push("span_close", "span", -1)
146146

@@ -190,7 +190,7 @@ def _attr_block_rule(
190190
return True
191191

192192
token = state.push("attrs_block", "", 0)
193-
token.attrs = attrs # type: ignore
193+
token.attrs = attrs # type: ignore[assignment]
194194
token.map = [startLine, startLine + 1]
195195

196196
state.line = startLine + 1
@@ -211,9 +211,9 @@ def _attr_resolve_block_rule(state: StateCore) -> None:
211211

212212
# classes are appended
213213
if "class" in state.tokens[i].attrs and "class" in next_token.attrs:
214-
state.tokens[i].attrs[
215-
"class"
216-
] = f"{state.tokens[i].attrs['class']} {next_token.attrs['class']}"
214+
state.tokens[i].attrs["class"] = (
215+
f"{state.tokens[i].attrs['class']} {next_token.attrs['class']}"
216+
)
217217

218218
if next_token.type == "attrs_block":
219219
# subsequent attribute blocks take precedence, when merging

‎mdit_py_plugins/attrs/parse.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class <- '.' name
1919
bareval <- (ASCII_ALPHANUM | ':' | '_' | '-')+
2020
quotedval <- '"' ([^"] | '\"') '"'
2121
"""
22+
2223
from __future__ import annotations
2324

2425
from enum import Enum

‎mdit_py_plugins/container/index.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Process block-level custom containers."""
2+
23
from __future__ import annotations
34

45
from math import floor
@@ -56,7 +57,7 @@ def renderDefault(
5657
if tokens[idx].nesting == 1:
5758
tokens[idx].attrJoin("class", name)
5859

59-
return self.renderToken(tokens, idx, _options, env) # type: ignore
60+
return self.renderToken(tokens, idx, _options, env) # type: ignore[attr-defined,no-any-return]
6061

6162
min_markers = 3
6263
marker_str = marker

‎mdit_py_plugins/deflist/index.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Process definition lists."""
2+
23
from markdown_it import MarkdownIt
34
from markdown_it.rules_block import StateBlock
45

‎mdit_py_plugins/dollarmath/index.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import re
4-
from typing import TYPE_CHECKING, Any, Callable, Dict, Optional, Sequence
4+
from typing import TYPE_CHECKING, Any, Callable, Sequence
55

66
from markdown_it import MarkdownIt
77
from markdown_it.common.utils import escapeHtml, isWhiteSpace
@@ -24,9 +24,9 @@ def dollarmath_plugin(
2424
allow_digits: bool = True,
2525
allow_blank_lines: bool = True,
2626
double_inline: bool = False,
27-
label_normalizer: Optional[Callable[[str], str]] = None,
28-
renderer: Optional[Callable[[str, Dict[str, Any]], str]] = None,
29-
label_renderer: Optional[Callable[[str], str]] = None,
27+
label_normalizer: Callable[[str], str] | None = None,
28+
renderer: Callable[[str, dict[str, Any]], str] | None = None,
29+
label_renderer: Callable[[str], str] | None = None,
3030
) -> None:
3131
"""Plugin for parsing dollar enclosed math,
3232
e.g. inline: ``$a=1$``, block: ``$$b=2$$``
@@ -53,7 +53,7 @@ def dollarmath_plugin(
5353
5454
"""
5555
if label_normalizer is None:
56-
label_normalizer = lambda label: re.sub(r"\s+", "-", label)
56+
label_normalizer = lambda label: re.sub(r"\s+", "-", label) # noqa: E731
5757

5858
md.inline.ruler.before(
5959
"escape",
@@ -76,7 +76,7 @@ def dollarmath_plugin(
7676

7777
_label_renderer: Callable[[str], str]
7878
if label_renderer is None:
79-
_label_renderer = (
79+
_label_renderer = ( # noqa: E731
8080
lambda label: f'<a href="#{label}" class="mathlabel" title="Permalink to this equation">¶</a>'
8181
)
8282
else:
@@ -286,7 +286,7 @@ def _math_inline_dollar(state: StateInline, silent: bool) -> bool:
286286

287287
def math_block_dollar(
288288
allow_labels: bool = True,
289-
label_normalizer: Optional[Callable[[str], str]] = None,
289+
label_normalizer: Callable[[str], str] | None = None,
290290
allow_blank_lines: bool = False,
291291
) -> Callable[[StateBlock, int, int, bool], bool]:
292292
"""Generate block dollar rule."""

‎mdit_py_plugins/field_list/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Field list plugin"""
2+
23
from contextlib import contextmanager
34
from typing import Iterator, Optional, Tuple
45

@@ -176,7 +177,7 @@ def _fieldlist_rule(
176177

177178
has_first_line = contentStart < maximum
178179
if block_indent is None: # no body content
179-
if not has_first_line: # noqa SIM108
180+
if not has_first_line: # noqa: SIM108
180181
# no body or first line, so just use default
181182
block_indent = 2
182183
else:

‎mdit_py_plugins/footnote/index.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""Process footnotes"""
2+
23
from __future__ import annotations
34

4-
from typing import TYPE_CHECKING, List, Optional, Sequence
5+
from typing import TYPE_CHECKING, Sequence
56

67
from markdown_it import MarkdownIt
78
from markdown_it.helpers import parseLinkLabel
@@ -184,7 +185,7 @@ def footnote_inline(state: StateInline, silent: bool) -> bool:
184185
refs = state.env.setdefault("footnotes", {}).setdefault("list", {})
185186
footnoteId = len(refs)
186187

187-
tokens: List[Token] = []
188+
tokens: list[Token] = []
188189
state.md.inline.parse(
189190
state.src[labelStart:labelEnd], state.md, state.env, tokens
190191
)
@@ -270,7 +271,7 @@ def footnote_tail(state: StateCore) -> None:
270271
if "footnotes" not in state.env:
271272
return
272273

273-
current: List[Token] = []
274+
current: list[Token] = []
274275
tok_filter = []
275276
for tok in state.tokens:
276277
if tok.type == "footnote_reference_open":
@@ -290,7 +291,7 @@ def footnote_tail(state: StateCore) -> None:
290291
if insideRef:
291292
current.append(tok)
292293

293-
tok_filter.append((not insideRef))
294+
tok_filter.append(not insideRef)
294295

295296
state.tokens = [t for t, f in zip(state.tokens, tok_filter) if f]
296297

@@ -329,7 +330,7 @@ def footnote_tail(state: StateCore) -> None:
329330

330331
state.tokens.extend(tokens)
331332
if state.tokens[len(state.tokens) - 1].type == "paragraph_close":
332-
lastParagraph: Optional[Token] = state.tokens.pop()
333+
lastParagraph: Token | None = state.tokens.pop()
333334
else:
334335
lastParagraph = None
335336

@@ -482,4 +483,4 @@ def render_footnote_anchor(
482483
ident += ":" + str(tokens[idx].meta["subId"])
483484

484485
# ↩ with escape code to prevent display as Apple Emoji on iOS
485-
return ' <a href="#fnref' + ident + '" class="footnote-backref">\u21a9\uFE0E</a>'
486+
return ' <a href="#fnref' + ident + '" class="footnote-backref">\u21a9\ufe0e</a>'

‎mdit_py_plugins/front_matter/index.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Process front matter."""
2+
23
from markdown_it import MarkdownIt
34
from markdown_it.rules_block import StateBlock
45

‎pyproject.toml

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,30 @@ exclude = [
5353
"tests/",
5454
]
5555

56-
[tool.isort]
57-
profile = "black"
58-
force_sort_within_sections = true
59-
known_first_party = ["mdit_py_plugins", "tests"]
56+
[tool.ruff.lint]
57+
extend-select = [
58+
"B", # flake8-bugbear
59+
"C4", # flake8-comprehensions
60+
"I", # isort
61+
"ICN", # flake8-import-conventions
62+
"ISC", # flake8-implicit-str-concat
63+
"N", # pep8-naming
64+
"PERF", # perflint (performance anti-patterns)
65+
"PGH", # pygrep-hooks
66+
"PIE", # flake8-pie
67+
"PTH", # flake8-use-pathlib
68+
"RUF", # Ruff-specific rules
69+
"SIM", # flake8-simplify
70+
"UP", # pyupgrade
71+
"T20", # flake8-print
72+
]
73+
extend-ignore = ["ISC001", "N802", "N803", "N806"]
74+
75+
[tool.ruff.lint.per-file-ignores]
76+
"tests/**.py" = ["T201"]
6077

61-
[tool.ruff]
62-
line-length = 110
63-
extend-select = ["B0", "C4", "ICN", "ISC", "N", "RUF", "SIM"]
64-
extend-ignore = ["E731", "N802", "N803", "N806"]
78+
[tool.ruff.lint.isort]
79+
force-sort-within-sections = true
6580

6681
[tool.mypy]
6782
show_error_codes = true

0 commit comments

Comments
 (0)