44
55
66class SafeNavigationRemovalModifier (RubyProceduralModifier ):
7- explanation : str = "A safe navigation operator (&.) has been removed, allowing nil to propagate."
7+ explanation : str = (
8+ "A safe navigation operator (&.) has been removed, allowing nil to propagate."
9+ )
810 name : str = "func_pm_ruby_safe_nav_removal"
911 conditions : list = [CodeProperty .IS_FUNCTION , CodeProperty .HAS_FUNCTION_CALL ]
1012
@@ -21,7 +23,9 @@ def modify(self, code_entity: CodeEntity) -> BugRewrite:
2123 candidates = []
2224 for call in calls :
2325 for child in call .children :
24- if child .type == "&." or (hasattr (child , 'text' ) and child .text == b"&." ):
26+ if child .type == "&." or (
27+ hasattr (child , "text" ) and child .text == b"&."
28+ ):
2529 candidates .append (child )
2630
2731 if not candidates :
@@ -42,7 +46,9 @@ def modify(self, code_entity: CodeEntity) -> BugRewrite:
4246
4347
4448class OrDefaultRemovalModifier (RubyProceduralModifier ):
45- explanation : str = "A fallback default (|| value) has been removed, allowing nil to propagate."
49+ explanation : str = (
50+ "A fallback default (|| value) has been removed, allowing nil to propagate."
51+ )
4652 name : str = "func_pm_ruby_or_default_removal"
4753 conditions : list = [CodeProperty .IS_FUNCTION , CodeProperty .HAS_BINARY_OP ]
4854
@@ -58,7 +64,7 @@ def modify(self, code_entity: CodeEntity) -> BugRewrite:
5864 candidates = []
5965 for node in binaries :
6066 for child in node .children :
61- if hasattr (child , ' text' ) and child .text in (b"||" , b"or" ):
67+ if hasattr (child , " text" ) and child .text in (b"||" , b"or" ):
6268 candidates .append (node )
6369 break
6470
@@ -68,7 +74,9 @@ def modify(self, code_entity: CodeEntity) -> BugRewrite:
6874 target = self .rand .choice (candidates )
6975 # Replace with just the left operand
7076 left = target .children [0 ]
71- left_text = code_entity .src_code .encode ("utf8" )[left .start_byte :left .end_byte ].decode ("utf8" )
77+ left_text = code_entity .src_code .encode ("utf8" )[
78+ left .start_byte : left .end_byte
79+ ].decode ("utf8" )
7280
7381 modified_code = self .replace_node (code_entity .src_code , target , left_text )
7482
@@ -122,7 +130,9 @@ def modify(self, code_entity: CodeEntity) -> BugRewrite:
122130
123131 call , receiver = self .rand .choice (candidates )
124132 src_bytes = code_entity .src_code .encode ("utf8" )
125- receiver_text = src_bytes [receiver .start_byte :receiver .end_byte ].decode ("utf8" )
133+ receiver_text = src_bytes [receiver .start_byte : receiver .end_byte ].decode (
134+ "utf8"
135+ )
126136 modified_code = self .replace_node (code_entity .src_code , call , receiver_text )
127137
128138 valid = self .validate_syntax (code_entity .src_code , modified_code )
@@ -140,7 +150,9 @@ def modify(self, code_entity: CodeEntity) -> BugRewrite:
140150
141151
142152class BangMethodStripModifier (RubyProceduralModifier ):
143- explanation : str = "A bang method (!) has been replaced with its non-raising variant."
153+ explanation : str = (
154+ "A bang method (!) has been replaced with its non-raising variant."
155+ )
144156 name : str = "func_pm_ruby_bang_method_strip"
145157 conditions : list = [CodeProperty .IS_FUNCTION , CodeProperty .HAS_FUNCTION_CALL ]
146158
@@ -180,7 +192,9 @@ def modify(self, code_entity: CodeEntity) -> BugRewrite:
180192
181193
182194class OrEqualsRemovalModifier (RubyProceduralModifier ):
183- explanation : str = "A memoization operator (||=) has been replaced with plain assignment."
195+ explanation : str = (
196+ "A memoization operator (||=) has been replaced with plain assignment."
197+ )
184198 name : str = "func_pm_ruby_or_equals_removal"
185199 conditions : list = [CodeProperty .IS_FUNCTION , CodeProperty .HAS_ASSIGNMENT ]
186200
@@ -196,7 +210,7 @@ def modify(self, code_entity: CodeEntity) -> BugRewrite:
196210 candidates = []
197211 for node in op_assigns :
198212 for child in node .children :
199- if hasattr (child , ' text' ) and child .text == b"||=" :
213+ if hasattr (child , " text" ) and child .text == b"||=" :
200214 candidates .append (child )
201215
202216 if not candidates :
0 commit comments