|
| 1 | +--- |
| 2 | +description: Apache Superset development standards and guidelines for Cursor IDE |
| 3 | +globs: ["**/*.py", "**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx", "**/*.sql", "**/*.md"] |
| 4 | +alwaysApply: true |
| 5 | +--- |
| 6 | + |
| 7 | +# Apache Superset Development Standards for Cursor IDE |
| 8 | + |
| 9 | +Apache Superset is a data visualization platform with Flask/Python backend and React/TypeScript frontend. |
| 10 | + |
| 11 | +## ⚠️ CRITICAL: Ongoing Refactors (What NOT to Do) |
| 12 | + |
| 13 | +**These migrations are actively happening - avoid deprecated patterns:** |
| 14 | + |
| 15 | +### Frontend Modernization |
| 16 | +- **NO `any` types** - Use proper TypeScript types |
| 17 | +- **NO JavaScript files** - Convert to TypeScript (.ts/.tsx) |
| 18 | +- **NO Enzyme** - Use React Testing Library/Jest (Enzyme fully removed) |
| 19 | +- **Use @superset-ui/core** - Don't import Ant Design directly |
| 20 | + |
| 21 | +### Testing Strategy Migration |
| 22 | +- **Prefer unit tests** over integration tests |
| 23 | +- **Prefer integration tests** over Cypress end-to-end tests |
| 24 | +- **Cypress is last resort** - Actively moving away from Cypress |
| 25 | +- **Use Jest + React Testing Library** for component testing |
| 26 | + |
| 27 | +### Backend Type Safety |
| 28 | +- **Add type hints** - All new Python code needs proper typing |
| 29 | +- **MyPy compliance** - Run `pre-commit run mypy` to validate |
| 30 | +- **SQLAlchemy typing** - Use proper model annotations |
| 31 | + |
| 32 | +## Code Standards |
| 33 | + |
| 34 | +### TypeScript Frontend |
| 35 | +- **NO `any` types** - Use proper TypeScript |
| 36 | +- **Functional components** with hooks |
| 37 | +- **@superset-ui/core** for UI components (not direct antd) |
| 38 | +- **Jest** for testing (NO Enzyme) |
| 39 | +- **Redux** for global state, hooks for local |
| 40 | + |
| 41 | +### Python Backend |
| 42 | +- **Type hints required** for all new code |
| 43 | +- **MyPy compliant** - run `pre-commit run mypy` |
| 44 | +- **SQLAlchemy models** with proper typing |
| 45 | +- **pytest** for testing |
| 46 | + |
| 47 | +### Apache License Headers |
| 48 | +- **New files require ASF license headers** - When creating new code files, include the standard Apache Software Foundation license header |
| 49 | +- **LLM instruction files are excluded** - Files like LLMS.md, CLAUDE.md, etc. are in `.rat-excludes` to avoid header token overhead |
| 50 | + |
| 51 | +## Key Directory Structure |
| 52 | + |
| 53 | +``` |
| 54 | +superset/ |
| 55 | +├── superset/ # Python backend (Flask, SQLAlchemy) |
| 56 | +│ ├── views/api/ # REST API endpoints |
| 57 | +│ ├── models/ # Database models |
| 58 | +│ └── connectors/ # Database connections |
| 59 | +├── superset-frontend/src/ # React TypeScript frontend |
| 60 | +│ ├── components/ # Reusable components |
| 61 | +│ ├── explore/ # Chart builder |
| 62 | +│ ├── dashboard/ # Dashboard interface |
| 63 | +│ └── SqlLab/ # SQL editor |
| 64 | +├── superset-frontend/packages/ |
| 65 | +│ └── superset-ui-core/ # UI component library (USE THIS) |
| 66 | +├── tests/ # Python/integration tests |
| 67 | +├── docs/ # Documentation (UPDATE FOR CHANGES) |
| 68 | +└── UPDATING.md # Breaking changes log |
| 69 | +``` |
| 70 | + |
| 71 | +## Architecture Patterns |
| 72 | + |
| 73 | +### Dataset-Centric Approach |
| 74 | +Charts built from enriched datasets containing: |
| 75 | +- Dimension columns with labels/descriptions |
| 76 | +- Predefined metrics as SQL expressions |
| 77 | +- Self-service analytics within defined contexts |
| 78 | + |
| 79 | +### Security & Features |
| 80 | +- **RBAC**: Role-based access via Flask-AppBuilder |
| 81 | +- **Feature flags**: Control feature rollouts |
| 82 | +- **Row-level security**: SQL-based data access control |
| 83 | + |
| 84 | +## Test Utilities |
| 85 | + |
| 86 | +### Python Test Helpers |
| 87 | +- **`SupersetTestCase`** - Base class in `tests/integration_tests/base_tests.py` |
| 88 | +- **`@with_config`** - Config mocking decorator |
| 89 | +- **`@with_feature_flags`** - Feature flag testing |
| 90 | +- **`login_as()`, `login_as_admin()`** - Authentication helpers |
| 91 | +- **`create_dashboard()`, `create_slice()`** - Data setup utilities |
| 92 | + |
| 93 | +### TypeScript Test Helpers |
| 94 | +- **`superset-frontend/spec/helpers/testing-library.tsx`** - Custom render() with providers |
| 95 | +- **`createWrapper()`** - Redux/Router/Theme wrapper |
| 96 | +- **`selectOption()`** - Select component helper |
| 97 | +- **React Testing Library** - NO Enzyme (removed) |
| 98 | + |
| 99 | +## Pre-commit Validation |
| 100 | + |
| 101 | +**Use pre-commit hooks for quality validation:** |
| 102 | + |
| 103 | +```bash |
| 104 | +# Install hooks |
| 105 | +pre-commit install |
| 106 | + |
| 107 | +# Quick validation (faster than --all-files) |
| 108 | +pre-commit run # Staged files only |
| 109 | +pre-commit run mypy # Python type checking |
| 110 | +pre-commit run prettier # Code formatting |
| 111 | +pre-commit run eslint # Frontend linting |
| 112 | +``` |
| 113 | + |
| 114 | +## Development Guidelines |
| 115 | + |
| 116 | +- **Documentation**: Update docs/ for any user-facing changes |
| 117 | +- **Breaking Changes**: Add to UPDATING.md |
| 118 | +- **Docstrings**: Required for new functions/classes |
| 119 | +- **Follow existing patterns**: Mimic code style, use existing libraries and utilities |
| 120 | +- **Type Safety**: This codebase is actively modernizing toward full TypeScript and type safety |
| 121 | +- **Always run `pre-commit run`** to validate changes before committing |
| 122 | + |
| 123 | +--- |
| 124 | + |
| 125 | +**Note**: This codebase is actively modernizing toward full TypeScript and type safety. Always run `pre-commit run` to validate changes. Follow the ongoing refactors section to avoid deprecated patterns. |
0 commit comments