R05SAFEfunctionOptional Parameter Added
Flags when a new optional parameter is added. Existing callers are unaffected because they are not required to provide the new argument.
Applies to
TypeScriptPythonGoJavaRust
Why it matters
This is flagged as safe because optional parameters do not break existing callers. The function continues to work with the same call signatures. However, it is still reported in the analysis because it represents a change to the public API surface that reviewers should be aware of.
Example
Before
// fetcher.ts
export function fetchData(
url: string
): Promise<Response> { ... }After (optional param added)
// fetcher.ts (SAFE — optional param added)
export function fetchData(
url: string,
options?: RequestOptions // New optional parameter
): Promise<Response> { ... }What you see in the terminal
$ npx dg check
[SAFE] fetchData (signature_change)
src/fetcher.ts:3
Optional parameter 'options' was added. Existing callers are unaffected.How detection works
The classifier counts the total parameter count in both signatures. If a new parameter exists in the new signature that was not in the old signature and it is marked optional (?, default value, or rest param), the rule fires with a safe severity.
Real-world scenario
A team adds an optional `options` parameter to a fetch utility function to support custom headers. All existing callers that call `fetchData(url)` continue to work without changes.
Edge cases
- A parameter with a default value is treated as optional
- Adding multiple optional params in one change generates one report per param