You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+71-25Lines changed: 71 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -51,6 +51,69 @@ These are some of the projects using Prettier Solidity:
51
51
-[UMA](https://umaproject.org/)
52
52
-[Uniswap](https://uniswap.org)
53
53
54
+
## Configuration File
55
+
56
+
Prettier provides a flexible system to configure the formatting rules of a project. For more information please refer to the [documentation](https://prettier.io/docs/en/configuration.html).
57
+
The following is the default configuration internally used by this plugin.
58
+
59
+
```json
60
+
{
61
+
"overrides": [
62
+
{
63
+
"files": "*.sol",
64
+
"options": {
65
+
"printWidth": 80,
66
+
"tabWidth": 4,
67
+
"useTabs": false,
68
+
"singleQuote": false,
69
+
"bracketSpacing": false,
70
+
"explicitTypes": "always"
71
+
}
72
+
}
73
+
]
74
+
}
75
+
```
76
+
77
+
Note the use of the [overrides property](https://prettier.io/docs/en/configuration.html#configuration-overrides) which allows for multiple configurations in case there are other languages in the project (i.e. JavaScript, JSON, Markdown).
78
+
79
+
Most options are described in Prettier's [documentation](https://prettier.io/docs/en/options.html).
80
+
81
+
### Explicit Types
82
+
83
+
Solidity provides the aliases `uint` and `int` for `uint256` and `int256` respectively.
84
+
Multiple developers will have different coding styles and prefer one over another.
85
+
This option was added to standardize the code across a project and enforce the usage of one alias over another.
86
+
87
+
Valid options:
88
+
89
+
-`"always"`: Prefer the explicit types `uint256`, `int256`.
90
+
-`"never"`: Prefer the type aliases `uint`, `int`.
91
+
-`"preserve"`: Respect the type used by the developer.
Note: switching between `uint` and `uint256` does not alter the bytecode at all and we have implemented tests for this. However, there will be a change in the AST reflecting the switch.
116
+
54
117
## Integrations
55
118
56
119
### Vim
@@ -100,13 +163,15 @@ Now Prettier will be run every time the file is saved.
100
163
101
164
### VSCode
102
165
103
-
VSCode is not familiar with the solidity language, so [`solidity support`](https://marketplace.visualstudio.com/items?itemName=JuanBlanco.solidity) needs to be installed.
166
+
VSCode is not familiar with the solidity language, so [`solidity`](https://marketplace.visualstudio.com/items?itemName=JuanBlanco.solidity) support needs to be installed.
104
167
105
168
```Bash
106
169
code --install-extension JuanBlanco.solidity
107
170
```
108
171
109
-
Having done that you should proceed to install [`prettier-vscode`](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode).
172
+
This extension provides basic integration with Prettier for most cases no further action is needed.
173
+
174
+
If you want more control over other details, you should proceed to install [`prettier-vscode`](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode).
110
175
111
176
```Bash
112
177
code --install-extension esbenp.prettier-vscode
@@ -118,31 +183,12 @@ To interact with 3rd party plugins, `prettier-vscode` will look in the project's
As a final check, make sure that VSCode is configured to format files on save.
122
-
123
-
You'll notice now that `prettier` is formatting every time the files are saved but the indentation is using 2 spaces instead of 4. This has been [reported](https://github.com/prettier/prettier-vscode/issues/961) and in the meantime you can use the following configuration in your `.prettierrc` file:
186
+
This will allow you to specify the version of the plugin in case you need to freeze the formatting since new versions of this plugin will implement tweaks on the possible formats.
124
187
125
-
```json
126
-
{
127
-
"overrides": [
128
-
{
129
-
"files": "*.sol",
130
-
"options": {
131
-
"printWidth": 80,
132
-
"tabWidth": 4,
133
-
"useTabs": false,
134
-
"singleQuote": false,
135
-
"bracketSpacing": false,
136
-
"explicitTypes": "always"
137
-
}
138
-
}
139
-
]
140
-
}
141
-
```
142
-
143
-
Note: When you install the npm package `prettier` in your project and create a `.prettierrc` file (which wasn't in your project before this), your VSCode's default settings or rules in `settings.json` are ignored ([prettier/prettier-vscode#1079](https://github.com/prettier/prettier-vscode/issues/1079)).
188
+
You'll have to let VSCode what formatter you prefer.
189
+
As a final check, make sure that VSCode is configured to format files on save.
144
190
145
-
If you want a different configuration for your javascript and solidity files, you can add an [overrides property](https://prettier.io/docs/en/configuration.html#configuration-overrides) to your `.prettierrc`.
191
+
Note: By design, Prettier prioritizes a local over a global configuration. If you have a `.prettierrc` file in your porject, your VSCode's default settings or rules in `settings.json` are ignored ([prettier/prettier-vscode#1079](https://github.com/prettier/prettier-vscode/issues/1079)).
0 commit comments