Skip to content

Commit 9de25e7

Browse files
committed
docs: enhance ESLint documentation and add Independent Modules guide
1 parent 746af5b commit 9de25e7

5 files changed

Lines changed: 294 additions & 27 deletions

File tree

documentation/docs/04-Guides/09-ESLint.md

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,25 @@ slug: /eslint-project-structure
33
sidebar_label: ESLint & Project Structure
44
title: ESLint & Project Structure
55
id: eslint-project-structure
6-
keywords: [eslint, project structure, code quality, linting, perfectionist, unicorn]
6+
keywords:
7+
[eslint, project structure, code quality, linting, perfectionist, unicorn]
78
---
89

910
Version 5.0 introduces powerful ESLint rules that enforce project structure, code composition, and module independence.
1011
These rules help maintain consistency and prevent common architectural issues as your project grows.
1112

13+
:::tip Architecture & Module Independence
14+
This guide covers **ESLint configuration and technical rules**. For a high-level understanding of the architectural model, layer hierarchy, and module dependency rules, see the [Independent Modules Architecture](/docs/independent-modules) guide.
15+
16+
Think of it this way:
17+
18+
- **Independent Modules** guide = "What is the architecture and why?"
19+
- **ESLint guide** = "How to configure and customize the rules?"
20+
:::
21+
1222
:::tip Optional Strict Rules
1323
The project structure enforcement rules are **intentionally strict** to maintain architectural consistency. However, they are:
24+
1425
- **Evolutionary**: These rules will be refined and updated over time as best practices emerge
1526
- **Optional**: If you find them too restrictive for your use case, you can disable them by commenting out the project-structure configuration in `eslint.config.mjs`:
1627

