|
| 1 | +# F2 Code Style Guidelines |
| 2 | + |
| 3 | +This document outlines the coding standards and best practices for the F2 visualization library. |
| 4 | + |
| 5 | +## TypeScript/JavaScript Style Guidelines |
| 6 | + |
| 7 | +### General Formatting |
| 8 | + |
| 9 | +- Use 2 spaces for indentation |
| 10 | +- Use single quotes for strings |
| 11 | +- Maximum line length: 100 characters |
| 12 | +- Use trailing commas in multi-line object literals and arrays |
| 13 | +- Use semicolons at the end of statements |
| 14 | +- Use LF line endings |
| 15 | +- Insert final newline at the end of files |
| 16 | +- Trim trailing whitespace |
| 17 | + |
| 18 | +### Naming Conventions |
| 19 | + |
| 20 | +- **Components**: Use PascalCase for component names (e.g., `LineChart`, `AreaSeries`) |
| 21 | +- **Functions**: Use camelCase for function names (e.g., `calculatePosition`, `formatData`) |
| 22 | +- **Variables**: Use camelCase for variable names (e.g., `dataSource`, `chartConfig`) |
| 23 | +- **Constants**: Use UPPER_SNAKE_CASE for constants (e.g., `DEFAULT_THEME`, `MAX_DATA_POINTS`) |
| 24 | +- **Interfaces/Types**: Use PascalCase with a descriptive name (e.g., `ChartProps`, `PointData`) |
| 25 | +- **Files**: Use kebab-case for file names (e.g., `line-chart.tsx`, `data-processor.ts`) |
| 26 | + |
| 27 | +### Component Structure |
| 28 | + |
| 29 | +- Each React component should be in its own file |
| 30 | +- Component props should be defined using TypeScript interfaces |
| 31 | +- Export components as named exports, not default exports |
| 32 | +- Keep components focused on a single responsibility |
| 33 | +- Use functional components with hooks instead of class components when possible |
| 34 | + |
| 35 | +### Code Organization |
| 36 | + |
| 37 | +- Group related functions and constants together |
| 38 | +- Place imports at the top of the file, grouped by: |
| 39 | + 1. External libraries |
| 40 | + 2. Internal modules |
| 41 | + 3. Local imports (from the same directory) |
| 42 | +- Export public API from index files |
| 43 | + |
| 44 | +### Documentation |
| 45 | + |
| 46 | +- Use JSDoc comments for functions, classes, and interfaces |
| 47 | +- Document parameters, return values, and thrown exceptions |
| 48 | +- Include examples for complex functions or components |
| 49 | +- Keep comments up-to-date with code changes |
| 50 | + |
| 51 | +### Best Practices |
| 52 | + |
| 53 | +- Avoid using `any` type in TypeScript |
| 54 | +- Use optional chaining (`?.`) and nullish coalescing (`??`) operators |
| 55 | +- Prefer early returns to reduce nesting |
| 56 | +- Use destructuring for props and state |
| 57 | +- Avoid magic numbers, use named constants |
| 58 | +- Write unit tests for critical functionality |
| 59 | +- Use meaningful variable and function names |
| 60 | +- Avoid unnecessary comments that just repeat what the code does |
| 61 | + |
| 62 | +## Visualization-Specific Guidelines |
| 63 | + |
| 64 | +### Chart Components |
| 65 | + |
| 66 | +- Follow a consistent API pattern across different chart types |
| 67 | +- Separate data processing logic from rendering logic |
| 68 | +- Implement proper accessibility features (ARIA attributes, keyboard navigation) |
| 69 | +- Support responsive layouts by default |
| 70 | + |
| 71 | +### Performance |
| 72 | + |
| 73 | +- Optimize rendering performance for large datasets |
| 74 | +- Use memoization for expensive calculations |
| 75 | +- Implement proper cleanup in component lifecycle methods |
| 76 | +- Avoid unnecessary re-renders |
| 77 | + |
| 78 | +### Theming |
| 79 | + |
| 80 | +- Use the theme system consistently |
| 81 | +- Don't hardcode colors or styles |
| 82 | +- Support dark mode where applicable |
| 83 | + |
| 84 | +## Git Workflow |
| 85 | + |
| 86 | +- Write clear, descriptive commit messages |
| 87 | +- Reference issue numbers in commit messages when applicable |
| 88 | +- Keep pull requests focused on a single feature or bug fix |
| 89 | +- Update documentation when changing public APIs |
| 90 | + |
| 91 | +Following these guidelines will help maintain code quality and consistency throughout the F2 project. |
0 commit comments