Skip to content
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

different output for stdin vs passing in filename #277

Closed
chrisplo opened this issue Jul 12, 2023 · 1 comment
Closed

different output for stdin vs passing in filename #277

chrisplo opened this issue Jul 12, 2023 · 1 comment

Comments

@chrisplo
Copy link

chrisplo commented Jul 12, 2023

using v0.5.0

import (
...
mymodule/mypackage
...
)
gets formatted in a separate block when running like gofumpt myfile.go
but cat myfile.go formats differently
in both cases the current working directory is the package for mayflie.go and that package is in the same module

I ran across this with null-ls integration at https://github.com/jose-elias-alvarez/null-ls.nvim/blob/main/lua/null-ls/builtins/formatting/gofumpt.lua uses stdin. There it uses stdin with the new file contents (can't use the file argument as the file is the old contents).

using stdin in the uql directory

cat client.go | gofumpt | head -8
package uql

import (
	"appsecviz/platform"
	"appsecviz/util" 

using filename in the uql directory

gofumpt client.go | head -8
package uql

import (
	"bytes"
	"context" 
@mvdan
Copy link
Owner

mvdan commented Jul 13, 2023

See #117 (comment). Your module path should contain a dot, otherwise we assume that it's the standard library. An exception is when we are formatting inside a Go module, in which case we know the module path and we group its packages separately. This does not happen when formatting standard input, since it's only files on disk which can be part of a module.

@mvdan mvdan closed this as not planned Won't fix, can't repro, duplicate, stale Jul 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants