Skip to content

Commit 2b27e68

Browse files
authored
Necessary tweaks to the current formatting (#1033)
1 parent 0023b9d commit 2b27e68

File tree

84 files changed

+1235
-1006
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+1235
-1006
lines changed

package-lock.json

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "prettier-plugin-solidity",
3-
"version": "1.3.1",
3+
"version": "1.4.0",
44
"description": "A Prettier Plugin for automatically formatting your Solidity code.",
55
"type": "module",
66
"main": "./src/index.js",
@@ -104,7 +104,7 @@
104104
"lines-and-columns": "^2.0.3",
105105
"prettier": "^3.1.1",
106106
"proxyquire": "^2.1.3",
107-
"solc": "^0.8.25",
107+
"solc": "^0.8.26",
108108
"webpack": "^5.88.2",
109109
"webpack-cli": "^5.1.4"
110110
},

src/nodes/AssemblyBlock.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@ import {
88
const { hardline } = doc.builders;
99

1010
export const AssemblyBlock = {
11-
print: ({ node, options, path, print }) => [
12-
'{',
13-
printSeparatedItem(
14-
[
15-
printPreservingEmptyLines(path, 'operations', options, print),
16-
printComments(node, path, options)
17-
],
18-
{ firstSeparator: hardline, grouped: false }
19-
),
20-
'}'
21-
]
11+
print: ({ node, options, path, print }) =>
12+
// if block is empty, just return the pair of braces
13+
node.operations.length === 0 && !node.comments
14+
? '{}'
15+
: [
16+
'{',
17+
printSeparatedItem(
18+
[
19+
printPreservingEmptyLines(path, 'operations', options, print),
20+
printComments(node, path, options)
21+
],
22+
{ firstSeparator: hardline, grouped: false }
23+
),
24+
'}'
25+
]
2226
};
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
import { doc } from 'prettier';
2+
3+
const { hardline } = doc.builders;
4+
15
export const AssemblyStackAssignment = {
26
print: ({ node, path, print }) => [
37
path.call(print, 'expression'),
4-
' =: ',
8+
hardline,
9+
'=: ',
510
node.name
611
]
712
};

src/nodes/Conditional.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { printSeparatedItem } from '../common/printer-helpers.js';
33

44
const { group, hardline, ifBreak, indent, line, softline } = doc.builders;
55

6-
let groupIndex = 0;
76
const experimentalTernaries = (node, path, print, options) => {
87
const parent = path.getParentNode();
98
const isNested = parent.type === 'Conditional';
@@ -30,11 +29,9 @@ const experimentalTernaries = (node, path, print, options) => {
3029

3130
const conditionAndTrueExpressionGroup = group(
3231
[conditionDoc, trueExpressionDoc],
33-
{ id: `Conditional.trueExpressionDoc-${groupIndex}` }
32+
{ id: Symbol('Conditional.trueExpression') }
3433
);
3534

36-
groupIndex += 1;
37-
3835
// For the odd case of `tabWidth` of 1 or 0 we initiate `fillTab` as a single
3936
// space.
4037
let fillTab = ' ';

src/nodes/ExpressionStatement.js

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,6 @@
1-
import { doc } from 'prettier';
2-
import { printComments } from '../common/printer-helpers.js';
3-
4-
const { hardline } = doc.builders;
5-
61
export const ExpressionStatement = {
7-
print: ({ node, options, path, print }) => {
8-
const parts = [];
9-
10-
const parent = path.getParentNode();
11-
12-
if (parent.type === 'IfStatement') {
13-
if (node.comments?.length) {
14-
const comments = printComments(node, path, options);
15-
if (comments?.length) {
16-
parts.push(comments);
17-
parts.push(hardline);
18-
}
19-
}
20-
}
21-
22-
parts.push(path.call(print, 'expression'));
23-
parts.push(node.omitSemicolon ? '' : ';');
24-
25-
return parts;
26-
}
2+
print: ({ node, path, print }) => [
3+
path.call(print, 'expression'),
4+
node.omitSemicolon ? '' : ';'
5+
]
276
};

src/nodes/FunctionCall.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ const printArguments = (path, print) =>
2424
lastSeparator: [softline, ')']
2525
});
2626

27-
let groupIndex = 0;
2827
export const FunctionCall = {
2928
print: ({ node, path, print, options }) => {
3029
let expressionDoc = path.call(print, 'expression');
@@ -42,11 +41,9 @@ export const FunctionCall = {
4241
// arguments accordingly.
4342
if (expressionDoc.label === 'MemberAccessChain') {
4443
expressionDoc = group(expressionDoc.contents, {
45-
id: `FunctionCall.expression-${groupIndex}`
44+
id: Symbol('FunctionCall.expression')
4645
});
4746

48-
groupIndex += 1;
49-
5047
argumentsDoc = indentIfBreak(argumentsDoc, {
5148
groupId: expressionDoc.id
5249
});

src/nodes/FunctionTypeName.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,19 @@ const stateMutability = (node) =>
2424
: '';
2525

2626
export const FunctionTypeName = {
27-
print: ({ node, path, print }) => [
28-
'function(',
29-
printSeparatedList(path.map(print, 'parameterTypes')),
30-
')',
31-
indent(
32-
group([
33-
visibility(node),
34-
stateMutability(node),
35-
returnTypes(node, path, print)
36-
])
37-
)
38-
]
27+
print: ({ node, path, print }) =>
28+
group([
29+
'function(',
30+
printSeparatedList(path.map(print, 'parameterTypes'), {
31+
grouped: false
32+
}),
33+
')',
34+
indent(
35+
group([
36+
visibility(node),
37+
stateMutability(node),
38+
returnTypes(node, path, print)
39+
])
40+
)
41+
])
3942
};

src/nodes/HexLiteral.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { doc } from 'prettier';
22
import { printString } from '../common/util.js';
33

4-
const { join, line } = doc.builders;
4+
const { join, hardline } = doc.builders;
55

66
export const HexLiteral = {
77
print: ({ node, options }) => {
88
const list = node.parts.map((part) => `hex${printString(part, options)}`);
9-
return join(line, list);
9+
return join(hardline, list);
1010
}
1111
};

src/nodes/IfStatement.js

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { doc } from 'prettier';
2-
import {
3-
printComments,
4-
printSeparatedItem
5-
} from '../common/printer-helpers.js';
2+
import { printSeparatedItem } from '../common/printer-helpers.js';
63

74
const { group, hardline, indent, line } = doc.builders;
85

@@ -22,10 +19,9 @@ const printFalseBody = (node, path, print) =>
2219
? [' ', path.call(print, 'falseBody')]
2320
: group(indent([line, path.call(print, 'falseBody')]));
2421

25-
const printElse = (node, path, print, commentsBetweenIfAndElse) => {
22+
const printElse = (node, path, print) => {
2623
if (node.falseBody) {
27-
const elseOnSameLine =
28-
node.trueBody.type === 'Block' && commentsBetweenIfAndElse.length === 0;
24+
const elseOnSameLine = node.trueBody.type === 'Block';
2925
return [
3026
elseOnSameLine ? ' ' : hardline,
3127
'else',
@@ -36,22 +32,11 @@ const printElse = (node, path, print, commentsBetweenIfAndElse) => {
3632
};
3733

3834
export const IfStatement = {
39-
print: ({ node, options, path, print }) => {
40-
const comments = node.comments || [];
41-
const commentsBetweenIfAndElse = comments.filter(
42-
(comment) => !comment.leading && !comment.trailing
43-
);
44-
45-
const parts = [];
46-
47-
parts.push('if (', printSeparatedItem(path.call(print, 'condition')), ')');
48-
parts.push(printTrueBody(node, path, print));
49-
if (commentsBetweenIfAndElse.length && node.falseBody) {
50-
parts.push(hardline);
51-
parts.push(printComments(node, path, options));
52-
}
53-
parts.push(printElse(node, path, print, commentsBetweenIfAndElse));
54-
55-
return parts;
56-
}
35+
print: ({ node, path, print }) => [
36+
'if (',
37+
printSeparatedItem(path.call(print, 'condition')),
38+
')',
39+
printTrueBody(node, path, print),
40+
printElse(node, path, print)
41+
]
5742
};

0 commit comments

Comments
 (0)