From e4cfa27a0a248529d2d8ce30720271878747cfd7 Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Sat, 18 Feb 2023 01:50:39 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Update=20pre-commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit and move from flake8 to ruff --- .pre-commit-config.yaml | 15 +++++++-------- mdit_py_plugins/admon/index.py | 2 +- mdit_py_plugins/amsmath/__init__.py | 8 ++------ mdit_py_plugins/anchors/index.py | 2 +- mdit_py_plugins/attrs/parse.py | 9 --------- mdit_py_plugins/colon_fence.py | 1 - mdit_py_plugins/container/index.py | 1 - mdit_py_plugins/deflist/index.py | 4 +--- mdit_py_plugins/dollarmath/index.py | 9 ++------- mdit_py_plugins/field_list/__init__.py | 11 +++-------- mdit_py_plugins/footnote/index.py | 1 - mdit_py_plugins/myst_blocks/index.py | 3 --- mdit_py_plugins/myst_role/index.py | 5 +---- mdit_py_plugins/tasklists/__init__.py | 3 +-- mdit_py_plugins/texmath/index.py | 18 ++++++++---------- mdit_py_plugins/wordcount/__init__.py | 2 +- pyproject.toml | 5 +++++ tests/test_dollarmath.py | 1 - tests/test_footnote.py | 3 --- tests/test_texmath.py | 1 - tox.ini | 4 ---- 21 files changed, 33 insertions(+), 75 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b357ba0..2e0ba94 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,7 +12,7 @@ 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 @@ -20,23 +20,22 @@ repos: - 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] diff --git a/mdit_py_plugins/admon/index.py b/mdit_py_plugins/admon/index.py index 8ebbe8f..a9efeef 100644 --- a/mdit_py_plugins/admon/index.py +++ b/mdit_py_plugins/admon/index.py @@ -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 diff --git a/mdit_py_plugins/amsmath/__init__.py b/mdit_py_plugins/amsmath/__init__.py index 0b367b5..197f1cc 100644 --- a/mdit_py_plugins/amsmath/__init__.py +++ b/mdit_py_plugins/amsmath/__init__.py @@ -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", @@ -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)) @@ -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 diff --git a/mdit_py_plugins/anchors/index.py b/mdit_py_plugins/anchors/index.py index abbd48a..b0179be 100644 --- a/mdit_py_plugins/anchors/index.py +++ b/mdit_py_plugins/anchors/index.py @@ -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]) diff --git a/mdit_py_plugins/attrs/parse.py b/mdit_py_plugins/attrs/parse.py index 4a30353..a99d43b 100644 --- a/mdit_py_plugins/attrs/parse.py +++ b/mdit_py_plugins/attrs/parse.py @@ -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 == "}": @@ -142,7 +140,6 @@ 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 @@ -150,7 +147,6 @@ def handle_scanning_comment(char: str, pos: int, tokens: TokenState) -> State: def handle_scanning_id(char: str, pos: int, tokens: TokenState) -> State: - if not REGEX_SPACE_PUNCTUATION.fullmatch(char): return State.SCANNING_ID @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/mdit_py_plugins/colon_fence.py b/mdit_py_plugins/colon_fence.py index e2356ed..b50de91 100644 --- a/mdit_py_plugins/colon_fence.py +++ b/mdit_py_plugins/colon_fence.py @@ -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] diff --git a/mdit_py_plugins/container/index.py b/mdit_py_plugins/container/index.py index b6edd43..df46d39 100644 --- a/mdit_py_plugins/container/index.py +++ b/mdit_py_plugins/container/index.py @@ -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] diff --git a/mdit_py_plugins/deflist/index.py b/mdit_py_plugins/deflist/index.py index 0b353db..8429b56 100644 --- a/mdit_py_plugins/deflist/index.py +++ b/mdit_py_plugins/deflist/index.py @@ -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.""" @@ -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 @@ -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: diff --git a/mdit_py_plugins/dollarmath/index.py b/mdit_py_plugins/dollarmath/index.py index 5fe0381..9c531da 100644 --- a/mdit_py_plugins/dollarmath/index.py +++ b/mdit_py_plugins/dollarmath/index.py @@ -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 = ( @@ -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: @@ -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 @@ -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())) diff --git a/mdit_py_plugins/field_list/__init__.py b/mdit_py_plugins/field_list/__init__.py index 9e21fb5..48ecca4 100644 --- a/mdit_py_plugins/field_list/__init__.py +++ b/mdit_py_plugins/field_list/__init__.py @@ -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] @@ -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) diff --git a/mdit_py_plugins/footnote/index.py b/mdit_py_plugins/footnote/index.py index 119fb71..7e66073 100644 --- a/mdit_py_plugins/footnote/index.py +++ b/mdit_py_plugins/footnote/index.py @@ -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 = [] diff --git a/mdit_py_plugins/myst_blocks/index.py b/mdit_py_plugins/myst_blocks/index.py index d0e4cf6..dcc93b9 100644 --- a/mdit_py_plugins/myst_blocks/index.py +++ b/mdit_py_plugins/myst_blocks/index.py @@ -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] @@ -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] @@ -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] diff --git a/mdit_py_plugins/myst_role/index.py b/mdit_py_plugins/myst_role/index.py index 53ef60e..fb0b894 100644 --- a/mdit_py_plugins/myst_role/index.py +++ b/mdit_py_plugins/myst_role/index.py @@ -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: @@ -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 ( - '' f"{{{name}}}[{escapeHtml(token.content)}]" "" - ) + return f'{{{name}}}[{escapeHtml(token.content)}]' diff --git a/mdit_py_plugins/tasklists/__init__.py b/mdit_py_plugins/tasklists/__init__.py index 40a6d67..3c4527f 100644 --- a/mdit_py_plugins/tasklists/__init__.py +++ b/mdit_py_plugins/tasklists/__init__.py @@ -47,7 +47,7 @@ def tasklists_plugin( :param enabled: True enables the rendered checkboxes :param label: True wraps the rendered list items in a