11# [ prettier-solidity-config] ( # )
22
3- ## Quickstart
3+ ## Quickstart
44
55``` js
66/**
7- * @file prettier.config.js
8- * @version v1.0.7
9- * @summary Prettier Configuration for Solidity
10- */
7+ * @file prettier.config.js
8+ * @version v1.0.7
9+ * @summary Prettier Configuration for Solidity
10+ */
1111
1212' use strict' ;
1313
@@ -19,7 +19,7 @@ module.exports = prettierConfig;
1919
2020Prettier configuration for Solidity
2121
22- ## Install
22+ ## Install
2323
2424#### Prettier
2525
@@ -28,6 +28,7 @@ npm i -D prettier prettier-plugin-solidity --save-exact
2828```
2929
3030#### with SolHint
31+
3132``` bash
3233npm install --save-dev solhint solhint-plugin-prettier prettier prettier-plugin-solidity --save-exact
3334```
@@ -43,26 +44,23 @@ npm install --save-dev solhint solhint-plugin-prettier prettier prettier-plugin-
4344
4445## Abstract
4546
46- This configuration is optimized to reduce ** diff churn** and improve AST results.
47+ This configuration is optimized to reduce ** diff churn** and improve AST results.
4748
48- The following rules are employed, with specific reasonings to their choice (source: airbnb style guide):
49+ The following rules are employed, with specific reasonings to their choice (source: airbnb style
50+ guide):
4951
50- ### whitespace
52+ ### whitespace
5153
5254[ source@airbnb/javascript#whitespace--in-braces] ( https://github.com/airbnb/javascript#whitespace--in-braces )
5355
5456- 19.12 Add spaces inside curly braces. eslint: object-curly-spacing
5557
5658``` jsx
59+ // bad
60+ const foo = { clark: ' kent' };
5761
58-
59-
60- // bad
61- const foo = {clark: ' kent' };
62-
63- // good
64- const foo = { clark: ' kent' };
65-
62+ // good
63+ const foo = { clark: ' kent' };
6664```
6765
6866#### arrow-parens
@@ -71,69 +69,72 @@ The following rules are employed, with specific reasonings to their choice (sour
7169
7270[ source@airbnb/javascript#arrows--one-arg-parens] ( https://github.com/airbnb/javascript#arrows--one-arg-parens )
7371
74- > Why? Minimizes diff churn when adding or removing arguments.
72+ > Why? Minimizes diff churn when adding or removing arguments.
73+
7574``` jsx
76- // bad
77- [1 , 2 , 3 ].map (x => x * x);
78-
79- // good
80- [1 , 2 , 3 ].map ((x ) => x * x);
81-
82- // bad
83- [1 , 2 , 3 ].map (number => (
84- ` A long string with the ${ number} . It’s so long that we don’t want it to take up space on the .map line!`
85- ));
86-
87- // good
88- [1 , 2 , 3 ].map ((number ) => (
89- ` A long string with the ${ number} . It’s so long that we don’t want it to take up space on the .map line!`
90- ));
91-
92- // bad
93- [1 , 2 , 3 ].map (x => {
94- const y = x + 1 ;
95- return x * y;
96- });
97-
98- // good
99- [1 , 2 , 3 ].map ((x ) => {
100- const y = x + 1 ;
101- return x * y;
102- });
75+ // bad
76+ [1 , 2 , 3 ].map ((x ) => x * x);
77+
78+ // good
79+ [1 , 2 , 3 ].map ((x ) => x * x);
80+
81+ // bad
82+ [1 , 2 , 3 ].map (
83+ (number ) =>
84+ ` A long string with the ${ number} . It’s so long that we don’t want it to take up space on the .map line!` ,
85+ );
86+
87+ // good
88+ [1 , 2 , 3 ].map (
89+ (number ) =>
90+ ` A long string with the ${ number} . It’s so long that we don’t want it to take up space on the .map line!` ,
91+ );
92+
93+ // bad
94+ [1 , 2 , 3 ].map ((x ) => {
95+ const y = x + 1 ;
96+ return x * y;
97+ });
98+
99+ // good
100+ [1 , 2 , 3 ].map ((x ) => {
101+ const y = x + 1 ;
102+ return x * y;
103+ });
103104```
104105
105106#### one var
106107
107108- 13.2 Use one const or let declaration per variable or assignment. eslint: one-var
108109
109- > Why? It’s easier to add new variable declarations this way, and you never have to worry about swapping out a ; for a ,
110- > or introducing punctuation-only diffs. You can also step through each declaration with the debugger, instead of jumping through all of them at once.
110+ > Why? It’s easier to add new variable declarations this way, and you never have to worry about
111+ > swapping out a ; for a , or introducing punctuation-only diffs. You can also step through each
112+ > declaration with the debugger, instead of jumping through all of them at once.
111113
112114##### [ ref: eslint /rules/one-var] ( https://eslint.org/docs/rules/one-var )
113115
114116``` jsx
115- // bad
116- const items = getItems (),
117- goSportsTeam = true ,
118- dragonball = ' z' ;
119-
120- // bad
121- // (compare to above, and try to spot the mistake)
122- const items = getItems (),
123- goSportsTeam = true ;
124- dragonball = ' z' ;
125-
126- // good
127- const items = getItems ();
128- const goSportsTeam = true ;
129- const dragonball = ' z' ;
117+ // bad
118+ const items = getItems (),
119+ goSportsTeam = true ,
120+ dragonball = ' z' ;
121+
122+ // bad
123+ // (compare to above, and try to spot the mistake)
124+ const items = getItems (),
125+ goSportsTeam = true ;
126+ dragonball = ' z' ;
127+
128+ // good
129+ const items = getItems ();
130+ const goSportsTeam = true ;
131+ const dragonball = ' z' ;
130132```
131133
132134#### 20.2 Additional trailing comma: Yup. eslint: comma-dangle
133135
134136 Why? This leads to cleaner git diffs. Also, transpilers like Babel will remove the additional trailing comma in the transpiled code which means you don’t have to worry about the trailing comma problem in legacy browsers.
135-
136-
137+
137138``` diff
138139// bad - git diff without trailing comma
139140const hero = {
@@ -154,19 +155,15 @@ const hero = {
154155#### 8.6 Enforce the location of arrow function bodies with implicit returns. eslint: implicit-arrow-linebreak
155156
156157``` js
157- // bad
158- (foo ) =>
159- bar;
160-
161- (foo ) =>
162- (bar);
163-
164- // good
165- (foo ) => bar;
166- (foo ) => (bar);
167- (foo ) => (
168- bar
169- )
158+ // bad
159+ (foo ) => bar;
160+
161+ (foo ) => bar;
162+
163+ // good
164+ (foo ) => bar;
165+ (foo ) => bar;
166+ (foo ) => bar;
170167```
171168
172169## License
0 commit comments