Delphi-RAG-Lint

drag-lint help

Lint rules new in 1.66

Since: 1.66.0-alpha

Seventeen rules new in 1.66: eight research rules (OFF), the R4 rule reserve (DI, labels, RSA keys, IVs, cookies) and variant-record-punning (OFF).

Read this when a 1.66 lint run shows a rule id you have not seen, or to switch on one of the OFF research rules: each rule with its category, severity, default, CWE and what it reports.

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 hardcoded-crypto-key

Full flag list: lint in the CLI reference.

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 raise-in-except-without-inner

Full flag list: lint in the CLI reference.

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 regex-redos-literal

Full flag list: lint in the CLI reference.

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 double-checked-locking

Full flag list: lint in the CLI reference.

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 stream-position-not-reset

Full flag list: lint in the CLI reference.

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 task-captures-modified-local

Full flag list: lint in the CLI reference.

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 oncalcfields-sets-datafield

Full flag list: lint in the CLI reference.

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 onchange-assigns-own-control

Full flag list: lint in the CLI reference.

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 nested-try-depth

Full flag list: lint in the CLI reference.

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 unused-label

Full flag list: lint in the CLI reference.

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 negated-condition-with-else

Full flag list: lint in the CLI reference.

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 rsa-key-too-short

Full flag list: lint in the CLI reference.

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 fixed-cipher-iv

Full flag list: lint in the CLI reference.

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 cookie-without-secure

Full flag list: lint in the CLI reference.

drag-lint lint-all [--profile <name>] [--target-compiler <ver|auto>] [--db <file.sqlite>] [--project <.dproj>] [--build-config <name>] [--rule <id>[,<id>...]] [--disable id,...] [--output <report.txt>] [--json] [--labels] [--quiet] [--lint-third-party] [--no-preprocess] [--shared-db <db> ...] [--library-db none] [--no-budget] [--changed-since <rev>]

Example:

drag-lint lint-all --db <project.sqlite> --rule variant-record-punning

Full flag list: lint-all in the CLI reference.

Where to click

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

Details

Seventeen rules arrived in 1.66. Every one is listed by drag-lint rules --json and explained by drag-lint explain <rule-id>. Rules marked OFF run only when named (--rule <id>, --enable <id>, or "enabled": [...] in the lint config).

drag-lint lint <unit.pas> --rule <id>                      per-file rules
drag-lint lint-all --db <project.sqlite> --rule <id>       project-wide rules (and every per-file rule over the project)

Research rules -- all OFF

rulecategoryseverityCWEwhat it reports
hardcoded-crypto-keysecuritywarningCWE-321a literal or const-literal key: HMAC key argument (THashSHA2 / MD5 / SHA1.GetHMAC), TDCP_* Init / InitStr, TIdHMAC*.Key :=
raise-in-except-without-innerbug-patternshint-raise <ctor>(.. E.Message ..) inside on E: T do that drops E (use Exception.RaiseOuterException)
regex-redos-literalsecuritywarningCWE-1333a literal TRegEx / TPerlRegEx pattern with a nested unbounded quantifier (a+)+ or a repeated duplicate alternative (a|a)*
double-checked-lockingbug-patternswarningCWE-609if F = nil then <lock>; if F = nil then F := ..Create on a field / global (CompareExchange and [volatile] exempt)
stream-position-not-resetbug-patternswarning-a local TMemoryStream / TStringStream / TBytesStream written and then read without Position := / Seek / Clear
task-captures-modified-localbug-patternswarningCWE-362an anonymous method given to TTask / TThread.Queue / TParallel.For uses a local that is assigned after the dispatch
oncalcfields-sets-datafieldfiredacwarning-an OnCalcFields handler assigns a persistent data field (reads the .dfm beside the unit)
onchange-assigns-own-controlbug-patternswarning-an OnChange-style handler assigns its own control without a compare-first guard (reads the .dfm beside the unit)

Fixtures with a hit and a non-hit for each: tests\fixtures\v166\rce1, tests\fixtures\v166\rce2 (runners tests\autotest\run_v166_RCE1.ps1, run_v166_RCE2.ps1). stream-position-not-reset has a manual-only, risky fixer (lint --fix --fix-rule stream-position-not-reset).

Rule reserve

rulecategoryseveritydefaultscopewhat it reports
di-per-thread-in-taskdependency-injectionwarningONprojecta Resolve of a singleton-per-thread interface inside a TTask.Run / Future / CreateAnonymousThread / TParallel.For closure
di-registered-never-resolveddependency-injectionhintOFFprojecta registration nothing resolves or injects (silent with a generic Resolve&lt;I&gt;)
nested-try-depthcomplexityhintOFFfilethe 4th nested try
unused-labeldead-codehintONfilea label no goto jumps to
negated-condition-with-elsestylehintOFFfileif not X then A else B with one plain negation and a non-if else
rsa-key-too-shortsecuritywarningONfilean RSA key size below 2048 (CWE-326)
fixed-cipher-ivsecuritywarningONfilea constant initialisation vector (CWE-329)
cookie-without-securesecuritywarningONfilea cookie created without Secure / HttpOnly (CWE-614, CWE-1004)

The two DI rules are also on the di-container-rules page. Runner: tests\autotest\run_v166_R4_rules.ps1. Measured on copies of the ORM3 SERVER / CLIENT indexes: the ON rules found 0.

Variant records

rulecategoryseveritydefaultwhat it reports
variant-record-punningbug-patternswarningOFFa variant-part field read through the receiver that last wrote another branch of the same variant part (CWE-843)

Details: v166-variant-record-punning.


All features | CLI reference | IDE menus