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

Chore/remove unused scripts #2468

Merged
merged 2 commits into from
Jun 4, 2024
Merged

Chore/remove unused scripts #2468

merged 2 commits into from
Jun 4, 2024

Conversation

0xalpharush
Copy link
Contributor

@0xalpharush 0xalpharush commented Jun 3, 2024

No description provided.

Copy link
Contributor

coderabbitai bot commented Jun 3, 2024

Walkthrough

Walkthrough

The recent updates focus on enhancing the detector selection mechanism in the slither tool. Key changes include the introduction of a helper function for including specific detectors, revisions to the exclusion logic based on impact classification, and the addition of a new command-line argument for specifying detectors to include. These improvements aim to provide more flexibility and precision in selecting and excluding detectors during analysis.

Changes

Files Change Summary
slither/__main__.py Refactored detector selection logic, added __include_detectors function, and new --include-detectors argument.
slither/utils/command_line.py Added detectors_to_include parameter to the FailOnLevel enum class.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant User
    participant CommandLine
    participant Main as slither/__main__.py
    participant Utils as slither/utils/command_line.py

    User->>CommandLine: Execute command with --include-detectors
    CommandLine->>Main: Parse arguments
    Main->>Utils: Include detectors based on user input
    Utils-->>Main: Return list of detectors to include
    Main->>Main: Use __include_detectors to refine selection
    Main->>User: Display selected detectors
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@0xalpharush 0xalpharush marked this pull request as ready for review June 4, 2024 20:11
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Outside diff range and nitpick comments (4)
slither/utils/command_line.py (4)

Line range hint 126-126: Use not in for membership tests to improve readability.

- if filter_wiki in detector.WIKI:
+ if filter_wiki not in detector.WIKI:

Line range hint 157-157: Consider renaming the variable l to a more descriptive name to avoid confusion with the number 1.


Line range hint 171-171: Consider renaming the variable l to a more descriptive name to avoid confusion with the number 1.


Line range hint 240-240: Use not in for membership tests to improve readability.

- if classification in classification_map.items():
+ if classification not in classification_map.items():
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9ee2ae0 and 221cfc6.

Files selected for processing (2)
  • slither/main.py (3 hunks)
  • slither/utils/command_line.py (1 hunks)
Additional context used
Ruff
slither/utils/command_line.py

126-126: Test for membership should be not in (E713)


157-157: Ambiguous variable name: l (E741)


171-171: Ambiguous variable name: l (E741)


240-240: Test for membership should be not in (E713)

Additional comments not posted (2)
slither/utils/command_line.py (1)

51-51: Ensure that the new detectors_to_include parameter is properly utilized in the code.

Verification successful

The new detectors_to_include parameter is properly utilized in the code.

  • Locations in the codebase:
    • slither/__main__.py: Multiple occurrences where detectors_to_include is used.
    • slither/utils/command_line.py: The parameter is defined.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the new parameter `detectors_to_include` is utilized properly in the code.

# Test: Search for the usage of `detectors_to_include`. Expect: At least one occurrence in the code.
rg --type python $'detectors_to_include'

Length of output: 70



Script:

#!/bin/bash
# Description: Verify that the new parameter `detectors_to_include` is utilized properly in the code.

# Test: Search for the usage of `detectors_to_include`. Expect: At least one occurrence in the code.
rg 'detectors_to_include' --glob '*.py'

Length of output: 518

slither/__main__.py (1)

14-14: Ensure that the updated import order follows PEP 8 guidelines.

Comment on lines +215 to +240
detectors_to_run = __include_detectors(
set(detectors_to_run), args.detectors_to_run, detectors
)
return detectors_to_run

