mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-28 22:42:11 +01:00
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:
@@ -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`
|
||||
|
||||
Reference in New Issue
Block a user