Skip to content

Commit 8fe1376

Browse files
committed
update docusaurus
1 parent 409b676 commit 8fe1376

File tree

2 files changed

+125
-86
lines changed

2 files changed

+125
-86
lines changed

website/src/components/Rule.tsx

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,37 @@
1+
import { useState } from 'react';
2+
import AnimateHeight from 'react-animate-height';
3+
import CodeBlock from '@theme/CodeBlock';
4+
15
type RuleProps = {
6+
children: string;
27
href: string;
8+
prefix?: string;
39
};
410

5-
export const Rule = ({ href }: RuleProps) => {
11+
export const Rule = ({ children, href, prefix }: RuleProps) => {
12+
const [descriptionHeight, setDescriptionHeight] = useState<'auto' | 0>(0);
13+
614
return (
7-
<a
8-
className="rounded-md bg-gray-100 px-1.5 py-1 text-xs font-medium text-neutral-600 hover:bg-gray-200 hover:no-underline dark:bg-blue-600 dark:bg-opacity-40 dark:text-neutral-200 dark:hover:bg-blue-700 dark:hover:bg-opacity-40"
9-
href={href}
10-
rel="noopener noreferrer"
11-
target="_blank"
12-
>
13-
📏 Rule
14-
</a>
15+
<div>
16+
{prefix}{' '}
17+
<span>
18+
<div
19+
className="mb-1 inline-flex cursor-pointer items-center rounded-md bg-gray-100 px-1.5 py-1 text-xs font-medium text-neutral-600 hover:bg-gray-200 dark:bg-blue-600 dark:bg-opacity-40 dark:text-neutral-200 dark:hover:bg-blue-700 dark:hover:bg-opacity-40"
20+
onClick={() => setDescriptionHeight((prev) => (prev === 0 ? 'auto' : 0))}
21+
>
22+
<div className="mr-1">📏 Rule</div>
23+
</div>
24+
<AnimateHeight duration={500} easing="ease" height={descriptionHeight}>
25+
<div className="rounded-md border-0 border-l-[5px] border-solid border-neutral-500 bg-gray-200 p-2 text-xs italic text-neutral-600 dark:border-gray-200 dark:bg-neutral-600 dark:text-gray-200 [&_p]:mb-0">
26+
<a className="text-sm" href={href} rel="noopener noreferrer" target="_blank">
27+
Rule
28+
</a>
29+
<CodeBlock className="!mb-0 mt-1 text-sm" language="ts" title="eslint.config.mjs">
30+
{children}
31+
</CodeBlock>
32+
</div>
33+
</AnimateHeight>
34+
</span>
35+
</div>
1536
);
1637
};

website/src/pages/index.mdx

Lines changed: 95 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ You may encounter discriminated unions under different names such as tagged unio
204204
Discriminated unions advantages:
205205

206206
- As mentioned in [Required & Optional Object Properties](#required--optional-object-properties), [Args as Discriminated Union](#args-as-discriminated-type) and [Props as Discriminated Type](#props-as-discriminated-type), discriminated union eliminates optional object properties which decreases complexity.
207-
- Exhaustiveness check - TypeScript can ensure that all possible variants of a type are implemented, eliminating the risk of undefined or unexpected behavior at runtime. <Rule href="https://typescript-eslint.io/rules/switch-exhaustiveness-check/" />
207+
- Exhaustiveness check - TypeScript can ensure that all possible variants of a type are implemented, eliminating the risk of undefined or unexpected behavior at runtime.
208+
209+
<Rule href="https://typescript-eslint.io/rules/switch-exhaustiveness-check/">{`"@typescript-eslint/switch-exhaustiveness-check": "error"`}</Rule>
208210

209211
```ts
210212
type Circle = { kind: 'circle'; radius: number };
@@ -234,7 +236,10 @@ Discriminated unions advantages:
234236

235237
### Return Types
236238

237-
Including return type annotations is highly encouraged, although not required <Rule href="https://typescript-eslint.io/rules/explicit-function-return-type/" />.
239+
<Rule
240+
prefix="Including return type annotations is highly encouraged, although not required"
241+
href="https://typescript-eslint.io/rules/explicit-function-return-type/"
242+
>{`"@typescript-eslint/explicit-function-return-type": "error"`}</Rule>
238243

239244
Consider benefits when explicitly typing the return value of a function:
240245

@@ -377,25 +382,22 @@ const renderUserAvatar = (avatar: string) => {...}
377382

378383
### Type Error
379384

380-
If TypeScript error can't be mitigated, as last resort use `@ts-expect-error` to suppress it <Rule href="https://typescript-eslint.io/rules/ban-ts-comment" />. If at any future point suppressed line becomes error-free, TypeScript compiler will indicate it.
381-
`@ts-ignore` is not allowed, where `@ts-expect-error` must be used with provided description <Rule href="https://typescript-eslint.io/rules/ban-ts-comment/#allow-with-description" />.
385+
If TypeScript error can't be mitigated, as last resort use `@ts-expect-error` to suppress it. If at any future point suppressed line becomes error-free, TypeScript compiler will indicate it. `@ts-ignore` is not
386+
allowed, where `@ts-expect-error` must be used with provided description.
382387

383-
```ts
384-
// .eslintrc.js
385-
'@typescript-eslint/ban-ts-comment': [
388+
<Rule href="https://typescript-eslint.io/rules/ban-ts-comment/#allow-with-description">{`'@typescript-eslint/ban-ts-comment': [
386389
'error',
387390
{
388391
'ts-expect-error': 'allow-with-description'
389392
},
390-
],
391-
```
393+
]`}</Rule>
392394

393395
```ts
394-
// ❌ Avoid @ts-ignore
396+
// ❌ Avoid @ts-ignore as it will do nothing if the following line is error-free.
395397
// @ts-ignore
396398
const newUser = createUser('Gabriel');
397399

398-
// ✅ Use @ts-expect-error with description
400+
// ✅ Use @ts-expect-error with description.
399401
// @ts-expect-error: The library type definition is wrong, createUser accepts string as an argument.
400402
const newUser = createUser('Gabriel');
401403
```
@@ -404,7 +406,10 @@ const newUser = createUser('Gabriel');
404406

405407
TypeScript offers two options for type definitions - `type` and `interface`. As they come with some functional differences in most cases they can be used interchangeably. We try to limit syntax difference and pick one for consistency.
406408

407-
All types must be defined with `type` alias <Rule href='https://typescript-eslint.io/rules/consistent-type-definitions/#type' />.
409+
<Rule
410+
prefix="All types must be defined with `type` alias"
411+
href="https://typescript-eslint.io/rules/consistent-type-definitions/#type"
412+
>{`'@typescript-eslint/consistent-type-definitions': ['error', 'type']`}</Rule>
408413

409414
<Note>
410415
Consider using interfaces when developing a package that may be extended in the future by third-party consumers or
@@ -450,8 +455,18 @@ app.listen(process.env.PORT, () => {...}
450455
451456
### Array Types
452457
453-
Array types must be defined with generic syntax <Rule href='https://typescript-eslint.io/rules/array-type/#generic' />.
454-
458+
<Rule
459+
prefix="Array types must be defined with generic syntax"
460+
href="https://typescript-eslint.io/rules/array-type/#generic"
461+
>
462+
{`'@typescript-eslint/naming-convention': [
463+
'error',
464+
{
465+
selector: 'typeAlias',
466+
format: ['PascalCase'],
467+
},
468+
]`}
469+
</Rule>
455470
<Note>
456471
As there is no functional difference between 'generic' and 'array' definition, feel free to set the one your team
457472
finds most readable to work with.
@@ -471,12 +486,14 @@ const y: ReadonlyArray<string> = ['foo', 'bar'];
471486
472487
TypeScript allows specifying a `type` keyword on imports to indicate that the export exists only in the type system, not at runtime.
473488
474-
Type imports must always be separated <Rule href="https://typescript-eslint.io/rules/consistent-type-imports/" />:
489+
Type imports must always be separated:
475490
476491
- Tree Shaking and Dead Code Elimination: If you use `import` for types instead of `import type`, the bundler might include the imported module in the bundle unnecessarily, increasing the size. Separating imports ensures that only necessary runtime code is included.
477492
- Minimizing Dependencies: Some modules may contain both runtime and type definitions. Mixing type imports with runtime imports might lead to accidental inclusion of unnecessary runtime code.
478493
- Improves code clarity by making the distinction between runtime dependencies and type-only imports explicit.
479494
495+
<Rule href="https://typescript-eslint.io/rules/consistent-type-imports/">{`'@typescript-eslint/consistent-type-imports': 'error'`}</Rule>
496+
480497
```ts
481498
// ❌ Avoid using `import` for both runtime and type
482499
import { MyClass } from 'some-library';
@@ -686,25 +703,26 @@ Strive to keep naming conventions consistent and readable, with important contex
686703
687704
### Named Export
688705
689-
Named exports must be used to ensure that all imports follow a uniform pattern <Rule href='https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-default-export.md' />.
690-
This keeps variables, functions etc. names consistent across the entire codebase.
691-
Named exports have the benefit of erroring when import statements try to import something that hasn't been declared.
692-
693-
In case of exceptions e.g. Next.js pages, disable rule:
706+
<Rule
707+
prefix="Named exports must be used to ensure that all imports follow a uniform pattern"
708+
href="https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-default-export.md"
709+
>{`'import/no-default-export': 'error'
694710

695-
```ts
696-
// .eslintrc.js
711+
// In case of exceptions disable the rule
697712
overrides: [
698-
{
699-
files: ["src/pages/**/*"],
700-
rules: { "import/no-default-export": "off" },
701-
},
702-
],
703-
```
713+
{
714+
files: ["src/pages/**/*"],
715+
rules: { "import/no-default-export": "off" },
716+
},
717+
]
718+
`}</Rule>
719+
720+
This keeps variables, functions etc. names consistent across the entire codebase. Named exports have the benefit of
721+
erroring when import statements try to import something that hasn't been declared.
704722
705723
### Naming Conventions
706724
707-
While it's often hard to find the best name, try optimize code for consistency and future reader by following conventions:
725+
While it's often hard to find the best name, aim to optimize code for consistency and future reader by following conventions:
708726
709727
#### Variables
710728
@@ -715,20 +733,19 @@ While it's often hard to find the best name, try optimize code for consistency a
715733
Prefixed with `is`, `has` etc.
716734
`isDisabled`, `hasProduct`
717735
718-
<Rule href="https://typescript-eslint.io/rules/naming-convention" /> implements:
736+
<Rule href="https://typescript-eslint.io/rules/naming-convention" />
719737
720-
```ts
721-
// .eslintrc.js
722-
'@typescript-eslint/naming-convention': [
723-
'error',
724-
{
725-
selector: 'variable',
726-
types: ['boolean'],
727-
format: ['PascalCase'],
728-
prefix: ['is', 'should', 'has', 'can', 'did', 'will'],
729-
},
730-
],
731-
```
738+
```ts
739+
'@typescript-eslint/naming-convention': [
740+
'error',
741+
{
742+
selector: 'variable',
743+
types: ['boolean'],
744+
format: ['PascalCase'],
745+
prefix: ['is', 'should', 'has', 'can', 'did', 'will'],
746+
},
747+
],
748+
```
732749
733750
- **Constants**
734751
Capitalized
@@ -772,18 +789,16 @@ Camel case
772789
Pascal case
773790
`OrderStatus`, `ProductItem`
774791
775-
<Rule href="https://typescript-eslint.io/rules/naming-convention" /> implements:
776-
777-
```ts
778-
// .eslintrc.js
792+
<Rule href="https://typescript-eslint.io/rules/naming-convention">
793+
{`
779794
'@typescript-eslint/naming-convention': [
780795
'error',
781796
{
782797
selector: 'typeAlias',
783798
format: ['PascalCase'],
784799
},
785-
],
786-
```
800+
]`}
801+
</Rule>
787802
788803
#### Generics
789804
@@ -792,6 +807,18 @@ A generic variable must start with the capital letter T followed by a descriptiv
792807
Creating more complex types often include generics, which can make them hard to read and understand, that's why we try to put best effort when naming them.
793808
Naming generics using popular convention with one letter `T`, `K` etc. is not allowed, the more variables we introduce, the easier it is to mistake them.
794809
810+
<Rule href="https://typescript-eslint.io/rules/naming-convention">
811+
{`'@typescript-eslint/naming-convention': [
812+
'error',
813+
{
814+
// Generic type parameter must start with letter T, followed by any uppercase letter.
815+
selector: 'typeParameter',
816+
format: ['PascalCase'],
817+
custom: { regex: '^T[A-Z]', match: true },
818+
},
819+
]`}
820+
</Rule>
821+
795822
```ts
796823
// ❌ Avoid naming generics with one letter
797824
const createPair = <T, K extends string>(first: T, second: K): [T, K] => {
@@ -806,21 +833,6 @@ const createPair = <TFirst, TSecond extends string>(first: TFirst, second: TSeco
806833
const pair = createPair(1, 'a');
807834
```
808835
809-
<Rule href="https://typescript-eslint.io/rules/naming-convention" /> implements:
810-
811-
```ts
812-
// .eslintrc.js
813-
'@typescript-eslint/naming-convention': [
814-
'error',
815-
{
816-
// Generic type parameter must start with letter T, followed by any uppercase letter.
817-
selector: 'typeParameter',
818-
format: ['PascalCase'],
819-
custom: { regex: '^T[A-Z]', match: true },
820-
},
821-
],
822-
```
823-
824836
#### Abbreviations & Acronyms
825837
826838
Treat acronyms as whole words, with capitalized first letter only.
@@ -858,7 +870,9 @@ React component name following "Props" postfix
858870
#### Callback Props
859871
860872
Event handler (callback) props are prefixed as `on*` - e.g. `onClick`.
861-
Event handler implementation functions are prefixed as `handle*` - e.g. `handleClick` <Rule href="https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-handler-names.md" />.
873+
Event handler implementation functions are prefixed as `handle*` - e.g. `handleClick`.
874+
875+
<Rule href="https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-handler-names.md" />
862876
863877
```tsx
864878
// ❌ Avoid inconsistent callback prop naming
@@ -872,7 +886,14 @@ Event handler implementation functions are prefixed as `handle*` - e.g. `handleC
872886
873887
#### React Hooks
874888
875-
Camel case, prefixed as 'use' <Rule href="https://github.com/facebook/react/tree/main/packages/eslint-plugin-react-hooks" />, symmetrically convention as `[value, setValue] = useState()` <Rule href="https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/hook-use-state.md#rule-details" />:
889+
<Rule
890+
prefix="Camel case, prefixed as 'use'"
891+
href="https://github.com/facebook/react/tree/main/packages/eslint-plugin-react-hooks"
892+
/>
893+
<Rule
894+
prefix="Symmetrically convention as [value, setValue] = useState()"
895+
href="https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/hook-use-state.md#rule-details"
896+
/>
876897
877898
```ts
878899
// ❌ Avoid inconsistent useState hook naming
@@ -886,7 +907,7 @@ const [color, setColor] = useState();
886907
const [isActive, setIsActive] = useState();
887908
```
888909
889-
Custom hook must always return an object:
910+
Custom hook must always return an object
890911
891912
```ts
892913
// ❌ Avoid
@@ -1288,17 +1309,14 @@ Automated test comes with benefits that helps us write better code and makes it
12881309
12891310
All test descriptions must follow naming convention as `it('should ... when ...')`.
12901311
1291-
<Rule href="https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/valid-title.md#mustmatch" /> implements:
1292-
1293-
```ts
1294-
// .eslintrc.js
1295-
'vitest/valid-title': [
1296-
'error',
1297-
{
1298-
mustMatch: { it: [/should.*when/u.source, "Test title must include 'should' and 'when'"] },
1299-
},
1300-
],
1301-
```
1312+
<Rule href="https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/valid-title.md#mustmatch">
1313+
{`'vitest/valid-title': [
1314+
'error',
1315+
{
1316+
mustMatch: { it: [/should.*when/u.source, "Test title must include 'should' and 'when'"] },
1317+
},
1318+
]`}
1319+
</Rule>
13021320
13031321
```ts
13041322
// ❌ Avoid

0 commit comments

Comments
 (0)