From 7ece46f684923244905c1882008ecaee677e9c0d Mon Sep 17 00:00:00 2001 From: Kim Christensen Date: Fri, 9 Feb 2024 23:17:11 +0100 Subject: [PATCH 1/3] Lint messages reported from porter not mention mixins Signed-off-by: Kim Christensen --- pkg/linter/linter.go | 8 ++++++-- pkg/linter/linter_test.go | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/pkg/linter/linter.go b/pkg/linter/linter.go index 93d83604f..17c1486f6 100644 --- a/pkg/linter/linter.go +++ b/pkg/linter/linter.go @@ -111,8 +111,12 @@ type Location struct { } func (l Location) String() string { - return fmt.Sprintf("%s: %s step in the %s mixin (%s)", - l.Action, humanize.Ordinal(l.StepNumber), l.Mixin, l.StepDescription) + mixin := "" + if l.Mixin != "" { + mixin = fmt.Sprintf("in the %s mixin ", l.Mixin) + } + return fmt.Sprintf("%s: %s step %s(%s)", + l.Action, humanize.Ordinal(l.StepNumber), mixin, l.StepDescription) } // Results is a set of items identified by the linter. diff --git a/pkg/linter/linter_test.go b/pkg/linter/linter_test.go index 8a8a490c7..641e1bca2 100644 --- a/pkg/linter/linter_test.go +++ b/pkg/linter/linter_test.go @@ -153,4 +153,24 @@ func TestLinter_Lint(t *testing.T) { require.NoError(t, err, "Lint failed") require.Len(t, results, 0, "linter should have returned 1 result") }) + + t.Run("lint messages does not mention mixins in message not coming from mixin", func(t *testing.T) { + cxt := portercontext.NewTestContext(t) + mixins := mixin.NewTestMixinProvider() + l := New(cxt.Context, mixins) + param := map[string]manifest.ParameterDefinition{ + "A": { + Name: "porter_test", + }, + } + + m := &manifest.Manifest{ + Parameters: param, + } + + results, err := l.Lint(ctx, m) + require.NoError(t, err, "Lint failed") + require.Len(t, results, 1, "linter should have returned 1 result") + require.NotContains(t, results[0].String(), ": 0th step in the mixin ()") + }) } From 29b28a9962b9eb5c38927a366b72765396bde19e Mon Sep 17 00:00:00 2001 From: Kim Christensen Date: Fri, 9 Feb 2024 23:11:18 +0100 Subject: [PATCH 2/3] Add to CONTRIBUTORS Signed-off-by: Kim Christensen --- CONTRIBUTORS.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 598189841..eec120e36 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -93,4 +93,5 @@ and we will add you. **All** contributors belong here. 💯 - [Xin Fu](https://github.com/imfing) - [KallyDev](https://github.com/kallydev) - [Salman Shah](https://github.com/sbshah97) -- [Ray Terrill](https://github.com/rayterrill) \ No newline at end of file +- [Ray Terrill](https://github.com/rayterrill) +- [Kim Christensen](https://github.com/kichristensen) From 10362c65c4aa6e8499a85f73e2d15521e3ed71fa Mon Sep 17 00:00:00 2001 From: Kim Christensen Date: Thu, 15 Feb 2024 22:55:07 +0100 Subject: [PATCH 3/3] Do not print location when mixin is empty Signed-off-by: Kim Christensen --- pkg/linter/linter.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/pkg/linter/linter.go b/pkg/linter/linter.go index 17c1486f6..73840f98b 100644 --- a/pkg/linter/linter.go +++ b/pkg/linter/linter.go @@ -68,7 +68,9 @@ type Result struct { func (r Result) String() string { var buffer strings.Builder buffer.WriteString(fmt.Sprintf("%s(%s) - %s\n", r.Level, r.Code, r.Title)) - buffer.WriteString(r.Location.String() + "\n") + if r.Location.Mixin != "" { + buffer.WriteString(r.Location.String() + "\n") + } if r.Message != "" { buffer.WriteString(r.Message + "\n") @@ -111,12 +113,8 @@ type Location struct { } func (l Location) String() string { - mixin := "" - if l.Mixin != "" { - mixin = fmt.Sprintf("in the %s mixin ", l.Mixin) - } - return fmt.Sprintf("%s: %s step %s(%s)", - l.Action, humanize.Ordinal(l.StepNumber), mixin, l.StepDescription) + return fmt.Sprintf("%s: %s step in the %s mixin (%s)", + l.Action, humanize.Ordinal(l.StepNumber), l.Mixin, l.StepDescription) } // Results is a set of items identified by the linter.