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

Filter out files _before_ parsing #272

Merged
merged 1 commit into from
Aug 23, 2023
Merged

Conversation

anderseknert
Copy link
Member

Also:

  • Allow files to be provided either from file paths, or programmatically as modules.
  • Marshal config directly to Config struct, and prefer to use the struct rather than passing around the config as a map.

Fixes #265

Copy link
Collaborator

@kristiansvalland kristiansvalland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great refactor and fix of the ignore logic. 🙂

I had just one question and one minor suggestion, but those are in no way blocking for this PR and can be ignored if they are wrong or you disagree.

@@ -72,6 +72,23 @@ func JSONRoundTrip(from any, to any) error {
return json.Unmarshal(bs, to) //nolint:wrapcheck
}

// YAMLRoundTrip convert any value to YAML and back again.
func YAMLRoundTrip(from any, to any) error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I am not very familiar with (un)marshalling YAML, I do not immediately see how making a roundtrip via YAML as the intermediate is any different from JSON when considering the end result. Or is there some go types that would behave differently in this case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, you're right. This remained from a point where I considered ditching JSON altogether, but I realized later we need that for output formats. I'll have this removed before merge.

Comment on lines 167 to 171
level, ok := result["level"].(string)
if !ok {
return errLevelMustBeString
}

if ignore, ok := result["ignore"]; ok {
var dst Ignore

err := rio.YAMLRoundTrip(ignore, &dst)
if err != nil {
return fmt.Errorf("unmarshalling rule ignore failed: %w", err)
}

rule.Ignore = dst
}

delete(result, "enabled")

rule.Level = level
rule.Extra = result

return nil
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not a big improvement, but could/should this part be shared with UnmarshalJSON to reduce code duplication?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough! Done.

Also:
* Allow files to be provided either from file paths, *or*
  programmatically as modules.
* Marshal config directly to Config struct, and prefer to use
  the struct rather than passing around the config as a map.

Fixes #265

Signed-off-by: Anders Eknert <anders@styra.com>
@anderseknert anderseknert merged commit 2b3d7ed into main Aug 23, 2023
1 check passed
@anderseknert anderseknert deleted the fix-ignore-parse-error branch August 23, 2023 21:06
srenatus pushed a commit to srenatus/regal that referenced this pull request Oct 1, 2024
Also:
* Allow files to be provided either from file paths, *or*
  programmatically as modules.
* Marshal config directly to Config struct, and prefer to use
  the struct rather than passing around the config as a map.

Fixes StyraInc#265

Signed-off-by: Anders Eknert <anders@styra.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Files ignored may still cause parse errors
2 participants