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

Aggregating All Rules Implemented for the Thesis (Do not merge!) #22

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ jobs:

cargo-test-linux:
name: "cargo test (linux)"
runs-on: depot-ubuntu-22.04-16
runs-on: ubuntu-latest
needs: determine_changes
if: ${{ needs.determine_changes.outputs.code == 'true' || github.ref == 'refs/heads/main' }}
timeout-minutes: 20
Expand Down Expand Up @@ -160,10 +160,10 @@ jobs:

cargo-test-linux-release:
name: "cargo test (linux, release)"
runs-on: depot-ubuntu-22.04-16
runs-on: ubuntu-latest
needs: determine_changes
if: ${{ needs.determine_changes.outputs.code == 'true' || github.ref == 'refs/heads/main' }}
timeout-minutes: 20
timeout-minutes: 25
steps:
- uses: actions/checkout@v4
- name: "Install Rust toolchain"
Expand All @@ -187,7 +187,7 @@ jobs:

cargo-test-windows:
name: "cargo test (windows)"
runs-on: windows-latest-xlarge
runs-on: windows-latest
needs: determine_changes
if: ${{ needs.determine_changes.outputs.code == 'true' || github.ref == 'refs/heads/main' }}
timeout-minutes: 20
Expand Down Expand Up @@ -362,7 +362,7 @@ jobs:

ecosystem:
name: "ecosystem"
runs-on: depot-ubuntu-latest-8
runs-on: ubuntu-latest
needs:
- cargo-test-linux
- determine_changes
Expand Down
133 changes: 133 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/ruff/RUF050.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import math # Import statements can appear at the top of a file or within a class

class ExampleClass:
"""A class demonstrating all kinds of statements."""

# Class attributes (class variables)
class_var1 = "class-level attribute"
class_var2 = 42

# Instance attributes will be defined in the constructor
def __init__(self, instance_var):
"""Constructor to initialize instance attributes."""
self.instance_var = instance_var # Instance variable
self.computed_var = self._helper_method() # Using a helper method in initialization

# Instance method
def instance_method(self):
"""Regular instance method."""
print("This is an instance method.")
self._private_method()

# Private method (conventionally prefixed with an underscore)
def _private_method(self):
"""A private helper method."""
print("This is a private method.")

# Protected method (by convention, a single leading underscore indicates protected)
def _protected_method(self):
print("This is a protected method.")

# Static method
@staticmethod
def static_method():
"""A static method."""
print("Static method called. No access to instance or class data.")

# Class method
@classmethod
def class_method(cls):
"""A class method."""
print(f"Class method called. class_var1 = {cls.class_var1}")

# Special method (dunder methods)
def __str__(self):
"""Special method for string representation."""
return f"ExampleClass(instance_var={self.instance_var}, computed_var={self.computed_var})"

def __len__(self):
"""Special method to define the behavior of len()."""
return len(self.instance_var)

# Nested class
class NestedClass:
"""A class defined within another class."""
def nested_method(self):
print("Method of a nested class.")

# Pass statement (used as a placeholder)
def placeholder_method(self):
"""A method with no implementation yet."""
pass

# Try/Except block inside a method
def error_handling_method(self):
"""A method with error handling."""
try:
result = 10 / 0 # Intentional error
except ZeroDivisionError as e:
print(f"Caught an exception: {e}")
finally:
print("Cleanup actions can be placed here.")

# Using a decorator
@property
def readonly_property(self):
"""A read-only property."""
return self.computed_var

@readonly_property.setter
def readonly_property(self, value):
"""Attempt to set this property raises an error."""
raise AttributeError("This property is read-only.")

# Conditional logic inside the class (not recommended but valid)
if math.pi > 3:
def conditionally_defined_method(self):
print("This method exists because math.pi > 3.")

# For loop inside the class (unusual but valid)
for i in range(3):
exec(f"def loop_method_{i}(self): print('Loop-defined method {i}')")

# Docstrings for the class
"""
Additional class-level comments can be included in the docstring.
"""

# List comprehensions inside a class (valid but rarely used)
squares = [x ** 2 for x in range(5)]

# Lambda functions inside a class (unusual but valid)
double = lambda x: x * 2


g = 'module attribute (module-global variable)'
"""This is g's docstring."""

class AClass:

c = 'class attribute'
"""This is AClass.c's docstring."""

