You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adding new options would require breaking changes to the function signature. While Scorecard has historically not cared about breaking changes, this is the single most important one, and we’ve broken it countless times when adding features.
Callers need to provide all parameters, even if they’re fine with the default values. Looking at our own usages, the vast majority of our calls use the default values.
Solution
We can use functional options to solve this problem. Functional options are a paradigm to pass an arbitrary number of options to a function to modify its behavior without changing its signature. At its core is the option type, which is unsurprisingly an alias for a function signature.
typeOptionfunc(*somePrivateState) error
The first step is splitting our current arguments into required and optional values. I’m arguing that the only required values are the context and the repo to analyze (for rationale, see Appendix). Every other existing argument will use default values, unless modified by an option:
With this starting point, options are easily added. Let’s use commit SHA and depth as an example, we just add a new field to our unexported state, and an exported option to manipulate it:
The default is to run all checks, but if --checks is provided, only those checks are run. However with structured results we're also seeing --probes added (see 🌱 Add probes to main call #3688)
Note: still tweaking this, but happy to get any feedback.
Problem
Our current top-level entrypoint,
RunScorecard
, has a long list of parameters.There’s two problems with this:
Solution
We can use functional options to solve this problem. Functional options are a paradigm to pass an arbitrary number of options to a function to modify its behavior without changing its signature. At its core is the option type, which is unsurprisingly an alias for a function signature.
The first step is splitting our current arguments into required and optional values. I’m arguing that the only required values are the context and the repo to analyze (for rationale, see Appendix). Every other existing argument will use default values, unless modified by an option:
With this starting point, options are easily added. Let’s use commit SHA and depth as an example, we just add a new field to our unexported state, and an exported option to manipulate it:
Existing callers don’t need to change their signature, but those that want to customize the behavior can:
Appendix
A lot of the arguments either have default behavior built in already. Or the callers tend to provide the same arguments.
commitSHA string
,clients.HeadSHA
is the default, unless someone provides the--commit
optioncommitDepth int
checksToRun checker.CheckNameToFnMap
--checks
is provided, only those checks are run. However with structured results we're also seeing--probes
added (see 🌱 Add probes to main call #3688)all of the repo clients
clients.DefaultCIIBestPracticesClient()
checker.GetClients
, which indirectly creates the default clientschecker.GetClients
The text was updated successfully, but these errors were encountered: