Skip to content

Commit 0a95bdf

Browse files
feat: add new rule no-illogical-any-of-usage
1 parent 01285fe commit 0a95bdf

File tree

7 files changed

+51
-0
lines changed

7 files changed

+51
-0
lines changed

packages/core/src/config/all.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ const all: RawGovernanceConfig<'built-in'> = {
118118
'tags-alphabetical': 'error',
119119
'no-duplicated-tag-names': 'error',
120120
'no-illogical-one-of-usage': 'error',
121+
'no-illogical-any-of-usage': 'error',
121122
},
122123
oas3_1Rules: {
123124
'array-parameter-serialization': 'error',
@@ -181,6 +182,7 @@ const all: RawGovernanceConfig<'built-in'> = {
181182
'tags-alphabetical': 'error',
182183
'no-duplicated-tag-names': 'error',
183184
'no-illogical-one-of-usage': 'error',
185+
'no-illogical-any-of-usage': 'error',
184186
},
185187
oas3_2Rules: {
186188
'array-parameter-serialization': 'error',
@@ -244,6 +246,7 @@ const all: RawGovernanceConfig<'built-in'> = {
244246
'tags-alphabetical': 'error',
245247
'no-duplicated-tag-names': 'error',
246248
'no-illogical-one-of-usage': 'error',
249+
'no-illogical-any-of-usage': 'error',
247250
},
248251
async2Rules: {
249252
'channels-kebab-case': 'error',

packages/core/src/config/minimal.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ const minimal: RawGovernanceConfig<'built-in'> = {
109109
'tags-alphabetical': 'off',
110110
'no-duplicated-tag-names': 'off',
111111
'no-illogical-one-of-usage': 'off',
112+
'no-illogical-any-of-usage': 'off',
112113
},
113114
oas3_1Rules: {
114115
'array-parameter-serialization': 'off',
@@ -166,6 +167,7 @@ const minimal: RawGovernanceConfig<'built-in'> = {
166167
'tags-alphabetical': 'off',
167168
'no-duplicated-tag-names': 'off',
168169
'no-illogical-one-of-usage': 'off',
170+
'no-illogical-any-of-usage': 'off',
169171
},
170172
oas3_2Rules: {
171173
'array-parameter-serialization': 'off',
@@ -223,6 +225,7 @@ const minimal: RawGovernanceConfig<'built-in'> = {
223225
'tags-alphabetical': 'off',
224226
'no-duplicated-tag-names': 'off',
225227
'no-illogical-one-of-usage': 'off',
228+
'no-illogical-any-of-usage': 'off',
226229
},
227230
async2Rules: {
228231
'channels-kebab-case': 'off',

packages/core/src/config/recommended-strict.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ const recommendedStrict: RawGovernanceConfig<'built-in'> = {
109109
'tags-alphabetical': 'off',
110110
'no-duplicated-tag-names': 'error',
111111
'no-illogical-one-of-usage': 'error',
112+
'no-illogical-any-of-usage': 'error',
112113
},
113114
oas3_1Rules: {
114115
'array-parameter-serialization': 'off',
@@ -166,6 +167,7 @@ const recommendedStrict: RawGovernanceConfig<'built-in'> = {
166167
'tags-alphabetical': 'off',
167168
'no-duplicated-tag-names': 'error',
168169
'no-illogical-one-of-usage': 'error',
170+
'no-illogical-any-of-usage': 'error',
169171
},
170172
oas3_2Rules: {
171173
'array-parameter-serialization': 'off',
@@ -223,6 +225,7 @@ const recommendedStrict: RawGovernanceConfig<'built-in'> = {
223225
'tags-alphabetical': 'off',
224226
'no-duplicated-tag-names': 'error',
225227
'no-illogical-one-of-usage': 'error',
228+
'no-illogical-any-of-usage': 'error',
226229
},
227230
async2Rules: {
228231
'channels-kebab-case': 'off',

packages/core/src/config/recommended.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ const recommended: RawGovernanceConfig<'built-in'> = {
109109
'tags-alphabetical': 'off',
110110
'no-duplicated-tag-names': 'warn',
111111
'no-illogical-one-of-usage': 'warn',
112+
'no-illogical-any-of-usage': 'warn',
112113
},
113114
oas3_1Rules: {
114115
'array-parameter-serialization': 'off',
@@ -166,6 +167,7 @@ const recommended: RawGovernanceConfig<'built-in'> = {
166167
'tags-alphabetical': 'off',
167168
'no-duplicated-tag-names': 'warn',
168169
'no-illogical-one-of-usage': 'warn',
170+
'no-illogical-any-of-usage': 'warn',
169171
},
170172
oas3_2Rules: {
171173
'array-parameter-serialization': 'off',
@@ -223,6 +225,7 @@ const recommended: RawGovernanceConfig<'built-in'> = {
223225
'tags-alphabetical': 'off',
224226
'no-duplicated-tag-names': 'warn',
225227
'no-illogical-one-of-usage': 'warn',
228+
'no-illogical-any-of-usage': 'warn',
226229
},
227230
async2Rules: {
228231
'channels-kebab-case': 'off',

packages/core/src/config/spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ const spec: RawGovernanceConfig<'built-in'> = {
109109
'tags-alphabetical': 'off',
110110
'nullable-type-sibling': 'error',
111111
'no-illogical-one-of-usage': 'off',
112+
'no-illogical-any-of-usage': 'off',
112113
},
113114
oas3_1Rules: {
114115
'array-parameter-serialization': 'off',
@@ -166,6 +167,7 @@ const spec: RawGovernanceConfig<'built-in'> = {
166167
'tag-description': 'off',
167168
'tags-alphabetical': 'off',
168169
'no-illogical-one-of-usage': 'error',
170+
'no-illogical-any-of-usage': 'error',
169171
},
170172
oas3_2Rules: {
171173
'array-parameter-serialization': 'off',
@@ -223,6 +225,7 @@ const spec: RawGovernanceConfig<'built-in'> = {
223225
'tag-description': 'off',
224226
'tags-alphabetical': 'off',
225227
'no-illogical-one-of-usage': 'error',
228+
'no-illogical-any-of-usage': 'error',
226229
},
227230
async2Rules: {
228231
'channels-kebab-case': 'off',

packages/core/src/rules/oas3/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import { NoSchemaTypeMismatch } from '../common/no-schema-type-mismatch.js';
5656
import { NoDuplicatedTagNames } from '../common/no-duplicated-tag-names.js';
5757
import { NullableTypeSibling } from './nullable-type-sibling.js';
5858
import { NoIllogicalOneOfUsage } from './no-illogical-one-of-usage.js';
59+
import { NoIllogicalAnyOfUsage } from './no-illogical-any-of-usage.js';
5960

6061
import type { Oas3RuleSet } from '../../oas-types.js';
6162
import type { Oas3Rule } from '../../visitors.js';
@@ -120,6 +121,7 @@ export const rules: Oas3RuleSet<'built-in'> = {
120121
'no-duplicated-tag-names': NoDuplicatedTagNames as Oas3Rule,
121122
'nullable-type-sibling': NullableTypeSibling,
122123
'no-illogical-one-of-usage': NoIllogicalOneOfUsage as Oas3Rule,
124+
'no-illogical-any-of-usage': NoIllogicalAnyOfUsage as Oas3Rule,
123125
};
124126

125127
export const preprocessors = {};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { areDuplicatedSchemas } from '../utils.js';
2+
3+
import type { Oas3Rule, Oas3Visitor } from '../../visitors.js';
4+
import type { Oas3Schema, Oas3_1Schema } from '../../typings/openapi.js';
5+
import type { UserContext } from '../../walk.js';
6+
7+
export const NoIllogicalAnyOfUsage: Oas3Rule = (): Oas3Visitor => {
8+
return {
9+
Schema: {
10+
skip(node) {
11+
return !node.anyOf;
12+
},
13+
enter(schema: Oas3Schema | Oas3_1Schema, { report, location }: UserContext) {
14+
if (!schema.anyOf) return;
15+
if (!Array.isArray(schema.anyOf)) return;
16+
17+
if (schema.anyOf.length < 2) {
18+
report({
19+
message: '`anyOf` must have at least two items',
20+
location,
21+
});
22+
} else {
23+
const { isDuplicated, reason: duplicatedReason } = areDuplicatedSchemas(schema.anyOf);
24+
if (isDuplicated && duplicatedReason) {
25+
report({
26+
message: duplicatedReason,
27+
location,
28+
});
29+
}
30+
}
31+
},
32+
},
33+
};
34+
};

0 commit comments

Comments
 (0)