Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔧 Update pre-commit #64

Merged
merged 1 commit into from
Feb 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,30 @@ exclude: >
repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: check-json
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/timothycrosley/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: 22.8.0
rev: 23.1.0
hooks:
- id: black

- repo: https://github.com/pycqa/flake8
rev: 3.9.2
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.247
hooks:
- id: flake8
additional_dependencies: [flake8-bugbear==21.3.1]
- id: ruff

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.971
rev: v1.0.0
hooks:
- id: mypy
additional_dependencies: [markdown-it-py~=2.0]
2 changes: 1 addition & 1 deletion mdit_py_plugins/admon/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def admonition(state: StateBlock, startLine: int, endLine: int, silent: bool) ->
maximum = state.eMarks[startLine]

# Check out the first character quickly, which should filter out most of non-containers
if MARKER_CHAR != ord(state.src[start]):
if ord(state.src[start]) != MARKER_CHAR:
return False

# Check out the rest of the marker string
Expand Down
8 changes: 2 additions & 6 deletions mdit_py_plugins/amsmath/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
ENVIRONMENTS = [
# 3.2 single equation with an automatically gen-erated number
"equation",
# 3.3 variation equation, used for equations that don’t fit on a single line
# 3.3 variation equation, used for equations that dont fit on a single line
"multline",
# 3.5 a group of consecutive equations when there is no alignment desired among them
"gather",
Expand Down Expand Up @@ -68,10 +68,7 @@ def amsmath_plugin(md: MarkdownIt, *, renderer: Optional[Callable[[str], str]] =
{"alt": ["paragraph", "reference", "blockquote", "list", "footnote_def"]},
)

if renderer is None:
_renderer = lambda content: escapeHtml(content)
else:
_renderer = renderer
_renderer = lambda content: escapeHtml(content) if renderer is None else renderer

def render_amsmath_block(self, tokens, idx, options, env):
content = _renderer(str(tokens[idx].content))
Expand All @@ -95,7 +92,6 @@ def match_environment(string):


def amsmath_block(state: StateBlock, startLine: int, endLine: int, silent: bool):

# if it's indented more than 3 spaces, it should be a code block
if state.sCount[startLine] - state.blkIndent >= 4:
return False
Expand Down
2 changes: 1 addition & 1 deletion mdit_py_plugins/anchors/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def _make_anchors_func(
):
def _anchor_func(state: StateCore):
slugs: Set[str] = set()
for (idx, token) in enumerate(state.tokens):
for idx, token in enumerate(state.tokens):
if token.type != "heading_open":
continue
level = int(token.tag[1])
Expand Down
9 changes: 0 additions & 9 deletions mdit_py_plugins/attrs/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,12 @@ def parse(string: str) -> tuple[int, dict[str, str]]:


def handle_start(char: str, pos: int, tokens: TokenState) -> State:

if char == "{":
return State.SCANNING
raise ParseError("Attributes must start with '{'", pos)


def handle_scanning(char: str, pos: int, tokens: TokenState) -> State:

if char == " " or char == "\t" or char == "\n" or char == "\r":
return State.SCANNING
if char == "}":
Expand All @@ -142,15 +140,13 @@ def handle_scanning(char: str, pos: int, tokens: TokenState) -> State:


def handle_scanning_comment(char: str, pos: int, tokens: TokenState) -> State:

if char == "%":
return State.SCANNING

return State.SCANNING_COMMENT


def handle_scanning_id(char: str, pos: int, tokens: TokenState) -> State:

if not REGEX_SPACE_PUNCTUATION.fullmatch(char):
return State.SCANNING_ID

Expand All @@ -168,7 +164,6 @@ def handle_scanning_id(char: str, pos: int, tokens: TokenState) -> State:


def handle_scanning_class(char: str, pos: int, tokens: TokenState) -> State:

if not REGEX_SPACE_PUNCTUATION.fullmatch(char):
return State.SCANNING_CLASS

Expand All @@ -186,7 +181,6 @@ def handle_scanning_class(char: str, pos: int, tokens: TokenState) -> State:


def handle_scanning_key(char: str, pos: int, tokens: TokenState) -> State:

if char == "=":
tokens.append(tokens.start, pos, "key")
return State.SCANNING_VALUE
Expand All @@ -198,7 +192,6 @@ def handle_scanning_key(char: str, pos: int, tokens: TokenState) -> State:


def handle_scanning_value(char: str, pos: int, tokens: TokenState) -> State:

if char == '"':
tokens.set_start(pos)
return State.SCANNING_QUOTED_VALUE
Expand All @@ -211,7 +204,6 @@ def handle_scanning_value(char: str, pos: int, tokens: TokenState) -> State:


def handle_scanning_bare_value(char: str, pos: int, tokens: TokenState) -> State:

if REGEX_KEY_CHARACTERS.fullmatch(char):
return State.SCANNING_BARE_VALUE

Expand All @@ -231,7 +223,6 @@ def handle_scanning_escaped(char: str, pos: int, tokens: TokenState) -> State:


def handle_scanning_quoted_value(char: str, pos: int, tokens: TokenState) -> State:

if char == '"':
tokens.append(tokens.start + 1, pos, "value")
return State.SCANNING
Expand Down
1 change: 0 additions & 1 deletion mdit_py_plugins/colon_fence.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def colon_fence_plugin(md: MarkdownIt):


def _rule(state: StateBlock, startLine: int, endLine: int, silent: bool):

haveEndMarker = False
pos = state.bMarks[startLine] + state.tShift[startLine]
maximum = state.eMarks[startLine]
Expand Down
1 change: 0 additions & 1 deletion mdit_py_plugins/container/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def renderDefault(self, tokens, idx, _options, env):
render = render or renderDefault

def container_func(state: StateBlock, startLine: int, endLine: int, silent: bool):

auto_closed = False
start = state.bMarks[startLine] + state.tShift[startLine]
maximum = state.eMarks[startLine]
Expand Down
4 changes: 1 addition & 3 deletions mdit_py_plugins/deflist/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def deflist_plugin(md: MarkdownIt):
~ Definition 2b

"""
isSpace = md.utils.isSpace # type: ignore
isSpace = md.utils.isSpace

def skipMarker(state: StateBlock, line: int):
"""Search `[:~][\n ]`, returns next pos after marker on success or -1 on fail."""
Expand Down Expand Up @@ -51,7 +51,6 @@ def skipMarker(state: StateBlock, line: int):
return start

def markTightParagraphs(state: StateBlock, idx: int):

level = state.level + 2

i = idx + 2
Expand All @@ -67,7 +66,6 @@ def markTightParagraphs(state: StateBlock, idx: int):
i += 1

def deflist(state: StateBlock, startLine: int, endLine: int, silent: bool):

if silent:
# quirk: validation mode validates a dd block only, not a whole deflist
if state.ddIndent < 0:
Expand Down
9 changes: 2 additions & 7 deletions mdit_py_plugins/dollarmath/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ def dollarmath_plugin(
# would be good to allow "proper" math rendering,
# e.g. https://github.com/roniemartinez/latex2mathml

if renderer is None:
_renderer = lambda content, _: escapeHtml(content)
else:
_renderer = renderer
_renderer = lambda content, _: escapeHtml(content) if renderer is None else renderer

if label_renderer is None:
_label_renderer = (
Expand Down Expand Up @@ -186,7 +183,7 @@ def _math_inline_dollar(state: StateInline, silent: bool) -> bool:
continue

try:
if is_double and not state.srcCharCode[end + 1] == 0x24:
if is_double and state.srcCharCode[end + 1] != 0x24:
pos = end + 1
continue
except IndexError:
Expand Down Expand Up @@ -253,7 +250,6 @@ def math_block_dollar(
def _math_block_dollar(
state: StateBlock, startLine: int, endLine: int, silent: bool
) -> bool:

# TODO internal backslash escaping

haveEndMarker = False
Expand All @@ -280,7 +276,6 @@ def _math_block_dollar(
# search for end of block on same line
lineText = state.src[startPos:end]
if len(lineText.strip()) > 3:

if lineText.strip().endswith("$$"):
haveEndMarker = True
end = end - 2 - (len(lineText) - len(lineText.strip()))
Expand Down
11 changes: 3 additions & 8 deletions mdit_py_plugins/field_list/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ def _fieldlist_rule(state: StateBlock, startLine: int, endLine: int, silent: boo
nextLine = startLine

with set_parent_type(state, "fieldlist"):

while nextLine < endLine:

# create name tokens
token = state.push("fieldlist_name_open", "dt", 1)
token.map = [startLine, startLine]
Expand Down Expand Up @@ -151,12 +149,9 @@ def _fieldlist_rule(state: StateBlock, startLine: int, endLine: int, silent: boo
contentStart = pos

# set indent for body text
if contentStart >= maximum:
# no body on first line, so use constant indentation
# TODO adapt to indentation of subsequent lines?
indent = 2
else:
indent = offset
# no body on first line, so use constant indentation
# TODO adapt to indentation of subsequent lines?
indent = 2 if contentStart >= maximum else offset

# Run subparser on the field body
token = state.push("fieldlist_body_open", "dd", 1)
Expand Down
1 change: 0 additions & 1 deletion mdit_py_plugins/footnote/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ def footnote_tail(state: StateBlock, *args, **kwargs):
current: List[Token] = []
tok_filter = []
for tok in state.tokens:

if tok.type == "footnote_reference_open":
insideRef = True
current = []
Expand Down
3 changes: 0 additions & 3 deletions mdit_py_plugins/myst_blocks/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def myst_block_plugin(md: MarkdownIt):


def line_comment(state: StateBlock, startLine: int, endLine: int, silent: bool):

pos = state.bMarks[startLine] + state.tShift[startLine]
maximum = state.eMarks[startLine]

Expand Down Expand Up @@ -67,7 +66,6 @@ def line_comment(state: StateBlock, startLine: int, endLine: int, silent: bool):


def block_break(state: StateBlock, startLine: int, endLine: int, silent: bool):

pos = state.bMarks[startLine] + state.tShift[startLine]
maximum = state.eMarks[startLine]

Expand Down Expand Up @@ -111,7 +109,6 @@ def block_break(state: StateBlock, startLine: int, endLine: int, silent: bool):


def target(state: StateBlock, startLine: int, endLine: int, silent: bool):

pos = state.bMarks[startLine] + state.tShift[startLine]
maximum = state.eMarks[startLine]

Expand Down
5 changes: 1 addition & 4 deletions mdit_py_plugins/myst_role/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def myst_role_plugin(md: MarkdownIt):


def myst_role(state: StateInline, silent: bool):

# check name
match = VALID_NAME_PATTERN.match(state.src[state.pos :])
if not match:
Expand Down Expand Up @@ -60,6 +59,4 @@ def myst_role(state: StateInline, silent: bool):
def render_myst_role(self, tokens, idx, options, env):
token = tokens[idx]
name = token.meta.get("name", "unknown")
return (
'<code class="myst role">' f"{{{name}}}[{escapeHtml(token.content)}]" "</code>"
)
return f'<code class="myst role">{{{name}}}[{escapeHtml(token.content)}]</code>'
3 changes: 1 addition & 2 deletions mdit_py_plugins/tasklists/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def tasklists_plugin(

:param enabled: True enables the rendered checkboxes
:param label: True wraps the rendered list items in a <label> element for UX purposes,
:param label_after: True adds the <label> element after the checkbox.
:param label_after: True adds the <label> element after the checkbox.
"""
disable_checkboxes = not enabled
use_label_wrapper = label
Expand All @@ -56,7 +56,6 @@ def tasklists_plugin(
def fcn(state):
tokens: List[Token] = state.tokens
for i in range(2, len(tokens) - 1):

if is_todo_item(tokens, i):
todoify(tokens[i], tokens[i].__class__)
tokens[i - 2].attrSet(
Expand Down
18 changes: 8 additions & 10 deletions mdit_py_plugins/texmath/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def texmath_plugin(md: MarkdownIt, delimiters="dollars", macros: Optional[dict]
)

def render_math_inline(self, tokens, idx, options, env):
return rule_inline["tmpl"].format(
return rule_inline["tmpl"].format( # noqa: B023
render(tokens[idx].content, False, macros)
)

Expand All @@ -39,15 +39,14 @@ def render_math_inline(self, tokens, idx, options, env):
)

def render_math_block(self, tokens, idx, options, env):
return rule_block["tmpl"].format(
return rule_block["tmpl"].format( # noqa: B023
render(tokens[idx].content, True, macros), tokens[idx].info
)

md.add_render_rule(rule_block["name"], render_math_block)


def applyRule(rule, string: str, begin, inBlockquote):

if not (
string.startswith(rule["tag"], begin)
and (rule["pre"](string, begin) if "pre" in rule else True)
Expand All @@ -60,13 +59,12 @@ def applyRule(rule, string: str, begin, inBlockquote):
return False

lastIndex = match.end() + begin - 1
if "post" in rule:
if not (
rule["post"](string, lastIndex) # valid post-condition
# remove evil blockquote bug (https:#github.com/goessner/mdmath/issues/50)
and (not inBlockquote or "\n" not in match.group(1))
):
return False
if "post" in rule and not (
rule["post"](string, lastIndex) # valid post-condition
# remove evil blockquote bug (https:#github.com/goessner/mdmath/issues/50)
and (not inBlockquote or "\n" not in match.group(1))
):
return False
return match


Expand Down
2 changes: 1 addition & 1 deletion mdit_py_plugins/wordcount/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def wordcount_plugin(
*,
per_minute: int = 200,
count_func: Callable[[str], int] = basic_count,
store_text: bool = False
store_text: bool = False,
):
"""Plugin for computing and storing the word count.

Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ profile = "black"
force_sort_within_sections = true
known_first_party = ["mdit_py_plugins", "tests"]

[tool.ruff]
line-length = 110
extend-select = ["B0", "C4", "ICN", "ISC", "N", "RUF", "SIM"]
extend-ignore = ["E731", "N802", "N803", "N806"]

[tool.mypy]
show_error_codes = true
warn_unused_ignores = true
Expand Down
Loading