Skip to content

Commit

Permalink
feat(nx-dev): update workspace conformance rule to check md files in …
Browse files Browse the repository at this point in the history
…general
  • Loading branch information
juristr committed Mar 4, 2025
1 parent c698b1e commit d428eec
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@
"rule": "@nx/workspace-plugin/conformance-rules/blog-description",
"projects": ["docs"],
"options": {
"mdGlobPattern": "blog/**/*.md"
"mdGlobPattern": "{blog,shared}/**/*.md"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default createConformanceRule<{ mdGlobPattern: string }>({
name: 'blog-description',
category: 'consistency',
description:
'Ensures that blog posts have a description in their frontmatter',
'Ensures that markdown documentation files have a description in their frontmatter',
reporter: 'project-files-reporter',
implementation: async ({ projectGraph, ruleOptions }) => {
const violations: ProjectFilesViolation[] = [];
Expand Down Expand Up @@ -43,26 +43,32 @@ export default createConformanceRule<{ mdGlobPattern: string }>({
const content = readFileSync(file, 'utf-8');
const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---/);

// Only check files with frontmatter
if (frontmatterMatch) {
try {
const frontmatter = yamlLoad(frontmatterMatch[1]) as Record<
string,
unknown
>;
if (!frontmatterMatch) {
violations.push({
message: 'Markdown documentation files must have frontmatter',
sourceProject: docsProject.name,
file: file,
});
continue;
}

try {
const frontmatter = yamlLoad(frontmatterMatch[1]) as Record<
string,
unknown
>;

if (!frontmatter.description) {
violations.push({
message:
'Blog posts with frontmatter must have a description field',
sourceProject: docsProject.name,
file: file,
});
}
} catch (e) {
// If YAML parsing fails, we skip the file
continue;
if (!frontmatter.description) {
violations.push({
message:
'Markdown documentation files must have a description field in their frontmatter',
sourceProject: docsProject.name,
file: file,
});
}
} catch (e) {
// If YAML parsing fails, we skip the file
continue;
}
}

Expand Down

0 comments on commit d428eec

Please sign in to comment.