Skip to content

Commit 5dbdee3

Browse files
l-trottapquentin
andcommitted
Implement union type validation for static language support (#5603)
* merge conflict * modify rule to skip null undefined * modify rule to skip null undefined * all ignore comments for existing violations * update variant rule * remove empty line * remove empty line * Switch from Array<string> to string[] in inference * fix * Remove empty lines --------- Co-authored-by: Quentin Pradet <[email protected]>
1 parent 015f13a commit 5dbdee3

File tree

27 files changed

+471
-4
lines changed

27 files changed

+471
-4
lines changed

specification/_global/delete/DeleteResponse.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export class Response {
2929
* the response is the same as the successful case, but with a 404.
3030
*/
3131
statusCodes: [404]
32+
// eslint-disable-next-line es-spec-validator/no-inline-unions, es-spec-validator/prefer-tagged-variants -- TODO: use tagged variant
3233
body: WriteResponseBase | ErrorResponseBase
3334
}
3435
]

specification/_global/get/GetResponse.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export class Response<TDocument> {
2929
// * index_not_found_exception as an error if the index doesn't exist
3030
// * GetResult with only the requested _id, _index properties and found as a false boolean
3131
statusCodes: [404]
32+
// eslint-disable-next-line es-spec-validator/no-inline-unions, es-spec-validator/prefer-tagged-variants -- TODO: use tagged variant
3233
body: GetResult<TDocument> | ErrorResponseBase
3334
}
3435
]

specification/_global/scripts_painless_execute/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,6 @@ export class PainlessScript {
9797
* * `long`: `emit(long)`
9898
* * `keyword`: `emit(String)`
9999
*/
100+
// eslint-disable-next-line es-spec-validator/no-inline-unions -- TODO: create named alias
100101
emit: boolean | DateTime | double | string | Ip | long
101102
}

specification/_global/search/_types/hits.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export class Hit<TDocument> {
5252
fields?: Dictionary<string, UserDefinedValue>
5353
highlight?: Dictionary<string, string[]>
5454
inner_hits?: Dictionary<string, InnerHitsResult>
55+
// eslint-disable-next-line es-spec-validator/no-inline-unions -- TODO: create named alias
5556
matched_queries?: string[] | Dictionary<string, double>
5657
_nested?: NestedIdentity
5758
_ignored?: string[]
@@ -69,6 +70,7 @@ export class Hit<TDocument> {
6970

7071
export class HitsMetadata<T> {
7172
/** Total hit count information, present only if `track_total_hits` wasn't `false` in the search request. */
73+
// eslint-disable-next-line es-spec-validator/no-inline-unions -- TODO: create named alias
7274
total?: TotalHits | long
7375
hits: Hit<T>[]
7476

specification/_global/search/_types/suggester.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ export class RegexOptions {
186186
* Optional operators for the regular expression.
187187
* @doc_id regexp-syntax
188188
*/
189+
// eslint-disable-next-line es-spec-validator/no-inline-unions -- TODO: create named alias
189190
flags?: integer | string
190191
/**
191192
* Maximum number of automaton states required for the query.

specification/_types/mapping/specialized.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export class SuggestContext {
4444
name: Name
4545
path?: Field
4646
type: string
47+
// eslint-disable-next-line es-spec-validator/no-inline-unions -- TODO: create named alias
4748
precision?: integer | string
4849
}
4950

specification/_types/query_dsl/compound.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export class ScriptScoreFunction {
143143

144144
export class RandomScoreFunction {
145145
field?: Field
146+
// eslint-disable-next-line es-spec-validator/no-inline-unions -- TODO: create named alias
146147
seed?: long | string
147148
}
148149

specification/_types/query_dsl/fulltext.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ export class MatchQuery extends QueryBase {
395395
*/
396396
// FIXME: docs states "date" as a possible format. Add DateMath, or DurationLarge?
397397
// Should also be consistent with MultiMatchQuery.query
398+
// eslint-disable-next-line es-spec-validator/no-inline-unions -- TODO: create named alias
398399
query: string | float | boolean
399400
/**
400401
* Indicates whether no documents are returned if the `analyzer` removes all tokens, such as when using a `stop` filter.

specification/_types/query_dsl/term.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export class FuzzyQuery extends QueryBase {
8282
// ES is lenient and accepts any primitive type, but ultimately converts it to a string.
8383
// Changing this field definition from UserDefinedValue to string breaks a recording produced from Nest tests,
8484
// but Nest is probably also overly flexible here and exposes an option that should not exist.
85+
// eslint-disable-next-line es-spec-validator/no-inline-unions -- TODO: create named alias
8586
value: string | double | boolean
8687
}
8788

specification/eslint.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export default defineConfig({
3838
'es-spec-validator/no-generic-number': 'error',
3939
'es-spec-validator/request-must-have-urls': 'error',
4040
'es-spec-validator/no-variants-on-responses': 'error',
41+
'es-spec-validator/no-inline-unions': 'error',
42+
'es-spec-validator/prefer-tagged-variants': 'error'
4143
'es-spec-validator/jsdoc-endpoint-check': [
4244
'error',
4345
{

0 commit comments

Comments
 (0)