if args.exclude_optimization:
detectors_to_run = [
d for d in detectors_to_run if d.IMPACT != DetectorClassification.OPTIMIZATION
]
classification_map = {
DetectorClassification.HIGH: args.exclude_high,
DetectorClassification.MEDIUM: args.exclude_medium,
DetectorClassification.LOW: args.exclude_low,
DetectorClassification.INFORMATIONAL: args.exclude_informational,
DetectorClassification.OPTIMIZATION: args.exclude_optimization,
}
excluded_classification = [
classification for classification, included in classification_map.items() if included
]
detectors_to_run = [d for d in detectors_to_run if d.IMPACT not in excluded_classification]

if args.exclude_informational:
detectors_to_run = [
d for d in detectors_to_run if d.IMPACT != DetectorClassification.INFORMATIONAL
]
if args.exclude_low:
detectors_to_run = [d for d in detectors_to_run if d.IMPACT != DetectorClassification.LOW]
if args.exclude_medium:
detectors_to_run = [
d for d in detectors_to_run if d.IMPACT != DetectorClassification.MEDIUM
]
if args.exclude_high:
detectors_to_run = [d for d in detectors_to_run if d.IMPACT != DetectorClassification.HIGH]
if args.detectors_to_exclude:
detectors_to_run = [
d for d in detectors_to_run if d.ARGUMENT not in args.detectors_to_exclude
]

detectors_to_run = sorted(detectors_to_run, key=lambda x: x.IMPACT)
if args.detectors_to_include:
detectors_to_run = __include_detectors(
set(detectors_to_run), args.detectors_to_include, detectors
)
Copy link
Contributor

Choose a reason for hiding this comment

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

The changes to choose_detectors introduce new logic for including detectors based on user input. Ensure this new functionality is covered by unit tests.

Would you like me to help with writing the unit tests for this functionality?

Comment on lines +245 to +259
def __include_detectors(
detectors_to_run: Set[Type[AbstractDetector]],
detectors_to_include: str,
detectors: Dict[str, Type[AbstractDetector]],
) -> List[Type[AbstractDetector]]:
include_detectors = detectors_to_include.split(",")

for detector in include_detectors:
if detector in detectors:
detectors_to_run.add(detectors[detector])
else:
raise ValueError(f"Error: {detector} is not a detector")

detectors_to_run = sorted(detectors_to_run, key=lambda x: x.IMPACT)
return detectors_to_run
Copy link
Contributor

Choose a reason for hiding this comment

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

The implementation of __include_detectors is straightforward and follows the expected logic. Consider improving error handling by providing more detailed error messages or suggestions for valid inputs when an error occurs.

- raise ValueError(f"Error: {detector} is not a detector")
+ raise ValueError(f"Error: {detector} is not a valid detector. Please check the detector name or refer to the documentation for a list of valid detectors.")
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
def __include_detectors(
detectors_to_run: Set[Type[AbstractDetector]],
detectors_to_include: str,
detectors: Dict[str, Type[AbstractDetector]],
) -> List[Type[AbstractDetector]]:
include_detectors = detectors_to_include.split(",")
for detector in include_detectors:
if detector in detectors:
detectors_to_run.add(detectors[detector])
else:
raise ValueError(f"Error: {detector} is not a detector")
detectors_to_run = sorted(detectors_to_run, key=lambda x: x.IMPACT)
return detectors_to_run
def __include_detectors(
detectors_to_run: Set[Type[AbstractDetector]],
detectors_to_include: str,
detectors: Dict[str, Type[AbstractDetector]],
) -> List[Type[AbstractDetector]]:
include_detectors = detectors_to_include.split(",")
for detector in include_detectors:
if detector in detectors:
detectors_to_run.add(detectors[detector])
else:
raise ValueError(f"Error: {detector} is not a valid detector. Please check the detector name or refer to the documentation for a list of valid detectors.")
detectors_to_run = sorted(detectors_to_run, key=lambda x: x.IMPACT)
return detectors_to_run

@0xalpharush 0xalpharush merged commit dc767b1 into dev Jun 4, 2024
83 checks passed
@0xalpharush 0xalpharush deleted the chore/remove-unused-scripts branch June 4, 2024 20:14
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.

2 participants