Skip to content

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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

github-actions[bot]
Copy link
Contributor

You can preview this rule here (updated a few minutes after each push).

Review

A dedicated reviewer checked the rule description successfully for:

  • logical errors and incorrect information
  • information gaps and missing content
  • text style and tone
  • PR summary and labels follow the guidelines

@Seppli11 Seppli11 force-pushed the rule/add-RSPEC-S7508 branch 3 times, most recently from 5fbb61a to ada9bd7 Compare May 19, 2025 14:27
@Seppli11 Seppli11 force-pushed the rule/add-RSPEC-S7508 branch from ada9bd7 to 1eda634 Compare May 19, 2025 14:41
@Seppli11 Seppli11 changed the title Create rule S7508 SONARPY-2865: Create rule S7508: Unnecessary <list/reversed/set/sorted/tuple> call within <list/set/sorted/tuple>() May 19, 2025

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.

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


== Resources
=== Documentation
* Python Documentation - https://docs.python.org/3/library/functions.html#list[list]

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

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


list_of_list = list(iterable) # Noncompliant
set_of_list = set(iterable) # Noncompliant
sorted_of_list = sorted(iterable) # Noncompliant

Choose a reason for hiding this comment

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

remove the noncompliant comment

Copy link
Contributor

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

@Seppli11 Seppli11 force-pushed the rule/add-RSPEC-S7508 branch from 97b564d to bdbcc1b Compare May 20, 2025 12:19
Copy link

Quality Gate passed Quality Gate passed for 'rspec-tools'

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
0 Dependency risks
No data about Coverage
No data about Duplication

See analysis details on SonarQube

Copy link

Quality Gate passed Quality Gate passed for 'rspec-frontend'

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
0 Dependency risks
No data about Coverage
No data about Duplication

See analysis details on SonarQube

Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants