-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow nilable Spoom::Location lines and columns attributes #587
Conversation
Are there perhaps two distinct concepts here that should be seperated out, e.g. |
Seconding Andy's question, |
lib/spoom/location.rb
Outdated
start_line, end_line = T.must(start_line).split("-", 2) | ||
return new(file, start_line: start_line.to_i, end_line: end_line.to_i) if end_line | ||
|
||
raise LocationError, "Invalid location. End line is missing in range format: #{location_string}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer an early raise and an unconditional return:
start_line, end_line = T.must(start_line).split("-", 2) | |
return new(file, start_line: start_line.to_i, end_line: end_line.to_i) if end_line | |
raise LocationError, "Invalid location. End line is missing in range format: #{location_string}" | |
start_line, end_line = T.must(start_line).split("-", 2) | |
raise LocationError, "Invalid location. End line is missing in range format: #{location_string}" unless end_line | |
return new(file, start_line: start_line.to_i, end_line: end_line.to_i) if end_line |
So the style and logic is coherent with the other branches.
Indeed, maybe the For now, the nilability change suits our needs and doesn't commit us to one direction or another 👍 |
f3cc42a
to
ad88da3
Compare
1cdfd36
to
4163416
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small nit, we can merge once fixed 🎉
lib/spoom/location.rb
Outdated
if rest.nil? | ||
raise LocationError, "Invalid location string `#{location_string}`: missing end line and column" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this fit in one line?
if rest.nil? | |
raise LocationError, "Invalid location string `#{location_string}`: missing end line and column" | |
raise LocationError, "Invalid location string `#{location_string}`: missing end line and column" if rest.nil? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does, good catch! 🕵️
This change allows the start/end line/column attributes of a Location to be nilable. A `Spoom::Location` can now either be a whole file `foo.rb`, have start and end lines `foo.rb:1-3`, or also include start and end columns `foo.rb:1:2-3:4`.
4163416
to
c60632f
Compare
Summary
This PR updates the
Spoom::Location
class to allow thestart_line
,end_line
,start_column
, andend_column
attributes to benilable
. This change provides greater flexibility in representing different types of locations within a file.Details
start_line
,end_line
,start_column
, andend_column
attributes ofSpoom::Location
can now be nil.Spoom::Location
Representation:foo.rb
.foo.rb:1-3
.foo.rb:1:2-3:4
.What should Reviewers pay attention to
Spoom::Location
class to improve debugging and error handling. Unsure if this is a good change.Float::Infinity
: IntroducedFloat::Infinity
to represent inclusivity when lines or columns are nil, ensuring that ranges can be handled correctly even when the start or end is not explicitly known.