Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Closed
nimratcoderabbit wants to merge 3 commits into main from preview/semgrep
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions semgrep/example.py
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import os, sys # F401: sys imported but unused
Copy link

@coderabbitai coderabbitai bot Jul 14, 2025

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 os and sys imports 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

!!️ 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.

Suggested change
import os, sys # F401: sys imported but unused
🧰 Tools
🪛 Ruff (0.12.2)

1-1: os imported but unused

Remove unused import

(F401)


1-1: sys imported but unused

Remove unused import

(F401)

🤖 Prompt for AI Agents
In semgrep/example.py at line 1, both 'os' and 'sys' modules are imported but
not used anywhere in the file. Remove the entire import statement to clean up
the code and eliminate linting warnings about unused imports.


def my_function( x, y ):
print( "Result:",x+y ) # E201, E202, E231, E221
Copy link

@coderabbitai coderabbitai bot Jul 14, 2025

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Fix spacing and formatting issues in the function.

The function has several style violations including extra spaces around parameters and missing spaces around operators.

-def my_function( x, y ):
- print( "Result:",x+y ) # E201, E202, E231, E221
+def my_function(x, y):
+ print("Result:", x + y)
📝 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.

Suggested change
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.


class myclass: # N801: class name should use CapWords convention
Copy link

@coderabbitai coderabbitai bot Jul 14, 2025

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.

Suggested change
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.

def __init__(self):
self.value =42 # E225: missing whitespace around operator
Copy link

@coderabbitai coderabbitai bot Jul 14, 2025

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.

Suggested change
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.


def doSomething(self): # N802: function name should be snake_case
if( self.value>0 ):
print("Positive")
else:
print( "Not positive" )
Copy link

@coderabbitai coderabbitai bot Jul 14, 2025

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.

Suggested change
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.


my_function(1,2)
8 changes: 8 additions & 0 deletions semgrep/semgrep.yml
View file Open in desktop
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

AltStyle によって変換されたページ (->オリジナル) /