Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for extensible enums #1

Merged
merged 4 commits into from
Jun 11, 2024
Merged

Conversation

hugowetterberg
Copy link
Contributor

@hugowetterberg hugowetterberg commented May 29, 2024

Adds the option to specify stand-alone extensible enums:

  "enums": [
    {
      "declare": "core/text-roles",
      "name": "Text block roles",
      "values": {
        "heading-1": {},
        "heading-2": {},
        "heading-3": {},
        "heading-4": {},
        "preamble": {},
        "blockquote": {}
      }
    }
  ],

It's possible to add, deprecate or forbid values:

  "enums": [
    {
      "match": "core/text-roles",
      "values": {
        "heading-3": {"forbidden":true},
        "heading-4": {"forbidden":true},
        "vignette": {},
        "dateline": {
          "deprecated": {
            "label": "dateline",
            "doc": "Use 'vignette' instead"
          }
        }
      }
    }
  ],

This is used to make it possible to create a core/text block and then extend it with different roles:

        {
          "declares": {"type":"core/text"},
          "attributes": {
            "role": {
              "optional":true,
              "enumReference": "core/text-roles"
            }
          },
          "data": {
            "text":{
              "allowEmpty":true,
              "format": "html"
            }
          }
        },

A lot of the code changes are in service of making it possible for string constraints to return deprecation information.

As far as I could tell DocumentConstraint.checkAttributes() duplicated validateDocumentAttributes() so I removed that method and the call to it.

checkDeprecation() was extended to accept multiple deprecations.

Document and block attributes, which always are "present" given that they map to struct fields and not map entries like data attributes, are not collected by revisor as values any more. Empty data attributes are still treated as signal.

(Deprecation, error) looks like a result-error pair to the linter, when it's
actually two classes of errors, one soft and one hard.
@hugowetterberg hugowetterberg merged commit 7dcfc59 into main Jun 11, 2024
2 checks passed
@hugowetterberg hugowetterberg deleted the feature/extensible-enums branch June 11, 2024 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants