-
Notifications
You must be signed in to change notification settings - Fork 47
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: Add lint cfg section handling include & exclude patterns #952
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# This is an example config to be used when running pint as a linter | ||
|
||
lint { | ||
# Check all files inside rules/alerting and rules/recording dirs. | ||
include = ["rules/(alerting|recording)/.+"] | ||
|
||
# Ignore all *.md and *.txt files. | ||
exclude = [".+.md", ".+.txt"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package config | ||
|
||
type Lint struct { | ||
Include []string `hcl:"include,optional" json:"include,omitempty"` | ||
Exclude []string `hcl:"exclude,optional" json:"exclude,omitempty"` | ||
} | ||
|
||
func (lint Lint) validate() error { | ||
if err := ValidatePaths(lint.Include); err != nil { | ||
return err | ||
} | ||
if err := ValidatePaths(lint.Exclude); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package config | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestLintSettings(t *testing.T) { | ||
type testCaseT struct { | ||
err error | ||
conf Lint | ||
} | ||
|
||
testCases := []testCaseT{ | ||
{ | ||
conf: Lint{ | ||
Include: []string{"foo/.+"}, | ||
Exclude: []string{"foo/.+"}, | ||
}, | ||
}, | ||
{ | ||
conf: Lint{ | ||
Include: []string{".+++"}, | ||
Exclude: []string{"foo/.+"}, | ||
}, | ||
err: errors.New("error parsing regexp: invalid nested repetition operator: `++`"), | ||
}, | ||
{ | ||
conf: Lint{ | ||
Include: []string{"foo/.+"}, | ||
Exclude: []string{".+++"}, | ||
}, | ||
err: errors.New("error parsing regexp: invalid nested repetition operator: `++`"), | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(fmt.Sprintf("%v", tc.conf), func(t *testing.T) { | ||
err := tc.conf.validate() | ||
if err == nil || tc.err == nil { | ||
require.Equal(t, err, tc.err) | ||
} else { | ||
require.EqualError(t, err, tc.err.Error()) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package config | ||
|
||
import ( | ||
"regexp" | ||
) | ||
|
||
func ValidatePaths(paths []string) error { | ||
for _, pattern := range paths { | ||
_, err := regexp.Compile(pattern) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package config | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestValidatePaths(t *testing.T) { | ||
type testCaseT struct { | ||
err error | ||
paths []string | ||
} | ||
|
||
testCases := []testCaseT{ | ||
{ | ||
paths: []string{"foo/.+"}, | ||
}, | ||
{ | ||
paths: []string{".+++"}, | ||
err: errors.New("error parsing regexp: invalid nested repetition operator: `++`"), | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(fmt.Sprintf("%v", tc.paths), func(t *testing.T) { | ||
err := ValidatePaths(tc.paths) | ||
if err == nil || tc.err == nil { | ||
require.Equal(t, err, tc.err) | ||
} else { | ||
require.EqualError(t, err, tc.err.Error()) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I like the idea of having multiple include/exclude options, we'll end up with
all having same values.
If we were to have another place to add include/exclude then both options should be moved to
parser {}
and used for all commands.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, as a user, I'd expect an ability to inherit a base set of paths, then add other exclusions or inclusions on a command-by-command basis.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@prymitive I see you just closed this MR. Can you please comment on the above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or better yet, follow up in the issue? I want to upstream the changes and would hate to have to fork this