.claude/skills/crane-code-style/SKILL.md
This skill should be used when the user asks about "code style", "naming convention", "imports", "section headers", "slot naming", "viaIR", "stack too deep", "formatting", or needs guidance on Crane's code conventions and style requirements.
npx skillsauth add cyotee/crane crane-code-styleInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Crane follows strict code conventions for consistency and maintainability. This skill covers section headers, imports, naming, and critical compilation rules.
Use 78-character wide comment blocks for major sections:
/* -------------------------------------------------------------------------- */
/* Section Name */
/* -------------------------------------------------------------------------- */
Shorter form for subsections:
/* ------ Feature Name ------ */
Group imports by source, with import aliases:
// External libraries
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@solady/utils/SafeERC20.sol";
// Crane interfaces
import {IFacet} from "@crane/contracts/interfaces/IFacet.sol";
import {IOperable} from "@crane/contracts/access/operable/interfaces/IOperable.sol";
// Crane contracts
import {OperableRepo} from "@crane/contracts/access/operable/OperableRepo.sol";
import {OperableTarget} from "@crane/contracts/access/operable/OperableTarget.sol";
// Test utilities (in test files)
import {Test} from "forge-std/Test.sol";
import {Vm, VM_ADDRESS} from "forge-std/Vm.sol";
Defined in foundry.toml and remappings.txt:
| Alias | Path |
|-------|------|
| @crane/ | Crane framework contracts |
| @solady/ | Solady library |
| @openzeppelin/ | OpenZeppelin contracts |
| forge-std/ | Foundry test utilities |
Order functions by visibility:
| Pattern | Usage | Example |
|---------|-------|---------|
| _layout() | Storage access | _layout(), _layout(bytes32 slot_) |
| _initialize() | Storage setup | _initialize(address owner_) |
| _functionName() | Internal Repo functions | _isOperator(), _setOperator() |
| _onlyXxx() | Guard functions in Repos | _onlyOwner(), _onlyOperator() |
| onlyXxx | Modifiers | onlyOwner, onlyOperator |
| layout | Storage parameter name | Storage storage layout |
| param_ | Function parameters | owner_, slot_, name_ |
All function parameters end with underscore to avoid shadowing:
function transfer(address to_, uint256 amount_) external {
// to_ and amount_ don't shadow state variables
}
Use hierarchical dot-notation for storage slot names:
| Category | Pattern | Example |
|----------|---------|---------|
| Crane core | crane.{domain}.{feature} | "crane.access.operable" |
| Protocol integrations | protocols.{category}.{protocol}.{version}.{feature} | "protocols.dexes.balancer.v3.vault.aware" |
| EIP implementations | eip.erc.{number} | "eip.erc.8023" |
bytes32 internal constant STORAGE_SLOT = keccak256(abi.encode("crane.access.operable"));
NEVER enable via_ir or viaIR in foundry.toml.
IR compilation is forbidden because:
When encountering "stack too deep" errors, refactor using structs:
// WRONG - too many local variables
function badFunction(
address tokenA,
address tokenB,
uint256 amountA,
uint256 amountB,
address recipient,
uint256 deadline
) external {
uint256 reserveA = pair.reserveA();
uint256 reserveB = pair.reserveB();
uint256 totalSupply = pair.totalSupply();
// ... stack too deep!
}
// CORRECT - group into structs
struct DepositParams {
address tokenA;
address tokenB;
uint256 amountA;
uint256 amountB;
address recipient;
uint256 deadline;
}
struct PoolState {
uint256 reserveA;
uint256 reserveB;
uint256 totalSupply;
}
function goodFunction(DepositParams memory params) external {
PoolState memory state = PoolState({
reserveA: pair.reserveA(),
reserveB: pair.reserveB(),
totalSupply: pair.totalSupply()
});
// Struct members don't consume stack slots
}
State or Context structsmemory for computation: Struct fields don't consume stack{ ... }Standard Crane configuration:
references/complete-style-guide.md - Full style guide with more examples/contracts/StyleGuide.sol - Reference template/foundry.toml - Build configuration/remappings.txt - Import aliasesdevelopment
Review UI code for Web Interface Guidelines compliance. Use when asked to "review my UI", "check accessibility", "audit design", "review UX", or "check my site against best practices".
documentation
Write to contracts and send transactions. Use when executing state-changing contract functions.
development
HTTP and WebSocket transports for blockchain connectivity. Use when configuring network connections.
data-ai
Read contract data with type-safe ABI. Use when querying smart contract view/pure functions.