Fix new Lint/AmbiguousRange unsafe offenses#62
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR addresses new Lint/AmbiguousRange offenses by replacing inclusive ranges with exclusive ones in string slicing.
- Replace
0..last_slash_pos - 1with0...last_slash_posinsplit_path - Update endless ranges to avoid ambiguous syntax in both
split_pathandsanitize_filename
Comments suppressed due to low confidence (2)
lib/sharepoint/client.rb:632
- Add a unit test for
split_pathwhenfile_pathcontains no/(solast_slash_posisnil) to ensure this new exclusive range usage handles that edge case without raising an error.
path: file_path[0...last_slash_pos],
lib/sharepoint/client.rb:743
- [nitpick] Consider adding tests for
sanitize_filenameboundary conditions (e.g., filenames without extensions, maximum lengths, or dot positions) to validate the new exclusive-end slicing logic behaves as expected.
sanitized_filename = sanitized_filename[0..upper_bound] + sanitized_filename[dot_index...sanitized_filename.length]
No functional change is intended, as these adjustments are semantically equivalent in this context. - Manually replaced ambiguous inclusive ranges (`..`) with exclusive ranges (`...`) for improved code clarity - Applied RuboCop's automatic correction to refactor ranges with expressions like `[(start + 1)..end]`
1f72e5e to
f343f24
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
- 1, by using...instead of..+ 1