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

Fix: Scaffolding now properly populates templatesge nam… #277

Merged
merged 6 commits into from
Sep 5, 2023

Conversation

ThomasKingoTM
Copy link
Contributor

The scaffolding "regal new rule" was adding incorrectly formatted package names in both the regal policy and the test.
This PR should fix the following:

  1. The package name of the regal policy and the test file.
  2. The import of the regal policy into the test file.
  3. The 'title' attribute in the output of rule.report.

Copy link
Member

@anderseknert anderseknert left a comment

Choose a reason for hiding this comment

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

Looks good! Just a minor correction required. I'm also not sure what the newly added .regal directory is there for?

cmd/new.go Outdated
} else {
tmplNameTestValue = "." + params.name + "_test"
tmplNameTestValue = "." + params.name + "-test"
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't change — the _test suffix is idiomatic for test packages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ran "regal new rule -t custom -c test -n some_name" a few times, so it might have created it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But why doesn't it build correctly?

Copy link
Member

Choose a reason for hiding this comment

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

Some rather strict linter rules for Go as well :P
Screenshot 2023-08-29 at 23 52 06

Copy link
Member

Choose a reason for hiding this comment

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

I ran "regal new rule -t custom -c test -n some_name" a few times, so it might have created it.

What I mean is — even if your linte rule would be called "foo-bar-baz", the idiomatic naming for its test package would be "foo-bar-baz_test". So the code should not rewrite that to be "foo-bar-baz-test".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

However, it still doesn't seem to build. I can't figure out why.

Copy link
Member

Choose a reason for hiding this comment

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

The linter is complaining that we're not using the first assignment, i.e.

// This assignment is never used
tmplNameValue := strings.ReplaceAll(params.name, "_", "-")

And it's correct about that. It was my code, so apologies for that! We should of course us it in the contains check:

tmplNameValue = strings.ReplaceAll(params.name, "_", "-")

if strings.Contains(tmplNameValue, "-") {

Same thing for the test template name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be fixed now. Still doesn't build - a ton of "Cannot open: file exists" errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Finally works - had to decuddle assignments (their linter sure is rough to get by) :)

Copy link
Member

Choose a reason for hiding this comment

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

Hehe, sure is! Yeah, those warnings are annoying but nothing to worry about. Some bug in the Go linter as I understood it.

I'd suggest getting golangcilint yourself so that you can run golangci-lint run ./... yourself before pushing your commits.

@anderseknert anderseknert merged commit 4e48367 into StyraInc:main Sep 5, 2023
1 check passed
@anderseknert
Copy link
Member

Thanks!

@ThomasKingoTM ThomasKingoTM deleted the scaffoldFix branch September 5, 2023 12:27
srenatus pushed a commit to srenatus/regal that referenced this pull request Oct 1, 2024
* fix, scaffolding now populates the templates with correct package names, imports the correct path 'as rule' and pupulates 'title' correctly in test.
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.

2 participants