Skip to content

Conversation

@chandler-solo
Copy link

@chandler-solo chandler-solo commented Nov 8, 2025

ln -s worktree wt && cd wt && golangci-lint fmt now works

'ln -s worktree wt && cd wt && golangci-lint fmt' now works

Signed-off-by: David L. Chandler <[email protected]>
@CLAassistant
Copy link

CLAassistant commented Nov 8, 2025

CLA assistant check
All committers have signed the CLA.

@boring-cyborg
Copy link

boring-cyborg bot commented Nov 8, 2025

Hey, thank you for opening your first Pull Request !

@ldez ldez self-requested a review November 8, 2025 04:46
@ldez ldez changed the title Fixes an issue with the 'fmt' command and symbolic links. fix: follows symbolic links with fmt command Nov 8, 2025
@ldez ldez self-assigned this Nov 8, 2025
@ldez ldez changed the title fix: follows symbolic links with fmt command fix: follows symbolic links with formatter exclusion paths Nov 8, 2025
@ldez ldez force-pushed the chandler/symlink-fmt branch from e7aa83f to f467aa2 Compare November 8, 2025 06:44
@ldez ldez removed their assignment Nov 10, 2025
@ldez ldez added the declined label Nov 10, 2025
@ldez
Copy link
Member

ldez commented Nov 10, 2025

The problem supposedly fixed by this PR "issue with the 'fmt' command and symbolic links" is not fixed.

At first, I was thinking the PR title was wrong because the only change was in the exclusions system.
So I made some changes to fit that assumption.

But in fact, this PR fixes nothing, because the problem with symlinks is not here.

This is why it's better to open an issue before opening a PR, and when opening a PR, a real description is important.

I close this PR, and I will try to create the real fix.

@ldez ldez closed this Nov 10, 2025
@chandler-solo
Copy link
Author

ln -s worktree wt && cd wt && golangci-lint fmt

This is how to reproduce, on MacOS 15.7.1, with golangci-lint 2.6.1. You can work around the issue with golangci-lint fmt $(pwd -P)

This has nothing to do with formatter exclusion paths. My test case fails on main and passes with my changes.

@ldez
Copy link
Member

ldez commented Nov 11, 2025

Your commit is only modifying RunnerOptions.MatchAnyPattern method.

  1. This method is only related to formatter exclusion paths (patterns -> cfg.Formatters.Exclusions.Paths).
    If there is no pattern (exclusion paths), this method is skipped.

for _, pattern := range cfg.Formatters.Exclusions.Paths {
exp, err := regexp.Compile(fsutils.NormalizePathInRegex(pattern))
if err != nil {
return RunnerOptions{}, fmt.Errorf("compile path pattern %q: %w", pattern, err)
}
opts.patterns = append(opts.patterns, exp)
opts.excludedPathCounter[exp] = 0
}

if len(o.patterns) == 0 {
return false, nil
}

  1. Your comment The basePath is already resolved via fsutils.Getwd() in NewRunnerOptions. is wrong: fsutils.Getwd() is only called when wd mode is used. This mode is only one of the four modes (and not the default).

case RelativePathModeWd:
wd, err := Getwd()

  1. All the tests, inside your commit, are only testing formatter exclusion paths, and in the wrong way by playing with unexposed fields.
A concrete reproducer
#!/bin/sh -e

ROOT=$(mktemp -d)
mkdir -p $ROOT/project/

## Create module
cat > $ROOT/project/go.mod <<EOF
module github.com/golangci/sandbox

go1.24.0
EOF

# Create golangci-lint configuration file.
cat > $ROOT/project/.golangci.yaml <<EOF
version: "2"

formatters:
  enable:
    - gofmt
EOF

## Create main.go file.
cat > $ROOT/project/main.go <<EOF
package main

import "fmt"

func main() {
fmt.Println("hello world") // Formatting problem.
}
EOF

## Create symlink to the project directory.
ln -s $ROOT/project/ $ROOT/workdir


## Run golangci-lint inside the real project directory.
cd $ROOT/project

echo
echo "--------------------------"
echo "Run on the real project directory ($(pwd)):"
echo

golangci-lint fmt --diff || true

## Run golangci-lint inside the symlinked project directory.
cd $ROOT/workdir

echo
echo "--------------------------"
echo "Run on the symlinked project directory ($(pwd)):"
echo

golangci-lint fmt --diff || true

rm -rf $ROOT
$ ./setup.sh

--------------------------
Run on the real project directory (/tmp/tmp.5C7AJyRYRC/project):

diff /tmp/tmp.5C7AJyRYRC/project/main.go.orig /tmp/tmp.5C7AJyRYRC/project/main.go
--- /tmp/tmp.5C7AJyRYRC/project/main.go.orig
+++ /tmp/tmp.5C7AJyRYRC/project/main.go
@@ -3,5 +3,5 @@
 import "fmt"
 
 func main() {
-fmt.Println("hello world") // Formatting problem.
+       fmt.Println("hello world") // Formatting problem.
 }

--------------------------
Run on the symlinked project directory (/tmp/tmp.5C7AJyRYRC/workdir):

$

I will create a PR with the real fix.

@chandler-solo
Copy link
Author

chandler-solo commented Nov 11, 2025

That is the perfect reproducer. I'll open an issue next time with a real reproducer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants