-
Notifications
You must be signed in to change notification settings - Fork 7
Semgrep Showcase #10
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
Semgrep Showcase #10
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,16 @@ | ||||||||||||||||||||||
| import os, sys # F401: sys imported but unused | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def my_function( x, y ): | ||||||||||||||||||||||
| print( "Result:",x+y ) # E201, E202, E231, E221 | ||||||||||||||||||||||
|
||||||||||||||||||||||
| def my_function( x, y ): | |
| print( "Result:",x+y ) # E201, E202, E231, E221 | |
| def my_function(x, y): | |
| print("Result:", x + y) |
🤖 Prompt for AI Agents
In semgrep/example.py around lines 3 to 4, fix the spacing and formatting issues
by removing extra spaces around the function parameters and adding appropriate
spaces around operators and after commas. Ensure the function definition and
print statement follow standard Python style conventions for readability.
Outdated
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.
🛠️ Refactor suggestion
Use CapWords convention for class names.
The class name myclass violates PEP8 naming conventions. Class names should use CapWords (PascalCase).
-class myclass: # N801: class name should use CapWords convention
+class MyClass:📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.
| class myclass: # N801: class name should use CapWords convention | |
| class MyClass: |
🤖 Prompt for AI Agents
In semgrep/example.py at line 6, the class name `myclass` does not follow PEP8
naming conventions which require class names to use CapWords (PascalCase).
Rename the class to `MyClass` or another appropriate PascalCase name to comply
with the style guide.
Outdated
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.
🛠️ Refactor suggestion
Fix whitespace around the assignment operator.
The assignment statement lacks proper spacing around the equals operator.
def __init__(self):
- self.value =42 # E225: missing whitespace around operator
+ self.value = 42📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.
| def __init__(self): | |
| self.value =42 # E225: missing whitespace around operator | |
| def __init__(self): | |
| - self.value =42 # E225: missing whitespace around operator | |
| + self.value = 42 |
🤖 Prompt for AI Agents
In semgrep/example.py at lines 7 to 8, the assignment statement in the __init__
method lacks proper spacing around the equals operator. Add a space before and
after the equals sign in "self.value =42" to correct the whitespace issue.
Outdated
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.
🛠️ Refactor suggestion
Apply snake_case naming and fix spacing issues.
The method name violates PEP8 conventions and the conditional statement has unnecessary parentheses with poor spacing.
- def doSomething(self): # N802: function name should be snake_case
- if( self.value>0 ):
- print("Positive")
- else:
- print( "Not positive" )
+ def do_something(self):
+ if self.value > 0:
+ print("Positive")
+ else:
+ print("Not positive")📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.
| def doSomething(self): # N802: function name should be snake_case | |
| if( self.value>0 ): | |
| print("Positive") | |
| else: | |
| print( "Not positive" ) | |
| def do_something(self): | |
| if self.value > 0: | |
| print("Positive") | |
| else: | |
| print("Not positive") |
🤖 Prompt for AI Agents
In semgrep/example.py around lines 10 to 14, rename the method doSomething to
do_something to follow snake_case naming conventions. Remove the unnecessary
parentheses around the if condition and fix spacing by adding spaces after if
and around the comparison operator. Also, ensure consistent spacing inside the
print statements by removing extra spaces.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| rules: | ||
| - id: hardcoded-password | ||
| pattern: password = "$SECRET" | ||
| message: "Avoid hardcoded passwords" | ||
| severity: ERROR | ||
| languages: [python] | ||
| metadata: | ||
| category: security |
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.
🛠️ Refactor suggestion
Remove unused imports to clean up the code.
Both
osandsysimports are unused throughout the file. Remove them to improve code clarity and avoid linting warnings.-import os, sys # F401: sys imported but unused📝 Committable suggestion
🧰 Tools
🪛 Ruff (0.12.2)
1-1:
osimported but unusedRemove unused import
(F401)
1-1:
sysimported but unusedRemove unused import
(F401)
🤖 Prompt for AI Agents