prettier-plugin-solidity 1.4.0 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/standalone.cjs +1 -1
- package/dist/standalone.cjs.map +1 -1
- package/package.json +16 -16
- package/src/nodes/ExpressionStatement.js +25 -4
- package/src/nodes/IfStatement.js +25 -10
- package/src/nodes/ImportDirective.js +9 -2
- package/src/nodes/VariableDeclaration.js +3 -0
- package/src/prettier-comments/language-js/comments.js +6 -36
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prettier-plugin-solidity",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"description": "A Prettier Plugin for automatically formatting your Solidity code.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -84,33 +84,33 @@
|
|
|
84
84
|
},
|
|
85
85
|
"homepage": "https://github.com/prettier-solidity/prettier-plugin-solidity#readme",
|
|
86
86
|
"engines": {
|
|
87
|
-
"node": ">=
|
|
87
|
+
"node": ">=18"
|
|
88
88
|
},
|
|
89
89
|
"devDependencies": {
|
|
90
|
-
"@babel/code-frame": "^7.
|
|
91
|
-
"c8": "^
|
|
90
|
+
"@babel/code-frame": "^7.26.2",
|
|
91
|
+
"c8": "^10.1.3",
|
|
92
92
|
"cross-env": "^7.0.3",
|
|
93
93
|
"eslint": "^8.47.0",
|
|
94
94
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
95
|
-
"eslint-config-prettier": "^9.
|
|
96
|
-
"eslint-plugin-import": "^2.
|
|
97
|
-
"esm-utils": "^4.
|
|
98
|
-
"esmock": "^2.
|
|
99
|
-
"jest": "^29.
|
|
95
|
+
"eslint-config-prettier": "^9.1.0",
|
|
96
|
+
"eslint-plugin-import": "^2.31.0",
|
|
97
|
+
"esm-utils": "^4.3.0",
|
|
98
|
+
"esmock": "^2.6.9",
|
|
99
|
+
"jest": "^29.7.0",
|
|
100
100
|
"jest-light-runner": "^0.6.0",
|
|
101
101
|
"jest-snapshot-serializer-ansi": "^2.1.0",
|
|
102
102
|
"jest-snapshot-serializer-raw": "^2.0.0",
|
|
103
103
|
"jest-watch-typeahead": "^2.2.2",
|
|
104
|
-
"lines-and-columns": "^2.0.
|
|
105
|
-
"prettier": "^3.
|
|
104
|
+
"lines-and-columns": "^2.0.4",
|
|
105
|
+
"prettier": "^3.3.3",
|
|
106
106
|
"proxyquire": "^2.1.3",
|
|
107
|
-
"solc": "^0.8.
|
|
108
|
-
"webpack": "^5.
|
|
109
|
-
"webpack-cli": "^
|
|
107
|
+
"solc": "^0.8.28",
|
|
108
|
+
"webpack": "^5.97.1",
|
|
109
|
+
"webpack-cli": "^6.0.1"
|
|
110
110
|
},
|
|
111
111
|
"dependencies": {
|
|
112
|
-
"@solidity-parser/parser": "^0.
|
|
113
|
-
"semver": "^7.
|
|
112
|
+
"@solidity-parser/parser": "^0.19.0",
|
|
113
|
+
"semver": "^7.6.3"
|
|
114
114
|
},
|
|
115
115
|
"peerDependencies": {
|
|
116
116
|
"prettier": ">=2.3.0"
|
|
@@ -1,6 +1,27 @@
|
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
import { printComments } from '../common/printer-helpers.js';
|
|
3
|
+
|
|
4
|
+
const { hardline } = doc.builders;
|
|
5
|
+
|
|
1
6
|
export const ExpressionStatement = {
|
|
2
|
-
print: ({ node, path, print }) =>
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
+
}
|
|
6
27
|
};
|
package/src/nodes/IfStatement.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { doc } from 'prettier';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
printComments,
|
|
4
|
+
printSeparatedItem
|
|
5
|
+
} from '../common/printer-helpers.js';
|
|
3
6
|
|
|
4
7
|
const { group, hardline, indent, line } = doc.builders;
|
|
5
8
|
|
|
@@ -19,9 +22,10 @@ const printFalseBody = (node, path, print) =>
|
|
|
19
22
|
? [' ', path.call(print, 'falseBody')]
|
|
20
23
|
: group(indent([line, path.call(print, 'falseBody')]));
|
|
21
24
|
|
|
22
|
-
const printElse = (node, path, print) => {
|
|
25
|
+
const printElse = (node, path, print, commentsBetweenIfAndElse) => {
|
|
23
26
|
if (node.falseBody) {
|
|
24
|
-
const elseOnSameLine =
|
|
27
|
+
const elseOnSameLine =
|
|
28
|
+
node.trueBody.type === 'Block' && commentsBetweenIfAndElse.length === 0;
|
|
25
29
|
return [
|
|
26
30
|
elseOnSameLine ? ' ' : hardline,
|
|
27
31
|
'else',
|
|
@@ -32,11 +36,22 @@ const printElse = (node, path, print) => {
|
|
|
32
36
|
};
|
|
33
37
|
|
|
34
38
|
export const IfStatement = {
|
|
35
|
-
print: ({ node, path, print }) =>
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
+
}
|
|
42
57
|
};
|
|
@@ -12,8 +12,15 @@ export const ImportDirective = {
|
|
|
12
12
|
let document;
|
|
13
13
|
|
|
14
14
|
if (node.unitAlias) {
|
|
15
|
-
// import
|
|
16
|
-
|
|
15
|
+
// First we look for '*' between the beginning of the import and the
|
|
16
|
+
// beginning of the importPath
|
|
17
|
+
document = options.originalText
|
|
18
|
+
.slice(options.locStart(node), options.locStart(node.pathLiteral))
|
|
19
|
+
.includes('*')
|
|
20
|
+
? // import * as Bar from "./Bar.sol";
|
|
21
|
+
['* as ', node.unitAlias, ' from ', importPath]
|
|
22
|
+
: // import "./Foo.sol" as Foo;
|
|
23
|
+
[importPath, ' as ', node.unitAlias];
|
|
17
24
|
} else if (node.symbolAliases) {
|
|
18
25
|
// import { Foo, Bar as Qux } from "./Foo.sol";
|
|
19
26
|
const compiler = coerce(options.compiler);
|
|
@@ -19,6 +19,8 @@ const storageLocation = (node) =>
|
|
|
19
19
|
|
|
20
20
|
const immutable = (node) => (node.isImmutable ? ' immutable' : '');
|
|
21
21
|
|
|
22
|
+
const transient = (node) => (node.isTransient ? ' transient' : '');
|
|
23
|
+
|
|
22
24
|
const override = (node, path, print) => {
|
|
23
25
|
if (!node.override) return '';
|
|
24
26
|
if (node.override.length === 0) return [line, 'override'];
|
|
@@ -43,6 +45,7 @@ export const VariableDeclaration = {
|
|
|
43
45
|
constantKeyword(node),
|
|
44
46
|
storageLocation(node),
|
|
45
47
|
immutable(node),
|
|
48
|
+
transient(node),
|
|
46
49
|
override(node, path, print),
|
|
47
50
|
name(node)
|
|
48
51
|
])
|
|
@@ -257,51 +257,21 @@ function handleIfStatementComments(
|
|
|
257
257
|
precedingNode === enclosingNode.trueBody &&
|
|
258
258
|
followingNode === enclosingNode.falseBody
|
|
259
259
|
) {
|
|
260
|
-
if (
|
|
261
|
-
|
|
262
|
-
addDanglingComment(followingNode, comment);
|
|
263
|
-
} else {
|
|
264
|
-
addLeadingComment(followingNode.statements[followingNode.statements.length - 1], comment);
|
|
265
|
-
}
|
|
266
|
-
} else if (followingNode.type === "IfStatement") {
|
|
267
|
-
if (followingNode.trueBody.type === "Block") {
|
|
268
|
-
if(followingNode.trueBody.statements.length === 0) {
|
|
269
|
-
addDanglingComment(followingNode.trueBody, comment);
|
|
270
|
-
} else {
|
|
271
|
-
addLeadingComment(followingNode.trueBody.statements[0], comment);
|
|
272
|
-
}
|
|
273
|
-
} else {
|
|
274
|
-
addLeadingComment(followingNode.trueBody, comment);
|
|
275
|
-
}
|
|
260
|
+
if (precedingNode.type === "ExpressionStatement") {
|
|
261
|
+
addTrailingComment(precedingNode, comment);
|
|
276
262
|
} else {
|
|
277
|
-
|
|
263
|
+
addDanglingComment(enclosingNode, comment);
|
|
278
264
|
}
|
|
279
265
|
return true;
|
|
280
266
|
}
|
|
281
267
|
|
|
282
|
-
if (
|
|
283
|
-
|
|
284
|
-
if(followingNode.statements.length === 0) {
|
|
285
|
-
addDanglingComment(followingNode, comment);
|
|
286
|
-
} else {
|
|
287
|
-
addLeadingComment(followingNode.statements[0], comment);
|
|
288
|
-
}
|
|
289
|
-
} else {
|
|
290
|
-
addLeadingComment(followingNode, comment);
|
|
291
|
-
}
|
|
268
|
+
if (followingNode.type === "ExpressionStatement") {
|
|
269
|
+
addBlockStatementFirstComment(followingNode, comment);
|
|
292
270
|
return true;
|
|
293
271
|
}
|
|
294
272
|
|
|
295
273
|
if (followingNode.type === "IfStatement") {
|
|
296
|
-
|
|
297
|
-
if(followingNode.trueBody.statements.length === 0) {
|
|
298
|
-
addDanglingComment(followingNode.trueBody, comment);
|
|
299
|
-
} else {
|
|
300
|
-
addLeadingComment(followingNode.trueBody.statements[0], comment);
|
|
301
|
-
}
|
|
302
|
-
} else {
|
|
303
|
-
addLeadingComment(followingNode.trueBody, comment);
|
|
304
|
-
}
|
|
274
|
+
addBlockOrNotComment(followingNode.trueBody, comment);
|
|
305
275
|
return true;
|
|
306
276
|
}
|
|
307
277
|
|