Skip to content

Commit c5e7272

Browse files
committed
docs(examples): streamline documentation content 📝
- Remove extensive invalid example code blocks - Simplify documentation structure across all rule examples - Reduce content verbosity while maintaining clarity
1 parent 51f8903 commit c5e7272

14 files changed

Lines changed: 948 additions & 2832 deletions

examples/async-function-naming.md

Lines changed: 45 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -2,109 +2,63 @@
22

33
This rule enforces that async function declarations must have the 'Async' suffix in their name.
44

5-
## ❌ Invalid Examples
6-
7-
```typescript
8-
// Async function declarations without 'Async' suffix
9-
async function fetchUser() {
10-
const response = await fetch('/api/user')
11-
return response.json()
12-
}
13-
14-
async function processData(data: any[]) {
15-
return data.map(item => item.processed)
16-
}
17-
18-
async function saveToDatabase(record: User) {
19-
await db.users.insert(record)
20-
}
21-
22-
async function validateInput(input: string) {
23-
return input.length > 0
24-
}
25-
26-
// Complex async functions without 'Async' suffix
27-
async function getUserByIdAndUpdate(id: string, updates: Partial<User>) {
28-
const user = await db.users.findById(id)
29-
if (user) {
30-
await db.users.update(id, updates)
5+
## Examples
6+
7+
### Basic Async Function Naming
8+
9+
```diff
10+
- async function fetchUser() {
11+
+ async function fetchUserAsync() {
12+
const response = await fetch('/api/user')
13+
return response.json()
3114
}
32-
return user
33-
}
34-
35-
async function handleRequest(req: Request) {
36-
const body = await req.json()
37-
const result = await processRequest(body)
38-
return new Response(JSON.stringify(result))
39-
}
4015
```
4116

42-
## ✅ Valid Examples
17+
### Async Function with Parameters
4318

44-
```typescript
45-
// Async function declarations with 'Async' suffix
46-
async function fetchUserAsync() {
47-
const response = await fetch('/api/user')
48-
return response.json()
49-
}
19+
```diff
20+
- async function processData(data: any[]) {
21+
+ async function processDataAsync(data: any[]) {
22+
return data.map(item => item.processed)
23+
}
24+
```
5025

51-
async function processDataAsync(data: any[]) {
52-
return data.map(item => item.processed)
53-
}
26+
### Async Function with Complex Logic
5427

55-
async function saveToDatabaseAsync(record: User) {
56-
await db.users.insert(record)
57-
}
28+
```diff
29+
- async function getUserByIdAndUpdate(id: string, updates: Partial<User>) {
30+
+ async function getUserByIdAndUpdateAsync(id: string, updates: Partial<User>) {
31+
const user = await db.users.findById(id)
32+
if (user) {
33+
await db.users.update(id, updates)
34+
}
35+
return user
36+
}
37+
```
5838

59-
async function validateInputAsync(input: string) {
60-
return input.length > 0
61-
}
39+
### Async Function with Return Type
6240

