feat(nx-dev): update workspace conformance rule to check md files in general
This commit is contained in:
parent
c698b1ef9c
commit
d428eec060
2
nx.json
2
nx.json
@ -253,7 +253,7 @@
|
||||
"rule": "@nx/workspace-plugin/conformance-rules/blog-description",
|
||||
"projects": ["docs"],
|
||||
"options": {
|
||||
"mdGlobPattern": "blog/**/*.md"
|
||||
"mdGlobPattern": "{blog,shared}/**/*.md"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@ -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[] = [];
|
||||
@ -43,8 +43,15 @@ 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) {
|
||||
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,
|
||||
@ -54,7 +61,7 @@ export default createConformanceRule<{ mdGlobPattern: string }>({
|
||||
if (!frontmatter.description) {
|
||||
violations.push({
|
||||
message:
|
||||
'Blog posts with frontmatter must have a description field',
|
||||
'Markdown documentation files must have a description field in their frontmatter',
|
||||
sourceProject: docsProject.name,
|
||||
file: file,
|
||||
});
|
||||
@ -64,7 +71,6 @@ export default createConformanceRule<{ mdGlobPattern: string }>({
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
severity: 'high',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user