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:

0 commit comments

Comments
 (0)