63-
// Complex async functions with 'Async' suffix
64-
async function getUserByIdAndUpdateAsync(id: string, updates: Partial<User>) {
65-
const user = await db.users.findById(id)
66-
if (user) {
67-
await db.users.update(id, updates)
41+
```diff
42+
- async function validateInput(input: string): Promise<boolean> {
43+
+ async function validateInputAsync(input: string): Promise<boolean> {
44+
return input.length > 0
6845
}
69-
return user
70-
}
71-
72-
async function handleRequestAsync(req: Request) {
73-
const body = await req.json()
74-
const result = await processRequest(body)
75-
return new Response(JSON.stringify(result))
76-
}
77-
78-
// Non-async functions (not affected by this rule)
79-
function calculateSum(a: number, b: number) {
80-
return a + b
81-
}
82-
83-
const processData = (data: any[]) => {
84-
return data.map(item => item.processed)
85-
}
86-
87-
// Arrow functions and function expressions (not affected by this rule)
88-
const fetchUser = async () => {
89-
const response = await fetch('/api/user')
90-
return response.json()
91-
}
92-
93-
const handler = async function (event: Event) {
94-
event.preventDefault()
95-
}
96-
97-
// Class methods (not affected by this rule)
98-
class UserService {
99-
async fetchUser() {
100-
const response = await fetch('/api/user')
101-
return response.json()
46+
```
47+
48+
### Multiple Async Functions
49+
50+
```diff
51+
- async function saveToDatabase(record: User) {
52+
+ async function saveToDatabaseAsync(record: User) {
53+
await db.users.insert(record)
10254
}
10355

104-
async saveUser(user: User) {
105-
await db.users.insert(user)
56+
- async function handleRequest(req: Request) {
57+
+ async function handleRequestAsync(req: Request) {
58+
const body = await req.json()
59+
const result = await processRequest(body)
60+
return new Response(JSON.stringify(result))
10661
}
107-
}
10862
```
10963

11064
## Rule Scope

examples/explicit-parameter-types.md

Lines changed: 34 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -2,173 +2,51 @@
22

33
This rule enforces explicit type annotations on all function parameters, including regular parameters, destructured parameters, rest parameters, and default parameters.
44

5-
## ❌ Invalid Examples
6-
7-
```typescript
8-
// Function declarations without parameter types
9-
function processUser(user) {
10-
return user.name.toUpperCase()
11-
}
12-
13-
function calculateSum(a, b) {
14-
return a + b
15-
}
16-
17-
// Arrow functions without parameter types
18-
const fetchData = url => {
19-
return fetch(url).then(res => res.json())
20-
}
21-
22-
const validateInput = (input, options) => {
23-
return input.length > 0 && options.strict
24-
}
25-
26-
// Function expressions without parameter types
27-
const handler = function (event, target) {
28-
event.preventDefault()
29-
target.focus()
30-
}
31-
32-
// Destructured parameters without types
33-
function createUser({ name, email, age }) {
34-
return { id: Date.now(), name, email, age }
35-
}
36-
37-
function processConfig({ apiUrl, timeout, retries }) {
38-
return { apiUrl, timeout: timeout || 5000, retries: retries || 3 }
39-
}
40-
41-
// Rest parameters without types
42-
function logMessages(...messages) {
43-
console.log(...messages)
44-
}
45-
46-
function combineArrays(...arrays) {
47-
return arrays.flat()
48-
}
49-
50-
// Default parameters without types
51-
function greetUser(name = 'Guest') {
52-
return `Hello, ${name}!`
53-
}
54-
55-
function createTimer(duration = 1000, callback) {
56-
setTimeout(callback, duration)
57-
}
58-
59-
// Mixed parameter types without annotations
60-
function complexFunction(regularParam, { destructuredProp }, ...restParams) {
61-
return { regularParam, destructuredProp, restParams }
62-
}
63-
64-
// Class methods without parameter types
65-
class UserService {
66-
constructor(apiUrl, timeout) {
67-
this.apiUrl = apiUrl
68-
this.timeout = timeout
69-
}
5+
## Examples
6+
7+
### Basic Function with Regular Parameters
708

71-
async fetchUser(id, includeProfile = false) {
72-
const response = await fetch(`${this.apiUrl}/users/${id}`)
73-
return response.json()
9+
```diff
10+
- function processUser(user) {
11+
+ function processUser(user: any) {
12+
return user.name.toUpperCase()
7413
}
14+
```
7515

76-
updateUser(id, { name, email }) {
77-
return this.api.updateUser(id, { name, email })
16+
### Arrow Function with Multiple Parameters
17+
18+
```diff
19+
- const validateInput = (input, options) => {
20+
+ const validateInput = (input: any, options: any) => {
21+
return input.length > 0 && options.strict
7822
}
79-
}
8023
```
8124

82-
## ✅ Valid Examples
83-
84-
```typescript
85-
// Function declarations with explicit parameter types
86-
function processUser(user: { name: string; email: string }) {
87-
return user.name.toUpperCase()
88-
}
89-
90-
function calculateSum(a: number, b: number): number {
91-
return a + b
92-
}
93-
94-
// Arrow functions with explicit parameter types
95-
const fetchData = (url: string): Promise<any> => {
96-
return fetch(url).then(res => res.json())
97-
}
98-
99-
const validateInput = (input: string, options: { strict: boolean }): boolean => {
100-
return input.length > 0 && options.strict
101-
}
102-
103-
// Function expressions with explicit parameter types
104-
const handler = function (event: Event, target: HTMLElement): void {
105-
event.preventDefault()
106-
target.focus()
107-
}
108-
109-
// Destructured parameters with explicit types
110-
function createUser({ name, email, age }: { name: string; email: string; age: number }) {
111-
return { id: Date.now(), name, email, age }
112-
}
113-
114-
function processConfig({
115-
apiUrl,
116-
timeout,
117-
retries
118-
}: {
119-
apiUrl: string
120-
timeout?: number
121-
retries?: number
122-
}) {
123-
return { apiUrl, timeout: timeout || 5000, retries: retries || 3 }
124-
}
125-
126-
// Rest parameters with explicit types
127-
function logMessages(...messages: string[]): void {
128-
console.log(...messages)
129-
}
130-
131-
function combineArrays(...arrays: any[][]): any[] {
132-
return arrays.flat()
133-
}
134-
135-
// Default parameters with explicit types
136-
function greetUser(name: string = 'Guest'): string {
137-
return `Hello, ${name}!`
138-
}
139-
140-
function createTimer(duration: number = 1000, callback: () => void): void {
141-
setTimeout(callback, duration)
142-
}
143-
144-
// Mixed parameter types with explicit annotations
145-
function complexFunction(
146-
regularParam: string,
147-
{ destructuredProp }: { destructuredProp: number },
148-
...restParams: any[]
149-
): object {
150-
return { regularParam, destructuredProp, restParams }
151-
}
152-
153-
// Class methods with explicit parameter types
154-
class UserService {
155-
private apiUrl: string
156-
private timeout: number
157-
158-
constructor(apiUrl: string, timeout: number) {
159-
this.apiUrl = apiUrl
160-
this.timeout = timeout
25+
### Function with Destructured Parameters
26+
27+
```diff
28+
- function createUser({ name, email, age }) {
29+
+ function createUser({ name, email, age }: any) {
30+
return { id: Date.now(), name, email, age }
16131
}
32+
```
33+
34+
### Function with Rest Parameters
16235

163-
async fetchUser(id: string, includeProfile: boolean = false): Promise<any> {
164-
const response = await fetch(`${this.apiUrl}/users/${id}`)
165-
return response.json()
36+
```diff
37+
- function logMessages(...messages) {
38+
+ function logMessages(...messages: any[]) {
39+
console.log(...messages)
16640
}
41+
```
42+
43+
### Function with Default Parameters
16744

168-
updateUser(id: string, { name, email }: { name: string; email: string }): Promise<void> {
169-
return this.api.updateUser(id, { name, email })
45+
```diff
46+
- function greetUser(name = 'Guest') {
47+
+ function greetUser(name: any = 'Guest') {
48+
return `Hello, ${name}!`
17049
}
171-
}
17250
```
17351

17452
## Rule Scope

0 commit comments

Comments
 (0)