Skip to content

Commit 3eac557

Browse files
committed
docs: display presets + installation
1 parent 1d622eb commit 3eac557

File tree

5 files changed

+82
-25
lines changed

5 files changed

+82
-25
lines changed

docs/.vitepress/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ export default defineConfig({
3636
],
3737

3838
nav: [
39-
{ text: "Presets", link: "/presets/", activeMatch: "^/presets/" },
40-
{ text: "Rules", link: "/rules/", activeMatch: "^/rules/" },
39+
{ text: "Installation", link: "/installation"},
40+
{ text: "Rules", link: "/rules", activeMatch: "^/rules/" },
4141
{ text: "Changelog", link: "/changelog" },
4242
{ text: "effector.dev", link: "https://effector.dev" },
4343
],

docs/index.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@ hero:
77
tagline: Enforcing best practices for Effector
88
actions:
99
- theme: brand
10-
text: All Rules
11-
link: /rules/
10+
text: See Rules
11+
link: /rules
1212
- theme: alt
13-
text: All Presets
14-
link: /presets/
13+
text: Install Plugin
14+
link: /installation
1515

1616
features:
1717
- icon: ☄️
1818
title: Recommended preset
1919
details: Config preset that is recommended for all projects using Effector
20-
link: /presets/recommended
20+
link: /rules#recommended
2121
- icon: 🔮
2222
title: Future preset
2323
details: Effector is evolving, this preset enforces best-practices for future releases of Effector
24-
link: /presets/future
24+
link: /rules#future
2525
- icon: ⚛️
2626
title: React preset
2727
details: This preset is recommended for projects that use React with Effector.
28-
link: /presets/react
28+
link: /rules#react
2929
---

docs/installation.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Installation
2+
3+
To install and configure this ESLint plugin, follow the steps below:
4+
5+
## Install the Plugin
6+
7+
Use your preferred package manager to install the plugin along with ESLint:
8+
9+
::: code-group
10+
11+
```sh [npm]
12+
npm install --save-dev eslint-plugin-effector eslint
13+
```
14+
15+
```sh [yarn]
16+
yarn add --dev eslint-plugin-effector eslint
17+
```
18+
19+
```sh [pnpm]
20+
pnpm install --save-dev eslint-plugin-effector eslint
21+
```
22+
23+
:::
24+
25+
## Configure ESLint
26+
27+
If you are using the flat config format, import the plugin and apply its `recommended` configuration. Here's an example:
28+
29+
```ts
30+
import effector from "eslint-plugin-effector" // [!code focus]
31+
32+
const config = [
33+
effector.configs.recommended, // [!code focus]
34+
]
35+
```
36+
37+
The `recommended` configuration is a preset that enforces best practices for using Effector. To explore all available rules and other presets, refer to the [Rules](./rules/) section of the documentation.
38+
39+
:::info
40+
This plugin requires TypeScript and type-aware linting to be enabled in your ESLint configuration. Refer to the official [`typescript-eslint` documentation](https://typescript-eslint.io/getting-started/typed-linting/) for guidance on providing type information to ESLint.
41+
:::

docs/rules/index.data.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
import path from "node:path"
22
import { ContentData, createContentLoader } from "vitepress"
3+
import { ruleset } from "../../src/ruleset"
34

45
const rules = path.join(process.cwd(), "src/rules")
56
const watch = path.relative(path.dirname(__dirname), rules)
67

7-
type RuleEntry = { key: string; description: string }
8+
type RuleEntry = { key: string; description: string; category: string | undefined }
9+
10+
const presetMap = ruleset as Record<string, Record<string, unknown>>
11+
const categoryOf = (name: string): keyof typeof ruleset | undefined =>
12+
Object.keys(ruleset).find((preset) => presetMap[preset][`effector/${name}`]) as keyof typeof ruleset
813

914
const transform = (data: ContentData[]) =>
10-
data.map<RuleEntry>((item) => ({ key: path.basename(item.url, ".html"), description: item.frontmatter.description }))
15+
data.map<RuleEntry>((item) => {
16+
const key = path.basename(item.url, ".html")
17+
return { key, description: item.frontmatter.description, category: categoryOf(key) }
18+
})
1119

1220
const loader = createContentLoader(path.join(watch, "*/*.md"), { transform })
1321

docs/rules/index.md

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,29 @@ aside: false
44

55
<script setup>
66
import { data } from "./index.data"
7+
8+
const categories = { recommended: "Recommended", react: "React", scope: "Scope" }
9+
10+
const rulesByCategory = (category) => data.filter((rule) => rule.category === category)
711
</script>
812

913
# Rules
1014

11-
<table>
12-
<thead>
13-
<tr>
14-
<th>Rule</th>
15-
<th>Description</th>
16-
</tr>
17-
</thead>
18-
<tbody>
19-
<tr v-for="rule in data" :key="rule.key">
20-
<td><a :href="`/rules/${rule.key}`">{{rule.key}}</a></td>
21-
<td>{{rule.description}}</td>
22-
</tr>
23-
</tbody>
24-
</table>
15+
<template v-for="(title, category) in categories" :key="category">
16+
<h2 :id="category">{{ title }}</h2>
17+
18+
<table>
19+
<thead>
20+
<tr>
21+
<th>Rule</th>
22+
<th>Description</th>
23+
</tr>
24+
</thead>
25+
<tbody>
26+
<tr v-for="rule in rulesByCategory(category)" :key="rule.key">
27+
<td><a :href="`/rules/${rule.key}`">{{rule.key}}</a></td>
28+
<td>{{rule.description}}</td>
29+
</tr>
30+
</tbody>
31+
</table>
32+
</template>

0 commit comments

Comments
 (0)