
The Solidity by Nomic Foundation extension (NomicFoundation.hardhat-solidity) v0.8.29 ships a "solidity.formatter": "forge" setting that replaces Prettier with forge fmt for .sol files — all rules come from foundry.toml [fmt], no second config file needed. The article walks through the one-line setup, the full table of 10 [fmt] options, foundry.toml auto-detection, and an honest assessment of the 8 open Foundry bugs and the quickfix-only-in-Hardhat limitation.
foundry.toml.[fmt] block that controls line length, quote style, import sorting, and eight other formatting rules. Running Prettier in parallel means maintaining two separate configs — and watching them silently disagree every time you save a file.NomicFoundation.hardhat-solidity) v0.8.29 has a formatter switch that routes all .sol formatting through forge fmt instead. 1 One config key, and VS Code's "Format Document" shortcut starts calling forge fmt using exactly the rules in your foundry.toml."solidity.formatter": "forge"Ctrl+Shift+P → Preferences: Open User Settings (JSON), or Cmd+Shift+P on macOS) and add:"solidity.formatter": "forge""prettier" (the default), "forge", and "none". 2 Setting it to "forge" makes every Save+Format or Shift+Alt+F call run forge fmt on the current file in-place."solidity.formatter": "forge",
"[solidity]": {
"editor.defaultFormatter": "NomicFoundation.hardhat-solidity"
}.prettierrc for Solidity, no extension conflict. forge fmt reads foundry.toml and formats accordingly.
.sol files — after setting "solidity.formatter": "forge", the Nomic Foundation extension handles all formatting calls. 1[fmt] controlsforge is the formatter backend, all rules come from your project's foundry.toml. The [fmt] section supports 10 options: 3| Option | Default | What it does |
|---|---|---|
line_length | 120 | Max characters per line before wrapping |
tab_width | 4 | Spaces per indentation level |
bracket_spacing | false | Space inside { and } in expression contexts |
quote_style | "double" | "single" or "double" for string literals |
sort_imports | false | Alphabetically sort import statements |
multiline_func_header | "attributes_first" | How to break long function signatures |
number_underscore | "preserve" | Underscore placement in numeric literals |
single_line_statement_blocks | "preserve" | Collapse if (x) { y; } to one line or not |
wrap_comments | false | Reflow // comment text to fit line_length |
ignore | [] | Glob patterns for files to skip formatting |
foundry.toml that sets tighter defaults than Foundry ships with:[profile.default]
src = "src"
out = "out"
libs = ["lib"]
solc_version = "0.8.28"
remappings = [
"@openzeppelin/=lib/openzeppelin-contracts/"
]
[fmt]
line_length = 80
tab_width = 2
bracket_spacing = true
quote_style = "single"
sort_imports = truefoundry.toml anywhere in the workspace. 2 Once active, the VS Code status bar shows a "Solidity" section with the project type — click it to open the config file directly.
foundry.toml. 1solc_version in [profile.default], used to run the correct solc binary for inline diagnostics (the red squiggles)remappings array in foundry.toml or from remappings.txt, used to resolve import paths for go-to-definition and autocomplete 4forge init to formatted contractcurl -L https://foundry.paradigm.xyz | bash && foundryup 5forge init my-project && cd my-projectcode . — the extension detects foundry.toml on first load"solidity.formatter": "forge" to VS Code settings JSONsrc/Counter.sol, press Shift+Alt+F — forge fmt runs and formats the fileforge build once in the terminal. That populates the compiler cache and clears the error. 6 This only affects brand-new projects before the first build; existing projects with a populated cache don't hit it.virtual/override, fix visibility) only activate for Hardhat projects. The README states this is "a limitation that will be lifted with future releases." 7node_modules, the extension scans those nested directories and can freeze VS Code or Cursor entirely. The root node_modules is correctly excluded, but nested ones aren't. 9 v0.8.27 fixed the case where Foundry projects sat inside node_modules, but the inverse (monorepo with nested node_modules) remains open.foundry.toml and a Hardhat config file, go-to-definition and autocomplete break for some imports. 8node_modules, the formatting and navigation features work reliably. If you're running a complex monorepo that mixes Hardhat and Foundry sub-projects in the same workspace, hold off.forge fmt, foundry.toml detection, remappings)
Install: NomicFoundation.hardhat-solidity on VS Code Marketplace · GitHubmarketplace.visualstudio.com
raw.githubusercontent.com
book.getfoundry.sh
book.getfoundry.sh
book.getfoundry.sh
github.com
This story was produced automatically by a channel. One sentence is all it takes for Neodrop to keep producing for you.