Skip to content

Commit 0baddb1

Browse files
committed
fix
1 parent 6e8c9af commit 0baddb1

File tree

6 files changed

+40
-4
lines changed

6 files changed

+40
-4
lines changed

specification/nodes/info/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ export class NodeInfoSettingsCluster {
143143
name: Name
144144
routing?: IndexRouting
145145
election: NodeInfoSettingsClusterElection
146-
// eslint-disable-next-line es-spec-validator/no-inline-unions -- TODO: create named alias
147146
initial_master_nodes?: string[] | string
148147
/**
149148
* @availability stack since=7.16.0
@@ -188,7 +187,6 @@ export class NodeInfoRepositoriesUrl {
188187
export class NodeInfoDiscover
189188
implements AdditionalProperties<string, UserDefinedValue>
190189
{
191-
// eslint-disable-next-line es-spec-validator/no-inline-unions -- TODO: create named alias
192190
seed_hosts?: string[] | string
193191
type?: string
194192
seed_providers?: string[]

specification/security/_types/RoleDescriptor.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ export class RoleDescriptor {
5555
* An object defining global privileges. A global privilege is a form of cluster privilege that is request-aware. Support for global privileges is currently limited to the management of application privileges.
5656
* @availability stack
5757
*/
58-
// eslint-disable-next-line es-spec-validator/no-inline-unions, es-spec-validator/prefer-tagged-variants -- TODO: use tagged variant
5958
global?: GlobalPrivilege[] | GlobalPrivilege
6059
/**
6160
* A list of application privilege entries
@@ -107,7 +106,6 @@ export class RoleDescriptorRead implements OverloadOf<RoleDescriptor> {
107106
/**
108107
* An object defining global privileges. A global privilege is a form of cluster privilege that is request-aware. Support for global privileges is currently limited to the management of application privileges.
109108
*/
110-
// eslint-disable-next-line es-spec-validator/no-inline-unions, es-spec-validator/prefer-tagged-variants -- TODO: use tagged variant
111109
global?: GlobalPrivilege[] | GlobalPrivilege
112110
/**
113111
* A list of application privilege entries

validator/rules/no-inline-unions.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,21 @@ export default createRule({
6464
}
6565
}
6666
}
67+
68+
// skip Type[] | Type pattern
69+
if (first.type === 'TSArrayType') {
70+
if (first.elementType?.type === second.type) {
71+
if (first.elementType.type === 'TSTypeReference' && second.type === 'TSTypeReference') {
72+
// for reference types, check names match
73+
if (first.elementType.typeName?.name === second.typeName?.name) {
74+
return;
75+
}
76+
} else if (first.elementType.type === second.type) {
77+
// for primitive types (string, number, etc.), types already match
78+
return;
79+
}
80+
}
81+
}
6782
}
6883

6984
context.report({

validator/rules/prefer-tagged-variants.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ export default createRule({
7070
// skip Type | Type[] pattern
7171
if (node.types.length === 2) {
7272
const [first, second] = node.types;
73+
74+
// check Type | Type[]
7375
if (second.type === 'TSArrayType' &&
7476
first.type === 'TSTypeReference' &&
7577
second.elementType?.type === 'TSTypeReference') {
@@ -79,6 +81,17 @@ export default createRule({
7981
return;
8082
}
8183
}
84+
85+
// check Type[] | Type
86+
if (first.type === 'TSArrayType' &&
87+
first.elementType?.type === 'TSTypeReference' &&
88+
second.type === 'TSTypeReference') {
89+
const firstName = first.elementType.typeName?.name;
90+
const secondName = second.typeName?.name;
91+
if (firstName && firstName === secondName) {
92+
return;
93+
}
94+
}
8295
}
8396

8497
const allMembersAreClasses = node.types.every(typeNode => {

validator/test/no-inline-unions.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ ruleTester.run('no-inline-unions', rule, {
6464
`interface MyInterface {
6565
input: string | string[]
6666
}`,
67+
`class MyClass {
68+
items: string[] | string
69+
}`,
70+
`interface Config {
71+
nodes: integer[] | integer
72+
}`,
6773
],
6874
invalid: [
6975
{

validator/test/prefer-tagged-variants.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ ruleTester.run('prefer-tagged-variants', rule, {
5858
`class SearchRequest {
5959
knn?: KnnSearch | KnnSearch[]
6060
}`,
61+
`class EqlRequest {
62+
filter?: QueryContainer[] | QueryContainer
63+
}`,
64+
`interface MyInterface {
65+
data: MyClass[] | MyClass
66+
}`,
6167
],
6268
invalid: [
6369
{

0 commit comments

Comments
 (0)