Skip to content

Sourcery refactored master branch#1

Open
sourcery-ai[bot] wants to merge 1 commit intomasterfrom
sourcery/master
Open

Sourcery refactored master branch#1
sourcery-ai[bot] wants to merge 1 commit intomasterfrom
sourcery/master

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented Jul 27, 2020

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^

self.attrs = attrs.copy()
else:
self.attrs = {}
self.attrs = attrs.copy() if attrs is not None else {}
Copy link
Author

Choose a reason for hiding this comment

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

Function FileBrowseWidget.__init__ refactored with the following changes:

  • Replace if statement with if expression (assign-if-exp)

Comment on lines -41 to +39
if self.directory:
if callable(self.directory):
if directory:
if callable(directory):
Copy link
Author

Choose a reason for hiding this comment

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

Function FileBrowseWidget.render refactored with the following changes:

  • Use previously assigned local variable (use-assigned-variable)

Comment on lines -80 to +77
if self.extensions and not file_extension in self.extensions:
if self.extensions and file_extension not in self.extensions:
Copy link
Author

Choose a reason for hiding this comment

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

Function FileBrowseFormField.clean refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

url = "http://"
else:
url = "/"
url = "http://" if args[0].startswith("http://") else "/"
Copy link
Author

Choose a reason for hiding this comment

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

Function url_join refactored with the following changes:

  • Replace if statement with if expression (assign-if-exp)

Comment on lines -214 to +211
if len(normalized) > 1:
value = '.'.join(normalized)
else:
value = normalized[0]

value = '.'.join(normalized) if len(normalized) > 1 else normalized[0]
Copy link
Author

Choose a reason for hiding this comment

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

Function convert_filename refactored with the following changes:

  • Replace if statement with if expression (assign-if-exp)

for k, v in EXTENSIONS.items():
counter[k] = 0

counter = {k: 0 for k, v in EXTENSIONS.items()}
Copy link
Author

Choose a reason for hiding this comment

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

Function browse refactored with the following changes:

  • Remove redundant conditional (remove-redundant-if)
  • Convert for loop into dictionary comprehension (dict-comprehension)

if k != "folder" and default_storage.exists(
os.path.join(get_directory(), folder, v)
):
fileArray[k] = v
Copy link
Author

Choose a reason for hiding this comment

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

Function _check_file refactored with the following changes:

  • Merge nested if conditions (merge-nested-ifs)

Comment on lines -20 to -22
ON_EACH_SIDE = 3
ON_ENDS = 2

Copy link
Author

Choose a reason for hiding this comment

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

Function pagination refactored with the following changes:

  • Move assignments closer to their usage (move-assign)
  • Replace range(0, x) with range(x) (remove-zero-from-range)

if filetype and format and filetype in SELECT_FORMATS[format]:
selectable = True
elif filetype and format and filetype not in SELECT_FORMATS[format]:
elif filetype and format:
Copy link
Author

Choose a reason for hiding this comment

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

Function SelectableNode.render refactored with the following changes:

  • Remove redundant conditional (remove-redundant-if)

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Jul 27, 2020

Sourcery Code Quality Report (beta)

✅  Merging this PR will increase code quality in the affected files by 0.02 out of 10.

Quality metrics Before After Change
Complexity 4.36 4.22 -0.14 🔵
Method Length 68.76 68.27 -0.49 🔵
Quality 8.20 8.22 0.02 🔵
Other metrics Before After Change
Lines 950 938 -12
Changed files Quality Before Quality After Quality Change
filebrowser_safe/fields.py 8.80 8.82 0.02 🔵
filebrowser_safe/functions.py 8.40 8.42 0.02 🔵
filebrowser_safe/views.py 7.29 7.32 0.03 🔵
filebrowser_safe/templatetags/fb_pagination.py 7.33 7.34 0.01 🔵
filebrowser_safe/templatetags/fb_tags.py 8.76 8.77 0.01 🔵

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

File Function Complexity Length Overall Recommendation
filebrowser_safe/views.py browse 45 474.13 1.51 Split out functionality. Reduce complexity
filebrowser_safe/views.py delete 14 279.75 4.21 Split out functionality
filebrowser_safe/views.py _upload_file 18 215.84 4.31 Split out functionality
filebrowser_safe/views.py rename 12 254.68 4.55 Split out functionality
filebrowser_safe/views.py mkdir 13 221.71 4.71 Split out functionality

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!

Let us know what you think of it via email or our Gitter!

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.

0 participants