Skip to content

Commit

Permalink
docs: Add rules meta info to rule pages (#15902)
Browse files Browse the repository at this point in the history
* docs: Add rules meta info to rule pages

* Address feedback

* Update release to include rules metadata

* Fix message

* Update git tag

* Fix conflicts

* Update docs/src/_includes/components/rule-categories.macro.html

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>

* Create annotated tag

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
  • Loading branch information
nzakas and mdjermanovic committed Jun 14, 2022
1 parent f364d47 commit b04bc6f
Show file tree
Hide file tree
Showing 6 changed files with 4,639 additions and 2,104 deletions.
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",
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 -a -f v${releaseInfo.version} -m ${releaseInfo.version}`);
}

/**
Expand Down Expand Up @@ -786,6 +811,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

0 comments on commit b04bc6f

Please sign in to comment.