Skip to content

Commit 9f2abf8

Browse files
feat: add loadYAML feature
1 parent 1bcbd53 commit 9f2abf8

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

website/_data/catalog.data.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createContentLoader, type ContentData } from 'vitepress'
22
import { ExampleLangs } from '../src/catalog/data'
3+
import { loadAll, JSON_SCHEMA } from 'js-yaml'
34

45
interface Rule {
56
id: string
@@ -38,6 +39,8 @@ function extractRuleInfo({ url, src }: ContentData): Rule {
3839
const language = url.split('/')[2] as ExampleLangs
3940
const name = source.match(/##\s*([^<\n]+)/)?.[1] || ''
4041

42+
const yamls = extractYAMLRule(source)
43+
4144
return {
4245
id,
4346
name,
@@ -46,7 +49,23 @@ function extractRuleInfo({ url, src }: ContentData): Rule {
4649
playgroundLink,
4750
language,
4851
hasFix,
49-
rules: [],
50-
features: [],
52+
rules: extractUsedRules(yamls),
53+
features: extractUsedFeatures(yamls),
54+
}
55+
}
56+
57+
function extractYAMLRule(source: string): Record<string, unknown>[] {
58+
const yaml = source.match(/```ya?ml\n([\s\S]+?)\n```/)?.[1] || ''
59+
if (!yaml) {
60+
return []
5161
}
62+
return loadAll(yaml, null, { schema: JSON_SCHEMA }) as Record<string, unknown>[]
63+
}
64+
65+
function extractUsedRules(yamls: Record<string, unknown>[]): string[] {
66+
return []
67+
}
68+
69+
function extractUsedFeatures(yamls: Record<string, unknown>[]): string[] {
70+
return []
5271
}

website/catalog/ruby/prefer-symbol-over-proc.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ id: prefer-symbol-over-proc
1616
language: ruby
1717
rule:
1818
pattern: $LIST.$ITER { |$V| $V.$METHOD }
19-
language: Ruby
2019
constraints:
2120
ITER:
2221
regex: 'map|select|each'

0 commit comments

Comments
 (0)