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

feat: format fixed files with the same formatters as the issues related to formatting #5267

Merged
merged 4 commits into from
Jan 1, 2025

Conversation

ldez
Copy link
Member

@ldez ldez commented Dec 31, 2024

Currently (since the PR about formatters) the reports related to formatting are handled by a dedicated processor, but the suggested fixes can produce formatting issues.
Inside the fixer, golangci-lint always calls the std formatter but it's better if it calls the formatters from the configuration too.

This PR also improves performance by formatting the files only one time, and by using fileCache instead of os.ReadFile to get the file content.

Note: the formatter processor is merged with the fixer.

This improves cases that can produce missing imports.

Example
linters:
  disable-all: true
  enable:
    - err113
    - goimports
package main

func Foo(e1, e2 error) bool {
	return e1 == e2
}

The command:

./golangci-lint run --fix

Before this PR, the result is:

package testdata

func Foo(e1, e2 error) bool {
	return errors.Is(e1, e2)
}

with this PR:

package testdata

import "errors"

func Foo(e1, e2 error) bool {
	return errors.Is(e1, e2)
}

because goimports fixes imports.

Related to #5232, #5246

@ldez ldez added enhancement New feature or improvement area: auto-fix labels Dec 31, 2024
@ldez ldez added this to the next milestone Dec 31, 2024
@ldez ldez requested review from alexandear and bombsimon December 31, 2024 01:20
@ldez ldez force-pushed the fix/meta-formatter branch from fd8f938 to 4caffa8 Compare December 31, 2024 01:52
@ldez ldez force-pushed the fix/meta-formatter branch 2 times, most recently from 522f484 to 6f95234 Compare December 31, 2024 12:35
@ldez ldez force-pushed the fix/meta-formatter branch from 6f95234 to 1d1dd0f Compare December 31, 2024 12:41
@ldez ldez changed the title feat: format the fixed file with the same formatters as the format issues feat: format the fixed files with the same formatters as the format issues Dec 31, 2024
@ldez ldez changed the title feat: format the fixed files with the same formatters as the format issues feat: format fixed files with the same formatters as the format issues Dec 31, 2024
@ldez ldez changed the title feat: format fixed files with the same formatters as the format issues feat: format fixed files with the same formatters as the issues related to formatting Dec 31, 2024
@ldez
Copy link
Member Author

ldez commented Jan 1, 2025

To follow the release plan, I will exceptionally merge this PR.

@ldez ldez merged commit 6bae718 into golangci:master Jan 1, 2025
15 checks passed
@ldez ldez deleted the fix/meta-formatter branch January 1, 2025 12:27
@ldez ldez modified the milestones: next, v1.63 Jan 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: auto-fix enhancement New feature or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants