Skip to content

Commit 66005f7

Browse files
committed
update docusaurus
1 parent 9c7f84d commit 66005f7

File tree

3 files changed

+42
-22
lines changed

3 files changed

+42
-22
lines changed

website/src/components/Rule.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react';
2+
3+
type RuleProps = {
4+
href: string;
5+
};
6+
7+
export const Rule = ({ href }: RuleProps) => {
8+
return (
9+
<a href={href} rel="noopener noreferrer" target="_blank">
10+
📏 Rule
11+
</a>
12+
);
13+
};

website/src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './Chip';
22
export * from './GithubStats';
33
export * from './MainTitle';
4+
export * from './Rule';
45
export * from './TableOfContents';

website/src/pages/index.mdx

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ toc_min_heading_level: 2
55
toc_max_heading_level: 2
66
---
77

8-
import { Chip, MainTitle, TableOfContents } from '@site/src/components';
8+
import { Chip, MainTitle, Rule, TableOfContents } from '@site/src/components';
99
import { UseDocumentTitle } from '@site/src/hooks';
1010

1111
<UseDocumentTitle>TypeScript Style Guide</UseDocumentTitle>
@@ -205,7 +205,7 @@ You may encounter discriminated unions under different names such as tagged unio
205205
Discriminated unions advantages:
206206

