-
Notifications
You must be signed in to change notification settings - Fork 551
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
refactor: pull out custom rules code #2751
Conversation
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.
Excellent initiative, the main flow feels much cleaner after this refactor.
Managed to successfully run it locally 🚀
Left a small refactor suggestion open for discussion.
iacOrgSettings: IacOrgSettings, | ||
options: IaCTestFlags, | ||
): Promise<{ | ||
isLocalCustomRules: boolean; |
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.
This is not a request, but rather an idea open for discussion.
I've given a bit of consideration to the return type of this function.
What we have here seems to be a tri-state value for provided custom rules.
Custom rules are either:
- Not provided.
- Provided locally.
- Provided remotely.
Instead of returning an object with 2 boolean flags, one for flagging rules provided locally, and one for flagging provided remotely, I'd like to propose returning a union type value here:
type RulesOrigin = 'local' | 'remote' | 'none';
Which can later be utilized in the addIacAnalytics
function, where these values are needed.
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.
Alternatively, the return value can be optional for the case where rules are not provided, and so the union values could be shortened to be:
type RulesOrigin = 'local' | 'remote';
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.
That was a really good suggestion. Makes the code much easier to ready 🤩
f9608aa
to
e791e19
Compare
What does this PR do?
This PR extracts the custom and internal Snyk rules code from the main
test
function into its own file. For increased readability and in preparation of adding extended Terraform language support, which will make this function even bigger. This is needed for #2752 (which is not ready for review yet and pending snyk/snyk-iac-parsers#7).How should this be manually tested?
To review, have a look at the new
initRules
function and notice how it matches up with the code extracted from thetest
function.To test it:
npm run build
snyk-iac-rules build ./fixtures/custom-rules -o bundle.tar.gz
snyk-dev iac test ./fixtures/custom-rules/rules/CUSTOM-1/fixtures
The acceptance tests would verify this plus the remote bundles, so if the tests pass then this is good to go.