diff --git a/src/codemodder/scripts/generate_docs.py b/src/codemodder/scripts/generate_docs.py index c98765d53..7d53f97a8 100644 --- a/src/codemodder/scripts/generate_docs.py +++ b/src/codemodder/scripts/generate_docs.py @@ -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.", ), } diff --git a/src/core_codemods/combine_startswith_endswith.py b/src/core_codemods/combine_startswith_endswith.py index eed14264d..070497bc1 100644 --- a/src/core_codemods/combine_startswith_endswith.py +++ b/src/core_codemods/combine_startswith_endswith.py @@ -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( diff --git a/src/core_codemods/docs/pixee_python_combine-startswith-endswith.md b/src/core_codemods/docs/pixee_python_combine-startswith-endswith.md index 7ece8b175..ca5e51fc9 100644 --- a/src/core_codemods/docs/pixee_python_combine-startswith-endswith.md +++ b/src/core_codemods/docs/pixee_python_combine-startswith-endswith.md @@ -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: