Skip to content

Configuration File

Leandro Baca edited this page Apr 9, 2021 · 3 revisions

This section describes the structure of the configuration file, which is written in JSON.

When invoked from the command line, the program will look for the configuration file by default in %USERPROFILE%\.pscodeanalyzer\settings.json in Windows environments, and ${HOME}/.pscodeanalyzer/settings.json in Linux. However, this path can be overridden, and must be specified explicitly when invoking the Python module from another script.

An example of the configuration file using all delivered evaluators is reproduced below:

{
    "profiles": {
        "default": {
            "substitutions": {
                "TICKET": "CR9999"
            },
            "evaluators": [
                {
                    "class": "RegexRule",
                    "description": "Project-specific comment not found: #TICKET#",
                    "code": 1,
                    "default_report_type": "WARNING",
                    "include_source_types": [],
                    "exclude_source_types": [],
                    "pattern": "(?m)^\\s*/\\* #TICKET# - ",
                    "invert": true
                },
                {
                    "class": "pscodeanalyzer.rules.peoplecode.PeopleCodeParserProxy",
                    "description": "PeopleCode parser rule proxy",
                    "evaluators": [
                        {
                            "class": "pscodeanalyzer.rules.peoplecode.SQLExecRule",
                            "description": "Look for SQLExec calls with string literals",
                            "code": 2
                        },
                        {
                            "class": "pscodeanalyzer.rules.peoplecode.SymbolDefinitionPhaseRule",
                            "description": "Symbol definition phase for undeclared variable validation",
                            "code": 9999,
                            "exclude_source_types": [58]
                        },
                        {
                            "class": "pscodeanalyzer.rules.peoplecode.SymbolReferencePhaseRule",
                            "description": "Symbol reference phase for undeclared variable validation",
                            "code": 3,
                            "exclude_source_types": [58],
                            "inherit_annotations": true
                        }
                    ],
                    "encoding": "utf-8"
                }
            ]
        }
    }
}

The root section of the configuration object consists solely of the profiles object. This object must consist of one or more profile objects under an identifying label (e.g., "default"). Each profile object must define a list of evaluator objects under the evaluators label, and can optionally define a substitutions object.

evaluator Object

The evaluator object's members will depend on whether the evaluator references a Rule or a Proxy. Each evaluator provides certain fixed configuration options, and each subclass implementation is free to define others.

In general terms, each evaluator defines the following properties:

Property Required? Description
class Yes The name of the class to instantiate; must be "Rule" (the null implementation), "RegexRule", "Proxy", or a fully-qualified subclass of any of these.
description No An optional property used as the description for the evaluator instance.

Rule-Specific Properties

If the class property denotes the Rule class or one of its subclasses, the following additional properties apply:

Property Required? Description
code Yes An integer between 1 and 9999 that uniquely identifies the rule. This value will be reflected in any Report instances and related printouts.
default_report_type No One of "ERROR" (default), "WARNING" or "INFO".
include_source_types No A list of source types that this rule applies to; if empty (default), all source types apply. The source type values are domain-specific, but in the specific context of PeopleSoft, they refer to the to object type values of the file being analyzed (i.e., 8 for Record PeopleCode, 58 for Application Package PeopleCode, etc.).
exclude_source_types No A list of integers that identify the source types that this rule does not apply to (defaults to empty); if a source type is an explicit member of both lists, it is excluded.

In addition, the value of the description property defined above is used as the default message for Report objects.

RegexRule-Specific Properties

The RegexRule class accepts the following properties in addition to those defined for the Rule and Evaluator classes:

Property Required? Description
pattern Yes A string with the regular expression pattern to search for (in Python-specific syntax).
invert No A Boolean indicating if the match should be inverted; if false (default), individual matches of the pattern are reported; if true, a single report is raised if the pattern is not matched.

PeopleCodeParserListenerRule-Specific Properties

The PeopleCodeParserListenerRule class accepts the following additional property:

Property Required? Description
inherit_annotations No A Boolean indicating whether this rule should inherit the annotations from the rule that ran before it (defaults to false).

Proxy-Specific Properties

If the class property denotes the Proxy class or one of its subclasses, the following additional property applies:

Property Required? Description
evaluators Yes A list of evaluator objects that will be encapsulated by the Proxy and evaluated in the stated order.

This implies that proxies can include both rules and other proxies.

PeopleCodeParserProxy-Specific Properties

The PeopleCodeParserProxy class accepts the following property in addition to those defined for the Proxy and Evaluator classes:

Property Required? Description
encoding No The encoding with which to open the source files (defaults to "utf-8").

substitutions Object

Every value present inside an evaluator object (searched recursively) can specify zero or more strings flanked by hashes ("#"), which will denote a substitution variable. These variables can be substituted from the command line (by means of the -s or --substitution argument) or when invoked from a Python script (by means of the substitutions argument). However, substitutions can be defined globally inside the configuration file by means of the substitutions object, which will map a substitution variable's name to its value.

Substitution variables passed in through the invocation will be added to those defined in the configuration profile. If the same variable name is provided as one defined in the substitutions object, the value passed in through the invocation takes precedence.