diff --git a/.eslintrc.js b/.eslintrc.js index eade1e93d..2693499d0 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -29,6 +29,7 @@ module.exports = { rules: { "consistent-docs-description": "error", "no-invalid-meta": "error", + "no-invalid-meta-docs-categories": "error", 'eslint-plugin/require-meta-type': 'error', "require-meta-docs-url": ["error", { "pattern": `https://eslint.vuejs.org/rules/{{name}}.html` diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index 3f8282598..0b78e7eba 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -5,11 +5,47 @@ 'use strict' const rules = require('../../tools/lib/rules') -const categories = require('../../tools/lib/categories') -const uncategorizedRules = rules.filter(rule => !rule.meta.docs.category && !rule.meta.deprecated) +const uncategorizedRules = rules.filter(rule => !rule.meta.docs.categories && !rule.meta.deprecated) const deprecatedRules = rules.filter(rule => rule.meta.deprecated) +const sidebarCategories = [ + { title: 'Base Rules', categoryIds: ['base'] }, + { title: 'Priority A: Essential', categoryIds: ['vue3-essential', 'essential'] }, + { title: 'Priority A: Essential for Vue.js 3.x', categoryIds: ['vue3-essential'] }, + { title: 'Priority A: Essential for Vue.js 2.x', categoryIds: ['essential'] }, + { title: 'Priority B: Strongly Recommended', categoryIds: ['vue3-strongly-recommended', 'strongly-recommended'] }, + { title: 'Priority B: Strongly Recommended for Vue.js 3.x', categoryIds: ['vue3-strongly-recommended'] }, + { title: 'Priority B: Strongly Recommended for Vue.js 2.x', categoryIds: ['strongly-recommended'] }, + { title: 'Priority C: Recommended', categoryIds: ['vue3-recommended', 'recommended'] }, + { title: 'Priority C: Recommended for Vue.js 3.x', categoryIds: ['vue3-recommended'] }, + { title: 'Priority C: Recommended for Vue.js 2.x', categoryIds: ['recommended'] } +] + +const categorizedRules = [] +for (const { title, categoryIds } of sidebarCategories) { + const categoryRules = rules + .filter(rule => rule.meta.docs.categories && !rule.meta.deprecated) + .filter(rule => categoryIds + .every(categoryId => rule.meta.docs.categories.includes(categoryId)) + ) + const children = categoryRules + .filter(({ ruleId }) => { + const exists = categorizedRules.some(({ children }) => children.some(([, alreadyRuleId]) => alreadyRuleId === ruleId)) + return !exists + }) + .map(({ ruleId, name }) => [`/rules/${name}`, ruleId]) + + if (children.length === 0) { + continue + } + categorizedRules.push({ + title, + collapsable: false, + children + }) +} + const extraCategories = [] if (uncategorizedRules.length > 0) { extraCategories.push({ @@ -59,11 +95,7 @@ module.exports = { '/rules/', // Rules in each category. - ...categories.map(({ title, rules }) => ({ - title: title.replace(/ \(.+?\)/, ''), - collapsable: false, - children: rules.map(({ ruleId, name }) => [`/rules/${name}`, ruleId]) - })), + ...categorizedRules, // Rules in no category. ...extraCategories diff --git a/docs/rules/README.md b/docs/rules/README.md index 5b21a0840..e184873e5 100644 --- a/docs/rules/README.md +++ b/docs/rules/README.md @@ -26,7 +26,114 @@ Enforce all the rules in this category, as well as all higher priority rules, wi | [vue/comment-directive](./comment-directive.md) | support comment-directives in `