Skip to content

Ruff Showcase #3

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
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
17 changes: 17 additions & 0 deletions ruff/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os, sys # F401: sys imported but unused
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove unused imports to clean up the code.

Both os and sys modules are imported but never used in the code. Remove these unused imports to improve code clarity and pass static analysis checks.

-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 ruff/example.py at line 1, both os and sys modules are imported but not used
anywhere in the code. Remove the entire import statement to eliminate unused
imports and improve code clarity.


def my_function( x, y ):
print( "Result:",x+y ) # E201, E202, E231, E221
Comment on lines +3 to +4
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix spacing and formatting issues in the function definition.

The function definition contains multiple formatting problems: excessive spaces around parameters, inconsistent spacing in the print statement, and missing space after the comma in the addition operation.

-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 ruff/example.py around lines 3 to 4, fix the spacing and formatting issues by
removing extra spaces around the parameters in the function definition, ensuring
consistent single spaces after commas and operators, and adjusting the print
statement to have proper spacing between elements for readability and compliance
with style guidelines.


class myclass: # N801: class name should use CapWords convention
def __init__(self):
self.value =42 # E225: missing whitespace around operator
Comment on lines +6 to +8
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Follow Python naming conventions and fix spacing issues.

The class name violates Python naming conventions (should use CapWords), and the assignment operator lacks proper whitespace.

-class myclass:  # N801: class name should use CapWords convention
- def __init__(self):
-     self.value =42  # E225: missing whitespace around operator
+class MyClass:
+    def __init__(self):
+        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
class myclass: # N801: class name should use CapWords convention
def __init__(self):
self.value =42 # E225: missing whitespace around operator
class MyClass:
def __init__(self):
self.value = 42
🤖 Prompt for AI Agents
In ruff/example.py around lines 6 to 8, rename the class from 'myclass' to
'MyClass' to follow Python's CapWords naming convention, and add spaces around
the assignment operator in 'self.value =42' to correct the spacing issue, making
it 'self.value = 42'.


def doSomething(self): # N802: function name should be snake_case
if( self.value>0 ):
print("Positive")
else:
print( "Not positive" )
Comment on lines +10 to +14
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Apply snake_case naming and fix formatting inconsistencies.

The method name violates Python naming conventions (should use snake_case), and the conditional statement has spacing issues and inconsistent indentation.

- 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 ruff/example.py around lines 10 to 14, rename the method from doSomething to
do_something to follow Python's snake_case naming convention. Also, fix
formatting by removing unnecessary parentheses around the if condition, adding
spaces around the comparison operator, and ensuring consistent indentation and
spacing inside the print statements.


my_function(1,2)