|
| 1 | +--- |
| 2 | +trigger: always_on |
| 3 | +--- |
| 4 | + |
| 5 | +# Code Quality and Standards |
| 6 | + |
| 7 | +## Why Code Quality Matters |
| 8 | + |
| 9 | +- Prevents production defects and reduces technical debt |
| 10 | +- Ensures maintainable and debuggable code |
| 11 | +- Enables predictable enhancements without side effects |
| 12 | +- Reduces legal, security, and brand risks |
| 13 | +- Improves developer experience and team efficiency |
| 14 | + |
| 15 | +## Folder Structure and Architecture |
| 16 | + |
| 17 | +- Follow strict pod-based architecture |
| 18 | +- Structure: `<podName>/<flowName>/container/<containerName>` |
| 19 | +- Structure: `<podName>/<flowName>/component/<componentName>` |
| 20 | +- Structure: `<podName>/<flowName>/feature/<featureName>` |
| 21 | +- Structure: `<podName>/common/utils|constants|feature` |
| 22 | +- Structure: `/common/<domainName>/utils|constants|feature` |
| 23 | +- Do NOT breach pod boundaries without architecture approval |
| 24 | + |
| 25 | +## Naming Conventions |
| 26 | + |
| 27 | +- **Variables**: camelCase (thisIsAVariable) |
| 28 | +- **Functions**: camelCase (thisIsAFunction) |
| 29 | +- **Constants**: UPPER_SNAKE_CASE (THIS_IS_A_CONSTANT) |
| 30 | +- **Acronyms**: UPPER_CASE (TIA = "This Is an Acronym") |
| 31 | +- **Components**: PascalCase (ThisIsAComponent) |
| 32 | +- **Object Props**: camelCase ({amount: 1, currency: 'USD'}) |
| 33 | +- **URLs**: lowercase with "-" or "/" separators |
| 34 | +- Use descriptive names, avoid abbreviations (shouldDisplayTravelWaiverMessage NOT shouldDsplyTrvlWavrMsg) |
| 35 | + |
| 36 | +## JavaScript Best Practices |
| 37 | + |
| 38 | +### General Rules |
| 39 | + |
| 40 | +- Use ES6+ syntax (arrow functions, destructuring, template literals) |
| 41 | +- Prefer `const` over `let`, avoid `var` completely |
| 42 | +- Avoid `let` whenever possible - seek immutability |
| 43 | +- No anonymous functions as event handlers - declare named functions |
| 44 | +- Remove all console.log and debugger statements before PR |
| 45 | +- No eslint-disable-line without architecture team approval |
| 46 | + |
| 47 | +### Prohibited or Restricted Patterns |
| 48 | + |
| 49 | +- Do NOT use `window` object (except with arch team clearance) |
| 50 | +- Do NOT import entire lodash library: `import get from 'lodash/get'` (allowed but discouraged) |
| 51 | +- Do NOT use `Date()` - use moment instead |
| 52 | +- Do NOT use `forEach` - use map, filter, reduce, or for...of |
| 53 | +- Do NOT use "will" lifecycle methods except componentWillUnmount |
| 54 | +- Do NOT trust BFF responses - always validate and set defaults |
| 55 | +- Do NOT use `tabIndex > 0` |
| 56 | + |
| 57 | +### Props and State Management |
| 58 | + |
| 59 | +- Destructure props at function signature level |
| 60 | +- Avoid prop drilling beyond 3 levels - use intermediate containers |
| 61 | +- Use Redux for global state, local state only for UI-specific concerns |
| 62 | +- Required props: Mark functions and data needed for functionality as required |
| 63 | +- PropTypes: Define in external file at wrapper level for reusability |
| 64 | +- Use null chain operator for service responses with mapper layer |
| 65 | + |
| 66 | +### Pure Functions and Complexity |
| 67 | + |
| 68 | +- Write pure functions whenever possible (no side effects) |
| 69 | +- Functions should do one thing well |
| 70 | +- Maximum function length: 50 lines |
| 71 | +- Remove dormant (dead) code immediately |
| 72 | +- Refactor when components exceed 200 lines |
| 73 | +- Extract complex logic to utility functions or selectors |
| 74 | + |
| 75 | +### Data Handling |
| 76 | + |
| 77 | +- Always validate service responses with null checks |
| 78 | +- Create mappers between services and store |
| 79 | +- Use selectors for all data transformations |
| 80 | +- Move data processing from render to selectors |
| 81 | +- Use constants file for string values and configuration |
| 82 | + |
| 83 | +## Component Standards |
| 84 | + |
| 85 | +### Component Types |
| 86 | + |
| 87 | +- Prefer functional components with hooks over class components |
| 88 | +- Use PureComponent ONLY if props are immutable (primitives or ImmutableJS) |
| 89 | +- Stateless pure presentational components preferred |
| 90 | +- Return `false` instead of `null` to keep children linked to tree |
| 91 | + |
| 92 | +### React Hooks |
| 93 | + |
| 94 | +- **useEffect**: Stay reactive, be mindful of dependencies array |
| 95 | +- **useMemo**: Use for expensive calculations only |
| 96 | +- **useCallback**: Use to prevent unnecessary re-renders |
| 97 | +- **useRef**: Bridge between JS DOM and React context |
| 98 | +- Custom hooks: Declare at component level or in hooks directory |
| 99 | + |
| 100 | +### Component Requirements |
| 101 | + |
| 102 | +- All components must have PropTypes defined |
| 103 | +- Provide defaultProps for optional props |
| 104 | +- Use fragments `<></>` instead of empty divs |
| 105 | +- Keys must come from data props, NOT array index or random IDs |
| 106 | +- Conditional rendering: All conditionals must be boolean (non-boolean values render) |
| 107 | +- Avoid prop drilling: Use intermediate containers beyond 3 levels |
| 108 | + |
| 109 | +### JSX Best Practices |
| 110 | + |
| 111 | +- Presentational components should receive data via props only |
| 112 | +- No business logic in JSX components - use selectors |
| 113 | +- Extract methods returning JSX as separate components |
| 114 | +- Use memoization for expensive rendering logic |
| 115 | +- Keep components small and reusable (<200 lines) |
| 116 | +- One responsibility per component |
| 117 | + |
| 118 | +## Styling |
| 119 | + |
| 120 | +### CSS/SCSS Standards |
| 121 | + |
| 122 | +- Use mobile-first approach (avoid max-width) |
| 123 | +- Do NOT use `:global` without architecture approval |
| 124 | +- Use `atm-u` utility classes, NOT `atm-c` component classes |
| 125 | +- All CSS must have parent class selector (no global impact) |
| 126 | +- Use Atmos components and design system |
| 127 | +- Maintain 4.5:1 contrast ratio for text, 3:1 for UI elements |
| 128 | + |
| 129 | +### Emotion/CSS-in-JS |
| 130 | + |
| 131 | +- Follow Atmos styling patterns |
| 132 | +- Use JSON theme values when available |
| 133 | +- Avoid inline styles unless absolutely necessary |
| 134 | + |
| 135 | +## Redux and State Management |
| 136 | + |
| 137 | +### Redux Patterns |
| 138 | + |
| 139 | +- Use Redux Toolkit for all new state management |
| 140 | +- Local state for UI-only concerns (modals, tooltips) |
| 141 | +- Global state for shared data and server responses |
| 142 | +- Do NOT use react-redux-form state - use model instead |
| 143 | +- Define actions and reducers in feature folders |
| 144 | + |
| 145 | +### Sagas |
| 146 | + |
| 147 | +- Follow saga implementation patterns |
| 148 | +- Handle async operations in sagas, not components |
| 149 | +- Use try-catch for error handling |
| 150 | +- Implement request/response cycle properly |
| 151 | +- Maintain immutability with "Current" record pattern |
| 152 | + |
| 153 | +## Internationalization (i18n) |
| 154 | + |
| 155 | +- Use `<FormattedMessage>` instead of `intl.formatMessage` in JSX |
| 156 | +- Extract messages after every change (provide screenshot for context) |
| 157 | +- Verify scope and ID match file location |
| 158 | +- Do NOT send variable messages to intl - validate existence with defaults |
| 159 | +- Inject intl at container level only once |
| 160 | + |
| 161 | +## Security and PII |
| 162 | + |
| 163 | +- Mask credit cards: First 12 digits as asterisks/bullets, last 4 visible |
| 164 | +- Follow PII masking guidelines for all personal data |
| 165 | +- No PCI/PII data in logs or monitoring |
| 166 | +- Validate and sanitize all user inputs |
0 commit comments