-
Notifications
You must be signed in to change notification settings - Fork 30
SONARPY-2865: Create rule S7508: Unnecessary <list/reversed/set/sorted/tuple> call within <list/set/sorted/tuple>() #5045
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
base: master
Are you sure you want to change the base?
Conversation
5fbb61a
to
ada9bd7
Compare
ada9bd7
to
1eda634
Compare
rules/S7508/python/rule.adoc
Outdated
|
||
When the outer function is given a collection but could be given an iterable, the unnecessary cast to the collection should be removed. For example, in `sorted(list(iterable))`, the outer `sorted()` function can accept an iterable directly, so the inner `list()` call is redundant and should be removed. | ||
|
||
When the function `sorted()` is casted to `list()`, remove the cast, since `sorted()` already returns a list. |
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.
as discussed we agreed to replace mentioning of the cast
to something like passing as an argument
rules/S7508/python/rule.adoc
Outdated
|
||
== Resources | ||
=== Documentation | ||
* Python Documentation - https://docs.python.org/3/library/functions.html#list[list] |
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.
|
||
list_of_list = list(list(iterable)) # Noncompliant | ||
set_of_list = set(list(iterable)) # Noncompliant | ||
sorted_of_list = list(sorted(iterable)) # Noncompliant |
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.
as discussed the sample code probably could show just single noncompliant case, otherwise it makes sense to split them by different diff-id
code section pairs
rules/S7508/python/rule.adoc
Outdated
|
||
list_of_list = list(iterable) # Noncompliant | ||
set_of_list = set(iterable) # Noncompliant | ||
sorted_of_list = sorted(iterable) # Noncompliant |
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.
remove the noncompliant comment
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.
Overall looks good, as discussed there are some things to be changed
97b564d
to
bdbcc1b
Compare
bdbcc1b
to
6db810a
Compare
|
|
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.
LGTM
You can preview this rule here (updated a few minutes after each push).
Review
A dedicated reviewer checked the rule description successfully for: