Skip to content

Commit a3a346c

Browse files
committed
Docs: tweak sidebar
1 parent a9bd87a commit a3a346c

File tree

6 files changed

+45
-41
lines changed

6 files changed

+45
-41
lines changed

docs/.vuepress/config.js

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
"use strict"
66

7-
const rules = require("../../scripts/lib/rules")
7+
const { withCategories } = require("../../scripts/lib/rules")
88
require("../../scripts/update-docs-headers")
99
require("../../scripts/update-docs-index")
1010

@@ -27,27 +27,23 @@ module.exports = {
2727
updatePopup: true,
2828
},
2929

30-
nav: [
31-
{ text: "Guide", link: "/guide/getting-started" },
32-
{ text: "Rules", link: "/rules/" },
33-
],
30+
nav: [{ text: "Guide", link: "/" }, { text: "Rules", link: "/rules/" }],
3431

3532
sidebarDepth: 0,
36-
sidebar: [
37-
{
38-
title: "Guide",
39-
collapsable: false,
40-
children: ["/", "/guide/getting-started"],
41-
},
42-
{
43-
title: "Rules",
44-
collapsable: false,
45-
children: [
46-
"/rules/",
47-
...rules.map(({ id, name }) => [`/rules/${name}`, id]),
48-
],
49-
},
50-
],
33+
sidebar: {
34+
"/rules/": [
35+
"/rules/",
36+
...withCategories.map(({ category, rules }) => ({
37+
title: category,
38+
collapsable: false,
39+
children: rules.map(rule => [
40+
`/rules/${rule.name}`,
41+
rule.id,
42+
]),
43+
})),
44+
],
45+
"/": ["/", "/getting-started", "/rules/"],
46+
},
5147
},
5248

5349
configureWebpack: {

docs/.vuepress/override.styl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
$accentColor = #463fd4
2+
3+
table a
4+
white-space nowrap
File renamed without changes.

docs/rules/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77

88
| Rule ID | Description | |
99
|:--------|:------------|:---|
10-
| [eslint-comments/disable-enable-pair](./disable-enable-pair.html) | require a `eslint-enable` comment for every `eslint-disable` comment | 🌟 |
11-
| [eslint-comments/no-aggregating-enable](./no-aggregating-enable.html) | disallow a `eslint-enable` comment for multiple `eslint-disable` comments | 🌟 |
12-
| [eslint-comments/no-duplicate-disable](./no-duplicate-disable.html) | disallow duplicate `eslint-disable` comments | 🌟 |
13-
| [eslint-comments/no-unlimited-disable](./no-unlimited-disable.html) | disallow `eslint-disable` comments without rule names | 🌟 |
14-
| [eslint-comments/no-unused-disable](./no-unused-disable.html) | disallow unused `eslint-disable` comments | |
15-
| [eslint-comments/no-unused-enable](./no-unused-enable.html) | disallow unused `eslint-enable` comments | 🌟 |
10+
| [eslint-comments/<wbr>disable-enable-pair](./disable-enable-pair.html) | require a `eslint-enable` comment for every `eslint-disable` comment | 🌟 |
11+
| [eslint-comments/<wbr>no-aggregating-enable](./no-aggregating-enable.html) | disallow a `eslint-enable` comment for multiple `eslint-disable` comments | 🌟 |
12+
| [eslint-comments/<wbr>no-duplicate-disable](./no-duplicate-disable.html) | disallow duplicate `eslint-disable` comments | 🌟 |
13+
| [eslint-comments/<wbr>no-unlimited-disable](./no-unlimited-disable.html) | disallow `eslint-disable` comments without rule names | 🌟 |
14+
| [eslint-comments/<wbr>no-unused-disable](./no-unused-disable.html) | disallow unused `eslint-disable` comments | |
15+
| [eslint-comments/<wbr>no-unused-enable](./no-unused-enable.html) | disallow unused `eslint-enable` comments | 🌟 |
1616

1717
## Stylistic Issues
1818

1919
| Rule ID | Description | |
2020
|:--------|:------------|:---|
21-
| [eslint-comments/no-restricted-disable](./no-restricted-disable.html) | disallow `eslint-disable` comments about specific rules | |
22-
| [eslint-comments/no-use](./no-use.html) | disallow ESLint directive-comments | |
21+
| [eslint-comments/<wbr>no-restricted-disable](./no-restricted-disable.html) | disallow `eslint-disable` comments about specific rules | |
22+
| [eslint-comments/<wbr>no-use](./no-use.html) | disallow ESLint directive-comments | |
2323

scripts/lib/rules.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const path = require("path")
1010
/**
1111
* @type {{id:string,name:string,category:string,description:string,recommended:boolean,fixable:boolean,deprecated:boolean,replacedBy:(string[]|null)}[]}
1212
*/
13-
module.exports = fs
13+
const rules = fs
1414
.readdirSync(path.resolve(__dirname, "../../lib/rules"))
1515
.map(fileName => path.basename(fileName, ".js"))
1616
.map(name => {
@@ -26,3 +26,13 @@ module.exports = fs
2626
replacedBy: meta.docs.replacedBy || null,
2727
}
2828
})
29+
30+
module.exports = rules
31+
module.exports.withCategories = ["Best Practices", "Stylistic Issues"].map(
32+
category => ({
33+
category,
34+
rules: rules.filter(
35+
rule => rule.category === category && !rule.deprecated
36+
),
37+
})
38+
)

