-
Notifications
You must be signed in to change notification settings - Fork 517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(lint): Implement front matter validator and linter #8295
Conversation
857ce9f
to
ac1a07b
Compare
f512b75
to
18a8f5d
Compare
@OnkarRuikar Thank you for this. Could we add this as an Maybe you could use a pattern like this to avoid defining the command inside yari/tool/commands/add-redirect.ts Lines 14 to 28 in 2b2d410
edit: Have you tried out the validator/linter on translated-content yet? As it makes it easier, we could run it on |
done
I already did. As per the config, there were only 3 validation issues. And there are 350+ files that need prettying and attribute order fix. Currently we are in process of removing
I haven't run this on translated content. We'll have to define separate schema in @teoli2003 , @wbamberg let me know if this configuration ok to address the #7900 (comment). |
This is so great.
I think one day we might want to have the set of page types in a separate file, to make it easier to reference from other places. But as it stands this is really easy to read and update, and it'll be great to have validation for this. I saw that you have |
The code does validate Error: ../content/files/en-us/glossary/aria/index.md
'page-type' property must be equal to one of the allowed values:
glossary-definition, glossary-disambiguation The code alters the schema based on document location to inject allowed page types.
The MDN and Glossary trees don't have |
Sorry, I didn't mean to imply that it didn't. I mean, "it is great that this PR will give us validation for page type".
I think this is an error and these pages should just use "guide".
That's a good point. I guess once we are done, we will be able to change this. |
I feel like using "guide" for the MDN meta docs overloads the page-type, because those (writer) guides/guidelines are probably distinct from the (user) guides. Are they not? |
|
Actually yes, I agree with this. I don't think these meta-docs should be in MDN at all, so using a different page-type would at least enable people to ignore them. So:
? But, let's not block this great PR on that discussion. |
Yes, there is no reason to block this PR on this: there will be additional page types in the future. |
After discussing with @teoli2003 :
yes, I think this at least is quite important (it means we can avoid having to coordinate PRs in 2 repos if we change things). But also, is there a reason this validation is in Yari at all? We are validating the content here, can we not have this validation in mdn/content CI? |
d058166
to
0f8072b
Compare
This way makes it available in various contexts like in husky, translated-content(CI & husky), from yari(with
Only thing remains is to decide on line length. With current 80 chars llimit, 54 files will have changes like below. Following is the most extreme one: ---
title: "ContentVisibilityAutoStateChangeEvent: ContentVisibilityAutoStateChangeEvent() constructor"
short-title: ContentVisibilityAutoStateChangeEvent()
slug: Web/API/ContentVisibilityAutoStateChangeEvent/ContentVisibilityAutoStateChangeEvent
page-type: web-api-constructor
browser-compat: api.ContentVisibilityAutoStateChangeEvent.ContentVisibilityAutoStateChangeEvent
---
to
---
title: >-
ContentVisibilityAutoStateChangeEvent: ContentVisibilityAutoStateChangeEvent()
constructor
short-title: ContentVisibilityAutoStateChangeEvent()
slug: >-
Web/API/ContentVisibilityAutoStateChangeEvent/ContentVisibilityAutoStateChangeEvent
page-type: web-api-constructor
browser-compat: >-
api.ContentVisibilityAutoStateChangeEvent.ContentVisibilityAutoStateChangeEvent
--- If we are ok with current config then I'll create a PR in content. |
This pull request has merge conflicts that must be resolved before it can be merged. |
But the set of permitted/mandatory keys is different in mdn/content and in mdn/translated-content. I think it would be OK to have the machinery that validates content against the config to be in Yari, but I think the config should be alongside the content. |
I see what you mean. As the structure and features in content and translated-content are different, it will be hard to write/maintain perfect code that will work with both. There are going to be a lot of 'if's and 'else's e.g. if @wbamberg and @teoli2003 may I move this entire utility(code+config) to |
This feature has been moved to |
"transform" |
Summary
Problem
Front matter now hold many important and complex values. Without the automated validator it starts accumulating errors. And there is no tool to find and report/fix these issues.
Implement a custom linter that will satisfy following requirements:
validation:
title
andslug
, mandatory.page-type
attribute. And allow only certain values based on technology/feature of the document.spec-urls
need to be URI format.prettier:
browser-compat
andspec-urls
support union data typestring|array
. If there is only one value then use string other wise use array for multivalue:automation:
Solution
Implement a custom solution similar to the filecheck tool.
Convert front matter YAML to JSON object and validate using JSON Schema which also supports the required union type. Following are the required steps:
front-matter-config.json
.js-yaml
library to convert yaml to jsonajv
library to validate the schemajs-yaml
libraryTo run the tool use following commands:
Let me know about following possiblities:
front-matter-config.json
tomdn/content
repo, so that configuration won't be attached to yarititle
is set to 150 chars in the PR, what is the required value?Screenshots
How did you test this change?
tag
using settingadditionalProperties: false
in the config. https://github.com/mdn/content/pull/24776/files