From 401ad8e9e768c03187a93dfd75e49f870d25027e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=20Kl=C3=A4rner?= Date: Sun, 2 Feb 2025 19:48:05 +0100 Subject: [PATCH 01/16] ci: run golangci-lint --- .github/workflows/ci.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4d33c0c6..80b04669 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,11 @@ on: pull_request: workflow_dispatch: +permissions: + contents: read + pull-requests: read + checks: write + jobs: ci: runs-on: ubuntu-latest @@ -25,3 +30,14 @@ jobs: - uses: codecov/codecov-action@v5 with: token: ${{ secrets.CODECOV_TOKEN }} + + golangci-lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: "go.mod" + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + From 6abb84c8a21cfd775dd3ae2dc064ca74a3988c57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=20Kl=C3=A4rner?= Date: Sun, 2 Feb 2025 20:26:51 +0100 Subject: [PATCH 02/16] fix(lint): errors should be printed as strings Since this was done with the go1.24 migration differently, I just remembered that printing the errors as strings should be the simpler approach. --- cmd/editorconfig-checker/main.go | 6 +++--- pkg/error/error.go | 8 ++++---- pkg/files/files.go | 2 +- pkg/validation/validation.go | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cmd/editorconfig-checker/main.go b/cmd/editorconfig-checker/main.go index 31780471..54da7fb1 100644 --- a/cmd/editorconfig-checker/main.go +++ b/cmd/editorconfig-checker/main.go @@ -120,7 +120,7 @@ func parseArguments() { if writeConfigFile { err := currentConfig.Save(version) if err != nil { - currentConfig.Logger.Error("%v", err.Error()) + currentConfig.Logger.Error("%s", err) exitProxy(exitCodeErrorOccurred) } @@ -131,7 +131,7 @@ func parseArguments() { // this error should be surpressed if the configFilePath was not set by the user // since the default config paths could trigger this if err != nil && !(configFilePath == "" && errors.Is(err, fs.ErrNotExist)) { - currentConfig.Logger.Error("%v", err.Error()) + currentConfig.Logger.Error("%s", err) exitProxy(exitCodeConfigFileNotFound) } @@ -175,7 +175,7 @@ func main() { filePaths, err := files.GetFiles(config) if err != nil { - config.Logger.Error("%v", err.Error()) + config.Logger.Error("%s", err) exitProxy(exitCodeErrorOccurred) } diff --git a/pkg/error/error.go b/pkg/error/error.go index 340785bb..175df056 100644 --- a/pkg/error/error.go +++ b/pkg/error/error.go @@ -104,7 +104,7 @@ func PrintErrorsAsHumanReadable(errors []ValidationErrors, config config.Config) relativeFilePath, err := files.GetRelativePath(fileErrors.FilePath) if err != nil { - config.Logger.Error("%v", err.Error()) + config.Logger.Error("%s", err) continue } @@ -139,7 +139,7 @@ func PrintErrorsAsGHA(errors []ValidationErrors, config config.Config) { relativeFilePath, err := files.GetRelativePath(fileErrors.FilePath) if err != nil { - config.Logger.Error("%v", err.Error()) + config.Logger.Error("%s", err) continue } @@ -175,7 +175,7 @@ func PrintErrorsAsGCC(errors []ValidationErrors, config config.Config) { relativeFilePath, err := files.GetRelativePath(fileErrors.FilePath) if err != nil { - config.Logger.Error("%v", err.Error()) + config.Logger.Error("%s", err) continue } @@ -204,7 +204,7 @@ func PrintErrorsAsCodeclimate(errors []ValidationErrors, config config.Config) { relativeFilePath, err := files.GetRelativePath(fileErrors.FilePath) if err != nil { - config.Logger.Error("%v", err.Error()) + config.Logger.Error("%s", err) continue } diff --git a/pkg/files/files.go b/pkg/files/files.go index 029fc3a8..0ea91b82 100644 --- a/pkg/files/files.go +++ b/pkg/files/files.go @@ -66,7 +66,7 @@ func AddToFiles(filePaths []string, filePath string, config config.Config) []str contentType, err := GetContentType(filePath, config) if err != nil { config.Logger.Error("Could not get the ContentType of file: %s", filePath) - config.Logger.Error("%v", err.Error()) + config.Logger.Error("%s", err) } config.Logger.Debug("AddToFiles: detected ContentType %s on file %s", contentType, filePath) diff --git a/pkg/validation/validation.go b/pkg/validation/validation.go index 51a22922..4c76ea1a 100644 --- a/pkg/validation/validation.go +++ b/pkg/validation/validation.go @@ -61,7 +61,7 @@ func ValidateFile(filePath string, config config.Config) []error.ValidationError charset = "unknown" } config.Logger.Error("Could not decode the %s encoded file: %s", charset, filePath) - config.Logger.Error("%v", err.Error()) + config.Logger.Error("%s", err) } break } @@ -84,7 +84,7 @@ func ValidateFile(filePath string, config config.Config) []error.ValidationError return validationErrors } if warnings != nil { - config.Logger.Warning("%v", warnings.Error()) + config.Logger.Warning("%s", warnings) } fileInformation := files.FileInformation{Content: fileContent, FilePath: filePath, Editorconfig: definition} From ca1b230a3d308e55b58dddc5ef72177ed51335dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=20Kl=C3=A4rner?= Date: Sun, 2 Feb 2025 20:28:11 +0100 Subject: [PATCH 03/16] fix(lint): declare that we intentionally ignore this returned error --- cmd/editorconfig-checker/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/editorconfig-checker/main.go b/cmd/editorconfig-checker/main.go index 54da7fb1..6e010049 100644 --- a/cmd/editorconfig-checker/main.go +++ b/cmd/editorconfig-checker/main.go @@ -97,7 +97,7 @@ func parseArguments() { nocolorParsedAsBool = true } if nocolorParsedAsBool { - enableNoColor("") + _ = enableNoColor("") } } From 3ec921d15ddc4ada90766ac836d04986e7a9cdfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=20Kl=C3=A4rner?= Date: Sun, 2 Feb 2025 22:26:02 +0100 Subject: [PATCH 04/16] ci: enable all golangci-lint linters by default --- .golangci.yaml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .golangci.yaml diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 00000000..8ba42364 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,2 @@ +linters: + enable-all: true From d848e2d988a1da4d08014763f1fbfcadfabc2d4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=20Kl=C3=A4rner?= Date: Sun, 2 Feb 2025 22:28:09 +0100 Subject: [PATCH 05/16] ci: disable the deprecated linters --- .golangci.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.golangci.yaml b/.golangci.yaml index 8ba42364..3efb3ef9 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,2 +1,7 @@ linters: enable-all: true + disable: + # all currently deprecated linters + - execinquery + - exportloopref + - gomnd From b29449fb01d5c1499450e5f46051e5a30ca88dfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=20Kl=C3=A4rner?= Date: Tue, 4 Feb 2025 08:15:06 +0100 Subject: [PATCH 06/16] ci: use a more sensible starting point for golangci-lint --- .golangci.yaml | 167 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 161 insertions(+), 6 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 3efb3ef9..0813494b 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,7 +1,162 @@ +--- +# golangci-lint configuration file made by @ccoVeille +# Source: https://github.com/ccoVeille/golangci-lint-config-examples/ +# Author: @ccoVeille +# License: MIT +# Variant: 03-safe +# Version: v1.1.0 +# linters: - enable-all: true - disable: - # all currently deprecated linters - - execinquery - - exportloopref - - gomnd + # some linters are enabled by default + # https://golangci-lint.run/usage/linters/ + # + # enable some extra linters + enable: + # Errcheck is a program for checking for unchecked errors in Go code. + - errcheck + + # Linter for Go source code that specializes in simplifying code. + - gosimple + + # Vet examines Go source code and reports suspicious constructs. + - govet + + # Detects when assignments to existing variables are not used. + - ineffassign + + # It's a set of rules from staticcheck. See https://staticcheck.io/ + - staticcheck + + # Fast, configurable, extensible, flexible, and beautiful linter for Go. + # Drop-in replacement of golint. + - revive + + # check imports order and makes it always deterministic. + - gci + + # make sure to use t.Helper() when needed + - thelper + + # mirror suggests rewrites to avoid unnecessary []byte/string conversion + - mirror + + # detect the possibility to use variables/constants from the Go standard library. + - usestdlibvars + + # Finds commonly misspelled English words. + - misspell + + # Checks for duplicate words in the source code. + - dupword + + # linter to detect errors invalid key values count + - loggercheck + + # detects nested contexts in loops or function literals + - fatcontext + +linters-settings: + gci: # define the section orders for imports + sections: + # Standard section: captures all standard packages. + - standard + # Default section: catchall that is not standard or custom + - default + # linters that related to local tool, so they should be separated + - localmodule + + revive: + rules: + # these are the default revive rules + # you can remove the whole "rules" node if you want + # BUT + # ! /!\ they all need to be present when you want to add more rules than the default ones + # otherwise, you won't have the default rules, but only the ones you define in the "rules" node + + # Blank import should be only in a main or test package, or have a comment justifying it. + - name: blank-imports + + # context.Context() should be the first parameter of a function when provided as argument. + - name: context-as-argument + arguments: + - allowTypesBefore: "*testing.T" + + # Basic types should not be used as a key in `context.WithValue` + - name: context-keys-type + + # Importing with `.` makes the programs much harder to understand + - name: dot-imports + + # Empty blocks make code less readable and could be a symptom of a bug or unfinished refactoring. + - name: empty-block + + # for better readability, variables of type `error` must be named with the prefix `err`. + - name: error-naming + + # for better readability, the errors should be last in the list of returned values by a function. + - name: error-return + + # for better readability, error messages should not be capitalized or end with punctuation or a newline. + - name: error-strings + + # report when replacing `errors.New(fmt.Sprintf())` with `fmt.Errorf()` is possible + - name: errorf + + # incrementing an integer variable by 1 is recommended to be done using the `++` operator + - name: increment-decrement + + # highlights redundant else-blocks that can be eliminated from the code + - name: indent-error-flow + + # This rule suggests a shorter way of writing ranges that do not use the second value. + - name: range + + # receiver names in a method should reflect the struct name (p for Person, for example) + - name: receiver-naming + + # redefining built in names (true, false, append, make) can lead to bugs very difficult to detect. + - name: redefines-builtin-id + + # redundant else-blocks that can be eliminated from the code. + - name: superfluous-else + + # prevent confusing name for variables when using `time` package + - name: time-naming + + # warns when an exported function or method returns a value of an un-exported type. + - name: unexported-return + + # spots and proposes to remove unreachable code. also helps to spot errors + - name: unreachable-code + + # Functions or methods with unused parameters can be a symptom of an unfinished refactoring or a bug. + - name: unused-parameter + + # report when a variable declaration can be simplified + - name: var-declaration + + # warns when initialism, variable or package naming conventions are not followed. + - name: var-naming + + dupword: + # Keywords used to ignore detection. + # Default: [] + ignore: [] + # - "blah" # this will accept "blah blah …" as a valid duplicate word + + misspell: + # Correct spellings using locale preferences for US or UK. + # Setting locale to US will correct the British spelling of 'colour' to 'color'. + # Default ("") is to use a neutral variety of English. + locale: US + + # List of words to ignore + # among the one defined in https://github.com/golangci/misspell/blob/master/words.go + ignore-words: [] + # - valor + # - and + + # Extra word corrections. + extra-words: [] + # - typo: "whattever" + # correction: "whatever" From bf9625743a8326788236a92f154854661eead3cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=20Kl=C3=A4rner?= Date: Tue, 4 Feb 2025 08:19:23 +0100 Subject: [PATCH 07/16] ci: ignore a misspelling, since it is a username, not an actual word --- .golangci.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 0813494b..0743b25a 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -152,9 +152,8 @@ linters-settings: # List of words to ignore # among the one defined in https://github.com/golangci/misspell/blob/master/words.go - ignore-words: [] - # - valor - # - and + ignore-words: + - baulk # username in an imported module path # Extra word corrections. extra-words: [] From 714107c2ea662e9d1d8b18de35a94151d4337930 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=20Kl=C3=A4rner?= Date: Tue, 4 Feb 2025 08:26:26 +0100 Subject: [PATCH 08/16] fix(lint): keep name consistent with the other functions --- pkg/outputformat/outputformat.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/outputformat/outputformat.go b/pkg/outputformat/outputformat.go index 37070bfc..c151a817 100644 --- a/pkg/outputformat/outputformat.go +++ b/pkg/outputformat/outputformat.go @@ -50,6 +50,6 @@ func (format OutputFormat) IsValid() bool { return slices.Contains(ValidOutputFormats, format) } -func (f OutputFormat) String() string { - return string(f) +func (format OutputFormat) String() string { + return string(format) } From ba0e539792cb632893f372fccfa89d774be76efd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=20Kl=C3=A4rner?= Date: Tue, 4 Feb 2025 08:26:55 +0100 Subject: [PATCH 09/16] fix(lint): rename variable to camelCase --- pkg/outputformat/outputformat.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/outputformat/outputformat.go b/pkg/outputformat/outputformat.go index c151a817..e493e3cf 100644 --- a/pkg/outputformat/outputformat.go +++ b/pkg/outputformat/outputformat.go @@ -24,11 +24,11 @@ var ValidOutputFormats = []OutputFormat{ } func GetArgumentChoiceText() string { - var output_strings []string + var outputStrings []string for _, f := range ValidOutputFormats { - output_strings = append(output_strings, string(f)) + outputStrings = append(outputStrings, string(f)) } - return strings.Join(output_strings, ", ") + return strings.Join(outputStrings, ", ") } func (format OutputFormat) MarshalText() ([]byte, error) { From 3f08cd1751ff2bfd7e9ce4bf24412b9b32ef3464 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=20Kl=C3=A4rner?= Date: Tue, 4 Feb 2025 08:30:49 +0100 Subject: [PATCH 10/16] fix(lint): discovered more typos --- cmd/editorconfig-checker/main.go | 2 +- pkg/outputformat/outputformat_test.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/editorconfig-checker/main.go b/cmd/editorconfig-checker/main.go index 6e010049..bce76986 100644 --- a/cmd/editorconfig-checker/main.go +++ b/cmd/editorconfig-checker/main.go @@ -128,7 +128,7 @@ func parseArguments() { } err := currentConfig.Parse() - // this error should be surpressed if the configFilePath was not set by the user + // this error should be suppressed if the configFilePath was not set by the user // since the default config paths could trigger this if err != nil && !(configFilePath == "" && errors.Is(err, fs.ErrNotExist)) { currentConfig.Logger.Error("%s", err) diff --git a/pkg/outputformat/outputformat_test.go b/pkg/outputformat/outputformat_test.go index e6853feb..45004a92 100644 --- a/pkg/outputformat/outputformat_test.go +++ b/pkg/outputformat/outputformat_test.go @@ -37,7 +37,7 @@ func TestMarshalling(t *testing.T) { } if f != u { - t.Errorf("marshalling and then unmarshalling of format %s failed to survive the roundtrip", f) + t.Errorf("marshaling and then unmarshalling of format %s failed to survive the roundtrip", f) } } } @@ -46,13 +46,13 @@ func TestMarshallingBrokenInputFails(t *testing.T) { broken := OutputFormat("invalid") _, err := broken.MarshalText() if err == nil { - t.Error("marshalling did not recognize an invalid value and marshalled it anyway") + t.Error("marshaling did not recognize an invalid value and marshaled it anyway") } } func TestUnmarshallingBrokenInputFails(t *testing.T) { var broken OutputFormat err := broken.UnmarshalText([]byte("invalid")) if err == nil { - t.Error("unmarshalling did not recognize an invalid value and unmarshalled it anyway") + t.Error("unmarshaling did not recognize an invalid value and unmarshaled it anyway") } } From 1f035f32bbaa097ab76e5fd2a24276001a432b2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=20Kl=C3=A4rner?= Date: Tue, 4 Feb 2025 08:33:43 +0100 Subject: [PATCH 11/16] fix(lint): arguments of type testing.T should always be first --- pkg/encoding/encoding_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/encoding/encoding_test.go b/pkg/encoding/encoding_test.go index c49e846f..38d99b35 100644 --- a/pkg/encoding/encoding_test.go +++ b/pkg/encoding/encoding_test.go @@ -86,7 +86,7 @@ func TestDecodeBytesText(t *testing.T) { errored := err != nil if charset != tt.charset { t.Errorf("DecodeBytes(%s): charset: expected: %v, got: %v (changed=%v, errored=%v)", tt.filename, tt.charset, charset, changed, errored) - listAllCharsets(rawFileContent, t) + listAllCharsets(t, rawFileContent) } if changed != tt.changed { t.Errorf("DecodeBytes(%s): content changed: expected: %v, got: %v (charset=%v, errored=%v)", tt.filename, tt.changed, changed, charset, errored) @@ -97,7 +97,7 @@ func TestDecodeBytesText(t *testing.T) { } } -func listAllCharsets(contentBytes []byte, t *testing.T) { +func listAllCharsets(t *testing.T, contentBytes []byte) { detector := chardet.NewTextDetector() results, err := detector.DetectAll(contentBytes) if err != nil { From e6262fe9c847c21c06814b2365c3377e956b1f4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=20Kl=C3=A4rner?= Date: Tue, 4 Feb 2025 08:34:12 +0100 Subject: [PATCH 12/16] =?UTF-8?q?fix(lint):=20listAllCharsets()=C2=A0is=20?= =?UTF-8?q?a=20helper=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/encoding/encoding_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/encoding/encoding_test.go b/pkg/encoding/encoding_test.go index 38d99b35..ed8a785c 100644 --- a/pkg/encoding/encoding_test.go +++ b/pkg/encoding/encoding_test.go @@ -98,6 +98,7 @@ func TestDecodeBytesText(t *testing.T) { } func listAllCharsets(t *testing.T, contentBytes []byte) { + t.Helper() detector := chardet.NewTextDetector() results, err := detector.DetectAll(contentBytes) if err != nil { From 0a3644b99d50ed1da7b12ec6c90bc6441fcbfcfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=20Kl=C3=A4rner?= Date: Tue, 4 Feb 2025 08:40:56 +0100 Subject: [PATCH 13/16] fix(lint): func GetContentTypeBytes() doesn't need the config, so remove the arg then remove the now unused variables and arguments from the functions earlier in the callchain --- pkg/files/files.go | 8 ++++---- pkg/files/files_test.go | 14 ++++++-------- pkg/validation/validation.go | 2 +- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/pkg/files/files.go b/pkg/files/files.go index 0ea91b82..a8545db7 100644 --- a/pkg/files/files.go +++ b/pkg/files/files.go @@ -63,7 +63,7 @@ func AddToFiles(filePaths []string, filePath string, config config.Config) []str return filePaths } - contentType, err := GetContentType(filePath, config) + contentType, err := GetContentType(filePath) if err != nil { config.Logger.Error("Could not get the ContentType of file: %s", filePath) config.Logger.Error("%s", err) @@ -167,7 +167,7 @@ func ReadLines(content string) []string { } // GetContentType returns the content type of a file -func GetContentType(path string, config config.Config) (string, error) { +func GetContentType(path string) (string, error) { fileStat, err := os.Stat(path) if err != nil { return "", err @@ -185,11 +185,11 @@ func GetContentType(path string, config config.Config) (string, error) { if err != nil { panic(err) } - return GetContentTypeBytes(rawFileContent, config) + return GetContentTypeBytes(rawFileContent) } // GetContentTypeBytes returns the content type of a byte slice -func GetContentTypeBytes(rawFileContent []byte, config config.Config) (string, error) { +func GetContentTypeBytes(rawFileContent []byte) (string, error) { bytesReader := bytes.NewReader(rawFileContent) mimeType, err := mimetype.DetectReader(bytesReader) diff --git a/pkg/files/files_test.go b/pkg/files/files_test.go index 63d948a1..9c4a21ba 100644 --- a/pkg/files/files_test.go +++ b/pkg/files/files_test.go @@ -14,35 +14,34 @@ import ( ) func TestGetContentType(t *testing.T) { - configuration := config.Config{} inputFile := "./files.go" expected := "text/plain" - contentType, _ := GetContentType(inputFile, configuration) + contentType, _ := GetContentType(inputFile) if !strings.Contains(contentType, expected) { t.Errorf("GetContentType(%q): expected %v, got %v", inputFile, expected, contentType) } inputFile = "./../../docs/logo.png" expected = "image/png" - contentType, _ = GetContentType(inputFile, configuration) + contentType, _ = GetContentType(inputFile) if !strings.Contains(contentType, expected) { t.Errorf("GetContentType(%q): expected %v, got %v", inputFile, expected, contentType) } inputFile = "." - _, err := GetContentType(inputFile, configuration) + _, err := GetContentType(inputFile) if err == nil { t.Errorf("GetContentType(%q): expected %v, got %v", inputFile, "an error", "nil") } inputFile = "a non-existent file" - _, err = GetContentType(inputFile, configuration) + _, err = GetContentType(inputFile) if err == nil { t.Errorf("GetContentType(%q): expected %v, got %v", inputFile, "an error", "nil") } inputFile = "testdata/empty.txt" - contentType, err = GetContentType(inputFile, configuration) + contentType, err = GetContentType(inputFile) if err != nil { t.Errorf("GetContentType(%q): expected %v, got %v", inputFile, "nil", err.Error()) } @@ -256,10 +255,9 @@ var getContentTypeFilesTests = []getContentTypeFilesTest{ } func TestGetContentTypeFiles(t *testing.T) { - configuration := config.Config{} for _, tt := range getContentTypeFilesTests { filePath := "../encoding/testdata/" + tt.filename - contentType, err := GetContentType(filePath, configuration) + contentType, err := GetContentType(filePath) if err != nil { t.Errorf("GetContentType(%q): expected %v, got %v", tt.filename, "nil", err.Error()) } diff --git a/pkg/validation/validation.go b/pkg/validation/validation.go index 4c76ea1a..0d1d2e57 100644 --- a/pkg/validation/validation.go +++ b/pkg/validation/validation.go @@ -47,7 +47,7 @@ func ValidateFile(filePath string, config config.Config) []error.ValidationError panic(err) } fileContent := string(rawFileContent) - mime, err := files.GetContentTypeBytes(rawFileContent, config) + mime, err := files.GetContentTypeBytes(rawFileContent) if err != nil { panic(err) } From 9d93d5dc711b0d697df32fc50426e06718a1d776 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=20Kl=C3=A4rner?= Date: Tue, 4 Feb 2025 08:42:37 +0100 Subject: [PATCH 14/16] fix(lint): remove initialization to the zero value --- pkg/config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index f632e12e..c53a7f99 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -129,7 +129,7 @@ func NewConfig(configPaths []string) *Config { Parser: editorconfig.NewCachedParser(), } - var configPath string = "" + var configPath string for _, path := range configPaths { if utils.IsRegularFile(path) { configPath = path From c37482af346133cbb63eb152ef8956bf45e64160 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=20Kl=C3=A4rner?= Date: Tue, 4 Feb 2025 08:44:11 +0100 Subject: [PATCH 15/16] fix(lint): infer types --- cmd/editorconfig-checker/main.go | 2 +- pkg/validation/validation.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/editorconfig-checker/main.go b/cmd/editorconfig-checker/main.go index bce76986..6a6a081c 100644 --- a/cmd/editorconfig-checker/main.go +++ b/cmd/editorconfig-checker/main.go @@ -21,7 +21,7 @@ import ( // version is used for the help and to verify against the version stored in the config file // version is dynamically set at compiletime -var version string = "v3.2.0" // x-release-please-version +var version = "v3.2.0" // x-release-please-version // defaultConfigFileNames determines the file names where the config is located var defaultConfigFileNames = []string{".editorconfig-checker.json", ".ecrc"} diff --git a/pkg/validation/validation.go b/pkg/validation/validation.go index 0d1d2e57..10bbde56 100644 --- a/pkg/validation/validation.go +++ b/pkg/validation/validation.go @@ -40,7 +40,7 @@ func ValidateFile(filePath string, config config.Config) []error.ValidationError const directiveEnable = directivePrefix + "enable" var validationErrors []error.ValidationError - var isDisabled bool = false + var isDisabled = false rawFileContent, err := os.ReadFile(filePath) if err != nil { From 98b6d2b89cb1de83b007411ff2afacbc247c7b66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=20Kl=C3=A4rner?= Date: Tue, 4 Feb 2025 22:59:57 +0100 Subject: [PATCH 16/16] ci: switch from gci to goimports --- .golangci.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.golangci.yaml b/.golangci.yaml index 0743b25a..bc63508e 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -32,7 +32,10 @@ linters: - revive # check imports order and makes it always deterministic. - - gci + #- gci + # prefer goimports for now, since gci cannot deal with the release-please-end markers + # (it tries to delete them, keeping only the starting markers) + - goimports # make sure to use t.Helper() when needed - thelper @@ -65,6 +68,9 @@ linters-settings: # linters that related to local tool, so they should be separated - localmodule + goimports: + local-prefixes: github.com/editorconfig-checker + revive: rules: # these are the default revive rules