From fd83519a6d1b8c3518fcf0e168b2a847935b6ef5 Mon Sep 17 00:00:00 2001 From: haumont <79776238+haumont@users.noreply.github.com> Date: Mon, 8 Apr 2024 04:20:32 -0500 Subject: [PATCH 01/14] fix: indent_style = space is ignored if indent_size = unset (#277) (#331) --- pkg/validation/validation_test.go | 8 +++++++- pkg/validation/validators/validators.go | 20 ++++++++++---------- testfiles/.editorconfig | 4 ++++ testfiles/spaces-with-tab.c | 14 ++++++++++++++ 4 files changed, 35 insertions(+), 11 deletions(-) create mode 100644 testfiles/spaces-with-tab.c diff --git a/pkg/validation/validation_test.go b/pkg/validation/validation_test.go index 14718324..7b12e577 100644 --- a/pkg/validation/validation_test.go +++ b/pkg/validation/validation_test.go @@ -127,7 +127,7 @@ func TestValidateFile(t *testing.T) { configuration = config.Config{Verbose: true} result = ValidateFile("./../../testfiles/line-to-long.txt", configuration) if len(result) != 1 { - t.Error("Should have no error, got", result) + t.Error("Should have one error, got", result) } configuration = config.Config{Verbose: true} @@ -136,4 +136,10 @@ func TestValidateFile(t *testing.T) { if len(result) != 0 { t.Error("Should have no error, got", result) } + + configuration = config.Config{Verbose: true} + result = ValidateFile("./../../testfiles/spaces-with-tab.c", configuration) + if len(result) != 1 { + t.Error("Should have one error, got", result) + } } diff --git a/pkg/validation/validators/validators.go b/pkg/validation/validators/validators.go index 272e5e21..61af6774 100644 --- a/pkg/validation/validators/validators.go +++ b/pkg/validation/validators/validators.go @@ -26,8 +26,16 @@ func Indentation(line string, indentStyle string, indentSize int, config config. // Space validates if a line is indented correctly respecting the indentSize func Space(line string, indentSize int, config config.Config) error { - if len(line) > 0 && indentSize > 0 { - if !config.Disable.IndentSize { + if len(line) > 0 { + // match recurring spaces and everything except tab characters + regexpPattern := `^( )*([^ \t]|$)` + matched, _ := regexp.MatchString(regexpPattern, line) + + if !matched { + return fmt.Errorf("Wrong indent style found (tabs instead of spaces)") + } + + if !config.Disable.IndentSize && indentSize > 0 { // match recurring spaces indentSize times - this can be recurring or never // match either a space followed by a * and maybe a space (block-comments) // or match everything despite a space or tab-character @@ -37,14 +45,6 @@ func Space(line string, indentSize int, config config.Config) error { if !matched { return fmt.Errorf("Wrong amount of left-padding spaces(want multiple of %d)", indentSize) } - } else { - // match recurring spaces and everything except tab characters - regexpPattern := `^( )*([^ \t]|$)` - matched, _ := regexp.MatchString(regexpPattern, line) - - if !matched { - return fmt.Errorf("Wrong indent style found (tabs instead of spaces)") - } } } diff --git a/testfiles/.editorconfig b/testfiles/.editorconfig index 7e7c604f..d77c8399 100644 --- a/testfiles/.editorconfig +++ b/testfiles/.editorconfig @@ -17,3 +17,7 @@ end_of_line = lf [line-to-long.txt] max_line_length = 2 + +[spaces-with-tab.c] +indent_style = space +indent_size = unset diff --git a/testfiles/spaces-with-tab.c b/testfiles/spaces-with-tab.c new file mode 100644 index 00000000..a015fa70 --- /dev/null +++ b/testfiles/spaces-with-tab.c @@ -0,0 +1,14 @@ +#include +#include + + +int main(int argc, char *argv[]) +{ + if (argc > 1) { + for (int i=0; i < argc; i++) { // This line is indented with tab + printf("%d: %s\n", i, argv[i]); + } + } + return 0; +} + From 2d43756dd83b5d9614dc4f4696ecbd52468c8c40 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 11 Apr 2024 08:16:47 +0000 Subject: [PATCH 02/14] chore(deps): bump wagoid/commitlint-github-action from 6.0.0 to 6.0.1 (#334) Bumps [wagoid/commitlint-github-action](https://github.com/wagoid/commitlint-github-action) from 6.0.0 to 6.0.1. - [Changelog](https://github.com/wagoid/commitlint-github-action/blob/master/CHANGELOG.md) - [Commits](https://github.com/wagoid/commitlint-github-action/compare/v6.0.0...v6.0.1) --- updated-dependencies: - dependency-name: wagoid/commitlint-github-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4a6f3f22..2097f840 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 - - uses: wagoid/commitlint-github-action@v6.0.0 + - uses: wagoid/commitlint-github-action@v6.0.1 if: ${{ github.ref != 'refs/heads/main' }} - uses: actions/setup-go@v5 with: From 1128923363fe2f2d6dc3a5a4f988d9b094b588fb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 12 Apr 2024 08:50:03 +0000 Subject: [PATCH 03/14] chore(deps): bump heinrichreimer/github-changelog-generator-action (#336) Bumps [heinrichreimer/github-changelog-generator-action](https://github.com/heinrichreimer/github-changelog-generator-action) from 2.1.1 to 2.4. - [Release notes](https://github.com/heinrichreimer/github-changelog-generator-action/releases) - [Commits](https://github.com/heinrichreimer/github-changelog-generator-action/compare/v2.1.1...v2.4) --- updated-dependencies: - dependency-name: heinrichreimer/github-changelog-generator-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2097f840..6b715a04 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: - run: ./bin/ec -config stuff.json -init && diff stuff.json ./testfiles/generated-config.json && rm stuff.json - run: make run - run: make bench - - uses: heinrichreimer/github-changelog-generator-action@v2.1.1 + - uses: heinrichreimer/github-changelog-generator-action@v2.4 with: token: ${{ secrets.GH_TOKEN_PAT }} - uses: codecov/codecov-action@v4 From cea3f274d3493fb04b47b5f4d232d02b6c05af0b Mon Sep 17 00:00:00 2001 From: Yoan Blanc Date: Sat, 20 Apr 2024 11:52:00 +0200 Subject: [PATCH 04/14] fix: v3 prefix is required (#339) Signed-off-by: Yoan Blanc --- README.md | 6 +++--- cmd/editorconfig-checker/main.go | 12 ++++++------ go.mod | 2 +- pkg/config/config.go | 4 ++-- pkg/error/error.go | 4 ++-- pkg/error/error_test.go | 2 +- pkg/files/files.go | 4 ++-- pkg/files/files_test.go | 2 +- pkg/validation/validation.go | 10 +++++----- pkg/validation/validation_test.go | 2 +- pkg/validation/validators/validators.go | 4 ++-- pkg/validation/validators/validators_test.go | 2 +- 12 files changed, 27 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 22c6164e..301d10eb 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![ci](https://github.com/editorconfig-checker/editorconfig-checker/actions/workflows/ci.yml/badge.svg)](https://github.com/editorconfig-checker/editorconfig-checker/actions/workflows/ci.yml) [![codecov](https://codecov.io/gh/editorconfig-checker/editorconfig-checker/branch/main/graph/badge.svg)](https://codecov.io/gh/editorconfig-checker/editorconfig-checker) [![Hits-of-Code](https://hitsofcode.com/github/editorconfig-checker/editorconfig-checker)](https://hitsofcode.com/view/github/editorconfig-checker/editorconfig-checker) -[![Go Report Card](https://goreportcard.com/badge/github.com/editorconfig-checker/editorconfig-checker/v2)](https://goreportcard.com/report/github.com/editorconfig-checker/editorconfig-checker/v2) +[![Go Report Card](https://goreportcard.com/badge/github.com/editorconfig-checker/editorconfig-checker/v3)](https://goreportcard.com/report/github.com/editorconfig-checker/editorconfig-checker/v3) ![Logo](docs/logo.png) @@ -66,7 +66,7 @@ tar xzf ec-$OS-$ARCH.tar.gz && \ Grab a binary from the [release page](https://github.com/editorconfig-checker/editorconfig-checker/releases). -If you have go installed you can run `go get github.com/editorconfig-checker/editorconfig-checker/v2` and run `make build` inside the project folder. +If you have go installed you can run `go get github.com/editorconfig-checker/editorconfig-checker/v3` and run `make build` inside the project folder. This will place a binary called `ec` into the `bin` directory. If you are using Arch Linux, you can use [pacman](https://wiki.archlinux.org/title/Pacman) to install from [extra repository](https://archlinux.org/packages/extra/x86_64/editorconfig-checker/): @@ -87,7 +87,7 @@ paru -S editorconfig-checker-git If go 1.16 or greater is installed, you can also install it globally via `go install`: ```shell -go install github.com/editorconfig-checker/editorconfig-checker/v2/cmd/editorconfig-checker@latest +go install github.com/editorconfig-checker/editorconfig-checker/v3/cmd/editorconfig-checker@latest ``` ## Usage diff --git a/cmd/editorconfig-checker/main.go b/cmd/editorconfig-checker/main.go index efe9365e..72961fd7 100644 --- a/cmd/editorconfig-checker/main.go +++ b/cmd/editorconfig-checker/main.go @@ -6,12 +6,12 @@ import ( "fmt" "os" - "github.com/editorconfig-checker/editorconfig-checker/v2/pkg/config" - "github.com/editorconfig-checker/editorconfig-checker/v2/pkg/error" - "github.com/editorconfig-checker/editorconfig-checker/v2/pkg/files" - "github.com/editorconfig-checker/editorconfig-checker/v2/pkg/logger" - "github.com/editorconfig-checker/editorconfig-checker/v2/pkg/utils" - "github.com/editorconfig-checker/editorconfig-checker/v2/pkg/validation" + "github.com/editorconfig-checker/editorconfig-checker/v3/pkg/config" + "github.com/editorconfig-checker/editorconfig-checker/v3/pkg/error" + "github.com/editorconfig-checker/editorconfig-checker/v3/pkg/files" + "github.com/editorconfig-checker/editorconfig-checker/v3/pkg/logger" + "github.com/editorconfig-checker/editorconfig-checker/v3/pkg/utils" + "github.com/editorconfig-checker/editorconfig-checker/v3/pkg/validation" ) // version is used vor the help diff --git a/go.mod b/go.mod index 0e15ab84..c2ca5ee2 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/editorconfig-checker/editorconfig-checker/v2 +module github.com/editorconfig-checker/editorconfig-checker/v3 go 1.21 diff --git a/pkg/config/config.go b/pkg/config/config.go index f1a0ab73..c76aaff0 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -9,8 +9,8 @@ import ( "github.com/editorconfig/editorconfig-core-go/v2" - "github.com/editorconfig-checker/editorconfig-checker/v2/pkg/logger" - "github.com/editorconfig-checker/editorconfig-checker/v2/pkg/utils" + "github.com/editorconfig-checker/editorconfig-checker/v3/pkg/logger" + "github.com/editorconfig-checker/editorconfig-checker/v3/pkg/utils" ) // DefaultExcludes is the regular expression for ignored files diff --git a/pkg/error/error.go b/pkg/error/error.go index 80c0601b..294edf0f 100644 --- a/pkg/error/error.go +++ b/pkg/error/error.go @@ -4,8 +4,8 @@ package error import ( "fmt" - "github.com/editorconfig-checker/editorconfig-checker/v2/pkg/config" - "github.com/editorconfig-checker/editorconfig-checker/v2/pkg/files" + "github.com/editorconfig-checker/editorconfig-checker/v3/pkg/config" + "github.com/editorconfig-checker/editorconfig-checker/v3/pkg/files" ) // ValidationError represents one validation error diff --git a/pkg/error/error_test.go b/pkg/error/error_test.go index 4549629c..79e38d5a 100644 --- a/pkg/error/error_test.go +++ b/pkg/error/error_test.go @@ -4,7 +4,7 @@ import ( "errors" "testing" - "github.com/editorconfig-checker/editorconfig-checker/v2/pkg/config" + "github.com/editorconfig-checker/editorconfig-checker/v3/pkg/config" ) func TestGetErrorCount(t *testing.T) { diff --git a/pkg/files/files.go b/pkg/files/files.go index c6d4dc97..a527124a 100644 --- a/pkg/files/files.go +++ b/pkg/files/files.go @@ -16,8 +16,8 @@ import ( "github.com/editorconfig/editorconfig-core-go/v2" - "github.com/editorconfig-checker/editorconfig-checker/v2/pkg/config" - "github.com/editorconfig-checker/editorconfig-checker/v2/pkg/utils" + "github.com/editorconfig-checker/editorconfig-checker/v3/pkg/config" + "github.com/editorconfig-checker/editorconfig-checker/v3/pkg/utils" ) const DefaultMimeType = "application/octet-stream" diff --git a/pkg/files/files_test.go b/pkg/files/files_test.go index 28856df4..c404d267 100644 --- a/pkg/files/files_test.go +++ b/pkg/files/files_test.go @@ -8,7 +8,7 @@ import ( "strings" "testing" - "github.com/editorconfig-checker/editorconfig-checker/v2/pkg/config" + "github.com/editorconfig-checker/editorconfig-checker/v3/pkg/config" ) func TestGetContentType(t *testing.T) { diff --git a/pkg/validation/validation.go b/pkg/validation/validation.go index 3de9fc2d..eb5a3ca7 100644 --- a/pkg/validation/validation.go +++ b/pkg/validation/validation.go @@ -8,11 +8,11 @@ import ( "strconv" "strings" - "github.com/editorconfig-checker/editorconfig-checker/v2/pkg/config" - "github.com/editorconfig-checker/editorconfig-checker/v2/pkg/encoding" - "github.com/editorconfig-checker/editorconfig-checker/v2/pkg/error" - "github.com/editorconfig-checker/editorconfig-checker/v2/pkg/files" - "github.com/editorconfig-checker/editorconfig-checker/v2/pkg/validation/validators" + "github.com/editorconfig-checker/editorconfig-checker/v3/pkg/config" + "github.com/editorconfig-checker/editorconfig-checker/v3/pkg/encoding" + "github.com/editorconfig-checker/editorconfig-checker/v3/pkg/error" + "github.com/editorconfig-checker/editorconfig-checker/v3/pkg/files" + "github.com/editorconfig-checker/editorconfig-checker/v3/pkg/validation/validators" "github.com/editorconfig/editorconfig-core-go/v2" ) diff --git a/pkg/validation/validation_test.go b/pkg/validation/validation_test.go index 7b12e577..fa19a13e 100644 --- a/pkg/validation/validation_test.go +++ b/pkg/validation/validation_test.go @@ -3,7 +3,7 @@ package validation import ( "testing" - "github.com/editorconfig-checker/editorconfig-checker/v2/pkg/config" + "github.com/editorconfig-checker/editorconfig-checker/v3/pkg/config" ) func TestProcessValidation(t *testing.T) { diff --git a/pkg/validation/validators/validators.go b/pkg/validation/validators/validators.go index 61af6774..14a07395 100644 --- a/pkg/validation/validators/validators.go +++ b/pkg/validation/validators/validators.go @@ -8,8 +8,8 @@ import ( "strings" "unicode/utf8" - "github.com/editorconfig-checker/editorconfig-checker/v2/pkg/config" - "github.com/editorconfig-checker/editorconfig-checker/v2/pkg/utils" + "github.com/editorconfig-checker/editorconfig-checker/v3/pkg/config" + "github.com/editorconfig-checker/editorconfig-checker/v3/pkg/utils" ) // Indentation validates a files indentation diff --git a/pkg/validation/validators/validators_test.go b/pkg/validation/validators/validators_test.go index 9f8b9e05..feb7ca6d 100644 --- a/pkg/validation/validators/validators_test.go +++ b/pkg/validation/validators/validators_test.go @@ -5,7 +5,7 @@ import ( "reflect" "testing" - "github.com/editorconfig-checker/editorconfig-checker/v2/pkg/config" + "github.com/editorconfig-checker/editorconfig-checker/v3/pkg/config" ) func TestFinalNewline(t *testing.T) { From ae0f240f6a408ca8ce478b200c3ead36d89ac6cb Mon Sep 17 00:00:00 2001 From: Yoan Blanc Date: Sat, 20 Apr 2024 12:38:53 +0200 Subject: [PATCH 05/14] fix: io/ioutil is deprecated (#340) Signed-off-by: Yoan Blanc --- pkg/config/config.go | 6 +++--- pkg/config/config_test.go | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index c76aaff0..8378f087 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -4,7 +4,7 @@ package config import ( "encoding/json" "fmt" - "io/ioutil" + "os" "strings" "github.com/editorconfig/editorconfig-core-go/v2" @@ -134,7 +134,7 @@ func NewConfig(configPath string) (*Config, error) { // Parse parses a config at a given path func (c *Config) Parse() error { if c.Path != "" { - configString, err := ioutil.ReadFile(c.Path) + configString, err := os.ReadFile(c.Path) if err != nil { return err } @@ -276,7 +276,7 @@ func (c Config) Save(version string) error { configJSON, _ := json.MarshalIndent(writtenConfig{Version: version}, "", " ") configString := strings.Replace(string(configJSON[:]), "null", "[]", -1) - err := ioutil.WriteFile(c.Path, []byte(configString), 0644) + err := os.WriteFile(c.Path, []byte(configString), 0644) return err } diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 68b8021a..afa30a0c 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -1,7 +1,6 @@ package config import ( - "io/ioutil" "os" "path/filepath" "reflect" @@ -158,7 +157,7 @@ func TestParse(t *testing.T) { } func TestSave(t *testing.T) { - dir, _ := ioutil.TempDir("", "example") + dir, _ := os.MkdirTemp("", "example") defer os.RemoveAll(dir) configFile := filepath.Join(dir, "config") c, _ := NewConfig(configFile) From dd3d0a712aa4171c404b80f235cfcafbec5ff20b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 May 2024 08:35:33 +0000 Subject: [PATCH 06/14] chore(deps): bump golang.org/x/text from 0.14.0 to 0.15.0 (#343) Bumps [golang.org/x/text](https://github.com/golang/text) from 0.14.0 to 0.15.0. - [Release notes](https://github.com/golang/text/releases) - [Commits](https://github.com/golang/text/compare/v0.14.0...v0.15.0) --- updated-dependencies: - dependency-name: golang.org/x/text dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index c2ca5ee2..5eb3b987 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/baulk/chardet v0.1.0 github.com/editorconfig/editorconfig-core-go/v2 v2.6.2 github.com/gabriel-vasile/mimetype v1.4.3 - golang.org/x/text v0.14.0 + golang.org/x/text v0.15.0 ) require ( diff --git a/go.sum b/go.sum index ef2ba8db..c8a1b812 100644 --- a/go.sum +++ b/go.sum @@ -16,8 +16,8 @@ golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic= golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= From a4452298f92832a50d77e3aa3703dcbe46021dca Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 24 May 2024 08:56:02 +0000 Subject: [PATCH 07/14] chore(deps): bump github.com/gabriel-vasile/mimetype from 1.4.3 to 1.4.4 (#345) Bumps [github.com/gabriel-vasile/mimetype](https://github.com/gabriel-vasile/mimetype) from 1.4.3 to 1.4.4. - [Release notes](https://github.com/gabriel-vasile/mimetype/releases) - [Commits](https://github.com/gabriel-vasile/mimetype/compare/v1.4.3...v1.4.4) --- updated-dependencies: - dependency-name: github.com/gabriel-vasile/mimetype dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 5eb3b987..17585a59 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.21 require ( github.com/baulk/chardet v0.1.0 github.com/editorconfig/editorconfig-core-go/v2 v2.6.2 - github.com/gabriel-vasile/mimetype v1.4.3 + github.com/gabriel-vasile/mimetype v1.4.4 golang.org/x/text v0.15.0 ) @@ -13,7 +13,7 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect golang.org/x/mod v0.16.0 // indirect - golang.org/x/net v0.17.0 // indirect + golang.org/x/net v0.25.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index c8a1b812..833d622a 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/editorconfig/editorconfig-core-go/v2 v2.6.2 h1:dKG8sc7n321deIVRcQtwlMNoBEra7j0qQ8RwxO8RN0w= github.com/editorconfig/editorconfig-core-go/v2 v2.6.2/go.mod h1:7dvD3GCm7eBw53xZ/lsiq72LqobdMg3ITbMBxnmJmqY= -github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= -github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= +github.com/gabriel-vasile/mimetype v1.4.4 h1:QjV6pZ7/XZ7ryI2KuyeEDE8wnh7fHP9YnQy+R0LnH8I= +github.com/gabriel-vasile/mimetype v1.4.4/go.mod h1:JwLei5XPtWdGiMFB5Pjle1oEeoSeEuJfJE+TtfvdB/s= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -14,8 +14,8 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic= golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= -golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= -golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From 31c666af53f614276b1b83c3ea892922bc8172d9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 5 Jun 2024 08:18:19 +0000 Subject: [PATCH 08/14] chore(deps): bump golang.org/x/text from 0.15.0 to 0.16.0 (#346) Bumps [golang.org/x/text](https://github.com/golang/text) from 0.15.0 to 0.16.0. - [Release notes](https://github.com/golang/text/releases) - [Commits](https://github.com/golang/text/compare/v0.15.0...v0.16.0) --- updated-dependencies: - dependency-name: golang.org/x/text dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 17585a59..c6b293fc 100644 --- a/go.mod +++ b/go.mod @@ -6,13 +6,13 @@ require ( github.com/baulk/chardet v0.1.0 github.com/editorconfig/editorconfig-core-go/v2 v2.6.2 github.com/gabriel-vasile/mimetype v1.4.4 - golang.org/x/text v0.15.0 + golang.org/x/text v0.16.0 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/mod v0.16.0 // indirect + golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.25.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index 833d622a..d8262e31 100644 --- a/go.sum +++ b/go.sum @@ -12,12 +12,12 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic= -golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= -golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= -golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= +golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= From 8373f2acff92f7e39b5d3dadcc558e2adc838d19 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 18 Jun 2024 08:10:18 +0000 Subject: [PATCH 09/14] chore(deps): bump docker/build-push-action from 5 to 6 (#349) Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 5 to 6. - [Release notes](https://github.com/docker/build-push-action/releases) - [Commits](https://github.com/docker/build-push-action/compare/v5...v6) --- updated-dependencies: - dependency-name: docker/build-push-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/docker-publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index b998569c..55c100d6 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -46,7 +46,7 @@ jobs: images: ${{ format('{0}/editorconfig-checker', secrets.DOCKER_USERNAME || 'dev') }} - name: Build and push Docker image - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v6 with: context: . push: ${{ github.event_name != 'pull_request' }} From 576114b4151ad3dfd1e602a58eb0b9927e7affb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20Str=C3=BCbing?= Date: Tue, 2 Jul 2024 10:30:32 +0200 Subject: [PATCH 10/14] ci: remove changelog gen (#352) --- .github/workflows/ci.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6b715a04..67d7272a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,4 @@ jobs: - run: ./bin/ec -config stuff.json -init && diff stuff.json ./testfiles/generated-config.json && rm stuff.json - run: make run - run: make bench - - uses: heinrichreimer/github-changelog-generator-action@v2.4 - with: - token: ${{ secrets.GH_TOKEN_PAT }} - uses: codecov/codecov-action@v4 From 0d6f59cfafeb9770ccdec2aec50f7165e4945b02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20Str=C3=BCbing?= Date: Tue, 2 Jul 2024 10:32:06 +0200 Subject: [PATCH 11/14] ci: run docker login and publish on main and on tags creation (#344) * Closes #342 --- .github/workflows/docker-publish.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 55c100d6..3d9ae613 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -33,7 +33,7 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Log in to Docker Hub - if: ${{ github.ref_name == 'main' }} + if: ${{ github.ref_name == 'main' || github.ref.type == 'tag' }} uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USERNAME }} @@ -49,7 +49,7 @@ jobs: uses: docker/build-push-action@v6 with: context: . - push: ${{ github.event_name != 'pull_request' }} + push: ${{ github.ref_name == 'main' || github.ref.type == 'tag' }} tags: | ${{ steps.meta.outputs.tags }} ${{ secrets.DOCKER_USERNAME || 'dev' }}/editorconfig-checker:latest From 64b76e74b138cd8f7f52472b452d5ba2e1d451f0 Mon Sep 17 00:00:00 2001 From: Simon Holesch <8659229+holesch@users.noreply.github.com> Date: Tue, 2 Jul 2024 13:15:40 +0200 Subject: [PATCH 12/14] fix: check if multiple newlines are at EOF (#350) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With insert_final_newline enabled, only a single final newline should be at the end of file. Add a check to fail, if there are multiple newlines. This new validation logic doesn't fail with wrong line endings anymore, there's already another validator for that. Fixes #341 Co-authored-by: Théo LUDWIG --- pkg/validation/validators/validators.go | 33 ++++++++++++----- pkg/validation/validators/validators_test.go | 38 ++++++++++++-------- testfiles/spaces-with-tab.c | 1 - 3 files changed, 47 insertions(+), 25 deletions(-) diff --git a/pkg/validation/validators/validators.go b/pkg/validation/validators/validators.go index 14a07395..8bd763e8 100644 --- a/pkg/validation/validators/validators.go +++ b/pkg/validation/validators/validators.go @@ -93,22 +93,37 @@ func TrailingWhitespace(line string, trimTrailingWhitespace bool) error { // FinalNewline validates if a file has a final and correct newline func FinalNewline(fileContent string, insertFinalNewline string, endOfLine string) error { - if endOfLine != "" && insertFinalNewline == "true" { - expectedEolChar := utils.GetEolChar(endOfLine) - if !strings.HasSuffix(fileContent, expectedEolChar) || (expectedEolChar == "\n" && strings.HasSuffix(fileContent, "\r\n")) { - return errors.New("Wrong line endings or no final newline") - } + if insertFinalNewline == "" { + return nil + } + + var expectedEolChars string + + if endOfLine != "" { + expectedEolChars = utils.GetEolChar(endOfLine) } else { - regexpPattern := "(\n|\r|\r\n)$" - hasFinalNewline, _ := regexp.MatchString(regexpPattern, fileContent) + expectedEolChars = `\r\n|\r|\n` + } + + re := regexp.MustCompile("(?:" + expectedEolChars + ")((?:" + expectedEolChars + ")?)$") + matches := re.FindStringSubmatch(fileContent) + + unexpectedCrLf := expectedEolChars == "\n" && strings.HasSuffix(fileContent, "\r\n") - if insertFinalNewline == "false" && hasFinalNewline { + if insertFinalNewline == "false" { + if matches != nil && !unexpectedCrLf { return errors.New("No final newline expected") } + } - if insertFinalNewline == "true" && !hasFinalNewline { + if insertFinalNewline == "true" { + if matches == nil || unexpectedCrLf { return errors.New("Final newline expected") } + + if matches[1] != "" { + return errors.New("Multiple newlines at end of file") + } } return nil diff --git a/pkg/validation/validators/validators_test.go b/pkg/validation/validators/validators_test.go index feb7ca6d..25c6ca63 100644 --- a/pkg/validation/validators/validators_test.go +++ b/pkg/validation/validators/validators_test.go @@ -19,33 +19,33 @@ func TestFinalNewline(t *testing.T) { {"x\r", "true", "cr", nil}, {"x\r\n", "true", "crlf", nil}, - {"x", "true", "lf", errors.New("Wrong line endings or no final newline")}, - {"x", "true", "cr", errors.New("Wrong line endings or no final newline")}, - {"x", "true", "crlf", errors.New("Wrong line endings or no final newline")}, + {"x", "true", "lf", errors.New("Final newline expected")}, + {"x", "true", "cr", errors.New("Final newline expected")}, + {"x", "true", "crlf", errors.New("Final newline expected")}, - {"x\n", "true", "cr", errors.New("Wrong line endings or no final newline")}, - {"x\n", "true", "crlf", errors.New("Wrong line endings or no final newline")}, + {"x\n", "true", "cr", errors.New("Final newline expected")}, + {"x\n", "true", "crlf", errors.New("Final newline expected")}, - {"x\r", "true", "lf", errors.New("Wrong line endings or no final newline")}, - {"x\r", "true", "crlf", errors.New("Wrong line endings or no final newline")}, + {"x\r", "true", "lf", errors.New("Final newline expected")}, + {"x\r", "true", "crlf", errors.New("Final newline expected")}, - {"x\r\n", "true", "lf", errors.New("Wrong line endings or no final newline")}, - {"x\r\n", "true", "cr", errors.New("Wrong line endings or no final newline")}, + {"x\r\n", "true", "lf", errors.New("Final newline expected")}, + {"x\r\n", "true", "cr", errors.New("Final newline expected")}, // insert_final_newline false {"x", "false", "lf", nil}, {"x\n", "false", "lf", errors.New("No final newline expected")}, - {"x\r", "false", "lf", errors.New("No final newline expected")}, - {"x\r\n", "false", "lf", errors.New("No final newline expected")}, + {"x\r", "false", "lf", nil}, + {"x\r\n", "false", "lf", nil}, {"x", "false", "cr", nil}, - {"x\n", "false", "cr", errors.New("No final newline expected")}, + {"x\n", "false", "cr", nil}, {"x\r", "false", "cr", errors.New("No final newline expected")}, - {"x\r\n", "false", "cr", errors.New("No final newline expected")}, + {"x\r\n", "false", "cr", nil}, {"x", "false", "crlf", nil}, - {"x\n", "false", "crlf", errors.New("No final newline expected")}, - {"x\r", "false", "crlf", errors.New("No final newline expected")}, + {"x\n", "false", "crlf", nil}, + {"x\r", "false", "crlf", nil}, {"x\r\n", "false", "crlf", errors.New("No final newline expected")}, // insert_final_newline not set @@ -71,6 +71,14 @@ func TestFinalNewline(t *testing.T) { {"x\r", "false", "", errors.New("No final newline expected")}, {"x\r\n", "true", "", nil}, {"x\r\n", "false", "", errors.New("No final newline expected")}, + + // multiple newlines + {"x\n\n", "true", "", errors.New("Multiple newlines at end of file")}, + {"x\r\r", "true", "", errors.New("Multiple newlines at end of file")}, + {"x\r\n\r\n", "true", "", errors.New("Multiple newlines at end of file")}, + {"x\n\n", "true", "lf", errors.New("Multiple newlines at end of file")}, + {"x\r\r", "true", "cr", errors.New("Multiple newlines at end of file")}, + {"x\r\n\r\n", "true", "crlf", errors.New("Multiple newlines at end of file")}, } for _, tt := range finalNewlineTests { diff --git a/testfiles/spaces-with-tab.c b/testfiles/spaces-with-tab.c index a015fa70..1ff9583b 100644 --- a/testfiles/spaces-with-tab.c +++ b/testfiles/spaces-with-tab.c @@ -11,4 +11,3 @@ int main(int argc, char *argv[]) } return 0; } - From 84ef7236b37ac17d52a1742bf7ca550f83d32684 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20Str=C3=BCbing?= Date: Tue, 2 Jul 2024 14:09:04 +0200 Subject: [PATCH 13/14] build: remove openbsd/mips64 I dont have access to a linux machine currently and this doesnt seem to work on Mac right now --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 7898470f..d0a665ce 100644 --- a/Makefile +++ b/Makefile @@ -142,7 +142,7 @@ _build-all-binaries: $(call _build_target,openbsd/amd64) $(call _build_target,openbsd/arm) $(call _build_target,openbsd/arm64) - $(call _build_target,openbsd/mips64) + # $(call _build_target,openbsd/mips64) $(call _build_target,plan9/386) $(call _build_target,plan9/amd64) $(call _build_target,plan9/arm) From eb2e935a80148cae36efebddda292fa842423a92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20Str=C3=BCbing?= Date: Tue, 2 Jul 2024 14:09:57 +0200 Subject: [PATCH 14/14] chore(release): v3.0.2 --- .ecrc | 2 +- README.md | 2 +- VERSION | 2 +- pkg/config/config_test.go | 4 ++-- testfiles/generated-config.json | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.ecrc b/.ecrc index d78b713c..c54f424b 100644 --- a/.ecrc +++ b/.ecrc @@ -1,5 +1,5 @@ { - "Version": "v3.0.1", + "Version": "v3.0.2", "Verbose": false, "Debug": false, "IgnoreDefaults": false, diff --git a/README.md b/README.md index 301d10eb..25c8c887 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ Unsupported features are: ## Quickstart ```shell -VERSION="v3.0.1" +VERSION="v3.0.2" OS="linux" ARCH="amd64" curl -O -L -C - https://github.com/editorconfig-checker/editorconfig-checker/releases/download/$VERSION/ec-$OS-$ARCH.tar.gz && \ diff --git a/VERSION b/VERSION index b105cea1..96506fd2 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v3.0.1 +v3.0.2 diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index afa30a0c..65fb2039 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -82,7 +82,7 @@ func TestMerge(t *testing.T) { mergeConfig = Config{ ShowVersion: true, - Version: "v3.0.1", + Version: "v3.0.2", Help: true, DryRun: true, Path: "some-other", @@ -175,7 +175,7 @@ func TestGetAsString(t *testing.T) { _ = c.Parse() actual := c.GetAsString() - expected := "Config: {ShowVersion:false Help:false DryRun:false Path:../../.ecrc Version:v3.0.1 Verbose:false Format: Debug:false IgnoreDefaults:false SpacesAftertabs:false NoColor:false Exclude:[testfiles testdata] AllowedContentTypes:[text/ application/octet-stream application/ecmascript application/json application/x-ndjson application/xml +json +xml] PassedFiles:[] Disable:{EndOfLine:false Indentation:false InsertFinalNewline:false TrimTrailingWhitespace:false IndentSize:false MaxLineLength:false} Logger:{Verbosee:false Debugg:false NoColor:false} EditorconfigConfig:0x" + expected := "Config: {ShowVersion:false Help:false DryRun:false Path:../../.ecrc Version:v3.0.2 Verbose:false Format: Debug:false IgnoreDefaults:false SpacesAftertabs:false NoColor:false Exclude:[testfiles testdata] AllowedContentTypes:[text/ application/octet-stream application/ecmascript application/json application/x-ndjson application/xml +json +xml] PassedFiles:[] Disable:{EndOfLine:false Indentation:false InsertFinalNewline:false TrimTrailingWhitespace:false IndentSize:false MaxLineLength:false} Logger:{Verbosee:false Debugg:false NoColor:false} EditorconfigConfig:0x" if !strings.HasPrefix(actual, expected) { t.Errorf("Expected: %v, got: %v ", expected, actual) diff --git a/testfiles/generated-config.json b/testfiles/generated-config.json index c2dc91fe..ce19fb03 100644 --- a/testfiles/generated-config.json +++ b/testfiles/generated-config.json @@ -1,5 +1,5 @@ { - "Version": "v3.0.1", + "Version": "v3.0.2", "Verbose": false, "Format": "", "Debug": false,