salesforce / utam-java

UTAM Java implementation
MIT License
25 stars 16 forks source link

feat: Add configurable lint rule for metadata object #197

Closed jimevanssfdc closed 1 year ago

jimevanssfdc commented 1 year ago

This PR adds a new rule for linting the metadata field (disabled by default, because it's an optional field), and can be configured in the compiler config with the following JSON:

{
  "lint": {
    "requiredMetadata": {
      "violation": "warning",
      "exclude": [],
      "additionalConfiguration": {
        "requiredProperties": [
          {
            "name": "foo"
          },
          {
            "name": "bar",
            "values": [ "baz", "quux", "corge" ]
          }
        ]
      }
    }
  }
}

The requiredMetadata property without any additionalConfiguration entries will simply check for the presence of the metadata property in each page object. Within additionalConfiguration, the user is able to specify a requiredProperties list that indicates the properties that must be present in the metadata object.

An object in the requiredProperties array with only a name field will check only for the presence of the property and that its value is not empty (or only containing whitespace). One with a values field will check for the presence of the property, and that the value is one of the values supplied in the array.

For now, we only handle string properties and values in metadata, but this could be extended in the future to include a type property (default "string"), and can specify different metadata types and different methods of validation. See the added unit tests and the resources therein for full examples.