Skip to content

Commit d428eec

Browse files
committedMar 4, 2025
feat(nx-dev): update workspace conformance rule to check md files in general
1 parent c698b1e commit d428eec

File tree

2 files changed

+26
-20
lines changed
  • tools/workspace-plugin/src/conformance-rules/blog-description

2 files changed

+26
-20
lines changed
 

Diff for: ‎nx.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@
253253
"rule": "@nx/workspace-plugin/conformance-rules/blog-description",
254254
"projects": ["docs"],
255255
"options": {
256-
"mdGlobPattern": "blog/**/*.md"
256+
"mdGlobPattern": "{blog,shared}/**/*.md"
257257
}
258258
},
259259
{

Diff for: ‎tools/workspace-plugin/src/conformance-rules/blog-description/index.ts

+25-19
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default createConformanceRule<{ mdGlobPattern: string }>({
1212
name: 'blog-description',
1313
category: 'consistency',
1414
description:
15-
'Ensures that blog posts have a description in their frontmatter',
15+
'Ensures that markdown documentation files have a description in their frontmatter',
1616
reporter: 'project-files-reporter',
1717
implementation: async ({ projectGraph, ruleOptions }) => {
1818
const violations: ProjectFilesViolation[] = [];
@@ -43,26 +43,32 @@ export default createConformanceRule<{ mdGlobPattern: string }>({
4343
const content = readFileSync(file, 'utf-8');
4444
const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---/);
4545

46-
// Only check files with frontmatter
47-
if (frontmatterMatch) {
48-
try {
49-
const frontmatter = yamlLoad(frontmatterMatch[1]) as Record<
50-
string,
51-
unknown
52-
>;
46+
if (!frontmatterMatch) {
47+
violations.push({
48+
message: 'Markdown documentation files must have frontmatter',
49+
sourceProject: docsProject.name,
50+
file: file,
51+
});
52+
continue;
53+
}
54+
55+
try {
56+
const frontmatter = yamlLoad(frontmatterMatch[1]) as Record<
57+
string,
58+
unknown
59+
>;
5360

54-
if (!frontmatter.description) {
55-
violations.push({
56-
message:
57-
'Blog posts with frontmatter must have a description field',
58-
sourceProject: docsProject.name,
59-
file: file,
60-
});
61-
}
62-
} catch (e) {
63-
// If YAML parsing fails, we skip the file
64-
continue;
61+
if (!frontmatter.description) {
62+
violations.push({
63+
message:
64+
'Markdown documentation files must have a description field in their frontmatter',
65+
sourceProject: docsProject.name,
66+
file: file,
67+
});
6568
}
69+
} catch (e) {
70+
// If YAML parsing fails, we skip the file
71+
continue;
6672
}
6773
}
6874

0 commit comments

Comments
 (0)
Please sign in to comment.