-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsca-rules.json
More file actions
3269 lines (3268 loc) · 203 KB
/
Copy pathsca-rules.json
File metadata and controls
3269 lines (3268 loc) · 203 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
"$schema": "./sca-rules.schema.json",
"version": "1.3",
"tool": {
"name": "StaticCodeAnalyser",
"version": "0.9.7",
"informationUri": "https://github.com/nrodear/StaticCodeAnalyser"
},
"profiles": {
"ide-fast": [
"MemoryLeak", "SQLInjection", "HardcodedSecret", "FormatMismatch",
"NilDeref", "MissingFinally", "DivByZero", "DeadCode",
"DebugOutput", "FileReadError",
"DfmHardcodedDbCreds", "DfmDeadEvent", "DfmDuplicateBinding",
"DfmSchemaMismatch", "DfmCircularDataSource", "DfmSqlFromUserInput",
"DfmRequiredFieldUnbound", "DfmRequiredFieldNotVisible",
"DfmCrossFormCoupling", "DfmActionMismatch"
],
"security": [
"SQLInjection", "HardcodedSecret", "HardcodedPath",
"InsecureCryptoAlgorithm", "CommandInjection",
"DfmHardcodedDbCreds", "DfmSqlFromUserInput"
],
"bugs-only": [
"MemoryLeak", "FormatMismatch", "NilDeref", "DivByZero",
"SQLInjection", "HardcodedSecret", "FileReadError",
"DfmDuplicateBinding", "DfmDeadEvent", "DfmSchemaMismatch",
"DfmCircularDataSource", "DfmRequiredFieldUnbound",
"DfmRequiredFieldNotVisible", "DfmCrossFormCoupling",
"DfmActionMismatch"
],
"code-quality": [
"EmptyExcept", "UnusedUses", "MissingFinally", "DeadCode",
"LongMethod", "LongParamList", "MagicNumber", "DebugOutput",
"DeepNesting", "TodoComment", "EmptyMethod", "CyclomaticComplexity",
"DuplicateString", "DuplicateBlock",
"DfmDefaultName", "DfmHardcodedCaption", "DfmOrphanHandler",
"DfmEmptyBoundEvent", "DfmFieldTypeMismatch", "DfmTabOrderConflict",
"DfmForbiddenClass", "DfmDbInUiForm", "DfmLayerViolation",
"DfmGodHandler"
],
"dfm-only": [
"DfmDefaultName", "DfmHardcodedCaption", "DfmHardcodedDbCreds",
"DfmDuplicateBinding", "DfmDeadEvent", "DfmOrphanHandler",
"DfmEmptyBoundEvent", "DfmSchemaMismatch", "DfmCircularDataSource",
"DfmSqlFromUserInput", "DfmRequiredFieldUnbound",
"DfmRequiredFieldNotVisible", "DfmFieldTypeMismatch",
"DfmTabOrderConflict", "DfmForbiddenClass", "DfmDbInUiForm",
"DfmCrossFormCoupling", "DfmLayerViolation", "DfmGodHandler",
"DfmActionMismatch"
],
"default": ["*"],
"strict": ["*", "UnusedUses"],
"selftest-quiet": [
"*",
"!BeginEndRequired",
"!TooLongLine",
"!UnsortedUses",
"!ConsecutiveSection",
"!ClassPerFile",
"!EmptyVisibilitySection",
"!ConcatToFormat",
"!NestedTry",
"!GroupedDeclaration",
"!NilComparison",
"!CommentedOutCode"
]
},
"rules": [
{
"id": "SCA001",
"kind": "MemoryLeak",
"name": "Object created without try/finally",
"shortDescription": "Object created but never freed (potential memory leak)",
"fullDescription": "TObject.Create (or LeakyClass.Create) without a protective try/finally block leaks the instance when subsequent code raises an exception. The Free call must run regardless of how the protected block exits.",
"defaultSeverity": "Error",
"type": "Bug",
"tags": ["memory", "resource-leak"],
"cwe": ["CWE-401"],
"configKey": "[Detectors] LeakyClasses",
"detectorUnit": "uLeakDetector2.pas",
"examples": {
"bad": "list := TStringList.Create;\nDoStuff(list); // <-- exception here leaks list",
"good": "list := TStringList.Create;\ntry\n DoStuff(list);\nfinally\n list.Free;\nend;"
},
"cleanCodeAttribute": "LAWFUL",
"impacts": [
{ "softwareQuality": "RELIABILITY", "severity": "HIGH" }
]
},
{
"id": "SCA002",
"kind": "EmptyExcept",
"name": "Empty except block",
"shortDescription": "Empty except block silently swallows every exception",
"fullDescription": "An except-block with no statements catches every exception including unexpected ones (EAccessViolation, EOutOfMemory). Bugs become invisible. At minimum log the exception or re-raise.",
"defaultSeverity": "Warning",
"type": "Code Smell",
"tags": ["error-handling"],
"cwe": ["CWE-390"],
"detectorUnit": "uCodeSmells2.pas",
"examples": {
"bad": "try DoStuff except end;",
"good": "try DoStuff except on E: Exception do LogError(E.Message); end;"
},
"cleanCodeAttribute": "LAWFUL",
"impacts": [
{ "softwareQuality": "RELIABILITY", "severity": "MEDIUM" }
]
},
{
"id": "SCA003",
"kind": "SQLInjection",
"name": "SQL string built via concatenation",
"shortDescription": "SQL string concatenated with '+' from user-controllable input (injection risk)",
"fullDescription": "Building SQL via 'WHERE x=' + user_input enables SQL injection if the input is untrusted. Use parameterized queries (Params.ParamByName(...).Value := ...) instead.",
"defaultSeverity": "Error",
"type": "Vulnerability",
"tags": ["sql", "injection", "security"],
"cwe": ["CWE-89"],
"owasp": ["A03:2021-Injection"],
"detectorUnit": "uSQLInjection.pas",
"examples": {
"bad": "Query.SQL.Text := 'SELECT * FROM Users WHERE Name=''' + UserName + '''';",
"good": "Query.SQL.Text := 'SELECT * FROM Users WHERE Name=:n';\nQuery.ParamByName('n').AsString := UserName;"
},
"cleanCodeAttribute": "LAWFUL",
"impacts": [
{ "softwareQuality": "SECURITY", "severity": "HIGH" }
]
},
{
"id": "SCA004",
"kind": "HardcodedSecret",
"name": "Hardcoded credential / API token",
"shortDescription": "Password / API key / token as string literal in source code",
"fullDescription": "Credentials in source code end up in version control, build artifacts, decompilers, and stack traces. Move secrets to environment variables, OS credential store, or encrypted configuration.",
"defaultSeverity": "Error",
"type": "Vulnerability",
"tags": ["credentials", "security"],
"cwe": ["CWE-798"],
"owasp": ["A07:2021-Identification-and-Authentication-Failures"],
"detectorUnit": "uHardcodedSecret.pas",
"examples": {
"bad": "Password := 'admin123';",
"good": "Password := GetEnvironmentVariable('DB_PASSWORD');"
},
"cleanCodeAttribute": "LAWFUL",
"impacts": [
{ "softwareQuality": "SECURITY", "severity": "BLOCKER" }
]
},
{
"id": "SCA005",
"kind": "FormatMismatch",
"name": "Format() placeholder count mismatch",
"shortDescription": "Format() / FormatUtf8() placeholder count does not match argument count",
"fullDescription": "Mismatched placeholders cause EConvertError at runtime. Detector handles RTL Format (%s/%d/...) and mORMot bare-% style (FormatUtf8/FormatString).",
"defaultSeverity": "Error",
"type": "Bug",
"tags": ["string-formatting"],
"configKey": "[Detectors] FormatFunctions",
"detectorUnit": "uFormatMismatch.pas",
"examples": {
"bad": "Format('%s is %d', [Name]); // <-- Age missing",
"good": "Format('%s is %d', [Name, Age]);"
},
"cleanCodeAttribute": "LOGICAL",
"impacts": [
{ "softwareQuality": "RELIABILITY", "severity": "MEDIUM" }
]
},
{
"id": "SCA006",
"kind": "FileReadError",
"name": "File could not be read or parsed",
"shortDescription": "Parser/IO error - source file unreadable or syntactically broken",
"fullDescription": "Special-case finding (no code defect): the file could not be loaded or the lexer/parser failed. Often indicates encoding issues, includes that don't resolve, or genuine syntax errors.",
"defaultSeverity": "Error",
"type": "File Error",
"tags": ["parser", "io"],
"detectorUnit": "(parser)",
"examples": {
"bad": "(file is not valid UTF-8 or has lexer-breaking content)",
"good": "(check encoding, fix syntax)"
},
"cleanCodeAttribute": "LAWFUL",
"impacts": [
{ "softwareQuality": "RELIABILITY", "severity": "INFO" }
]
},
{
"id": "SCA007",
"kind": "UnusedUses",
"name": "Unused unit in uses clause",
"shortDescription": "Uses-entry possibly unused (no identifier from it referenced)",
"fullDescription": "Heuristic: scans for any identifier from the used unit. False positives possible for units that only register classes / initialize global state via initialization sections.",
"defaultSeverity": "Hint",
"type": "Code Smell",
"tags": ["dead-code", "uses-cleanup"],
"detectorUnit": "uUnusedUses.pas",
"examples": {
"bad": "uses ..., MyUnusedHelper, ...;",
"good": "(remove if truly unused; otherwise add a comment why it stays)"
},
"cleanCodeAttribute": "FOCUSED",
"impacts": [
{ "softwareQuality": "MAINTAINABILITY", "severity": "LOW" }
]
},
{
"id": "SCA008",
"kind": "NilDeref",
"name": "Possible nil-dereference",
"shortDescription": "Access to a variable that may be nil at this point",
"fullDescription": "Variable was assigned a value that could be nil (e.g. Find...-method returning nil) and is dereferenced without prior nil-check. Crashes with EAccessViolation at runtime.",
"defaultSeverity": "Warning",
"type": "Bug",
"tags": ["nil-safety"],
"cwe": ["CWE-476"],
"detectorUnit": "uNilDeref.pas",
"examples": {
"bad": "obj := FindObject(id);\nobj.DoStuff; // <-- AV if FindObject returns nil",
"good": "obj := FindObject(id);\nif Assigned(obj) then obj.DoStuff;"
},
"cleanCodeAttribute": "LOGICAL",
"impacts": [
{ "softwareQuality": "RELIABILITY", "severity": "HIGH" }
]
},
{
"id": "SCA009",
"kind": "MissingFinally",
"name": "Object created without protective try/finally",
"shortDescription": ".Create call without surrounding try/finally - leak risk on exception",
"fullDescription": "Similar to MemoryLeak but checked structurally: any .Create followed by code without an enclosing try/finally is flagged regardless of whether Free is called eventually.",
"defaultSeverity": "Warning",
"type": "Code Smell",
"tags": ["memory", "exception-safety"],
"detectorUnit": "uMissingFinally.pas",
"examples": {
"bad": "obj := TFoo.Create;\nobj.DoStuff;\nobj.Free;",
"good": "obj := TFoo.Create;\ntry obj.DoStuff finally obj.Free end;"
},
"cleanCodeAttribute": "LAWFUL",
"impacts": [
{ "softwareQuality": "RELIABILITY", "severity": "HIGH" }
]
},
{
"id": "SCA010",
"kind": "DivByZero",
"name": "Possible division by zero",
"shortDescription": "Division by a variable / expression that may be zero",
"fullDescription": "Right-hand side of div, mod, or / is a variable without prior guard against zero. Integer division crashes with EDivByZero, float division silently produces Inf/NaN.",
"defaultSeverity": "Warning",
"type": "Bug",
"tags": ["arithmetic"],
"cwe": ["CWE-369"],
"detectorUnit": "uDivByZero.pas",
"examples": {
"bad": "result := total / count;",
"good": "if count <> 0 then result := total / count;"
},
"cleanCodeAttribute": "LOGICAL",
"impacts": [
{ "softwareQuality": "RELIABILITY", "severity": "HIGH" }
]
},
{
"id": "SCA011",
"kind": "DeadCode",
"name": "Code after Exit/Raise is unreachable",
"shortDescription": "Statement after Exit, raise, or Halt is dead code",
"fullDescription": "Anything after an unconditional terminator (Exit, raise, Halt, Continue, Break) in the same block is never executed. Usually leftover code from refactoring.",
"defaultSeverity": "Warning",
"type": "Code Smell",
"tags": ["dead-code"],
"cwe": ["CWE-561"],
"detectorUnit": "uDeadCode.pas",
"examples": {
"bad": "Exit;\nWriteLn('never reached');",
"good": "(remove the unreachable line)"
},
"cleanCodeAttribute": "FOCUSED",
"impacts": [
{ "softwareQuality": "MAINTAINABILITY", "severity": "MEDIUM" }
]
},
{
"id": "SCA012",
"kind": "LongMethod",
"name": "Method exceeds line-count threshold",
"shortDescription": "Method longer than configured maximum (default 80 lines)",
"fullDescription": "Methods over ~80 statements are correlated with high defect density (Robert C. Martin, McConnell): the reader keeps context in working memory and once the method spills past one screen, that context overflows. Long methods also resist unit testing - test setup ends up duplicating internal state. Refactor: pull cohesive blocks into private helpers (ParseInput/Validate/Persist), or split per responsibility (data fetch vs. transform vs. emit). Threshold is configurable via [Detectors] LongMethodMax / DetectorMaxBodyLines; lines are counted between the routine's `begin` and matching `end;`, comments and blank lines included. Compound-statement detection ignores nested anonymous methods so a method body that only contains a closure is not falsely reported.",
"defaultSeverity": "Hint",
"type": "Code Smell",
"tags": ["maintainability", "complexity"],
"configKey": "[Detectors] LongMethodMax",
"detectorUnit": "uLongMethod.pas",
"examples": {
"bad": "(150-line procedure doing parsing + validation + persistence)",
"good": "(extract into ParseInput, Validate, Persist helper methods)"
},
"cleanCodeAttribute": "FOCUSED",
"impacts": [
{ "softwareQuality": "MAINTAINABILITY", "severity": "MEDIUM" }
]
},
{
"id": "SCA013",
"kind": "LongParamList",
"name": "Too many parameters",
"shortDescription": "Method has more parameters than configured maximum (default 7)",
"fullDescription": "High parameter counts are a leading indicator of an SRP violation: the routine is juggling concerns that should be split. Long lists also bring positional confusion (the third Integer is which one again?) and force callers to fill defaults that may not apply. Refactor: group cohesive parameters into a record (TOrderInput), promote configuration to a builder pattern (FluentQuery.Where(...).OrderBy(...)), or split the method by axis (SaveOrder + SaveOrderItems). Threshold via [Detectors] LongParamMax / DetectorMaxParams (default 5). out/var parameters count just like value parameters; the implicit Self for class methods does not count.",
"defaultSeverity": "Hint",
"type": "Code Smell",
"tags": ["api-design"],
"configKey": "[Detectors] LongParamMax",
"detectorUnit": "uLongParamList.pas",
"examples": {
"bad": "procedure SaveOrder(id, customer, address, city, zip, country, total, tax, shipping: ...);",
"good": "procedure SaveOrder(const Order: TOrder);"
},
"cleanCodeAttribute": "FOCUSED",
"impacts": [
{ "softwareQuality": "MAINTAINABILITY", "severity": "MEDIUM" }
]
},
{
"id": "SCA014",
"kind": "MagicNumber",
"name": "Numeric literal without named constant",
"shortDescription": "Numeric literal in expression - extract to a named constant",
"fullDescription": "Numeric literals embedded directly in business logic carry no meaning: `if RetryCount > 3` forces every reader to guess what 3 represents and forces every maintenance change to find every occurrence by hand. Extract a named constant so the value has a documented purpose and exactly one source of truth. The detector skips trivials (0, 1, 2, -1, common power-of-2 sizes, indexing into known-tiny collections) - see [Detectors] MagicTrivials for the active list. Loop bounds against `Length(arr)` and array index 0 are also ignored. Use the global config to add project-specific trivials (e.g. a fixed PageSize).",
"defaultSeverity": "Hint",
"type": "Code Smell",
"tags": ["maintainability"],
"detectorUnit": "uMagicNumbers.pas",
"examples": {
"bad": "if RetryCount > 3 then ...",
"good": "const MAX_RETRIES = 3;\nif RetryCount > MAX_RETRIES then ..."
},
"cleanCodeAttribute": "CLEAR",
"impacts": [
{ "softwareQuality": "MAINTAINABILITY", "severity": "LOW" }
]
},
{
"id": "SCA015",
"kind": "DuplicateString",
"name": "String literal repeated across multiple sites",
"shortDescription": "Same string literal appears N+ times - extract to constant",
"fullDescription": "Repeated strings are change-coupling hazards (typo in one place silently diverges from the others). Extract to a const, especially for user-facing messages.",
"defaultSeverity": "Hint",
"type": "Code Duplication",
"tags": ["maintainability"],
"configKey": "[Detectors] DuplicateStringMin",
"detectorUnit": "uDuplicateString.pas",
"examples": {
"bad": "ShowMessage('File not found');\n... \nLogError('File not found');",
"good": "const MSG_FILE_NOT_FOUND = 'File not found';\nShowMessage(MSG_FILE_NOT_FOUND);"
},
"cleanCodeAttribute": "DISTINCT",
"impacts": [
{ "softwareQuality": "MAINTAINABILITY", "severity": "LOW" }
]
},
{
"id": "SCA016",
"kind": "HardcodedPath",
"name": "Filesystem path as string literal",
"shortDescription": "Hardcoded C:\\ / UNC / Linux path in source",
"fullDescription": "Hardcoded paths break portability and CI deployment. Use config files, environment variables, or platform-aware path helpers (TPath.Combine, etc).",
"defaultSeverity": "Warning",
"type": "Security Hotspot",
"tags": ["portability", "configuration"],
"detectorUnit": "uHardcodedPath.pas",
"examples": {
"bad": "LogFile := 'C:\\Logs\\app.log';",
"good": "LogFile := TPath.Combine(GetEnvironmentVariable('LOGDIR'), 'app.log');"
},
"cleanCodeAttribute": "CLEAR",
"impacts": [
{ "softwareQuality": "MAINTAINABILITY", "severity": "MEDIUM" }
]
},
{
"id": "SCA017",
"kind": "DebugOutput",
"name": "WriteLn/ShowMessage in production code",
"shortDescription": "Debug output statement found in production unit",
"fullDescription": "WriteLn / ShowMessage / OutputDebugString / OutputDebugStringA in non-test code is almost always leftover debugging: ShowMessage in particular blocks the UI thread and is unfit for any production code path. Replace with a structured logger (TLogger, mORMot TSynLog, log4d) so the call site captures severity, category, and source location, and ops can dial verbosity at runtime. The detector skips units under `*\\tests\\*`, `*\\test\\*` and units flagged by the project as test/cli (`*Console*`, `*TestProject*`). A `// noinspection DebugOutput` marker suppresses individual lines (e.g. interactive CLI banners).",
"defaultSeverity": "Warning",
"type": "Code Smell",
"tags": ["debug-code"],
"detectorUnit": "uDebugOutput.pas",
"examples": {
"bad": "WriteLn('here #3');",
"good": "Logger.Debug('reached step 3');"
},
"cleanCodeAttribute": "CONVENTIONAL",
"impacts": [
{ "softwareQuality": "MAINTAINABILITY", "severity": "LOW" }
]
},
{
"id": "SCA018",
"kind": "DeepNesting",
"name": "Block nesting exceeds threshold",
"shortDescription": "Nested if/for/while depth higher than configured maximum (default 4)",
"fullDescription": "Deep nesting hurts readability and indicates the method is doing too much. Use guard clauses (early Exit) or extract inner blocks into helper methods.",
"defaultSeverity": "Hint",
"type": "Code Smell",
"tags": ["complexity"],
"configKey": "[Detectors] DeepNestingMax",
"detectorUnit": "uDeepNesting.pas",
"examples": {
"bad": "if a then\n if b then\n if c then\n if d then DoStuff;",
"good": "if not a then Exit;\nif not b then Exit;\nif not c then Exit;\nif d then DoStuff;"
},
"cleanCodeAttribute": "FOCUSED",
"impacts": [
{ "softwareQuality": "MAINTAINABILITY", "severity": "MEDIUM" }
]
},
{
"id": "SCA019",
"kind": "TodoComment",
"name": "TODO/FIXME marker in comment",
"shortDescription": "Open TODO / FIXME / HACK / XXX marker - resolve before release",
"fullDescription": "Open work markers (TODO, FIXME, HACK, XXX, BUG, NOTE) live as a parallel work tracker inside the source. The pattern fails by accretion: markers added years apart never get triaged together, the original author leaves, and the next reader cannot tell whether the TODO is still relevant or has been silently shipped. SCA surfaces every such marker so CI gates can enforce a zero-TODO release branch or PR-time triage. Recognised forms: `// TODO`, `{ TODO ... }`, `(* TODO *)`, case-insensitive, with optional jira-id suffix (`// TODO PROJ-123: ...`). Marker tokens are configurable; the default set matches SonarDelphi.",
"defaultSeverity": "Hint",
"type": "Code Smell",
"tags": ["work-tracking"],
"detectorUnit": "uTodoComment.pas",
"examples": {
"bad": "// TODO: handle the case where input is empty",
"good": "(implement the case OR file an issue and reference it)"
},
"cleanCodeAttribute": "COMPLETE",
"impacts": [
{ "softwareQuality": "MAINTAINABILITY", "severity": "LOW" }
]
},
{
"id": "SCA020",
"kind": "EmptyMethod",
"name": "Empty method body",
"shortDescription": "Method body has no statements",
"fullDescription": "Empty method may indicate a forgotten implementation, a TODO that was never followed up, or an interface stub. Make intent explicit (assert, exception, or comment).",
"defaultSeverity": "Hint",
"type": "Code Smell",
"tags": ["maintainability"],
"detectorUnit": "uEmptyMethod.pas",
"examples": {
"bad": "procedure DoStuff;\nbegin\nend;",
"good": "procedure DoStuff;\nbegin\n raise ENotImplemented.Create('...');\nend;"
},
"cleanCodeAttribute": "COMPLETE",
"impacts": [
{ "softwareQuality": "MAINTAINABILITY", "severity": "LOW" }
]
},
{
"id": "SCA021",
"kind": "DuplicateBlock",
"name": "Duplicated code block",
"shortDescription": "Multiple identical code blocks (>= configured minimum lines)",
"fullDescription": "Detects N+ consecutive identical lines that appear in two or more places in the codebase (default minimum: 8 lines). The DRY violation creates change-coupling: a bugfix on one copy silently diverges from the others, and reviewers cannot easily tell that a behaviour-fix only addressed one of N call sites. Refactor: extract into a helper method or a shared constant. Tokens are normalised (whitespace collapsed, identifiers lowered) so cosmetic differences do not mask a true duplicate. Trivial duplicates (uses lists, type alias declarations) are skipped. Threshold via [Detectors] DuplicateBlockMinLines.",
"defaultSeverity": "Hint",
"type": "Code Duplication",
"tags": ["dry"],
"configKey": "[Detectors] DuplicateBlockMinLines",
"detectorUnit": "uDuplicateBlock.pas",
"examples": {
"bad": "(20 lines of validation code copy-pasted across 3 methods)",
"good": "(extract into a single ValidateXxx procedure)"
},
"cleanCodeAttribute": "DISTINCT",
"impacts": [
{ "softwareQuality": "MAINTAINABILITY", "severity": "MEDIUM" }
]
},
{
"id": "SCA022",
"kind": "CyclomaticComplexity",
"name": "Method exceeds McCabe complexity threshold",
"shortDescription": "Cyclomatic Complexity > configured threshold (default 10)",
"fullDescription": "McCabe complexity counts decision points (1 base + if + case-arm + for/while/repeat + on-handler + and/or/xor). High complexity is hard to test and understand.",
"defaultSeverity": "Hint",
"type": "Code Smell",
"tags": ["complexity", "maintainability", "metrics"],
"configKey": "[Detectors] CyclomaticMax",
"detectorUnit": "uCyclomaticComplexity.pas",
"examples": {
"bad": "(method with 15+ if/case/for branches in one body)",
"good": "(extract decision groups into named helper methods)"
},
"cleanCodeAttribute": "FOCUSED",
"impacts": [
{ "softwareQuality": "MAINTAINABILITY", "severity": "MEDIUM" }
]
},
{
"id": "SCA023",
"kind": "CustomRule",
"name": "User-defined custom rule",
"shortDescription": "Pattern matched by a rule loaded from analyser-rules.yml",
"fullDescription": "Generic kind for user-defined regex / AST rules loaded at runtime from analyser-rules.yml. Specific rule ID, message, and severity come from the YAML entry; this catalog entry is a placeholder so the dispatcher and SARIF exporter have stable metadata.",
"defaultSeverity": "Warning",
"type": "Code Smell",
"tags": ["custom", "user-defined"],
"configKey": "analyser-rules.yml",
"detectorUnit": "uCustomRuleDetector.pas",
"examples": {
"bad": "(pattern from analyser-rules.yml matches)",
"good": "(fix per the custom rule's message)"
},
"cleanCodeAttribute": "CONVENTIONAL",
"impacts": [
{ "softwareQuality": "MAINTAINABILITY", "severity": "MEDIUM" }
]
},
{
"id": "SCA024",
"kind": "DfmDefaultName",
"name": "Component with default name",
"shortDescription": "Component left at wizard-default name (Button1, Edit3, Panel2 ...)",
"fullDescription": "Default names hide intent and break find-usages / rename refactorings. Rename UI controls to convey purpose (btnSave, edUserName, pnlToolbar ...).",
"defaultSeverity": "Hint",
"type": "Code Smell",
"tags": ["dfm", "naming"],
"detectorUnit": "uDfmDefaultName.pas",
"examples": {
"bad": "object Button1: TButton\n Caption = 'Save'\nend",
"good": "object btnSave: TButton\n Caption = 'Save'\nend"
},
"cleanCodeAttribute": "CONVENTIONAL",
"impacts": [
{ "softwareQuality": "MAINTAINABILITY", "severity": "LOW" }
]
},
{
"id": "SCA025",
"kind": "DfmHardcodedCaption",
"name": "Hardcoded UI text in DFM",
"shortDescription": "Caption / Hint / Text property as literal in DFM, not via i18n layer",
"fullDescription": "User-facing strings embedded in a .dfm cannot be localised, A/B-tested, or kept in a translation catalog. Assign at form construction time from a resourcestring or i18n helper.",
"defaultSeverity": "Hint",
"type": "Code Smell",
"tags": ["dfm", "i18n", "localization"],
"detectorUnit": "uDfmHardcodedCaption.pas",
"examples": {
"bad": "object btnSave: TButton\n Caption = 'Speichern'\nend",
"good": "btnSave.Caption := _('btn.save'); // i18n at runtime"
},
"cleanCodeAttribute": "CONVENTIONAL",
"impacts": [
{ "softwareQuality": "MAINTAINABILITY", "severity": "MEDIUM" }
]
},
{
"id": "SCA026",
"kind": "DfmHardcodedDbCreds",
"name": "Hardcoded DB credentials in DFM",
"shortDescription": "Plaintext Password / ConnectionString with Pwd= on a DB component",
"fullDescription": "Database credentials persisted in a .dfm leak into version control, build artifacts, and any decompiler. Move secrets to environment variables, OS credential store, or encrypted configuration and assign at runtime.",
"defaultSeverity": "Error",
"type": "Vulnerability",
"tags": ["dfm", "credentials", "security"],
"cwe": ["CWE-798"],
"owasp": ["A07:2021-Identification-and-Authentication-Failures"],
"detectorUnit": "uDfmHardcodedDbCreds.pas",
"examples": {
"bad": "object FDConnection1: TFDConnection\n Params.Strings = ('Password=admin123' 'User_Name=sa')\nend",
"good": "FDConnection1.Params.Values['Password'] := GetEnvironmentVariable('DB_PWD');"
},
"cleanCodeAttribute": "LAWFUL",
"impacts": [
{ "softwareQuality": "SECURITY", "severity": "BLOCKER" }
]
},
{
"id": "SCA027",
"kind": "DfmDuplicateBinding",
"name": "Duplicate (DataSource, DataField) binding",
"shortDescription": "Two or more controls bind the same (DataSource, DataField) pair",
"fullDescription": "When the user edits one bound control, the second receives a parallel update from the dataset - racey, hard-to-debug overwrites. Bind each (DataSource, DataField) to exactly one control.",
"defaultSeverity": "Warning",
"type": "Bug",
"tags": ["dfm", "db-binding"],
"detectorUnit": "uDfmDuplicateBinding.pas",
"examples": {
"bad": "DBEdit1.DataField = 'NAME'\nDBEdit2.DataField = 'NAME' // same DataSource",
"good": "(bind 'NAME' to exactly one control)"
},
"cleanCodeAttribute": "LOGICAL",
"impacts": [
{ "softwareQuality": "RELIABILITY", "severity": "MEDIUM" }
]
},
{
"id": "SCA028",
"kind": "DfmDeadEvent",
"name": "DFM event handler references missing method",
"shortDescription": "OnClick / On... points to a method that does not exist in the form class",
"fullDescription": "DFM streaming crashes at form-load time with 'class TForm has no published method X'. Usually caused by a manual rename in the .pas without updating the .dfm.",
"defaultSeverity": "Error",
"type": "Bug",
"tags": ["dfm", "streaming", "dead-code"],
"detectorUnit": "uDfmDeadEvent.pas",
"examples": {
"bad": "object btnSave: TButton\n OnClick = btnSaveClick // method removed in .pas\nend",
"good": "(restore the method or clear OnClick in the designer)"
},
"cleanCodeAttribute": "COMPLETE",
"impacts": [
{ "softwareQuality": "RELIABILITY", "severity": "HIGH" }
]
},
{
"id": "SCA029",
"kind": "DfmOrphanHandler",
"name": "Orphan event handler",
"shortDescription": "Published TNotifyEvent-shaped method has no DFM binding",
"fullDescription": "Method looks like an event handler (Sender: TObject) but nothing in any .dfm references it. Likely leftover from a deleted control - remove or wire it up.",
"defaultSeverity": "Hint",
"type": "Code Smell",
"tags": ["dfm", "dead-code"],
"detectorUnit": "uDfmOrphanHandler.pas",
"examples": {
"bad": "procedure TForm1.btnOldClick(Sender: TObject); // nothing binds this\nbegin\n ...\nend;",
"good": "(remove the method or bind it from a control)"
},
"cleanCodeAttribute": "FOCUSED",
"impacts": [
{ "softwareQuality": "MAINTAINABILITY", "severity": "LOW" }
]
},
{
"id": "SCA030",
"kind": "DfmEmptyBoundEvent",
"name": "Empty bound event handler",
"shortDescription": "Event is wired in DFM, method exists, body is empty",
"fullDescription": "An empty handler with a live DFM binding is almost always a stub forgotten after the designer added it. Either remove the binding or implement the handler.",
"defaultSeverity": "Hint",
"type": "Code Smell",
"tags": ["dfm", "stub"],
"detectorUnit": "uDfmEmptyBoundEvent.pas",
"examples": {
"bad": "procedure TForm1.btnSaveClick(Sender: TObject);\nbegin\nend;",
"good": "(implement the handler or clear OnClick in the designer)"
},
"cleanCodeAttribute": "COMPLETE",
"impacts": [
{ "softwareQuality": "MAINTAINABILITY", "severity": "LOW" }
]
},
{
"id": "SCA031",
"kind": "DfmSchemaMismatch",
"name": "DFM component without published field",
"shortDescription": "Component in DFM has no matching published field in the form class",
"fullDescription": "DFM streaming requires every named component to have a corresponding published field in the host class. A missing field crashes form construction with EReadError.",
"defaultSeverity": "Error",
"type": "Bug",
"tags": ["dfm", "streaming"],
"detectorUnit": "uDfmSchemaMismatch.pas",
"examples": {
"bad": "// .dfm contains object btnSave: TButton, but TForm1 has no btnSave: TButton field",
"good": "(add the field to the published section of TForm1)"
},
"cleanCodeAttribute": "COMPLETE",
"impacts": [
{ "softwareQuality": "RELIABILITY", "severity": "HIGH" }
]
},
{
"id": "SCA032",
"kind": "DfmCircularDataSource",
"name": "Circular DataSource / Master-Detail loop",
"shortDescription": "Cycle in DataSource.DataSet / DataSet.MasterSource edges",
"fullDescription": "A cycle in the master-detail graph causes infinite recursion during BeforeOpen or any refresh and stack-overflows the process. Break the cycle by removing one of the links.",
"defaultSeverity": "Error",
"type": "Bug",
"tags": ["dfm", "data-access", "infinite-loop"],
"detectorUnit": "uDfmCircularDataSource.pas",
"examples": {
"bad": "QA.MasterSource = dsB QB.MasterSource = dsA // cycle",
"good": "(make one query the parent, the other the detail)"
},
"cleanCodeAttribute": "LOGICAL",
"impacts": [
{ "softwareQuality": "RELIABILITY", "severity": "HIGH" }
]
},
{
"id": "SCA033",
"kind": "DfmSqlFromUserInput",
"name": "SQL property built from UI input",
"shortDescription": "Query.SQL assembled from form-control Text / Caption properties",
"fullDescription": "A DB-query SQL property (TADOQuery / TFDQuery / TUniQuery / TZQuery / TKSQLQuery.SQL.Text) is assembled by concatenating the Text / Caption / Hint / EditText / ItemText property of a UI input control (TEdit, TComboBox, TMaskEdit, ...) - classic SQL injection through the form. A user typing `' OR ''1''=''1' --` into the search field reads any row; `'; DROP TABLE Users; --` is destructive. Refactor: bind named parameters and assign via ParamByName, never concatenate. This detector is the DFM/UI-path companion to SCA003 (lexical SQL injection) and SCA058 (dangerous SQL statement).",
"defaultSeverity": "Error",
"type": "Vulnerability",
"tags": ["dfm", "sql", "injection", "security"],
"cwe": ["CWE-89"],
"owasp": ["A03:2021-Injection"],
"detectorUnit": "uDfmSqlFromUserInput.pas",
"examples": {
"bad": "FDQuery1.SQL.Text := 'SELECT * FROM U WHERE Name=''' + EdName.Text + '''';",
"good": "FDQuery1.SQL.Text := 'SELECT * FROM U WHERE Name=:n';\nFDQuery1.ParamByName('n').AsString := EdName.Text;"
},
"cleanCodeAttribute": "LAWFUL",
"impacts": [
{ "softwareQuality": "SECURITY", "severity": "HIGH" }
]
},
{
"id": "SCA034",
"kind": "DfmRequiredFieldUnbound",
"name": "Required field has no UI binding",
"shortDescription": "TField with Required=True has no bound input control",
"fullDescription": "A required field that the user cannot reach makes every insert fail with 'Field X must have a value'. Either bind a control or drop the Required=True.",
"defaultSeverity": "Warning",
"type": "Bug",
"tags": ["dfm", "ux", "required-field"],
"detectorUnit": "uDfmRequiredField.pas",
"examples": {
"bad": "FieldDefs: Email Required=True // no DBEdit / DBLookup bound to it",
"good": "(bind a DBEdit to the Email field)"
},
"cleanCodeAttribute": "COMPLETE",
"impacts": [
{ "softwareQuality": "RELIABILITY", "severity": "MEDIUM" }
]
},
{
"id": "SCA035",
"kind": "DfmRequiredFieldNotVisible",
"name": "Required field only on hidden controls",
"shortDescription": "TField with Required=True is bound only to Visible=False controls",
"fullDescription": "Control exists but the user cannot see or interact with it - inserts fail every time. Make at least one bound control visible or drop the Required=True.",
"defaultSeverity": "Warning",
"type": "Bug",
"tags": ["dfm", "ux", "required-field"],
"detectorUnit": "uDfmRequiredField.pas",
"examples": {
"bad": "DBEdit1.DataField = 'Email' DBEdit1.Visible = False",
"good": "(make the control visible or remove Required=True)"
},
"cleanCodeAttribute": "COMPLETE",
"impacts": [
{ "softwareQuality": "RELIABILITY", "severity": "MEDIUM" }
]
},
{
"id": "SCA036",
"kind": "DfmFieldTypeMismatch",
"name": "UI control type mismatched with TField",
"shortDescription": "DB control class does not match TField.DataType (TDBEdit for TBooleanField)",
"fullDescription": "User sees the raw value and can corrupt the type. Pick a control compatible with the field type (TDBCheckBox for booleans, TDBLookupComboBox for FKs).",
"defaultSeverity": "Hint",
"type": "Code Smell",
"tags": ["dfm", "ux", "db-binding"],
"detectorUnit": "uDfmFieldTypeMismatch.pas",
"examples": {
"bad": "DBEdit1.DataField = 'IsActive' // TBooleanField",
"good": "DBCheckBox1.DataField = 'IsActive'"
},
"cleanCodeAttribute": "LOGICAL",
"impacts": [
{ "softwareQuality": "RELIABILITY", "severity": "MEDIUM" }
]
},
{
"id": "SCA037",
"kind": "DfmTabOrderConflict",
"name": "Duplicate TabOrder among siblings",
"shortDescription": "Two sibling controls in the same parent share the same TabOrder value",
"fullDescription": "VCL serialisation tolerates duplicate TabOrder but tab navigation becomes order-of-declaration dependent and unpredictable for the user. Renumber so TabOrder is unique per parent.",
"defaultSeverity": "Hint",
"type": "Code Smell",
"tags": ["dfm", "ux"],
"detectorUnit": "uDfmTabOrderConflict.pas",
"examples": {
"bad": "EdA.TabOrder = 0\nEdB.TabOrder = 0 // same parent",
"good": "EdA.TabOrder = 0\nEdB.TabOrder = 1"
},
"cleanCodeAttribute": "CONVENTIONAL",
"impacts": [
{ "softwareQuality": "MAINTAINABILITY", "severity": "LOW" }
]
},
{
"id": "SCA038",
"kind": "DfmForbiddenClass",
"name": "Component uses forbidden class",
"shortDescription": "Component class is in the project's ForbiddenClasses list",
"fullDescription": "Style-guide enforcement for project-specific class bans (TQuery, TLabel if you have a TStyledLabel, ...). Detector stays silent unless the project sets `[Components] ForbiddenClasses=...` in analyser.ini.",
"defaultSeverity": "Hint",
"type": "Code Smell",
"tags": ["dfm", "style-guide"],
"configKey": "[Components] ForbiddenClasses",
"detectorUnit": "uDfmForbiddenClass.pas",
"examples": {
"bad": "object Query1: TQuery // ForbiddenClasses=TQuery",
"good": "object FDQuery1: TFDQuery"
},
"cleanCodeAttribute": "CONVENTIONAL",
"impacts": [
{ "softwareQuality": "MAINTAINABILITY", "severity": "LOW" }
]
},
{
"id": "SCA039",
"kind": "DfmDbInUiForm",
"name": "DB component on UI form",
"shortDescription": "TFDQuery / TFDConnection directly on a TForm/TFrame instead of a DataModule",
"fullDescription": "Database infrastructure on a UI form couples persistence to presentation - hard to reuse, hard to test. Move to a TDataModule and reference it from the form.",
"defaultSeverity": "Hint",
"type": "Code Smell",
"tags": ["dfm", "architecture", "data-access"],
"detectorUnit": "uDfmDbInUiForm.pas",
"examples": {
"bad": "object frmInvoice: TForm\n object FDQuery1: TFDQuery ...",
"good": "object dmInvoice: TDataModule\n object FDQuery1: TFDQuery ..."
},
"cleanCodeAttribute": "MODULAR",
"impacts": [
{ "softwareQuality": "MAINTAINABILITY", "severity": "MEDIUM" }
]
},
{
"id": "SCA040",
"kind": "DfmCrossFormCoupling",
"name": "Cross-form field access",
"shortDescription": "Code in Form1 reads / writes Form2.<published_field> directly",
"fullDescription": "Reaching across forms to grab a child control breaks encapsulation - any rename in Form2 silently breaks Form1. Expose a property or method on Form2 instead.",
"defaultSeverity": "Warning",
"type": "Bug",
"tags": ["dfm", "architecture", "coupling"],
"detectorUnit": "uDfmCrossFormCoupling.pas",
"examples": {
"bad": "Form2.EdName.Text := 'x';",
"good": "Form2.UserName := 'x'; // property on Form2"
},
"cleanCodeAttribute": "MODULAR",
"impacts": [
{ "softwareQuality": "MAINTAINABILITY", "severity": "MEDIUM" }
]
},
{
"id": "SCA041",
"kind": "DfmLayerViolation",
"name": "Input control directly on TForm",
"shortDescription": "Input control sits on the form instead of being embedded in a TPanel / TGroupBox",
"fullDescription": "Layered layout (Form > Panel > Group > Controls) makes resizing, DPI-scaling, and theming significantly easier. Wrap controls in a layout container.",
"defaultSeverity": "Hint",
"type": "Code Smell",
"tags": ["dfm", "layout"],
"detectorUnit": "uDfmLayerViolation.pas",
"examples": {
"bad": "object frmEdit: TForm\n object EdName: TEdit // direct child of form",
"good": "object frmEdit: TForm\n object pnlBody: TPanel\n object EdName: TEdit"
},
"cleanCodeAttribute": "CONVENTIONAL",
"impacts": [
{ "softwareQuality": "MAINTAINABILITY", "severity": "LOW" }
]
},
{
"id": "SCA042",
"kind": "DfmGodHandler",
"name": "God event handler",
"shortDescription": "Single method wired to >= N component events (default N=5)",
"fullDescription": "Spaghetti indicator: one handler dispatching dozens of events is hard to read, hard to change, and almost always has cohesion problems. Split by responsibility.",
"defaultSeverity": "Hint",
"type": "Code Smell",
"tags": ["dfm", "design"],
"configKey": "[Detectors] DfmGodHandlerMaxEvents",
"detectorUnit": "uDfmGodHandler.pas",
"examples": {
"bad": "btn1.OnClick = HandleEverything\nbtn2.OnClick = HandleEverything\nbtn3.OnClick = HandleEverything\nbtn4.OnClick = HandleEverything\nbtn5.OnClick = HandleEverything",
"good": "(one handler per logical action)"
},
"cleanCodeAttribute": "FOCUSED",
"impacts": [
{ "softwareQuality": "MAINTAINABILITY", "severity": "MEDIUM" }
]
},
{
"id": "SCA043",
"kind": "DfmActionMismatch",
"name": "Component has Action + OnClick",
"shortDescription": "Action and OnClick both set - Action wins, OnClick is dead code",
"fullDescription": "When a TAction is assigned, VCL routes events through the action object and the OnClick never fires. Pick one or call the OnClick body from the action's OnExecute.",
"defaultSeverity": "Warning",
"type": "Bug",
"tags": ["dfm", "dead-code"],
"detectorUnit": "uDfmActionMismatch.pas",
"examples": {
"bad": "object btnSave: TButton\n Action = actSave\n OnClick = btnSaveClick // never fires\nend",
"good": "(remove OnClick or remove Action)"
},
"cleanCodeAttribute": "LOGICAL",
"impacts": [
{ "softwareQuality": "MAINTAINABILITY", "severity": "MEDIUM" }
]
},
{
"id": "SCA044",
"kind": "ConcatToFormat",
"name": "Long string concat - prefer Format()",
"shortDescription": "Multi-segment string concatenation - extract to a Format() call",
"fullDescription": "Chains of `'a' + Var + 'b' + IntToStr(N)` (three or more concatenations involving non-literal segments) are harder to scan and harder to translate than `Format('a%sb%d', [Var, N])`: every IntToStr / FloatToStr / FormatDateTime in the middle of a string is one more place where a `resourcestring` cannot capture the message template. The detector triggers from 3 segments / 2 non-literal pieces upward, ignores trivial cases (`'<' + Name + '>'`) and skips lines under an active `// noinspection ConcatToFormat`. The flagged form may be intentional in performance-critical inner loops where Format's varargs box; the suppression marker is for that case.",
"defaultSeverity": "Warning",
"type": "Code Smell",
"tags": ["maintainability", "string-formatting"],
"detectorUnit": "uConcatToFormat.pas",
"examples": {
"bad": "Msg := 'User ' + Name + ' has ' + IntToStr(N) + ' open tickets';",
"good": "Msg := Format('User %s has %d open tickets', [Name, N]);"
},
"cleanCodeAttribute": "EFFICIENT",
"impacts": [
{ "softwareQuality": "MAINTAINABILITY", "severity": "LOW" }
]
},
{
"id": "SCA045",
"kind": "WithStatement",
"name": "with X do ...",
"shortDescription": "with statement - scope-shadowing trap the compiler does not warn about",
"fullDescription": "Marco Cantu, delphi.org and Stack Overflow consistently rank `with` among the top Delphi bug sources. Identifiers from the outer scope get silently shadowed by members of the with-target. Use a local variable alias instead.",
"defaultSeverity": "Warning",
"type": "Code Smell",
"tags": ["scope", "delphi-classic"],
"detectorUnit": "uWithStatement.pas",
"examples": {
"bad": "with Customer do\nbegin\n Name := SomeName; // Customer.Name? or local Name?\nend;",
"good": "C := Customer;\nC.Name := SomeName;"
},
"cleanCodeAttribute": "CLEAR",
"impacts": [
{ "softwareQuality": "MAINTAINABILITY", "severity": "LOW" }
]
},
{
"id": "SCA046",
"kind": "ReversedForRange",
"name": "for i := High to Low - missing downto",
"shortDescription": "for i := 10 to 1 do - loop body never executes",
"fullDescription": "`for i := 10 to 1 do` is a downto-vs-to typo: in Pascal a `to`-loop with start > end iterates zero times, so the body silently never runs and the bug shows up as missing side-effects with no compiler warning. The detector evaluates compile-time integer expressions on both sides (literals, simple negations, and `Length(arr)-1` for constant-length declarations) so `for i := Length(L)-1 to 0` is flagged. Variable-bounded loops are excluded - they may legitimately do nothing depending on runtime data. To iterate descending, write `downto`; to express 'maybe empty' explicitly, guard with an `if From <= To`.",
"defaultSeverity": "Error",
"type": "Bug",
"tags": ["loop", "typo"],
"detectorUnit": "uReversedForRange.pas",
"examples": {
"bad": "for i := 10 to 1 do DoStuff(i);",
"good": "for i := 10 downto 1 do DoStuff(i);"
},
"cleanCodeAttribute": "LOGICAL",
"impacts": [
{ "softwareQuality": "RELIABILITY", "severity": "HIGH" }
]
},
{
"id": "SCA047",
"kind": "SelfAssignment",
"name": "x := x",
"shortDescription": "Self-assignment - no-op or copy-paste typo",
"fullDescription": "Detector excludes property setters with documented side effects. A bare `x := x` is almost always a typo where one side should be a different variable.",
"defaultSeverity": "Warning",
"type": "Bug",
"tags": ["typo", "no-op"],
"detectorUnit": "uSelfAssignment.pas",
"examples": {
"bad": "Customer.Name := Customer.Name;",
"good": "Customer.Name := NewName;"
},
"cleanCodeAttribute": "LOGICAL",
"impacts": [
{ "softwareQuality": "RELIABILITY", "severity": "MEDIUM" }
]
},
{
"id": "SCA048",
"kind": "VirtualCallInCtor",
"name": "Virtual call in constructor",
"shortDescription": "Virtual method invoked from constructor - subclass override sees half-initialised Self",
"fullDescription": "C++ FAQ 23.5 / Effective Java item 17 in Delphi form: virtual dispatch in a ctor runs the most-derived override before subclass fields are initialised. Defer to a non-virtual post-construction hook.",
"defaultSeverity": "Error",
"type": "Bug",
"tags": ["oop", "initialization-order"],
"cwe": ["CWE-665"],
"detectorUnit": "uVirtualCallInCtor.pas",
"examples": {
"bad": "constructor TBase.Create;\nbegin\n Configure; // virtual\nend;",