Skip to content

path/filepath: improve Rel's documentation #75893

@miekg

Description

@miekg

Go version

1.25.2

Output of go env in your module/workspace:

not relevant

What did you do?

godoc filepath.Rel

What did you see happen?

it shows:

func Rel(basepath, targpath string) (string, error)
    Rel returns a relative path that is lexically equivalent to targpath when
    joined to basepath with an intervening separator. That is, Join(basepath,
    Rel(basepath, targpath)) is equivalent to targpath itself. On success,
    the returned path will always be relative to basepath, even if basepath and
    targpath share no elements. An error is returned if targpath can't be made
    relative to basepath or if knowing the current working directory would be
    necessary to compute it. Rel calls Clean on the result.

What did you expect to see?

As a non-native English speaker, I have a very hard time parsing this text. I (mostly) need this function to figure out if targpath sits below basepath, but whenever I reach for it, I'm stumped every time.

I'm not sure how a better text would look like though. The words 'lexically' and 'intervening seperator' in the first sentence don't help though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.FixPendingIssues that have a fix which has not yet been reviewed or submitted.help wanted

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions