-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
whitespace: failed to get line path/parse/yaccpar:329 #3967
Comments
Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors. |
Hello,
you have checked this box, can you give me the output of the whitespace linter? |
This linter is an old linter that doesn't follow our current standard for a linter, so there is no way to run it as a standalone linter or with I'm currently discussing with the author of this linter about another topic and this linter is unmaintained. For now, you have to disable whitespace linter. |
Thanks. I worked around this issue by using the |
The
So if you ask for the This code will print package main
import (
"fmt"
"go/ast"
"go/parser"
"go/token"
)
const src = `package main
//line yaccpar:1
func main() {}`
func main() {
fset := token.NewFileSet()
file, _ := parser.ParseFile(fset, "src.go", src, parser.ParseComments)
decl := file.Decls[0].(*ast.FuncDecl)
fmt.Println(fset.Position(decl.Body.Pos()).Filename)
} Thus this doesn't seem to be isolated to Sine we pass each file to My filename attemptdiff --git a/pkg/golinters/whitespace.go b/pkg/golinters/whitespace.go
index e5941fa5..0f509208 100644
--- a/pkg/golinters/whitespace.go
+++ b/pkg/golinters/whitespace.go
@@ -63,9 +63,19 @@ func NewWhitespace(settings *config.WhitespaceSettings) *goanalysis.Linter {
}
func runWhitespace(lintCtx *linter.Context, pass *analysis.Pass, wsSettings whitespace.Settings) ([]goanalysis.Issue, error) {
- var messages []whitespace.Message
+ type whitespaceIssue struct {
+ whitespaceMessage whitespace.Message
+ filename string
+ }
+
+ var messages []whitespaceIssue
for _, file := range pass.Files {
- messages = append(messages, whitespace.Run(file, pass.Fset, wsSettings)...)
+ for _, message := range whitespace.Run(file, pass.Fset, wsSettings) {
+ messages = append(messages, whitespaceIssue{
+ whitespaceMessage: message,
+ filename: pass.Fset.Position(file.Pos()).Filename,
+ })
+ }
}
if len(messages) == 0 {
@@ -73,10 +83,12 @@ func runWhitespace(lintCtx *linter.Context, pass *analysis.Pass, wsSettings whit
}
issues := make([]goanalysis.Issue, len(messages))
- for k, i := range messages {
+ for k, wi := range messages {
+ i := wi.whitespaceMessage
+
issue := result.Issue{
Pos: token.Position{
- Filename: i.Pos.Filename,
+ Filename: wi.filename,
Line: i.Pos.Line,
},
LineRange: &result.Range{From: i.Pos.Line, To: i.Pos.Line},
@@ -85,9 +97,9 @@ func runWhitespace(lintCtx *linter.Context, pass *analysis.Pass, wsSettings whit
Replacement: &result.Replacement{},
}
- bracketLine, err := lintCtx.LineCache.GetLine(issue.Pos.Filename, issue.Pos.Line)
+ bracketLine, err := lintCtx.LineCache.GetLine(wi.filename, issue.Pos.Line)
if err != nil {
- return nil, fmt.Errorf("failed to get line %s:%d: %w", issue.Pos.Filename, issue.Pos.Line, err)
+ return nil, fmt.Errorf("failed to get line %s:%d: %w", wi.filename, issue.Pos.Line, err)
}
switch i.Type { |
I found the solution and it's simply to use |
@bombsimon whitespace is unmaintained 😉 |
Yeah I saw the thread but I also saw someone merged a PR in |
Maybe my email had its effect... |
Yes, our apologies for the delays. We are striving to maintain the packages. As said in ultraware/funlen#15 (comment) We are open to pull request. And we will strive to discuss/review/maintain the repositores |
so whitespace should be written to follow our current standard (the custom code inside golangci-lint should be removed) |
Yes, I can do that. I have limited time the following ~1-2 weeks but I'll start and open a new PR when ready. |
you can do something like that: https://github.com/4meepo/tagalign/blob/43dc5d806d929c9454a82a2116728b45e1b6f0f0/tagalign.go#L158-L191 |
This is now fixed in #4003 |
Welcome
Description of the problem
Similar to #2788, but chokes on files generated by goyacc, it chokes on lines like this:
//line yaccpar:1
Oddly, if I remove lines starting with
//line yacc
, I get a different error, where it looks likegolangci-lint
tries to validate the.y
grammar file? The error is:Version of golangci-lint
Configuration
Go environment
Verbose output of running
Code example or link to a public repository
Validation
The text was updated successfully, but these errors were encountered: