@@ -443,22 +443,22 @@ You can configure GNATcheck rules using an LKQL file, provided through the
443
443
described in the following paragraph).
444
444
445
445
By default, GNATcheck will look for a ``rules.lkql `` file besides the specified
446
- project file if any. If there is one and no other rule configuration has been
447
- provided (through an LKQL rule file, or through the rule options), GNATcheck
448
- will load it as the LKQL rule options file, as if it was provided through the
449
- `` --rule-file `` option.
446
+ project file if any. If one is found and no other rule configuration has been
447
+ provided (either through the LKQL -- rule- file option , or by the now deprecated
448
+ legacy -rules options), GNATcheck will load the rule configuration file as if
449
+ it was provided by the --rule-file option.
450
450
451
451
.. note ::
452
452
453
453
You can use the ``--emit-lkql-rule-file `` CLI switch to generate an LKQL rule
454
- file from a legacy rule configuration provided through the ``-rules ``
455
- section.
454
+ file from a legacy rule configuration provided by the ``-rules `` section.
456
455
457
- This file must be a valid LKQL file that exports at least a ``rules `` top-level
458
- symbol. This symbol must refer to an object value containing rules
459
- configuration; keys are GNATcheck rules to enable; and values are objects
460
- containing rule parameters. A rule parameter value can be a boolean, an
461
- integer, a string, or a list of strings.
456
+ An LKQL rule file can be any valid LKQL file, the only requirement is that it
457
+ must export a ``rules `` top-level symbol. This symbol defines an object value
458
+ containing rules configuration; keys are GNATcheck rules to enable; and values
459
+ are objects containing the rule parameters. A rule parameter value can be of
460
+ the boolean, the integer, the string, or the list of strings type, as shown in
461
+ the simple example below:
462
462
463
463
::
464
464
@@ -467,25 +467,13 @@ integer, a string, or a list of strings.
467
467
Forbidden_Attributes: {Forbidden: ["GNAT"], Allowed: ["First", "Last"]}
468
468
}
469
469
470
- For example, to map a boolean parameter from a ``+R `` rule option to an LKQL
471
- rule file, you have to associate a boolean LKQL value to the parameter name:
472
-
473
- ::
474
-
475
- +RGoto_Statements:Only_Unconditional
476
-
477
- maps to:
478
-
479
- ::
480
-
481
- val rules = @{
482
- Goto_Statements: {Only_Unconditional: true}
483
- }
470
+ Please read the :ref: `Predefined_Rules ` documentation to view examples on how
471
+ to provide parameters to rules through LKQL rule files.
484
472
485
473
.. attention ::
486
474
487
475
You cannot provide the same key twice; thus, the following code will result
488
- in a runtime error.
476
+ in a GNATcheck error.
489
477
490
478
::
491
479
@@ -494,24 +482,42 @@ maps to:
494
482
Forbidden_Attributes: {Forbidden: ["GNAT"], Allowed: ["First", "Last"]}
495
483
}
496
484
497
- If you want to create many instances of the same rule, you can associate a list
498
- to the rule name and add an ``instance_name `` key in argument objects to define
499
- their names.
485
+ If you want to create multiple instances of the same rule, you can associate
486
+ a list value to the rule name in the rule configuration object. Elements of
487
+ this list must be parameter objects containing an additional
488
+ ``instance_name `` parameter defining the name of the instance described by
489
+ the enclosing object. If none is provided, the instance is named after the
490
+ rule it is instantiated from, as shown in the following example:
500
491
501
- ::
492
+ ::
502
493
503
- val rules = @{
504
- Goto_Statements,
505
- Forbidden_Attributes: [
506
- {Forbidden: ["First", "Last"]},
507
- {Forbidden: ["Length"], instance_name: "Length_Attr"}
508
- ]
509
- }
494
+ val rules = @{
495
+ Goto_Statements,
496
+ Forbidden_Attributes: [
497
+ # "Forbidden_Attributes" instance of the "Forbidden_Attributes" rule, checking for 'First and 'Last
498
+ {Forbidden: ["First", "Last"]},
499
+
500
+ # "Length_Attr" instance of the "Forbidden_Attributes" rule, checking for 'Length
501
+ {Forbidden: ["Length"], instance_name: "Length_Attr"}
502
+ ]
503
+ }
510
504
511
- Additionally to the ``rules `` top-level symbol, the LKQL rule file may export ``ada_rules ``
512
- and ``spark_rules `` symbols to enable associated rules, respectively, only on Ada code and
513
- only on SPARK code. Those symbols must also refer to an object value formatted like the
514
- ``rules `` value.
505
+ Moreover, each instance must be identifiable through a unique name, thus the
506
+ following configuration is invalid and will lead to a GNATCheck error:
507
+
508
+ ::
509
+
510
+ val rules = @{
511
+ Forbidden_Attributes: [
512
+ {Forbidden: ["First", "Last"], instance_name: "Instance"},
513
+ {Forbidden: ["Length"], instance_name: "Instance"},
514
+ ]
515
+ }
516
+
517
+ Additionally to the ``rules `` top-level symbol, an LKQL rule file may export
518
+ ``ada_rules `` and ``spark_rules `` symbols to enable associated rules,
519
+ respectively, only on Ada code or only on SPARK code. Those symbols must also
520
+ refer to an object value formatted like the ``rules `` value.
515
521
516
522
::
517
523
@@ -540,10 +546,28 @@ the following configuration will raise an error:
540
546
Warnings: "a"
541
547
}
542
548
543
- .. note ::
549
+ .. attention ::
544
550
545
- Note that an LKQL rules config file may contain arbitrary computation logic; the only
546
- rule for this type of file is to export a ``rules `` symbol referring to an object value.
551
+ Instance uniqueness must also be respected between all rule sets, meaning
552
+ that such config is invalid:
553
+
554
+ ::
555
+
556
+ val rules = @{
557
+ # Clashing with "Goto_Statement" in ada_rules
558
+ Goto_Statements,
559
+
560
+ # Clashing with "Forbid_Attr" instance in spark_rules
561
+ Forbidden_Attributes: {Forbidden: ["GNAT"], instance_name: "Forbid_Attr"}
562
+ }
563
+
564
+ val ada_rules = @{
565
+ Goto_Statements
566
+ }
567
+
568
+ val spark_rules = @{
569
+ Forbidden_Attributes: {Forbidden: ["Length"], instance_name: "Forbid_Attr"}
570
+ }
547
571
548
572
549
573
.. _gnatcheck_Rule_Options :
0 commit comments