Skip to content

[FEATURE]: enum-value-formatting: harden meta:enum handling and issue paths #820

@Mehrn0ush

Description

@Mehrn0ush

Describe the feature

Harden tools/src/main/js/linter/checks/enum-value-formatting.check.js so meta:enum handling is deterministic and lint output is accurate/noise-free (especially for edge-case inputs).

Use-cases

  • Schemas that correctly use meta:enum should not trigger false positives (e.g., “missing description” when the key exists).
  • Schemas with malformed meta:enum (wrong type, inherited properties) should produce a clear error instead of silent/incorrect behavior.
  • Reports should point to the correct location (meta:enum paths), and duplicate enum literals should not generate duplicate issues.

Scope / Out of scope

  • Scope: this single check file only.
  • Out of scope: changing the public API/config of the linter; adding new dependencies.

Possible solutions

Proposed changes (all within the check):

  1. Use own-property detection for meta:enum on the parent:

    • Replace 'meta:enum' in parent with Object.prototype.hasOwnProperty.call(parent, 'meta:enum')
      to avoid consulting the prototype chain (hardens the check against prototype-chain manipulation,
      including prototype-pollution scenarios).
  2. Validate meta:enum type before using it:

    • Require a plain object (non-null object, not array, prototype is Object.prototype or null).
    • If present but invalid, emit one ERROR:
      • Message: meta:enum must be a plain object mapping enum values to descriptions.
      • Context: actualType (array or typeof).
  3. Fix coverage logic:

    • Replace !metaEnum[value] with !Object.prototype.hasOwnProperty.call(metaEnum, value) to test key presence only.
    • Avoid counting inherited keys as “present”.
  4. Fix path reporting:

    • Avoid literal "undefined" / "null" paths by using a safe fallback for paths.
    • Derive a single metaEnumBasePath by replacing trailing .enum with .meta:enum (and handle root / fallback cases).
    • Report “missing description” at the meta:enum location, not the enum array.
  5. De-duplicate enum-value checks:

    • Iterate over unique string values (Set) so duplicate enum literals don't emit duplicate issues.

Additional context

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions