Skip to content

Commit 042b18c

Browse files
committed
Fixed skipping logic
1 parent 5c37c17 commit 042b18c

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/codemodder/codemods/base_codemod.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ def _apply_remediation(
193193
"""
194194
Applies remediation behavior to a codemod, that is, each changeset will only be associated with a single finging and no files will be written.
195195
"""
196+
if self._should_skip(context):
197+
return None
196198
results: ResultSet | None = self._apply_detector(context)
197199

198200
if results is not None and not results:
@@ -248,6 +250,8 @@ def _apply_hardening(
248250
"""
249251
Applies hardening behavior to a codemod with the goal of integrating all fixes for each finding into the files.
250252
"""
253+
if self._should_skip(context):
254+
return None
251255
results: ResultSet | None = self._apply_detector(context)
252256

253257
if results is not None and not results:
@@ -276,15 +280,15 @@ def _apply_hardening(
276280
context.process_results(self.id, contexts)
277281
return None
278282

279-
def _apply_detector(self, context: CodemodExecutionContext) -> ResultSet | None:
283+
def _should_skip(self, context: CodemodExecutionContext):
280284
if self.provider and (
281285
not (provider := context.providers.get_provider(self.provider))
282286
or not provider.is_available
283287
):
284288
logger.warning(
285289
"provider %s is not available, skipping codemod", self.provider
286290
)
287-
return None
291+
return True
288292

289293
if isinstance(self.detector, SemgrepRuleDetector):
290294
if (
@@ -296,7 +300,10 @@ def _apply_detector(self, context: CodemodExecutionContext) -> ResultSet | None:
296300
"no results from semgrep for %s, skipping analysis",
297301
self.id,
298302
)
299-
return None
303+
return True
304+
return False
305+
306+
def _apply_detector(self, context: CodemodExecutionContext) -> ResultSet | None:
300307

301308
results: ResultSet | None = (
302309
# It seems like semgrep doesn't like our fully-specified id format so pass in short name instead.
@@ -429,6 +436,7 @@ def apply(
429436
self, context: CodemodExecutionContext, remediation: bool = False
430437
) -> None | TokenUsage:
431438
if remediation:
439+
print("0000000000000000000000000000000000000000000000000000000000")
432440
return self._apply_remediation(context, self.requested_rules)
433441
return self._apply_hardening(context, self.requested_rules)
434442

0 commit comments

Comments
 (0)