Provide FastLED coding standards and best practices.
(
arguments: dict[str, Any], project_root: Path
)
| 863 | |
| 864 | |
| 865 | async def coding_standards( |
| 866 | arguments: dict[str, Any], project_root: Path |
| 867 | ) -> CallToolResult: |
| 868 | """Provide FastLED coding standards and best practices.""" |
| 869 | topic = arguments.get("topic", "all") |
| 870 | |
| 871 | standards = { |
| 872 | "exceptions": """ |
| 873 | # Exception Handling Standards |
| 874 | |
| 875 | ⚠️ **CRITICAL: DO NOT use try-catch blocks or C++ exception handling in FastLED code** |
| 876 | |
| 877 | ## Why No Exceptions? |
| 878 | FastLED is designed for embedded systems like Arduino where: |
| 879 | - Exception handling may not be available |
| 880 | - Exceptions consume significant memory and performance |
| 881 | - Reliable operation across all platforms is required |
| 882 | |
| 883 | ## What to Avoid: |
| 884 | [ERROR] `try { ... } catch (const std::exception& e) { ... }` |
| 885 | [ERROR] `throw std::runtime_error("error message")` |
| 886 | [ERROR] `#include <exception>` or `#include <stdexcept>` |
| 887 | |
| 888 | ## Use Instead: |
| 889 | [OK] **Return error codes:** `bool function() { return false; }` |
| 890 | [OK] **Optional types:** `fl::optional<T>` |
| 891 | [OK] **Assertions:** `FL_ASSERT(condition)` |
| 892 | [OK] **Early returns:** `if (!valid) return false;` |
| 893 | [OK] **Status objects:** Custom result types |
| 894 | |
| 895 | ## Examples: |
| 896 | ```cpp |
| 897 | // Good: Using return codes |
| 898 | bool initializeHardware() { |
| 899 | if (!setupPins()) { |
| 900 | FL_WARN("Failed to setup pins"); |
| 901 | return false; |
| 902 | } |
| 903 | return true; |
| 904 | } |
| 905 | |
| 906 | // Good: Using fl::optional |
| 907 | fl::optional<float> calculateValue(int input) { |
| 908 | if (input < 0) { |
| 909 | return fl::nullopt; |
| 910 | } |
| 911 | return fl::make_optional(sqrt(input)); |
| 912 | } |
| 913 | ``` |
| 914 | """, |
| 915 | "std_namespace": """ |
| 916 | # Standard Library Namespace Standards |
| 917 | |
| 918 | ⚠️ **DO NOT use std:: prefixed functions or headers** |
| 919 | |
| 920 | FastLED provides its own STL-equivalent implementations under the `fl::` namespace. |
| 921 | |
| 922 | ## Common Replacements: |