Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Dan D'Avella <[email protected]>
  • Loading branch information
clavedeluna and drdavella authored Jan 5, 2024
1 parent 71f5844 commit 542445d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/codemodder/scripts/generate_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class DocMetadata:
),
"combine-startswith-endswith": DocMetadata(
importance="Low",
guidance_explained="Combining two `startswith` or `endswith` calls is safe and cleans up code.",
guidance_explained="Simplifying expressions involving `startswith` or `endswith` calls is safe.",
),
}

Expand Down
4 changes: 2 additions & 2 deletions src/core_codemods/combine_startswith_endswith.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

class CombineStartswithEndswith(BaseCodemod, NameResolutionMixin):
NAME = "combine-startswith-endswith"
SUMMARY = "Combine Two `startswith` or `endswith` Calls"
SUMMARY = "Simplify Boolean Expressions Using `startswith` and `endswith`"
REVIEW_GUIDANCE = ReviewGuidance.MERGE_WITHOUT_REVIEW
DESCRIPTION = "Combine two calls to either `startswith` or `endswith` joined by an `or` statement."
DESCRIPTION = "Use tuple of matches instead of boolean expression"
REFERENCES: list = []

def leave_BooleanOperation(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
This codemod updates places where two separate calls to either `startswith` or `endswith` are joined by an `or` statement.
The replacement code takes advantage of the fact that these two methods can accept a tuple as an argument.
Many developers are not necessarily aware that the `startswith` and `endswith` methods of `str` objects can accept a tuple of strings to match. This means that there is a lot of code that uses boolean expressions such as `x.startswith('foo') or x.startswith('bar')` instead of the simpler expression `x.startswith(('foo', 'bar'))`.

This codemod simplifies the boolean expressions where possible which leads to cleaner and more concise code.

The changes from this codemod look like this:

Expand Down

0 comments on commit 542445d

Please sign in to comment.