Delphi-RAG-Lint

drag-lint help

Lint rules for results, parameters, nested addresses and overlays

Since: 1.54.0-alpha

Eight rules: a managed Result read too early, one variable in two var parameters, nested routine addresses, overlays, parameters, constant returns.

Read this to see what each of the eight rules reports, when it stays silent, and which four you have to turn on.

How to run it

drag-lint lint <path> [--profile <name>] [--target-compiler <ver|auto>] [--rule <id>|help] [--disable id1,id2] [--rules-dir <dir>] [--json] [--labels] [--no-preprocess] [--library-db <lib.sqlite>] [--build-config <name>] [--no-budget]

Example:

drag-lint lint <file.pas> --rule managed-result-read-first --db <index.sqlite>

Full flag list: lint in the CLI reference.

Where to click

No IDE surface: this feature runs from the CLI (see How to run it).

Details

Eight rules that run in lint and lint-all, in the IDE and in VS Code.

drag-lint lint <unit.pas> --db <project.sqlite> --rule managed-result-read-first
drag-lint lint-all --db <project.sqlite> --enable constant-return,redundant-field-init
ruleseveritydefaultneeds the index
managed-result-read-firstwarningONno (type names of other units: yes)
same-variable-two-var-paramswarningONyes
address-of-nested-routinewarningONno
absolute-overlayhintOFFno
constant-returnhintOFFyes
redundant-field-inithintOFFno
var-param-never-writtenhintOFFyes
value-param-assignedhintOFFno

Turn one off with "disabled": ["absolute-overlay"] in the lint config, on with "enabled": [..] or --enable, or approve one line with a dl:ok marker. The OFF rules cost nothing while they are off.

managed-result-read-first

The result of a function that returns a string, a dynamic array, an interface or a Variant is a hidden var parameter: on entry it can hold what the caller's variable held. The rule reports the first place where the function uses Result before every path has set it:

function Join(const A: TArray<string>): string;
begin
  for var S in A do
    Result := Result + S;      // in a loop of the caller the old text stays in front
end;

Also SetLength(Result, Length(Result) + 1), if Result = nil and while Length(Result) < N. One finding per function.

When an assignment can come before the read, the rule reports it only if a path without one is certain: the read runs on every call, nothing before it leaves the function, and one if or case holds all the assignments before it. A read under a condition, in a counted loop or behind and / or may go together with the assignment (`if I = 0 then Result := S[I] else Result := Result + ',' + S[I], aFoundflag) and is silent; so are assignments in a loop, in atrywithexcept` or in a case over an enumeration. Result := Result + X is no assignment in this sense.

Silent when every path sets Result first (assignment, own name, Exit(value), an element or a field of it); Result is passed to a routine that can fill it (SetLength(Result, N), Fill(Result), @Result); a nested routine or an anonymous method uses it; the other branch ends in a routine that always raises (of the unit, RaiseLastOSError, or noreturn in the index); the result is a record, a short string or an unmanaged type; the routine holds asm.

same-variable-two-var-params

Swap(S, S): one variable, two parameters that can both write it. Also Parse(const S: string; out S), where the call clears the text it is about to read. The callee must be the one certain target in the index.

Silent for untyped parameters (Move), for a const with a var, for const with out of an unmanaged type, for different fields or indexes (A[I], A[J]), and when the two arguments are not written the same way.

address-of-nested-routine

@Nested and Addr(Nested) of a routine declared inside another routine. Measured with Delphi 13: on Win64 the arguments of a call through the pointer arrive shifted even when the nested routine uses no outer local (EnumWindows(@Nested, 42) gave 32767 for the 42); on both platforms the first use of an outer local is an access violation.

Silent for unit routines, methods and variables, and when a parameter or local variable hides the routine's name, and when the address goes to a routine of the unit that holds asm.

absolute-overlay

GAlias: Integer absolute GBytes: two names for one memory cell, no conversion and no size check. A hint, for review.

Silent when the target is an untyped parameter (absolute Buf on var Buf): that is the way to give it a type; or when both sides are object references (or type names nobody knows).

constant-return (OFF)

A function with at least two Result := .. / Exit(..) that all give the same literal. Either a branch does not do what it says, or the function needs no result.

Silent for one assignment (a stub), for a function that raises, reads Result, passes it on or sets it in a nested routine, and where somebody else dictates the signature: virtual, override, message, external, stdcall / cdecl, published methods, a Sender parameter, a method name an interface of the project has, a class that lists interfaces, a routine used as a value.

redundant-field-init (OFF)

FCount := 0 (or nil, False, '') among the first statements of a constructor: a new object is already zero.

Silent for records, inherited fields, properties, class fields, after the first statement that is not inherited or a plain assignment, when the field was set before, when the class replaces NewInstance, and after a call that can run code of the class (inherited Create, a T.Create(Self)) when the class has virtual routines, messages, interfaces or a form file and another routine of it names the field.

var-param-never-written (OFF)

A typed var parameter that is read and never written, passed on, or changed through a method of a record.

Silent in the same signature cases as constant-return, and for a routine with asm.

value-param-assigned (OFF)

A by-value parameter that is assigned (or Inc / Dec) and so used as a local variable. One finding per parameter.

What the rules add over the compiler

dcc64 37.0 with all warnings and hints compiles every positive fixture without a message about these cases. W1035 covers unmanaged results only; H2077 does not see any of them.

Measured

2026-11-24, copies of project indexes and a private index of the Delphi 37 source\vcl folder, one rule at a time.

corpusresult-firstsame-varnestedoverlayconstantfield-initvar-unwrittenvalue-set
drag-lint (448 files)11002121046
Micronite2027 (583 units)0003043040
Loader202500010200
TableTools370P000300012
YADF GuardTest00000102
VCL (126 files)60010237420
  • managed-result-read-first: 7 of 7 right (read in source; a test program shows the old value for string, array, interface and Variant on Win32 and Win64). same-variable-two-var-params: 1 of 1 right (the const text arrives empty). Both ON.
  • address-of-nested-routine: the 5 of the VCL go through an asm thunk that pushes the frame; that shape is silent now; re-measured with the final engine: VCL 0, Micronite 0, so nothing left to be wrong on those corpora. ON.
  • absolute-overlay: the VCL and 4 of 7 Micronite findings were one object reference over another (a cast without a check); that shape is silent now. Re-measured with the final engine: VCL 1 (TColor under TRGBTriple), Micronite 3 (a Single bitcast to Cardinal), all deliberate bit casts: a reviewer would dismiss every one, so OFF (owner may switch it on).
  • constant-return: 1 of 2 is a command handler with a uniform signature: OFF. var-param-never-written: 1 of 17 reads a field the callee changes on the way, 2 unsure: OFF. redundant-field-init: no false one found, style only: OFF. value-param-assigned: OFF, 420 in one corpus.

All features | CLI reference | IDE menus