solidity-style-guide
Skill32 starsChanged 8 months agoMITView on GitHub
Apply the Aboudjem/solidity-style-guide rules to Solidity code — review, rewrite, or audit for naming, layout, formatting, NatSpec, custom errors, ERC-7201 storage, gas patterns, and Foundry test structure. Trigger when the user asks to "review Solidity style", "apply the style guide", "format .sol file", or mentions Solhint / Prettier / Foundry conventions in a Solidity repo.
The file
Show its rules and text
We split this skill into the rules it gives an agent
14 rules. About 0 are common, 4 are distinctive, and 10 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
10
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 11
Use this skill whenever you are reviewing or writing Solidity, Foundry tests, or related configuration.
- Very specific: line 50
Never ^0.8.0 ^0.9.0 or other multi-constraint forms
- Very specific: line 54
Always explicit: uint256, int256, bytes1 — never uint, int, byte
- Very specific: line 56
Prefer bytes over string when non-human-readable
- Very specific: line 83
Prefer custom errors. Use require(cond, CustomError(arg1, arg2)) when on Solidity ≥ 0.8.26 (via-ir) or ≥ 0.8.27 (legacy).
- Very specific: line 84
If a require string message is unavoidable, keep it under 32 bytes.
- Distinctive: line 87
Prefer named returns for functions with ≥ 2 return values.
- Distinctive: line 88
Prefer named arguments in calls, events, errors with ≥ 3 parameters.
- Distinctive: line 93
Avoid inline assembly unless there is no high-level alternative.
- Distinctive: line 94
Prefer composition over inheritance.
- Very specific: line 104
Test names: test_Description, testFuzz_Description, test_RevertWhen_Condition, test_RevertIf_Condition, testFork_Description, …
- Very specific: line 106
No assertions inside setUp.
- Very specific: line 112
Prefer uint256 over smaller ints unless packing is intentional
- Very specific: line 114
Use transient storage (tstore / tload, EIP-1153) for per-transaction flags like reentrancy locks when the EVM target supports it (Cancun+).
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Solidity Style Guide — Claude Code Skill
Use this skill whenever you are reviewing or writing Solidity, Foundry tests, or related configuration. It codifies the rules in Aboudjem/solidity-style-guide targeting Solidity 0.8.34.
When to invoke
Trigger automatically on:
.solfiles in the workspacefoundry.toml,remappings.txt,.solhint.jsonpresent- User says: review my contract, clean up this Solidity, apply the style guide, is this gas-optimal?, make this audit-ready
Output contract
- Produce a checklist of violations grouped by category (layout → naming → formatting → NatSpec → best practices → tests → gas → security).
- Quote the offending snippet with file path and line number.
- Propose a minimal diff that makes it compliant. Preserve behavior; style changes only unless asked.
- Cite the rule inline, e.g.,
[§Best Practices > Using Custom Errors Over Require]. - Stop before applying unless the user asked for an auto-fix.
Hard rules (block the review on violation)
Files & layout
- SPDX license identifier on every
.solfile - One contract / interface / library per file; filename matches the core type
- Top-level order: pragmas → imports → events → errors → interfaces → libraries → contracts
- Inside a contract: type declarations → state vars → events → errors → modifiers → functions
- Function order:
constructor→receive→fallback→external→public→internal→private - Within each visibility group, put
viewthenpurelast
Imports
- Named imports only:
import {X} from "./X.sol"; - Sort by path length within groups; blank line between external and internal
- No wildcard imports
Pragma
- Applications: pin to a single version —
pragma solidity 0.8.34; - Libraries / mixins: open range —
pragma solidity ^0.8.20; - Never
^0.8.0 ^0.9.0or other multi-constraint forms
Types
- Always explicit:
uint256,int256,bytes1— neveruint,int,byte boolbooleans, notuintflags- Prefer
bytesoverstringwhen non-human-readable
Naming
| Element | Style | Notes |
| Contract / Library / Interface | PascalCase | Interfaces prefixed I |
| Struct / Event / Enum / custom Error | PascalCase | Events in past tense |
| Function / modifier / variable / argument | camelCase | |
| Public constant | SNAKE_UPPER_CASE | |
| Private / internal constant | _SNAKE_UPPER_CASE | Leading _ |
| Non-external fn / state var | _leadingUnderscore | |
| Avoid | l, O, I single-letter | Visually ambiguous |
Formatting
- 4-space indent, spaces (no tabs)
- Max line length 120 chars
- Strings in double quotes
- One space around binary operators; no space inside parens / brackets
mapping(K => V)— no space aftermappinguint[]— no space before[]- Braces on same line as declaration;
elseon the same line as the closing brace - Long signature: each arg on its own line, closing
)and{on their own lines
Best practices
- Prefer custom errors. Use
require(cond, CustomError(arg1, arg2))when on Solidity ≥ 0.8.26 (via-ir) or ≥ 0.8.27 (legacy). Otherwiseif (!cond) revert CustomError(...);. - If a
requirestring message is unavoidable, keep it under 32 bytes. calldatafor read-only array / struct params onexternalfunctions.- Cache
.lengthbefore the loop header. - Prefer named returns for functions with ≥ 2 return values.
- Prefer named arguments in calls, events, errors with ≥ 3 parameters.
- Named parameters in mappings:
mapping(address user => mapping(address asset => uint256 amount)). - Interact with external contracts through typed interfaces; if using
call, useabi.encodeWithSelector. - For upgradeable contracts, use ERC-7201 namespaced storage with
@custom:storage-location erc7201:<namespace>. - Events in past tense:
OwnerUpdated,FundsDeposited. - Avoid inline assembly unless there is no high-level alternative; when used, document every opcode.
- Prefer composition over inheritance.
NatSpec
@title,@author,@notice,@dev,@param,@returnon every public / external function- Internal / library functions used by other devs: also NatSpec
Foundry testing conventions
- File naming:
MyContract.sol↔MyContract.t.sol; split large:MyContract.owner.t.sol,MyContract.deposits.t.sol - Test names:
test_Description,testFuzz_Description,test_RevertWhen_Condition,test_RevertIf_Condition,testFork_Description,testForkFuzz_RevertIf_Condition - Invariants:
invariant_Property(e.g.,invariant_TotalSupplyEqualsSumOfBalances) - No assertions inside
setUp; use a dedicatedtest_SetUpState - Verbose assertion messages:
assertEq(x, y, "Invariant violated: …")
Gas patterns
- Mark values set once as
immutable; mark compile-time values asconstant - Prefer
uint256over smaller ints unless packing is intentional - Hoist array length out of loops; use
unchecked { ++i; }where safe (Solidity ≥ 0.8.22 already optimizes simple++iincrements, butuncheckedstill helps for custom counters) - Use transient storage (
tstore/tload, EIP-1153) for per-transaction flags like reentrancy locks when the EVM target supports it (Cancun+). Solidity 0.8.34 default EVM is Prague.
Security
- Checks → Effects → Interactions
- Reentrancy guard (mutex) around any external call that precedes state writes
call{value: x}("")for Ether transfers; always check the returnedbool- No
tx.originfor authorization - Pull over push payment patterns where feasible
Invocation recipes
/solidity-style-guide:review
Scan the repo, produce a categorised violations report, do not edit.
/solidity-style-guide:review --fix
Apply the minimal formatting and naming diffs (no logic changes) and print a summary. Behavior-changing rewrites remain advisory.
/solidity-style-guide:apply-config
Copy the .solhint.json, .prettierrc, .editorconfig, and .prettierignore from this repo into the current project (do not overwrite if present without asking).
References
- README — full rule catalog with ✅ / ❌ examples
- Solidity Style Guide (official)
- Foundry Best Practices
- ERC-7201 Namespaced Storage Layout
- EIP-1153 Transient Storage Opcodes
- Coinbase Solidity Style Guide
- RareSkills Solidity Style Guide
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

