Skip to content

xlflow analyze

Analyze VBA source for runtime-risk patterns without Excel COM.

Usage

bash
xlflow analyze

Options and Arguments

Option / argumentDescriptionDefault
--jsonReturn structured analysis findings.false

Examples

bash
xlflow analyze
xlflow analyze --json

Notes

TIP

Use analyze for fast source-level feedback before opening Excel.

IMPORTANT

Findings that block automation return a failure status and exit code 1.

Rules

CodeSeverityDescription
VBA101warningObject variable assignment likely missing Set.
VBA102warningObject-returning project function assignment likely missing Set.
VBA103warningObject-returning function body likely missing Set <FunctionName> = ....
VBA104errorKnown Excel object/member mismatch such as Worksheet.DisplayGridlines.
VBA105errorRemoved XlflowLog trace helper call.
VBA106errorRemoved XlflowSetTraceFile trace helper call.
VBA201warningRange.Find result is dereferenced before a Nothing check.
VBA202warningObject variable may be used before an obvious Set assignment.
VBA203warningApplication state is changed without an obvious restore path.
VBA204warningNormal execution can fall through into an error-handler label.
VBA205warningUnqualified or active Excel object access depends on runtime sheet state.
VBA206warningLikely ByRef argument type mismatch against a project-local procedure.
VBA207warningDictionary or Collection item access has no obvious existence guard.
VBA208warningReDim Preserve is used on a multi-dimensional array.
VBA209warningObject or array is compared with scalar equality.
VBA210warningFunction may exit without assigning its return value.
VBA211errorExpanded known Excel object/member mismatch.
VBA212warningObject Nothing guard and dereference share a non-short-circuit expression.

Disable configurable analyzer rules with [analyze].disabled_rules:

toml
[analyze]
disabled_rules = ["VBA205", "VBA211"]

Legacy per-rule booleans such as forbid_unqualified_excel_objects = false remain accepted for compatibility, but xlflow emits a deprecation warning. If both formats disagree, disabled_rules takes precedence and xlflow reports a conflict warning.

Use inline suppression comments for intentional local exceptions while keeping rules enabled globally:

vb
' xlflow:disable-next-line VBA205
Range("A1").Value = 1

Cells(1, 1).Value = 2 ' xlflow:disable-line VBA205

Multiple IDs may be listed with spaces. Unknown IDs, unsupported preflight-blocking IDs, and suppressions that no longer match an analyzer diagnostic are reported as warnings.

Rules VBA201 through VBA205, VBA208, VBA209, VBA211, and VBA212 are enabled by default. Rules VBA206, VBA207, and VBA210 are opt-in through legacy [analyze] settings because they are more dataflow-sensitive. Diagnostics VBA101 through VBA106 are always enabled.

JSON Output Example

Failed --json output uses the xlflow envelope plus command-specific fields.

json
{
  "status": "failed",
  "command": "analyze",
  "error": {
    "code": "analyze_failed",
    "message": "1 analysis finding(s) found"
  },
  "analysis": [
    {
      "code": "VBA201",
      "severity": "warning",
      "file": "src/modules/Main.bas",
      "module": "Main",
      "procedure": "Run",
      "line": 12,
      "message": "Range.Find result found is dereferenced before a Nothing check."
    }
  ]
}

Released under the MIT License.