Skip to content

The option --follow-symlinks can't follow relative symlinks #836

Closed
@kkebo

Description

@kkebo

Description

The subcommands lint and format have the option --follow-symlinks. However, although it can follow absolute symlinks, it can't follow relative symlinks.

Steps to reproduce

$ mkdir symlink-test
$ cd symlink-test/
$ echo 'let foo:Int=0' > .foo.swift
$ ln -s .foo.swift bar.swift
$ swift format dump-configuration > .swift-format
$ cd ..
$ swift format lint -rs --follow-symlinks symlink-test/
<unknown>: error: Unable to open .foo.swift: file is not readable or does not exist

If the current working directory is the symlink's directory, it works.

$ cd symlink-test
$ swift format lint -rs --follow-symlinks .
.foo.swift:1:9: warning: [Spacing] add 1 space
.foo.swift:1:12: warning: [Spacing] add 1 space
.foo.swift:1:13: warning: [Spacing] add 1 space

It's because the following line is using relativeTo: workingDirectory.

URL(fileURLWithPath: relativePath, isDirectory: false, relativeTo: workingDirectory)

Environment

  • swift-format (bundled in Swift 6.0.1 toolchain)
  • Debian 12 (aarch64)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions