Skip to content

Commit

Permalink
fix: improve detection of named options to be mentioned in rule docs
Browse files Browse the repository at this point in the history
  • Loading branch information
bmish committed Dec 15, 2022
1 parent 1e1debc commit 3641e94
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 449 deletions.
21 changes: 8 additions & 13 deletions lib/rule-options.ts
@@ -1,3 +1,4 @@
import * as traverse from 'json-schema-traverse';
import type { JSONSchema } from '@typescript-eslint/utils';

/**
Expand All @@ -8,25 +9,19 @@ import type { JSONSchema } from '@typescript-eslint/utils';
export function getAllNamedOptions(
jsonSchema: JSONSchema.JSONSchema4
): readonly string[] {
if (!jsonSchema) {
return [];
}

if (Array.isArray(jsonSchema)) {
return jsonSchema.flatMap((js: JSONSchema.JSONSchema4) =>
getAllNamedOptions(js)
);
}

if (jsonSchema.items) {
return getAllNamedOptions(jsonSchema.items);
}

if (jsonSchema.properties) {
return Object.keys(jsonSchema.properties);
}

return [];
const options: string[] = [];
traverse(jsonSchema, (js: JSONSchema.JSONSchema4) => {
if (js.properties) {
options.push(...Object.keys(js.properties));
}
});
return options;
}

/**
Expand Down

0 comments on commit 3641e94

Please sign in to comment.