Skip to content

Commit 64d301b

Browse files
committed
Update README
1 parent cfe9bf7 commit 64d301b

1 file changed

Lines changed: 27 additions & 51 deletions

File tree

README.md

Lines changed: 27 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@
1010

1111
A [Prettier plugin](https://prettier.io/docs/en/plugins.html) for automatically formatting your [Solidity](https://github.com/ethereum/solidity) code.
1212

13-
## Nomic Foundation's Slang
14-
15-
Nomic Foundation has put a lot of effort in providing a set of compiler APIs that helped us rethink our approach to parsing and rely on their flexibility, detail oriented solution and continuos support of new and old Solidity syntaxes.
16-
17-
Since v2.0.0 this package will ship with the Slang parser and this change must be implemented in existing configurations by replacing `parser: 'antlr'` with `parser: 'slang'`.
18-
19-
The `antlr4` parser (`antlr`) is still supported for the time being and will trigger a deprecation warning, since Slang gives us a much more powerful tool, is faster, allowed us to fully transition into typescript (minimizing the introduction of mismatching type bugs), and allows prettier to format the code in a much more decoupled way and position comments with a greater precision.
20-
2113
## Installation and usage
2214

2315
### Using in NodeJS
@@ -28,7 +20,7 @@ Install both `prettier` and `prettier-plugin-solidity`:
2820
npm install --save-dev prettier prettier-plugin-solidity
2921
```
3022

31-
> :package: ** Make sure `prettier`'s version is at least `3.0.0`**
23+
> :package: **Make sure `prettier`'s version is at least `3.0.0`**
3224
3325
Run prettier in your contracts:
3426

@@ -52,13 +44,11 @@ Or you can use it as part of your linting to check that all your code is prettif
5244
5345
### Using in the Browser
5446

55-
_Added in v1.1.0_
56-
5747
To use this package in the browser, you need to load Prettier's standalone bundle before loading the build provided in this package.
5848

5949
Prettier's unpkg field points to `https://unpkg.com/prettier/standalone.js`, in a similar way this plugin points to `https://unpkg.com/prettier-plugin-solidity/dist/standalone.js`.
6050

61-
Once the scripts are loaded you will have access the globals `prettier` and `prettierPlugins`.
51+
Once the scripts are loaded you will have access to the globals `prettier` and `prettierPlugins`.
6252

6353
We follow Prettier's strategy for populating their plugins in the object `prettierPlugins`, you can load other plugins like `https://unpkg.com/[email protected]/parser-markdown.js` and Prettier will have access to multiple parsers.
6454

@@ -73,22 +63,20 @@ We follow Prettier's strategy for populating their plugins in the object `pretti
7363
7464
async function format(code) {
7565
return await prettier.format(code, {
76-
parser: 'slang',
66+
parser: "slang",
7767
plugins: [solidityPlugin]
7868
});
7969
}
8070
81-
const originalCode = 'contract Foo {}';
71+
const originalCode = "contract Foo {}";
8272
const formattedCode = format(originalCode);
8373
</script>
8474
```
8575

86-
For more details and please have a look at [Prettier's documentation](https://prettier.io/docs/en/browser.html).
76+
For more details, have a look at [Prettier's documentation](https://prettier.io/docs/en/browser.html).
8777

8878
### Creating a package for the Browser
8979

90-
_Added in v1.2.0_
91-
9280
If you are creating your own package to be run in a browser, you might want to import the standalone files directly.
9381

9482
```Javascript
@@ -102,7 +90,7 @@ async function format(code) {
10290
});
10391
}
10492

105-
const originalCode = 'contract Foo {}';
93+
const originalCode = "contract Foo {}";
10694
const formattedCode = format(originalCode);
10795
```
10896

@@ -138,7 +126,7 @@ Most options are described in Prettier's [documentation](https://prettier.io/doc
138126

139127
### Compiler
140128

141-
Many versions of the Solidity compiler have changes that affect how the code should be formatted. This plugin, by default, tries to format the code in the most compatible way that it's possible, but you can use the `compiler` option to nudge it in the right direction.
129+
Many versions of the Solidity compiler have changes that affect how the code should be formatted. This plugin, by default, tries to format the code in the most compatible way that is possible, but you can use the `compiler` option to nudge it in the right direction.
142130

143131
One example of this is import directives. Before `0.7.4`, the compiler didn't accept multi-line import statements, so we always format them in a single line. But if you use the `compiler` option to indicate that you are using a version greater or equal than `0.7.4`, the plugin will use multi-line imports when it makes sense.
144132

@@ -218,9 +206,18 @@ You might have a multi-version project, where different files are compiled with
218206
| ------- | --------------------- | ---------------------- |
219207
| None | `--compiler <string>` | `compiler: "<string>"` |
220208

221-
### Experimental Ternaries
209+
### Parser
210+
211+
You can configure the parser used by Prettier Solidity. Two Solidity parsers are supported:
212+
213+
- [Slang](https://nomicfoundation.github.io/slang) (the default), a more powerful and correct parser that results in better formatting for some edge cases, especially when comments are involved.
214+
- [Solidity Parser for JavaScript](https://github.com/solidity-parser/parser/), an [ANTLR](https://www.antlr.org/)-based parser. This is the version that Prettier Solidity v1 used by default. This parser is still supported in v2, but it's deprecated and will be removed in the next major version. You can use this parser by setting `parser: "antlr"` in your Prettier configuration.
222215

223-
_Added in v1.3.0_
216+
| Default | CLI Override | API Override |
217+
| ------- | ------------------- | -------------------- |
218+
| `slang` | `--parser <string>` | `parser: "<string>"` |
219+
220+
### Experimental Ternaries
224221

225222
Mimicking prettier's [new ternary formatting](https://prettier.io/blog/2023/11/13/curious-ternaries) for the community to try.
226223

@@ -262,8 +259,7 @@ Plug 'prettier/vim-prettier', {
262259
\ 'solidity'] }
263260
```
264261

