52 lines
1.8 KiB
TypeScript
52 lines
1.8 KiB
TypeScript
import { writeFileSync } from 'fs'
|
|
import type { Rule, Config } from '../types'
|
|
import { allRules, allConfig } from '../lib/helpers/get-rules'
|
|
|
|
main()
|
|
|
|
function main() {
|
|
const markdown = []
|
|
// Some rule messages contain text that will trigger markdownlint errors
|
|
markdown.push('<!-- markdownlint-disable -->')
|
|
markdown.push(
|
|
'<!-- This file is automatically generated. Manual changes will be overwritten by a 🤖 -->',
|
|
)
|
|
markdown.push('| Rule ID | Rule Name(s) | Description | Severity | Tags |')
|
|
markdown.push('| ------- | ------------ | ----------- | -------- | ---- |')
|
|
|
|
for (const rule of allRules as Rule[]) {
|
|
const ruleName = rule.names.find((name) => name in allConfig)
|
|
if (!ruleName) continue
|
|
if (rule.names.includes('search-replace')) {
|
|
markdown.push(...getSearchReplaceRules(rule, allConfig[ruleName]))
|
|
continue
|
|
}
|
|
const row = []
|
|
const ruleId = rule.information ? `[${rule.names[0]}](${rule.information})` : rule.names[0]
|
|
row.push(ruleId)
|
|
row.push(rule.names.slice(1).join(', '))
|
|
row.push(rule.description)
|
|
row.push(allConfig[ruleName].severity)
|
|
row.push(rule.tags.join(', '))
|
|
markdown.push(`| ${row.join(' | ')} |`)
|
|
}
|
|
writeFileSync('data/reusables/contributing/content-linter-rules.md', markdown.join('\n'))
|
|
}
|
|
|
|
// The search-replace rule configures multiple psuedo-rules
|
|
// under the rules key.
|
|
function getSearchReplaceRules(srRule: Rule, ruleConfig: Config) {
|
|
const name = srRule.information ? `[search-replace](${srRule.information})` : 'search-replace'
|
|
const markdown = []
|
|
for (const rule of ruleConfig.rules || []) {
|
|
const row = []
|
|
row.push(name)
|
|
row.push(rule.name)
|
|
row.push(rule.message)
|
|
row.push(rule.severity)
|
|
row.push('')
|
|
markdown.push(`| ${row.join(' | ')} |`)
|
|
}
|
|
return markdown
|
|
}
|