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

Sourcery refactored master branch #22

Closed
wants to merge 1 commit into from
Closed

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Aug 30, 2022

Branch master 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 master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

kw.update({'yscrollcommand': self.vbar.set})
kw['yscrollcommand'] = self.vbar.set
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _ScrolledText.__init__ refactored with the following changes:

Comment on lines -54 to +56
if not 'wrap' in kwargs.keys():
if 'wrap' not in kwargs.keys():
self.config(wrap='word')
if not 'background' in kwargs.keys():
if 'background' not in kwargs.keys():
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function HTMLScrolledText._w_init refactored with the following changes:

  • Simplify logical expression using De Morgan identities [×2] (de-morgan)

Comment on lines -111 to +120
if not 'background' in kwargs.keys():
if 'background' not in kwargs.keys():
if sys.platform.startswith('win'):
self.config(background='SystemButtonFace')
else:
self.config(background='#d9d9d9')

if not 'borderwidth' in kwargs.keys():
if 'borderwidth' not in kwargs.keys():
self.config(borderwidth=0)

if not 'padx' in kwargs.keys():
if 'padx' not in kwargs.keys():
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function HTMLLabel._w_init refactored with the following changes:

  • Simplify logical expression using De Morgan identities [×3] (de-morgan)

Comment on lines -225 to +232
#------------------------------------------------------------------------------------------
if self.ordered:
if self.type == HTML.TypeOrderedList._1:
return str(self.index)
elif self.type == HTML.TypeOrderedList.a:
return self._index_to_str(self.index).lower()
elif self.type == HTML.TypeOrderedList.A:
return self._index_to_str(self.index).upper()
else:
if not self.ordered:
return chr(8226)
if self.type == HTML.TypeOrderedList._1:
return str(self.index)
elif self.type == HTML.TypeOrderedList.a:
return self._index_to_str(self.index).lower()
elif self.type == HTML.TypeOrderedList.A:
return self._index_to_str(self.index).upper()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ListTag.line_index refactored with the following changes:

This removes the following comments ( why? ):

#------------------------------------------------------------------------------------------

Comment on lines -343 to +341

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found the following improvement in Function HTMLTextParser._stack_pop:

Comment on lines -440 to +437
elif tag == HTML.Tag.I or tag == HTML.Tag.EM:
elif tag in [HTML.Tag.I, HTML.Tag.EM]:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function HTMLTextParser.handle_starttag refactored with the following changes:

This removes the following comments ( why? ):

#------------------------------------------------------------------ [ LISTS_LINES ]

Comment on lines +559 to +562
elif double:
self._w.insert(tk.INSERT, "\n\n")
else:
if double:
self._w.insert(tk.INSERT, "\n\n")
else:
self._w.insert(tk.INSERT, "\n")
self._w.insert(tk.INSERT, "\n")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function HTMLTextParser._insert_new_line refactored with the following changes:

Comment on lines -593 to +607
#------------------------------------------------------------------------------------------
if self.strip:
if len(self.html_tags) and self.html_tags[-1] in (HTML.Tag.PRE, HTML.Tag.CODE):
pass
elif not data.strip():
if len(self.html_tags) and self.html_tags[-1] in (HTML.Tag.PRE, HTML.Tag.CODE):
pass
elif not data.strip():
if self.strip:
data = ""
else:
# left strip
if self._w.index("end-1c").endswith(".0"):
data = data.lstrip()
elif self._w.get("end-2c", "end-1c") == " ":
data = data.lstrip()

data = data.replace("\n", " ").replace("\t", " ")
data = data + " "
data = self._remove_multi_spaces(data)
if len(self.html_tags):
level = len(self.list_tags)
if self.html_tags[-1] in (HTML.Tag.UL, HTML.Tag.OL):
self._w.insert(tk.INSERT, "\t" * 2 * level)
elif self.strip:
# left strip
if self._w.index("end-1c").endswith(".0"):
data = data.lstrip()
elif self._w.get("end-2c", "end-1c") == " ":
data = data.lstrip()

data = data.replace("\n", " ").replace("\t", " ")
data = f"{data} "
data = self._remove_multi_spaces(data)
if len(self.html_tags) and self.html_tags[-1] in (
HTML.Tag.UL,
HTML.Tag.OL,
):
level = len(self.list_tags)
self._w.insert(tk.INSERT, "\t" * 2 * level)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function HTMLTextParser.handle_data refactored with the following changes:

This removes the following comments ( why? ):

#------------------------------------------------------------------------------------------

Comment on lines -640 to +641
elif tag == HTML.Tag.I or tag == HTML.Tag.EM:
elif tag in [HTML.Tag.I, HTML.Tag.EM]:
self._stack_pop(tag, Fnt.SLANT)

elif tag == HTML.Tag.A:
self._stack_pop(tag, Bind.LINK)

elif tag == HTML.Tag.OL or tag == HTML.Tag.UL:
elif tag in [HTML.Tag.OL, HTML.Tag.UL]:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function HTMLTextParser.handle_endtag refactored with the following changes:

  • Replace multiple comparisons of same variable with in operator [×2] (merge-comparisons)

return "<%s: %s>" % (self.__class__.__name__, self._file)
return f"<{self.__class__.__name__}: {self._file}>"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function RenderHTML.__repr__ refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Aug 30, 2022

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.79%.

Quality metrics Before After Change
Complexity 20.61 😞 19.25 😞 -1.36 👍
Method Length 103.09 🙂 102.95 🙂 -0.14 👍
Working memory 11.17 😞 10.85 😞 -0.32 👍
Quality 50.08% 🙂 50.87% 🙂 0.79% 👍
Other metrics Before After Change
Lines 743 738 -5
Changed files Quality Before Quality After Quality Change
tkhtmlview/init.py 77.09% ⭐ 77.25% ⭐ 0.16% 👍
tkhtmlview/html_parser.py 44.61% 😞 45.51% 😞 0.90% 👍
tkhtmlview/utils.py 90.44% ⭐ 88.77% ⭐ -1.67% 👎

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
tkhtmlview/html_parser.py HTMLTextParser.handle_starttag 72 ⛔ 816 ⛔ 22 ⛔ 3.94% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
tkhtmlview/html_parser.py HTMLTextParser._parse_styles 41 ⛔ 734 ⛔ 14 😞 15.08% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
tkhtmlview/html_parser.py HTMLTextParser.handle_endtag 21 😞 296 ⛔ 12 😞 31.11% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
tkhtmlview/html_parser.py HTMLTextParser.handle_data 12 🙂 169 😞 13 😞 44.32% 😞 Try splitting into smaller methods. Extract out complex expressions
tkhtmlview/html_parser.py HTMLTextParser._parse_attrs 11 🙂 154 😞 12 😞 48.26% 😞 Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

@bauripalash bauripalash closed this Sep 8, 2022
@bauripalash bauripalash deleted the sourcery/master branch September 17, 2022 06:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant