6.4 KiB
AGENTS.md - AI Assistant Guide for Oxc
This document provides guidance for AI assistants working with the Oxc codebase. It contains essential information about the project structure, development workflows, and best practices to help AI systems navigate and contribute to this repository effectively.
🚀 Project Overview
Oxc (The Oxidation Compiler) is a collection of high-performance tools for JavaScript and TypeScript written in Rust. The project includes:
- Parser: JavaScript/TypeScript parsing with full AST support
- Linter (oxlint): Fast ESLint-compatible linter
- Formatter: Code formatting tools
- Transformer: Code transformation and compilation
- Minifier: Code minification for production
📁 Repository Structure
The repository follows a Rust workspace structure with multiple crates:
Key Directories
crates/- Core Rust crates containing the main functionalityapps/- Application binaries (currently containsoxlint)napi/- Node.js bindings for JavaScript/TypeScript integrationnpm/- npm packages and Node.js-related codetasks/- Development tools, testing, and automation scriptseditors/- Editor integrations (VS Code extension, etc.)
Important Crates Overview
oxc_parser- JavaScript/TypeScript parseroxc_ast- Abstract Syntax Tree definitions and utilitiesoxc_linter- Linting engine and rulesoxc_semantic- Semantic analysis and symbol resolutionoxc_transformer- Code transformation utilitiesoxc_codegen- Code generation from ASToxc_minifier- Code minificationoxc_formatter- Code formattingoxc_diagnostics- Error reporting and diagnosticsoxc- Main crate that ties everything together
🛠️ Development Workflow
Prerequisites
The project uses several tools for development:
- Rust: Latest stable (MSRV: 1.86.0)
- Node.js: Version specified in
.node-version - pnpm: Package manager for Node.js dependencies
- just: Command runner (alternative to make)
Common Commands
The project uses just as the primary command runner. Key commands include:
# Initialize development environment
just init
# Run all checks (the "ready" command)
just ready
# Individual commands
just fmt # Format code
just check # Check code without building
just test # Run tests
just lint # Run linting
just doc # Generate documentation
just ast # When directory `crates/oxc_ast` changes
Building and Testing
# Build all crates
cargo build
# Run all tests
cargo test
# Build Node.js bindings
pnpm build
# Run Node.js tests
pnpm test
🧭 Code Navigation Tips
Understanding the AST
- Start with
oxc_astto understand the AST structure - Look at
oxc_ast_visitfor traversal patterns - Check
oxc_semanticfor symbol resolution and scoping
Linting Rules
- Linting rules are in
crates/oxc_linter/src/rules/ - Each rule typically has its own module with tests
- Rule implementations follow a visitor pattern
Parser Architecture
- Parser entry point:
crates/oxc_parser/src/lib.rs - Lexer:
crates/oxc_parser/src/lexer/ - Parser modules organized by language constructs
Testing Patterns
- Unit tests are co-located with source code
- Integration tests in
tests/directories - Snapshot testing using
instacrate for AST and output verification - Conformance testing against real-world codebases
📝 Code Style and Conventions
Rust Conventions
- Follow standard Rust formatting (rustfmt configuration in
.rustfmt.toml) - Use Clippy lints as defined in
Cargo.toml - Prefer explicit over implicit where it improves readability
- Use the allocator pattern (
oxc_allocator) for memory management
Error Handling
- Use
oxc_diagnosticsfor user-facing errors - Follow the diagnostic pattern for error reporting
- Include source location information in diagnostics
Performance Considerations
- This is a high-performance project - consider memory allocation patterns
- Use the arena allocator (
oxc_allocator) for AST nodes - Be mindful of string allocations and prefer string interning where appropriate
- Benchmark performance-critical changes
🤝 Contributing Guidelines for AI
Making Changes
- Understand the scope: Oxc is a complex project with many interdependent parts
- Start small: Focus on specific, well-defined changes
- Test thoroughly: Run the full test suite and add appropriate tests
- Follow patterns: Study existing code patterns before implementing new features
- Consider performance: This is a performance-critical project
Common Tasks
Adding a New Linting Rule
- Create a new module in
crates/oxc_linter/src/rules/ - Implement the rule following the visitor pattern
- Add tests in the same module
- Register the rule in the appropriate category
- Update documentation if needed
Modifying the Parser
- Changes to grammar should be well-researched and tested
- Update AST definitions in
oxc_astif needed - Ensure all existing tests pass
- Add new tests for new language features
Working with Transformations
- Understand the AST structure thoroughly
- Use the visitor pattern for traversing
- Be careful with node ownership and the allocator
- Test with various input patterns
Testing Strategy
- Run
just readybefore submitting changes - Add unit tests for new functionality
- Use snapshot tests for complex outputs
- Test against real-world codebases when possible
- Consider edge cases and error conditions
🔍 Debugging Tips
Common Issues
- Build failures: Check Rust version compatibility and dependencies
- Test failures: May indicate AST changes or semantic differences
- Performance regressions: Use benchmarking tools in
tasks/benchmark/
📚 Additional Resources
- Website: oxc.rs - Official documentation
⚠️ Important Notes
- This is a rapidly evolving project - APIs may change
- Performance is a key consideration in all changes
- Compatibility with JavaScript/TypeScript standards is critical
- The project maintains high code quality standards
- Breaking changes should be well-documented and discussed
This document is intended to help AI assistants understand and work effectively with the Oxc codebase. For human contributors, please refer to CONTRIBUTING.md and the project website for complete guidelines.