Conversation
| rules = component.get("rules", None) | ||
| if rules: | ||
| if rules := component.get("rules", None): | ||
| self[name].ruler.enableOnly(rules) | ||
| rules2 = component.get("rules2", None) | ||
| if rules2: | ||
| if rules2 := component.get("rules2", None): |
There was a problem hiding this comment.
Function MarkdownIt.configure refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression)
| result = "" | ||
|
|
||
| for i, token in enumerate(tokens): | ||
| if token.type in self.rules: | ||
| result += self.rules[token.type](tokens, i, options, env) | ||
| else: | ||
| result += self.renderToken(tokens, i, options, env) | ||
|
|
||
| return result | ||
| return "".join( | ||
| self.rules[token.type](tokens, i, options, env) | ||
| if token.type in self.rules | ||
| else self.renderToken(tokens, i, options, env) | ||
| for i, token in enumerate(tokens) | ||
| ) |
There was a problem hiding this comment.
Function RendererHTML.renderInline refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable) - Use str.join() instead of for loop (
use-join) - Replace if statement with if expression (
assign-if-exp)
| if token.nesting == 1: | ||
| if idx + 1 < len(tokens): | ||
| nextToken = tokens[idx + 1] | ||
| if token.nesting == 1 and idx + 1 < len(tokens): | ||
| nextToken = tokens[idx + 1] | ||
|
|
||
| if nextToken.type == "inline" or nextToken.hidden: | ||
| # Block-level tag containing an inline tag. | ||
| # | ||
| needLf = False | ||
| if nextToken.type == "inline" or nextToken.hidden: | ||
| # Block-level tag containing an inline tag. | ||
| # | ||
| needLf = False | ||
|
|
||
| elif nextToken.nesting == -1 and nextToken.tag == token.tag: | ||
| # Opening tag + closing tag of the same type. E.g. `<li></li>`. | ||
| # | ||
| needLf = False | ||
| elif nextToken.nesting == -1 and nextToken.tag == token.tag: | ||
| # Opening tag + closing tag of the same type. E.g. `<li></li>`. | ||
| # | ||
| needLf = False |
There was a problem hiding this comment.
Function RendererHTML.renderToken refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs)
| result = "" | ||
|
|
||
| for key, value in token.attrItems(): | ||
| result += " " + escapeHtml(key) + '="' + escapeHtml(str(value)) + '"' | ||
|
|
||
| return result | ||
| return "".join( | ||
| f' {escapeHtml(key)}' + '="' + escapeHtml(str(value)) + '"' | ||
| for key, value in token.attrItems() | ||
| ) |
There was a problem hiding this comment.
Function RendererHTML.renderAttrs refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable) - Use str.join() instead of for loop (
use-join) - Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| return ( | ||
| "<code" | ||
| return (("<code" | ||
| + self.renderAttrs(token) | ||
| + ">" | ||
| + escapeHtml(tokens[idx].content) | ||
| + "</code>" | ||
| ) | ||
| + ">" + escapeHtml(token.content)) + "</code>") |
There was a problem hiding this comment.
Function RendererHTML.code_inline refactored with the following changes:
- Use previously assigned local variable (
use-assigned-variable)
| if scheme in RECODE_HOSTNAME_FOR: | ||
| url = urlunparse( | ||
| return urlunparse( |
There was a problem hiding this comment.
Function normalizeLink refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable) - Replace if statement with if expression (
assign-if-exp)
| if scheme in RECODE_HOSTNAME_FOR: | ||
| url = urlunparse( | ||
| return urlunparse( |
There was a problem hiding this comment.
Function normalizeLinkText refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable) - Replace if statement with if expression (
assign-if-exp)
| if c >= 0xFDD0 and c <= 0xFDEF: | ||
| return False | ||
| if ((c & 0xFFFF) == 0xFFFF) or ((c & 0xFFFF) == 0xFFFE): | ||
| if c & 0xFFFF in [0xFFFF, 0xFFFE]: |
There was a problem hiding this comment.
Function isValidEntityCode refactored with the following changes:
- Replace multiple comparisons of same variable with
inoperator (merge-comparisons)
|
|
||
| ESCAPABLE = r"""\\!"#$%&'()*+,./:;<=>?@\[\]^`{}|_~-""" | ||
| ESCAPE_CHAR = re.compile(r"\\([" + ESCAPABLE + r"])") | ||
| ESCAPE_CHAR = re.compile(f'\\\\([{ESCAPABLE}])') |
There was a problem hiding this comment.
Lines 153-153 refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| def escapeRE(string: str) -> str: | ||
| string = REGEXP_ESCAPE_RE.sub("\\$&", string) | ||
| return string | ||
| return REGEXP_ESCAPE_RE.sub("\\$&", string) |
There was a problem hiding this comment.
Function escapeRE refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
Branch
xinrefactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
xinbranch, then run:Help us improve this pull request!