Skip to content
This repository has been archived by the owner on Apr 29, 2022. It is now read-only.

Commit

Permalink
fix: Don't fail doc parsing on new docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kgilpin committed Mar 17, 2022
1 parent 93d57c5 commit 58761f6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/rules/lib/parseRuleDescription.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import fs from 'fs';
import { ValidationError } from '../../errors';
import { join } from 'path';

export default function parseRuleDescription(id: string): string {
const content = fs.readFileSync(join(__dirname, `../../../doc/rules/${id}.md`), 'utf-8');
const propertiesContent = content.match(/---\n((?:.*\n)+)---\n((?:.*\n)+?)###/);
const propertiesContent = content.match(/---\n((?:.*\n)+)---\n((?:.*\n)+?)##?#?/);

if (!propertiesContent) {
throw new ValidationError(`Unable to read description for rule "${id}".`);
// This is probably a new doc that doesn't have front matter yet.
// It's all description.
return content;
}

return propertiesContent[2].replace(/\n/g, ' ').trim();
Expand Down

0 comments on commit 58761f6

Please sign in to comment.