Skip to content

Conversation

@margaretjgu
Copy link
Member

@margaretjgu margaretjgu commented Nov 3, 2025

Closes #4737

Implements two new validation rules to improve code generation for statically-typed languages:

  1. no-inline-unions - Forbids inline union types in properties
  2. prefer-tagged-variants - Enforces tagged variants for unions of class types

Total existing violations: 91

  • no-inline-unions: 37
  • prefer-tagged-variants: 54

The rules automatically skips the following patterns:

  1. Type | null / Type | undefined
  2. Type | Type[] patterns

@margaretjgu margaretjgu changed the title union rules Implement union type validation for static language support Nov 3, 2025
@margaretjgu margaretjgu requested review from a team as code owners November 4, 2025 20:55
@github-actions
Copy link
Contributor

github-actions bot commented Nov 4, 2025

Following you can find the validation changes against the target branch for the APIs.

No changes detected.

You can validate these APIs yourself by using the make validate target.

Comment on lines +87 to 88
// eslint-disable-next-line es-spec-validator/no-inline-unions -- TODO: create named alias
number_of_shards?: integer | string // TODO: should be only int
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record, this a known issue with index settings that they can be passed as strings too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should actually be Stringyfied I think.

@flobernd
Copy link
Member

flobernd commented Nov 6, 2025

Let's backport all the nice validations to 8.19 LTS branch as well, if they don't have incompatible changes 🙂

Comment on lines 110 to 111
// eslint-disable-next-line es-spec-validator/no-inline-unions, es-spec-validator/prefer-tagged-variants -- TODO: use tagged variant
global?: GlobalPrivilege[] | GlobalPrivilege
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is valid. We have two options here:

  1. Change this to GlobalPrivilege | GlobalPrivilege[]
  2. Change the logic do detect this case

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vote for 2.! The validation should not care about the order.

* Either a string or an array of strings.
*/
// eslint-disable-next-line es-spec-validator/no-inline-unions -- TODO: create named alias
input: string | Array<string>
Copy link
Member

@pquentin pquentin Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that string | Array<string> is the same as string | string[]. I've pushed #5603 (6e8c9affd) to fix it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other validation about using native types should catch and prevent this case in the future, I guess.

@pquentin
Copy link
Member

pquentin commented Nov 6, 2025

Let's backport all the nice validations to 8.19 LTS branch as well, if they don't have incompatible changes 🙂

None of the validation work exists in 8.19, so this is out of scope.

@margaretjgu margaretjgu requested a review from pquentin November 6, 2025 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[validation] Union related ESLint rules

4 participants