-
Notifications
You must be signed in to change notification settings - Fork 0
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
Sourcery refactored xin branch #1
base: xin
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 & 0xFFFF) == 0xFFFF) or ((c & 0xFFFF) == 0xFFFE): | ||
if c & 0xFFFF in [0xFFFF, 0xFFFE]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function isValidEntityCode
refactored with the following changes:
- Replace multiple comparisons of same variable with
in
operator (merge-comparisons
)
ESCAPE_CHAR = re.compile(r"\\([" + ESCAPABLE + r"])") | ||
ESCAPE_CHAR = re.compile(f'\\\\([{ESCAPABLE}])') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 153-153
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
string = REGEXP_ESCAPE_RE.sub("\\$&", string) | ||
return string | ||
return REGEXP_ESCAPE_RE.sub("\\$&", string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function escapeRE
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
Branch
xin
refactored 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
xin
branch, then run:Help us improve this pull request!