Skip to content
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

docs: Add rules meta info to rule pages #15902

Merged
merged 8 commits into from Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 30 additions & 3 deletions Makefile.js
Expand Up @@ -181,10 +181,14 @@ function generateFormatterExamples(formatterInfo, prereleaseVersion) {
* @returns {void}
*/
function generateRuleIndexPage() {
const outputFile = "../website/_data/rules.yml",
const legacyWebsiteOutputFile = "../website/_data/rules.yml",
docsSiteOutputFile = "docs/src/_data/rules.json",
docsSiteMetaOutputFile = "docs/src/_data/rules_meta.json",
nzakas marked this conversation as resolved.
Show resolved Hide resolved
ruleTypes = "conf/rule-type-list.json",
ruleTypesData = JSON.parse(cat(path.resolve(ruleTypes)));

const meta = {};

RULE_FILES
.map(filename => [filename, path.basename(filename, ".js")])
.sort((a, b) => a[1].localeCompare(b[1]))
Expand All @@ -193,6 +197,20 @@ function generateRuleIndexPage() {
const basename = pair[1];
const rule = require(path.resolve(filename));

/*
* Eleventy interprets the {{ }} in messages as being variables,
* which can cause an error if there's syntax it doesn't expect.
* Because we don't use this info in the website anyway, it's safer
* to just remove it.
*
* Also removing the schema because we don't need it.
*/
meta[basename] = {
...rule.meta,
schema: void 0,
messages: void 0
};

if (rule.meta.deprecated) {
ruleTypesData.deprecated.rules.push({
name: basename,
Expand All @@ -219,9 +237,12 @@ function generateRuleIndexPage() {
// `.rules` will be `undefined` if all rules in category are deprecated.
ruleTypesData.types = ruleTypesData.types.filter(ruleType => !!ruleType.rules);

const output = yaml.dump(ruleTypesData, { sortKeys: true });
JSON.stringify(ruleTypesData, null, 4).to(docsSiteOutputFile);
JSON.stringify(meta, null, 4).to(docsSiteMetaOutputFile);

const legacyOutput = yaml.dump(ruleTypesData, { sortKeys: true });

output.to(outputFile);
legacyOutput.to(legacyWebsiteOutputFile);
}

/**
Expand Down Expand Up @@ -271,6 +292,10 @@ function generateRelease() {
target.gensite();
generateBlogPost(releaseInfo);
commitSiteToGit(`v${releaseInfo.version}`);

echo("Updating commit with docs data");
exec("git add docs/src/_data && git commit --amend --no-edit");
exec(`git tag -f v${releaseInfo.version}`);
Copy link
Member

Choose a reason for hiding this comment

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

This works well, but there will be one difference compared to previous releases: npm version creates an annotated tag, while this creates a lightweight one. I'm not sure if that's important, though.

Copy link
Member Author

Choose a reason for hiding this comment

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

I’ll have to check if the annotation remains after this or if it’s lost.

Copy link
Member Author

Choose a reason for hiding this comment

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

It looks like everything is lost, so I updated to create a new annotated tag with the version as a message (to duplicate what npm version does).

}

/**
Expand Down Expand Up @@ -782,6 +807,8 @@ target.gensite = function(prereleaseVersion) {
echo("Done generating eslint.org");
};

target.generateRuleIndexPage = generateRuleIndexPage;

target.webpack = function(mode = "none") {
exec(`${getBinFile("webpack")} --mode=${mode} --output-path=${BUILD_DIR}`);
};
Expand Down