@@ -79,10 +90,12 @@ export default defineConfig([
7990
```
8091

8192
When you choose JavaScript during project initialization, TypeScript-specific type-checking rules are automatically disabled for `.js` and `.jsx` files. This includes:
93+
8294
- All rules requiring type information (from `strictTypeChecked` and `stylisticTypeChecked`)
8395
- Type-aware linting rules
8496

8597
**All other rules remain active for JavaScript:**
98+
8699
- Project structure enforcement
87100
- Code composition rules
88101
- Import sorting (perfectionist)
@@ -130,14 +143,17 @@ This prevents files from being placed in incorrect locations and enforces the bo
130143
Enforces what each file can contain based on its location:
131144

132145
**Hook files** (`hooks/**/*.ts`):
146+
133147
- ✅ Only function declarations and exports
134148
- ❌ No class declarations, no inline objects
135149

136150
**Domain API files** (`services/domains/*/*.api.ts`):
151+
137152
- ✅ Only function declarations, exports, and API object
138153
- ❌ No React components, no hooks
139154

140155
**Component files** (`components/**/*.tsx`):
156+
141157
- ✅ React components and related types
142158
- ❌ No API calls, no business logic
143159

@@ -181,6 +197,10 @@ Prevents circular dependencies and enforces module boundaries:
181197

182198
This creates a clear dependency hierarchy and prevents tight coupling.
183199

200+
:::info Learn More
201+
For a complete understanding of the module architecture, layer hierarchy, and detailed import rules, see the dedicated guide: [Independent Modules Architecture](/docs/independent-modules)
202+
:::
203+
184204
### 2. eslint-plugin-perfectionist
185205

186206
Automatically sorts and organizes code elements alphabetically:
@@ -216,6 +236,7 @@ import { Text, View } from 'react-native';
216236
Enforces modern JavaScript/TypeScript best practices:
217237

218238
Examples:
239+
219240
- Prefer `node:` protocol for Node.js imports
220241
- Prefer array method callbacks over inline functions
221242
- Prefer `String#startsWith()` over regex
@@ -224,11 +245,13 @@ Examples:
224245

225246
```tsx
226247
// ❌ Avoid
227-
if (str.match(/^foo/)) { }
248+
if (str.match(/^foo/)) {
249+
}
228250
const btn = document.getElementById('btn');
229251

230252
// ✅ Prefer
231-
if (str.startsWith('foo')) { }
253+
if (str.startsWith('foo')) {
254+
}
232255
const button = document.getElementById('button');
233256
```
234257

@@ -254,7 +277,7 @@ useEffect(() => {
254277
}, [userId]);
255278

256279
// ✅ Prefer - Key-based reset
257-
<UserProfile key={userId} userId={userId} />
280+
<UserProfile key={userId} userId={userId} />;
258281
```
259282

260283
## File Naming Conventions
@@ -307,23 +330,29 @@ Theme (theme/) & Translations
307330
### Detailed Import Rules
308331

309332
#### app.tsx
333+
310334
**Can import:**
335+
311336
- `@/components/*` (all component barrels: atoms, molecules, organisms, templates, providers)
312337
- `@/hooks` (hooks barrel)
313338
- `@/theme/assets/icons/*` and `@/theme/assets/images/*`
314339
- `@/services/**/*`
315340
- `@/navigators` (navigators barrel)
316341

317342
#### Navigators (`src/navigators/**/*.tsx`)
343+
318344
**Can import:**
345+
319346
- `@/screens` (screens barrel)
320347
- `@/components/*` (all component barrels)
321348
- `@/hooks` (hooks barrel)
322349
- Theme assets (icons/images)
323350
- `@/services/**/*`
324351

325352
#### Screens (`src/screens/**/*.tsx`)
353+
326354
**Can import:**
355+
327356
- `@/components/*` (all component barrels)
328357
- `@/hooks` (hooks barrel)
329358
- Theme assets (icons/images)
@@ -336,6 +365,7 @@ Theme (theme/) & Translations
336365
Components follow the atomic design hierarchy:
337366

338367
**Templates** (`src/components/templates/**/*.tsx`):
368+
339369
- ✅ Other templates (same family)
340370
- ✅ Atoms, Molecules, Organisms, Providers (via barrels)
341371
- ✅ Hooks barrel
@@ -344,58 +374,70 @@ Components follow the atomic design hierarchy:
344374
- ❌ Screens, Navigators
345375

346376
**Organisms** (`src/components/organisms/**/*.tsx`):
377+
347378
- ✅ Atoms, Molecules, Providers (via barrels)
348379
- ✅ Hooks barrel
349380
- ✅ Theme assets and `get-assets-context`
350381
- ✅ Services
351382
- ❌ Templates, Screens, Navigators
352383

353384
**Molecules** (`src/components/molecules/**/*.tsx`):
385+
354386
- ✅ Atoms, Providers (via barrels)
355387
- ✅ Hooks barrel
356388
- ✅ Theme assets and `get-assets-context`
357389
- ✅ Services
358390
- ❌ Molecules, Organisms, Templates, Screens, Navigators
359391

360392
**Atoms** (`src/components/atoms/**/*.tsx`):
393+
361394
- ✅ Providers (via barrel)
362395
- ✅ Hooks barrel
363396
- ✅ Theme assets and `get-assets-context`
364397
- ✅ Services
365398
- ❌ Other component types, Screens, Navigators
366399

367400
**Providers** (`src/components/providers/**/*.tsx`):
401+
368402
- ✅ Hooks barrel
369403
- ✅ Services
370404
-`get-assets-context`
371405
- ❌ Other components, Screens, Navigators
372406

373407
**Special case - Theme Provider** (`src/components/providers/theme-provider/theme-provider.tsx`):
408+
374409
- ✅ Hooks barrel
375410
- ✅ Services
376411
-`get-assets-context`
377412
- ✅ Theme config (`src/theme/*.ts`)
378413

379414
#### Hooks (`src/hooks/**/*.tsx`)
415+
380416
**Can import:**
417+
381418
- ✅ Other hooks from the same family (e.g., `use-*.ts`)
382419
- ✅ Services
383420
- ❌ Components, Screens, Navigators, Theme (except via services)
384421

385422
#### Services (`src/services/**/*.ts`)
423+
386424
**Can import:**
425+
387426
- ✅ Other services (same family)
388427
- ✅ Translations (`src/translations/*.json`)
389428
- ✅ Theme assets (icons/images)
390429
- ❌ Components, Hooks, Screens, Navigators
391430

392431
#### Theme (`src/theme/**/*.ts`)
432+
393433
**Can import:**
434+
394435
- ✅ Other theme files (same family)
395436
- ✅ Theme generation service (`src/services/theme-generation/**/*`)
396437
- ❌ Everything else
397438

398439
#### Translations (`src/translations/**/*`)
440+
399441
**Cannot import anything** - they are pure data files.
400442

401443
### Key Principles
@@ -443,6 +485,7 @@ npm run lint -- --fix
443485
```
444486

445487
This will automatically:
488+
446489
- Sort imports
447490
- Sort object keys
448491
- Fix naming issues (where possible)

0 commit comments

Comments
 (0)