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.
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’m a little skeptical of this. When forming a URL, we provide a
baseURL
and a path relative to it. Generally, I wouldn’t expect it to matter what’s part of the base URL and what’s part of the relative path. For example, I would have expectedurl = URL(string: url.absoluteString)
to not have any effect on the output but with this change it does.What I’d prefer instead is some way of stripping off a known base path from
context.fileURL
here (though I don’t have concrete suggestions of how to do so at the moment).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.
FWIW, this change would bring the pretty printer to be consistent with how we're using the
relativePath
property elsewhere.When we create the
SourceLocationConverter
that the other non-pretty-printer rules use in Context.swift, we use therelativePath
property.Then, in FileIterator.swift, we have a bunch of logic that explicitly constructs the
URL
s this way. (In fact, I thought we were usingFileManager.DirectoryEnumerationOptions.producesRelativePathURLs
here, but that doesn't seem to be the case. That might have been historical, or there might have been a platform-specific issue that prevented it.)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.
As @allevato mentioned, other parts of the codebase already use
relativePath
except forPrettyPrinter
, so I thought it would be fine to change it to use the same property for consistency.Would it be better to implement a separate logic to derive relative path, similar to what's done in FileIterator, and apply it across all rule diagnostics, including
PrettyPrinter
?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.
Oh, OK. I didn’t realize that we already used
relativePath
elsewhere. While I have the same objection still in principle, I don’t object to adding another use for it if there’s already precedence.