style(guidelines): change function export style to arrow functions

Replace function declarations with arrow function expressions assigned to constants
for better testability when mocking functions during unit tests.

This makes the codebase more consistent and addresses issues with function mocking.
This commit is contained in:
Lorenz Hilpert
2025-04-25 17:09:40 +02:00
parent 337ef46acb
commit a48ff29051
2 changed files with 78 additions and 27 deletions

View File

@@ -309,6 +309,7 @@ This section extends the core code style principles with Angular-specific and ad
- **Functions and Methods**:
- Always export functions as arrow function expressions (const) instead of function declarations
- Use arrow functions for callbacks and class methods
- Explicitly type parameters and return values
- Keep functions pure when possible
@@ -322,16 +323,21 @@ This section extends the core code style principles with Angular-specific and ad
* @param id - The user's unique identifier
* @param includeDetails - Whether to include additional user details
*/
const getUser = (id: string, includeDetails = false): Promise<User> => {
export const getUser = (id: string, includeDetails = false): Promise<User> => {
// ...implementation
};
// Bad
function getUser(id) {
export function getUser(id) {
// ...implementation
}
```
// Reason for using arrow function expressions:
// 1. More consistent with modern JavaScript practices
// 2. Easier to mock in unit tests
// 3. Avoids 'this' binding issues
- **Generics**:
- Use meaningful type parameter names (e.g., `T` for type, `K` for key)
- Constrain generic types when possible using `extends`