265-
We modified the `do` instruction to also install this plugin. Then you'll have to configure the plugin to always use the
266-
version installed in the vim plugin's directory. The vim-plug directory depends on value you use in `call plug#begin('~/.vim/<dir>')`:
262+
We modified the `do` instruction to also install this plugin. Then you'll have to configure the plugin to always use the version installed in the vim plugin's directory. The vim-plug directory depends on the value you use in `call plug#begin('~/.vim/<dir>')`:
267263

268264
```vim
269265
let g:prettier#exec_cmd_path = '~/.vim/plugged/vim-prettier/node_modules/.bin/prettier'
@@ -282,24 +278,20 @@ Now Prettier will be run every time the file is saved.
282278

283279
### VSCode
284280

285-
VSCode is not familiar with the Solidity language.
286-
There are 2 extensions that you can install to provide support for Solidity:
281+
VSCode is not familiar with the Solidity language. There are two extensions that you can install to provide support for Solidity:
287282

288-
- [`solidity`](https://marketplace.visualstudio.com/items?itemName=JuanBlanco.solidity)
289283
- [`hardhat-solidity`](https://marketplace.visualstudio.com/items?itemName=NomicFoundation.hardhat-solidity)
284+
- [`solidity`](https://marketplace.visualstudio.com/items?itemName=JuanBlanco.solidity)
285+
286+
We recommend using the `hardhat-solidity` extension:
290287

291288
```Bash
292-
code --install-extension JuanBlanco.solidity
293-
# or
294289
code --install-extension NomicFoundation.hardhat-solidity
295290
```
296291

297-
> :warning: **These 2 extensions offer similar functionality and will clash with each other**: Please choose which one matches your projects better.
298-
299292
These extensions provide basic integration with Prettier; in most cases, no further action is needed.
300293

301-
Make sure your editor has format on save set to true.
302-
When you save VSCode will ask you what formatter would you like to use for the Solidity language, you can choose `JuanBlanco.solidity` or `NomicFoundation.hardhat-solidity`.
294+
Make sure your editor has format-on-save set to true. When you save, VSCode will ask you what formatter would you like to use for the Solidity language. We recommend choosing `NomicFoundation.hardhat-solidity`.
303295

304296
At this point VSCode's `settings.json` should have a configuration similar to this:
305297

@@ -308,8 +300,7 @@ At this point VSCode's `settings.json` should have a configuration similar to th
308300
"editor.formatOnSave": true,
309301
"solidity.formatter": "prettier", // This is the default so it might be missing.
310302
"[solidity]": {
311-
// "editor.defaultFormatter": "JuanBlanco.solidity"
312-
// "editor.defaultFormatter": "NomicFoundation.hardhat-solidity"
303+
"editor.defaultFormatter": "NomicFoundation.hardhat-solidity"
313304
}
314305
}
315306
```
@@ -328,7 +319,7 @@ npm install --save-dev prettier prettier-plugin-solidity
328319

329320
This will allow you to specify the version of the plugin in case you want to use the latest version of the plugin or need to freeze the formatting since new versions of this plugin will implement tweaks on the possible formats.
330321

331-
You'll have to let VSCode what formatter you prefer.
322+
You'll have to let VSCode know what formatter you prefer.
332323
This can be done by opening the command palette and executing:
333324

334325
```
@@ -351,7 +342,7 @@ Now VSCode's `settings.json` should have this:
351342

352343
Note: By design, Prettier prioritizes a local over a global configuration. If you have a `.prettierrc` file in your project, your VSCode's default settings or rules in `settings.json` are ignored ([prettier/prettier-vscode#1079](https://github.com/prettier/prettier-vscode/issues/1079)).
353344

354-
### Pnpm
345+
### pnpm
355346

356347
To make Prettier Solidity work in your project, you have to add a `.prettierrc` file as shown [here](#configuration-file).
357348

@@ -400,21 +391,6 @@ Notice that the unnecessary parentheses in `modifier2` were removed in the funct
400391
5. Push to the branch (`git push origin feature/fooBar`)
401392
6. Create a new Pull Request
402393

403-
## Who's using it?
404-
405-
These are some of the projects using Prettier Solidity:
406-
407-
- [Bancor](https://app.bancor.network)
408-
- [Gelato](https://gelato.network/)
409-
- [Gnosis Protocol](https://docs.gnosis.io/protocol/)
410-
- [PieDAO](https://www.piedao.org/)
411-
- [Sablier](https://sablier.finance/)
412-
- [Synthetix](https://www.synthetix.io)
413-
- [The Sandbox](https://www.sandbox.game/en/)
414-
- [UMA](https://umaproject.org/)
415-
- [Uniswap](https://uniswap.org)
416-
- [Zora](https://zora.co)
417-
418394
## License
419395

420396
Distributed under the MIT license. See [LICENSE](LICENSE) for more information.

0 commit comments

Comments
 (0)