207207
- 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.
208-
- Exhaustiveness check - TypeScript can ensure that all possible variants of a type are implemented, eliminating the risk of undefined or unexpected behavior at runtime. ([eslint rule](https://typescript-eslint.io/rules/switch-exhaustiveness-check/))
208+
- 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/" />
209209

210210
```ts
211211
type Circle = { kind: 'circle'; radius: number };
@@ -217,14 +217,19 @@ Discriminated unions advantages:
217217

218218
// TypeScript warns us with errors in calculateArea function
219219
const calculateArea = (shape: Shape) => {
220-
// Error - Switch is not exhaustive. Cases not matched: "triangle"
221-
switch (shape.kind) {
222-
case 'circle':
223-
return Math.PI * shape.radius ** 2;
224-
case 'square':
225-
return shape.size * shape.width; // Error - Property 'width' does not exist on type 'square'
226-
}
220+
// Error - Switch is not exhaustive. Cases not matched: "triangle"
221+
switch (shape.kind) {
222+
case 'circle':
223+
return Math.PI _ shape.radius \*\* 2;
224+
case 'square':
225+
return shape.size _ shape.width; // Error - Property 'width' does not exist on type 'square'
226+
}
227227
};
228+
229+
```
230+
231+
```
232+
228233
```
229234

230235
- Avoid code complexity introduced by [flag variables](#type-union--boolean-flags).
@@ -235,7 +240,7 @@ Discriminated unions advantages:
235240

236241
### Return Types
237242

238-
Including return type annotations is highly encouraged, although not required ([eslint rule](https://typescript-eslint.io/rules/explicit-function-return-type/)).
243+
Including return type annotations is highly encouraged, although not required <Rule href="https://typescript-eslint.io/rules/explicit-function-return-type/" />.
239244

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

@@ -323,8 +328,8 @@ const renderUserAvatar = (avatar: string) => {...}
323328

324329
### Type Error
325330

326-
If TypeScript error can't be mitigated, as last resort use `@ts-expect-error` to suppress it ([eslint rule](https://typescript-eslint.io/rules/prefer-ts-expect-error/)). If at any future point suppressed line becomes error-free, TypeScript compiler will indicate it.
327-
`@ts-ignore` is not allowed, where `@ts-expect-error` must be used with provided description ([eslint rule](https://typescript-eslint.io/rules/ban-ts-comment/#allow-with-description)).
331+
If TypeScript error can't be mitigated, as last resort use `@ts-expect-error` to suppress it <Rule href="https://typescript-eslint.io/rules/prefer-ts-expect-error/" />. If at any future point suppressed line becomes error-free, TypeScript compiler will indicate it.
332+
`@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" />.
328333

329334
```ts
330335
// ❌ Avoid @ts-ignore
@@ -340,7 +345,7 @@ const newUser = createUser('Gabriel');
340345

341346
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.
342347

343-
All types must be defined with `type` alias [(eslint rule)](https://typescript-eslint.io/rules/consistent-type-definitions/#type).
348+
All types must be defined with `type` alias <Rule href='https://typescript-eslint.io/rules/consistent-type-definitions/#type' />.
344349

345350
<Chip>
346351
Consider using interfaces if developing a package that can be further extended, team is more comfortable working with
@@ -386,7 +391,7 @@ app.listen(process.env.PORT, () => {...}
386391
387392
### Array Types
388393
389-
Array types must be defined with generic syntax ([eslint rule](https://typescript-eslint.io/rules/array-type/#generic)).
394+
Array types must be defined with generic syntax <Rule href='https://typescript-eslint.io/rules/array-type/#generic' />.
390395
391396
<Chip>
392397
As there is no functional difference between 'generic' and 'array' definition, feel free to set the one your team
@@ -602,7 +607,7 @@ Strive to keep naming conventions consistent and readable, with important contex
602607
603608
### Named Export
604609
605-
Named exports must be used to ensure that all imports follow a uniform pattern ([eslint rule](https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-default-export.md)).
610+
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' />.
606611
This keeps variables, functions... names consistent across the entire codebase.
607612
Named exports have the benefit of erroring when import statements try to import something that hasn't been declared.
608613
@@ -631,7 +636,7 @@ While it's often hard to find the best name, try optimize code for consistency a
631636
Prefixed with `is`, `has` etc.
632637
`isDisabled`, `hasProduct`
633638
634-
[Eslint rule](https://typescript-eslint.io/rules/naming-convention) implements:
639+
<Rule href="https://typescript-eslint.io/rules/naming-convention" /> implements:
635640
636641
```ts
637642
// .eslintrc.js
@@ -688,7 +693,7 @@ Camel case
688693
Pascal case
689694
`OrderStatus`, `ProductItem`
690695
691-
[Eslint rule](https://typescript-eslint.io/rules/naming-convention) implements:
696+
<Rule href="https://typescript-eslint.io/rules/naming-convention" /> implements:
692697
693698
```ts
694699
// .eslintrc.js
@@ -722,7 +727,7 @@ const createPair = <TFirst, TSecond extends string>(first: TFirst, second: TSeco
722727
const pair = createPair(1, 'a');
723728
```
724729
725-
[Eslint rule](https://typescript-eslint.io/rules/naming-convention) implements:
730+
<Rule href="https://typescript-eslint.io/rules/naming-convention" /> implements:
726731
727732
```ts
728733
// .eslintrc.js
@@ -774,7 +779,7 @@ React component name following "Props" postfix
774779
#### Callback Props
775780
776781
Event handler (callback) props are prefixed as `on*` - e.g. `onClick`.
777-
Event handler implementation functions are prefixed as `handle*` - e.g. `handleClick` ([eslint rule](https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-handler-names.md)).
782+
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" />.
778783
779784
```tsx
780785
// ❌ Avoid inconsistent callback prop naming
@@ -788,7 +793,7 @@ Event handler (callback) props are prefixed as `on*` - e.g. `onClick`.
788793
789794
#### React Hooks
790795
791-
Camel case, prefixed as 'use' ([eslint rule](https://github.com/facebook/react/tree/main/packages/eslint-plugin-react-hooks)), symmetrically convention as `[value, setValue] = useState()` ([eslint rule](https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/hook-use-state.md#rule-details))
796+
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" />:
792797
793798
```ts
794799
// ❌ Avoid inconsistent useState hook naming
@@ -1202,8 +1207,9 @@ Automated test comes with benefits that helps us write better code and makes it
12021207
12031208
### Test Description
12041209
1205-
All test descriptions must follow naming convention as `it('should ... when ...')`.
1206-
[Eslint rule](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/valid-title.md#mustmatch) implements:
1210+
All test descriptions must follow naming convention as `it('should ... when ...')`.
1211+
1212+
<Rule href="https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/valid-title.md#mustmatch" /> implements:
12071213
12081214
```ts
12091215
// .eslintrc.js

0 commit comments

Comments
 (0)