def __init__(self):
"""Method __init__'s docstring."""

self.i = 'instance attribute'
"""This is self.i's docstring."""

class BClass:
...

class CClass:
pass

class DClass:
"""Empty class."""

def f(x):
"""Function f's docstring."""
return x**2

f.a = 1
"""Function attribute f.a's docstring."""
40 changes: 40 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/ruff/RUF051.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
x1 in {"TEST"} # [RUF051]

x2 in ["TEST"] # [RUF051]

x3 in {"x": "TEST"} # [RUF051]

single = ["TEST"]
single.append("TEST2")

x4 in single

single = ["TEST"]

x5 in single

x6 in [single] # [RUF051]

x7 in [*single]

x8 in ["TEST", "TEST"] in ["TEST"] # [RUF051]

x9 in ["TEST"] in ["TEST", "TEST"] # [RUF051]

2 < x10 in [3] # [RUF051]

x10 in (2,) # [RUF051]

x11 in {"1": 1, "2": 2}

x12 in [1, 2]

x13 in {1, 2}

x14 in (1, 4)

x15 in [x for x in range(1)]

x16 in [1] in [2] # 2x [RUF051]

17 in [17] in [[17]] # 2x [RUF051]
38 changes: 38 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/wps_light/WPS116.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

# correct

a: int

for _ in range(1):
pass

_ = 1

_private_variable = 1

CONSTANT_VARIABLE = 1

def function_name():
in_function_variable = 1

long_variable_name = 1

class ClassName:
def __dunder_method__(self, parameter_x):
pass


# incorect

_private__variable = 1

CONSTANT__VARIABLE = 1

def function__name():
in_function__variable = 1

long__variable___name = 1

class ClassName:
def __dunder___method__(self, parameter_x):
pass
38 changes: 38 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/wps_light/WPS117.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

def x1(a, b, self): ...

def x2(a, b, c):
cls = 3

class X:
self = 3
cls = 3
mcs = 3

def x3(a, b, self): ...

def x4(a, b, c):
cls = 3

def x4(self=3):
...

x = cls = 5
x = lambda self: self + 12
self = 2
mcs = 2


self_ = 3
cls_ = 3
mcs_ = 3

class X:
self_ = 3
cls_ = 3
mcs_ = 3

def x5(self, a): ...

def x6(cls, c):
cls.self_ = 3
66 changes: 66 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/wps_light/WPS303.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
.1
1.
1E+1
1E-1
1.E+1
1.0E+1
1.1E+1

x = 123456789
x = 123456
x = .1
x = 1.
x = 1E+1
x = 1E-1
x = 1.000_000_01
x = 123456789.123456789
x = 123456789.123456789E123456789
x = 123456789E123456789
x = 123456789J
x = 123456789.123456789J
x = 0XB1ACC
x = 0B1011
x = 0O777
x = 0.000000006
x = 10000
x = 133333

# Attribute access
x = 1. .imag
x = 1E+1.imag
x = 1E-1.real
x = 123456789.123456789.hex()
x = 123456789.123456789E123456789 .real
x = 123456789E123456789 .conjugate()
x = 123456789J.real
x = 123456789.123456789J.__add__(0b1011.bit_length())
x = 0XB1ACC.conjugate()
x = 0B1011 .conjugate()
x = 0O777 .real
x = 0.000000006 .hex()
x = -100.0000J

if 10 .real:
...

# This is a type error, not a syntax error
y = 100[no]
y = 100(no)

bin = 0b1001_1010_0001_0100
hex = 0x1b_a0_44_fe
dec = 33_554_432
real = 1_000.111_1e-1_000

valid = 0_0_0
also_ok = 000
4_2
1_0000_0000
0b1001_0100
0xffff_ffff
0o5_7_7
1_00_00.5
1e1_0
.1_4
0x_f
0o_5
18 changes: 18 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/wps_light/WPS362.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
a[1:3] = [1, 2]
a[slice(1)] = [1, 3]

a[:0], a[-1:] = prefix, suffix

a[:] = complete_replacement

a[0:0] = prepend

a[0] = 1


size = 3
board = [["_"] * size for _ in range(size)]

board[0:1][1:2] = "X"

board[0] = board[0:1] = board[1:2] = [board[0][:], board[1][:], board[2][:]] = board
Loading
Loading