scripts/update-docs-index.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66

77
const fs = require("fs")
88
const path = require("path")
9-
const rules = require("./lib/rules")
10-
const README_FILE_PATH = path.resolve(__dirname, "../docs/rules/README.md")
11-
const CATEGORIES = ["Best Practices", "Stylistic Issues"]
9+
const { withCategories } = require("./lib/rules")
1210

1311
/**
1412
* Convert a given rule to a table row.
@@ -17,35 +15,32 @@ const CATEGORIES = ["Best Practices", "Stylistic Issues"]
1715
*/
1816
function toTableRow(rule) {
1917
const mark = `${rule.recommended ? "🌟" : ""}${rule.fixable ? "✒️" : ""}`
20-
const link = `[${rule.id}](./${rule.name}.html)`
18+
const link = `[eslint-comments/<wbr>${rule.name}](./${rule.name}.html)`
2119
const description = rule.description || "(no description)"
2220
return `| ${link} | ${description} | ${mark} |`
2321
}
2422

2523
/**
2624
* Convert a given category to the section of the category.
27-
* @param {string} category The category to convert.
25+
* @param {{category:string,rules:{id:string,name:string,category:string,description:string,recommended:boolean,fixable:boolean,deprecated:boolean,replacedBy:string[]}[]}} categoryInfo The category information to convert.
2826
* @returns {string} The section of the category.
2927
*/
30-
function toCategorySection(category) {
28+
function toCategorySection({ category, rules }) {
3129
return `## ${category}
3230
3331
| Rule ID | Description | |
3432
|:--------|:------------|:---|
35-
${rules
36-
.filter(rule => rule.category === category && !rule.deprecated)
37-
.map(toTableRow)
38-
.join("\n")}
33+
${rules.map(toTableRow).join("\n")}
3934
`
4035
}
4136

4237
fs.writeFileSync(
43-
README_FILE_PATH,
38+
path.resolve(__dirname, "../docs/rules/README.md"),
4439
`# All Rules
4540
4641
- 🌟 mark: the rule which is enabled by \`eslint-comments/recommended\` preset.
4742
- ✒️ mark: the rule which is fixable by \`eslint --fix\` command.
4843
49-
${CATEGORIES.map(category => toCategorySection(category, rules)).join("\n")}
44+
${withCategories.map(toCategorySection).join("\n")}
5045
`
5146
)

0 commit comments

Comments
 (0)