Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

[exp]: add cursor rules (#4408)

Shahmir Varqha57dd32c4502d
diff --git a/.cursor/rules/python.mdc b/.cursor/rules/python.mdc
new file mode 100644
index 0000000000..ca09c069b3
--- /dev/null
+++ b/.cursor/rules/python.mdc
@@ -0,0 +1,71 @@
+---
+description:
+globs:
+alwaysApply: true
+---
+---
+description: Rules for writing Python (backend of marimo)
+globs: marimo/*.py scripts/*.py test/*.py pyodide/*.py
+---
+
+You are an expert in Python and websockets protocol with Python.
+
+Key Principles
+ - Write clear, technical responses with precise examples.
+ - Prioritize readability and maintainability; follow PEP 8 coding style guide
+ - Use descriptive variable and function names; adhere to naming conventions (e.g., lowercase with underscores for functions and variables).
+ - Use type hints consistently throughout the codebase
+ - Keep comments to a minimum; be concise when writing them
+
+Error Handling and Validation
+ - Use try-except blocks to handle cases where the code can fail
+ - Follow established error handling patterns with specific or custom exceptions
+
+Logging
+ - As a general rule, we should have logs for every unexpected action of the application, using the appropriate log level.
+ - A log level or log severity is a piece of information telling how important a given log message is:
+ - debug: should be used for information that may be needed for diagnosing issues and troubleshooting or when running application in the test environment for the purpose of making sure everything is running correctly
+ - info should be used as standard log level, indicating that something happened
+ - warn: should be used when something unexpected happened but the code can continue the work
+ - error: should be used when the application hits an issue preventing one or more functionalities from properly functioning
+
+Logging Format
+ - Always use marimo's logger:
+
+ ```python
+ from marimo import _loggers
+
+ LOGGER = _loggers.marimo_logger()
+
+ LOGGER.info("Debugging applications with params %s %s", "key1", "key2")
+ ```
+
+ will produce:
+
+ ```sh
+ [D 250406 21:43:21 runtime:2055] Debugging applications with params key1 key2
+ ```
+
+Security
+ - Don’t log sensitive information. Make sure you never log:
+ - authorization tokens
+ - passwords
+
+Testing
+ - Changes or new functionality in the codebase should come with unit tests using pytest.
+ - Tests exist in the tests folder.
+ - Utilize snapshot testing where appropriate:
+
+ ```
+ from tests.mocks import snapshotter
+
+ snapshot = snapshotter(__file__)
+
+ snapshot(filename, output)
+ ```
+
+Unit tests
+ - A good unit test should:
+ - focus on a single use-case at a time
+ - have a minimal set of assertions per test
+ - demonstrate every use case. The rule of thumb is: if it can happen, it should be covered
\ No newline at end of file
diff --git a/.cursor/rules/react-typescript.mdc b/.cursor/rules/react-typescript.mdc
new file mode 100644
index 0000000000..df1e3c4ce8
--- /dev/null
+++ b/.cursor/rules/react-typescript.mdc
@@ -0,0 +1,45 @@
+---
+description:
+globs:
+alwaysApply: true
+---
+---
+description: Rules for writing React with Typescript (frontend of marimo)
+globs: frontend/*.ts?(x) openapi/*.ts?(x) lsp/*.ts?(x)
+---
+
+You are an expert in React, TypeScript, TailwindCSS, Radix, Zod, React Hook Form and UX design.
+
+Key Principles
+ - Write clear, understandable code
+ - Prioritize maintainable code over development speed / shorter syntax.
+
+Code Style and Structure
+ - Write TypeScript with proper typing for all new code
+ - Use functional programming patterns; avoid classes. Prefer composition over inheritance.
+ - Favor iteration and modularization to adhere to DRY principles and avoid code duplication.
+ - Use descriptive variable names with auxiliary verbs (e.g., isLoading, hasError).
+ - Don't use `useState` or `useEffect` to store local state. It's false convenience. Take the extra 3 minutes and change it to a `logic` early on in the development.
+ - Structure files logically: main logic, component, types, utils
+ - Keep comments to a minimum; be concise when writing them
+
+Naming Conventions
+ - Use lowercase with dashes for directories (e.g., components/auth-wizard).
+ - Use named exports; avoid default exports
+ - Use clear, yet functional names (`searchResults` vs `data`).
+ - Logics are camelCase (`dashboardLogic`)
+ - React components are PascalCase (`DashboardMenu`).
+
+UI and Styling
+ - Use Tailwind CSS as primary styling solution
+ - There are many UI components taken from radix and customized in '@/components/ui'. Develop reusable UI components in that folder instead of directly importing from radix.
+
+Build System
+ - Use Vite
+
+Forms
+ - Use React Hook Form with Zod
+
+Testing Requirements
+ - Use Vitest for testing
+ - Test components for all edge cases. The rule of thumb is: if it can happen, it should be covered
\ No newline at end of file