Skip to content
This repository has been archived by the owner on Sep 7, 2021. It is now read-only.

Lint for missing frontmatter that will break build-json #209

Merged
merged 5 commits into from
Oct 30, 2019

Conversation

ddbeck
Copy link
Contributor

@ddbeck ddbeck commented Oct 29, 2019

While working on #207, I wrote this to check for build-json-breaking frontmatter omissions. It's only got a few right now, and they're hard coded, but I imagine we can build on this. Thankfully, this doesn't introduce any new warnings. 😃

@ddbeck ddbeck requested a review from a team October 29, 2019 16:15
const requiredFrontmatter = [];

// Right now, there's no way to collect the required frontmatter
// keys from the recipe itself, so they're hardcoded for now.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you look at meta. keys that don't have a ? suffix? This will fail because we don't yet understand info_box, but it might be better to do this and comment info_box out of the recipe. Or is there some other reason this won't work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would partially work. examples would be fixed by checking the recipe. But attributes is a weird one: it requires some nested keys that aren't in the recipe. global is conventional, though best as I can tell it's not used to build any JSON yet; element_specific is used in build-json but the only place it's described is in scripts/build-json/build-recipe-page-json.js.

There's a little bit of tension here in that I want to check that some frontmatter exists, but I'm not ready to build out complete checks for well-formed frontmatter (mostly because I don't think we actually know what well formed is yet).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that checking the top-level properties can be done in a common way using the recipe, but any digging deeper (e.g. attributes.global) should not, and should be done individually for that ingredient. Because you have to, anyway. For example, attributes.element_specific has its own structure that you'll need to check (must be an array of paths to files, the directories must exist, maybe they must be lowercase. Then the files pointed to must also satisfy some rules). So in any case, you're going to have to write some code per-ingredient to check it. So I had envisaged you just use the recipe to check the top level, and to figure out which bit of linting code to call the check the details.

This is what build-json does: it looks at the recipe and for each top-level ingredient listed, calls some custom code to build the attributes, or the examples, or the BCD.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, that sounds reasonable. I've changed it to check the recipe for top-level required frontmatter and ignore the nested keys. We can tackle the finer details (e.g., checking for valid spec URLs) in other PRs. Want to take another look?

if (typeof entry === "string") {
return entry;
} else {
return Object.keys(entry)[0];
Copy link

@wbamberg wbamberg Oct 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to bring this up only now, but I think recipe body items should only be strings, see #106. We should fix css-property's info_box accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not clear on what the actual fix is here. Do I remove the nested info_box pieces? Or are we changing the notation for info box (e.g., info_box_thing1 or info_box.thing1 as top-level items)?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For HTML elements we've removed the nested pieces, so the recipe is like:

...
- prose.*
- meta.examples
- meta.info_box
- meta.specifications
- meta.browser_compatibility
...

I think we should do the same for CSS properties. (I haven't done any maintaining of the CSS properties while I've been wrestling only with HTML documentation, so it has fallen behind. Which was fine, except we are now linting them).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, thank you. I understand now. I've pushed a change to the recipe and removed the type checking on the recipe body entries.

Copy link

@wbamberg wbamberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @ddbeck , this looks good and works well.

It does now introduce new errors, for the CSS properties. I'm not sure whether we should fix them, or just delete the CSS property pages, since we're not focusing on them at the moment. Probably the latter.

@wbamberg wbamberg merged commit e701fc5 into mdn:master Oct 30, 2019
@ddbeck ddbeck deleted the linter-required-frontmatter branch October 30, 2019 18:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants