Delphi-RAG-Lint
← DL (drag-lint) · Lint and fix

Rules that know the whole project.

Most linters read one file at a time. DL lints against its index, so a rule can ask who calls a routine, what a form file binds, which table column a field maps to, or whether anything in the project assigns a field at all. And when a rule can fix what it finds, the compiler checks the fix before you keep it.

540rules
413on by default
136can fix the code
267carry a CWE id
01 — The categories

From bug patterns to security

The rules fall into 22 categories. The full list, with every rule’s default and whether it can fix the code, is in the rules reference; drag-lint explain <rule> tells you about one rule in plain words.

CategoryWhat it looks forRules
bug-patternsCode that compiles but misbehaves: Format arguments that do not match, raise inside a destructor, Exit in a finally block, UI calls from a thread.195
complexityRoutines too long, too deep or too branched: cyclomatic and cognitive complexity, nesting, duplicated blocks.15
concurrencyWaits whose outcome nobody checks: a WaitFor with a timeout whose result is thrown away, so a timeout looks like success.1
data-flowValues on the wrong path: a variable used before assignment, a Result or out parameter not set on every path, a double free.13
dead-codeCode nothing needs: unused locals and parameters, identical branches, event handlers no form binds.23
dependency-injectionSpring4D container mistakes: a Resolve of an interface nothing registers, an interface registered twice, a class registered for an interface it does not implement, registrations nothing runs, a singleton that holds a short-lived dependency, a Resolve inside a paint or timer handler.11
documentationDocInsight comments missing on public declarations, left as placeholders, or drifted from the code.8
field-repoForms and code that disagree with the Field Repository: lookup and key fields that differ, generators, enums, display formats and visibility that drifted, fields and handlers nothing uses. Silent without a repository.11
firedacFireDAC misuse: ParamByName of a parameter the SQL lacks, FieldByName in a loop, a query run once per iteration.5
metricsClass design measures: coupling, cohesion, inheritance depth, response set. Beside the rules, drag-lint metrics --halstead reports Halstead counts and a 0..100 maintainability index per routine, rolled up to unit and folder.8
modernizeOlder idioms with a newer form: digit separators, if-expressions, is not, for..in loops.6
namingNames that break your conventions: prefixes, casing, a name spelled differently from its declaration.14
otherUnfinished or leftover work: TODO markers, debug output, safety directives switched off, strings built up in a loop.17
platformWin64 and portability: pointers cast to 32-bit integers, asm without a 64-bit variant, GetTickCount wrap-around, fixed pixel sizes.16
policyYour own project rules: a required file header, disallowed types, identifiers, calls or form properties.6
project-wideRules that need the whole project: a field nothing assigns, a used unit that resolves nowhere, an INSERT that leaves out a required column.69
refactoringSimplifications with a known shape: a parameter that can be const, nested ifs that collapse, a literal that wants a name.36
resource-lifetimeObjects and memory: use after Free, GetMem without release, a field freed outside the destructor.24
review-markersYour own dl:ok reviews: markers that no longer match, name no rule, or carry no review date.6
securitySQL injection, path traversal, weak or broken ciphers, cleartext transport, secrets in string literals, untrusted data reaching a process launch. Across all categories, 267 rules carry a CWE id.34
structureScope and encapsulation: with statements, public fields, goto, components still named as the designer named them.21
uiForm code that fails at run time: SetFocus in the handler the form file binds as OnCreate, before the form is visible.1
02 — Fixes

Fixes the compiler checks

136 rules can fix the code for you. lint --fix --apply --project goes through the compile gate by default: DL builds the project after the edit, and a compiler error stops the fix or rolls it back. New warnings and hints are reported, so you see anything a fix stirred up.

In RAD Studio a finding in the Structure window has Fix it on its right-click menu, next to Fix all in unit and Fix all in project. An unused unit is removed, or moved to the implementation section, only after a compile proves it can go.

Lint --fix through the compile gate · Fix it · Fix all in project

03 — Your rules, your call

On by default, and how to quiet a rule

413 rules are on out of the box; the rest are there when you want them, such as the magic-literal, commented-out-code and opaque-to-analysis checks. When a finding is right but you keep the code, record a dl:ok review on the line, with the reason and a date, and it stops being reported. A rule can also be switched off for one unit or the whole project. The review-marker rules keep those reviews honest: a marker whose finding has gone away is reported too.

267 rules carry a CWE id, and some also a CERT or MISRA id; --labels prints them and rules --standard filters by standard. The taint rules follow data from where it enters the program to an SQL text, a process launch or a file path.

explain · allow (dl:ok) · Disable a rule · Compliance labels · Taint analysis

04 — Where it runs

One file, or the whole project

lint checks one file; lint-all checks the whole project and adds the project-wide rules that only make sense across units. In RAD Studio, Code Quality > Run Lint All (Full Report) does the same, findings are refreshed when you save, and you can lint an editor buffer before you save it. In VS Code and other editors the language server reports findings as problems.

With a Field Repository, schema rules also check MAXLEN constants, string lengths and SQL columns against the columns of your database.

Run Lint All · Lint an unsaved buffer · Schema-aware lint

Every rule here has run on the source of HTR Micronite, our own large Delphi application, before it reached you.