Skip to content

Conversation

kseniadumpling
Copy link
Contributor

@kseniadumpling kseniadumpling commented Jun 18, 2023

The issue was with parsing diffpkg.Hunk in parseDiffLines(). The func operated only with lines in hunk.Body. Such body doesn't contain any info about EOF issue, it simply has "-" and "+" with the same content:

INFO [linters_context] DUBUG: printing hunk: &diff.Hunk{OrigStartLine:7, OrigLines:4, OrigNoNewlineAt:30, NewStartLine:7, NewLines:4, Section:"", StartPosition:1, Body:[]uint8{0x20, 0x9, 0x9, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x31, 0xa, 0x20, 0x9, 0x7d, 0xa, 0x20, 0x9, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x32, 0xa, 0x2d, 0x7d, 0xa, 0x2b, 0x7d, 0xa}} 
INFO [linters_context] DUBUG: printing h.Body line-by-line 
INFO [linters_context] DUBUG: line 7:           return 1 
INFO [linters_context] DUBUG: line 8:   }         
INFO [linters_context] DUBUG: line 9:   return 2  
INFO [linters_context] DUBUG: line 10: -}         
INFO [linters_context] DUBUG: line 11: +}         
INFO [linters_context] DUBUG: line 11:            

The new code checks OrigNoNewlineAt flag and adds a new line right after the last problematic line (currentOriginalLineNumber + 1)

fixes #3747
fixes #1373

@boring-cyborg
Copy link

boring-cyborg bot commented Jun 18, 2023

Hey, thank you for opening your first Pull Request !

@CLAassistant
Copy link

CLAassistant commented Jun 18, 2023

CLA assistant check
All committers have signed the CLA.

@ldez ldez added bug Something isn't working area: auto-fix labels Jun 18, 2023
@ldez ldez changed the title fix: gofmt doesn't fix missing newline at EOF gofmt: autofix missing newline at EOF Jun 18, 2023
Copy link
Member

@ldez ldez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for taking the time to fix this issue.

@ldez ldez merged commit 28f0560 into golangci:master Jun 18, 2023
@ldez ldez added this to the v1.54 milestone Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: auto-fix bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

goimports with --fix doesn't fix missing newline at EOF goimports --fix not fixing new lines

3 participants