Skip to content

Commit

Permalink
fix: validate order
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Jul 29, 2023
1 parent 22371bb commit d62f000
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/rules/no-invalid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,18 @@ function reportCannotResolvedObject(context: RuleContext) {
}

type SchemaKind = "$schema" | "catalog" | "options";
const SCHEMA_KINDS: SchemaKind[] = ["$schema", "options", "catalog"];

/** Get mergeSchemas option */
function parseMergeSchemasOption(
option: boolean | string[] | undefined,
): SchemaKind[] | null {
return option === true
? ["$schema", "catalog", "options"]
? SCHEMA_KINDS
: Array.isArray(option)
? (option as SchemaKind[])
? [...(option as SchemaKind[])].sort(
(a, b) => SCHEMA_KINDS.indexOf(a) - SCHEMA_KINDS.indexOf(b),
)
: null;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/src/rules/no-invalid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ tester.run(
},
],
errors: [
"Root must have required property 'foo'.",
"Root must have required property 'version'.",
"Root must have required property 'inherit'.",
"Root must match a schema in anyOf.",
"Root must have required property 'foo'.",
'"extends" must be string.',
'"extends" must match exactly one schema in oneOf.',
'"extends[0]" must be string.',
Expand Down Expand Up @@ -161,10 +161,10 @@ tester.run(
},
],
errors: [
"Root must have required property 'foo'.",
"Root must have required property 'version'.",
"Root must have required property 'inherit'.",
"Root must match a schema in anyOf.",
"Root must have required property 'foo'.",
],
},
{
Expand Down

0 comments on commit d62f000

Please sign in to comment.