prettier-plugin-solidity 1.1.0 → 1.1.1
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.js +1 -1
- package/dist/standalone.js.map +1 -1
- package/package.json +5 -8
- package/src/clean.js +4 -6
- package/src/common/util.js +6 -1
- package/src/nodes/BinaryOperation.js +10 -4
- package/src/nodes/ExpressionStatement.js +1 -1
- package/src/nodes/FunctionDefinition.js +1 -1
- package/src/nodes/print-comments.js +29 -19
- package/src/parser.js +1 -1
- package/src/printer.js +5 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prettier-plugin-solidity",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "A Prettier Plugin for automatically formatting your Solidity code.",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"browser": "./dist/standalone.js",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"c8": "^7.12.0",
|
|
84
84
|
"cross-env": "^7.0.3",
|
|
85
85
|
"dir-to-object": "^2.0.0",
|
|
86
|
-
"eslint": "^8.
|
|
86
|
+
"eslint": "^8.30.0",
|
|
87
87
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
88
88
|
"eslint-config-prettier": "^8.5.0",
|
|
89
89
|
"eslint-plugin-import": "^2.26.0",
|
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
"jest-snapshot-serializer-raw": "^1.2.0",
|
|
96
96
|
"jest-watch-typeahead": "^2.2.1",
|
|
97
97
|
"lines-and-columns": "^2.0.3",
|
|
98
|
-
"prettier": "^
|
|
98
|
+
"prettier": "^3.0.0-alpha.4",
|
|
99
99
|
"proxyquire": "^2.1.3",
|
|
100
100
|
"solc": "^0.8.17",
|
|
101
101
|
"webpack": "^5.75.0",
|
|
@@ -103,14 +103,11 @@
|
|
|
103
103
|
},
|
|
104
104
|
"dependencies": {
|
|
105
105
|
"@solidity-parser/parser": "^0.14.5",
|
|
106
|
-
"emoji-regex": "^10.2.1",
|
|
107
|
-
"escape-string-regexp": "^4.0.0",
|
|
108
106
|
"semver": "^7.3.8",
|
|
109
|
-
"solidity-comments-extractor": "^0.0.7"
|
|
110
|
-
"string-width": "^4.2.3"
|
|
107
|
+
"solidity-comments-extractor": "^0.0.7"
|
|
111
108
|
},
|
|
112
109
|
"peerDependencies": {
|
|
113
|
-
"prettier": "
|
|
110
|
+
"prettier": ">=2.3.0 || >=3.0.0-alpha.0"
|
|
114
111
|
},
|
|
115
112
|
"browserslist": {
|
|
116
113
|
"production": [
|
package/src/clean.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
}
|
|
1
|
+
// Prettier offers a clean way to define ignored properties.
|
|
2
|
+
const ignoredProperties = new Set(['loc', 'range', 'comments']);
|
|
3
|
+
function clean(/* ast, newObj, parent */) {}
|
|
4
|
+
clean.ignoredProperties = ignoredProperties;
|
|
7
5
|
|
|
8
6
|
module.exports = clean;
|
package/src/common/util.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
const {
|
|
2
|
-
util: { getNextNonSpaceNonCommentCharacterIndex, makeString }
|
|
2
|
+
util: { getNextNonSpaceNonCommentCharacterIndex, makeString },
|
|
3
|
+
version
|
|
3
4
|
} = require('prettier');
|
|
5
|
+
const satisfies = require('semver/functions/satisfies');
|
|
6
|
+
|
|
7
|
+
const prettierVersionSatisfies = (range) => satisfies(version, range);
|
|
4
8
|
|
|
5
9
|
function getNextNonSpaceNonCommentCharacter(text, node, locEnd) {
|
|
6
10
|
return text.charAt(
|
|
@@ -55,5 +59,6 @@ function hasNodeIgnoreComment(node) {
|
|
|
55
59
|
module.exports = {
|
|
56
60
|
getNextNonSpaceNonCommentCharacter,
|
|
57
61
|
printString,
|
|
62
|
+
prettierVersionSatisfies,
|
|
58
63
|
hasNodeIgnoreComment
|
|
59
64
|
};
|
|
@@ -3,11 +3,17 @@ const printers = require('../binary-operator-printers');
|
|
|
3
3
|
|
|
4
4
|
const BinaryOperation = {
|
|
5
5
|
print: ({ node, path, print, options }) => {
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
const binaryOperationPrinter = Object.values(printers).find((printer) =>
|
|
7
|
+
printer.match(node.operator)
|
|
8
|
+
);
|
|
9
|
+
if (binaryOperationPrinter === undefined) {
|
|
10
|
+
throw new Error(
|
|
11
|
+
`Assertion error: no printer found for operator ${JSON.stringify(
|
|
12
|
+
node.operator
|
|
13
|
+
)}`
|
|
14
|
+
);
|
|
10
15
|
}
|
|
16
|
+
return binaryOperationPrinter.print(node, path, print, options);
|
|
11
17
|
}
|
|
12
18
|
};
|
|
13
19
|
|
|
@@ -15,7 +15,7 @@ const ExpressionStatement = {
|
|
|
15
15
|
if (parent.type === 'IfStatement') {
|
|
16
16
|
if (node.comments && node.comments.length) {
|
|
17
17
|
const comments = printComments(node, path, options);
|
|
18
|
-
if (comments && comments.
|
|
18
|
+
if (comments && comments.length) {
|
|
19
19
|
parts.push(comments);
|
|
20
20
|
parts.push(hardline);
|
|
21
21
|
}
|
|
@@ -3,25 +3,35 @@ const {
|
|
|
3
3
|
builders: { join, line }
|
|
4
4
|
}
|
|
5
5
|
} = require('prettier');
|
|
6
|
+
const { prettierVersionSatisfies } = require('../common/util');
|
|
6
7
|
|
|
7
|
-
const printComments = (node, path, options, filter = () => true) =>
|
|
8
|
-
node.comments
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
8
|
+
const printComments = (node, path, options, filter = () => true) => {
|
|
9
|
+
if (!node.comments) return '';
|
|
10
|
+
const doc = join(
|
|
11
|
+
line,
|
|
12
|
+
path
|
|
13
|
+
.map((commentPath) => {
|
|
14
|
+
const comment = commentPath.getValue();
|
|
15
|
+
if (comment.trailing || comment.leading || comment.printed) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
if (!filter(comment)) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
comment.printed = true;
|
|
22
|
+
return options.printer.printComment(commentPath);
|
|
23
|
+
}, 'comments')
|
|
24
|
+
.filter(Boolean)
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
// The following if statement will never be 100% covered in a single run
|
|
28
|
+
// since it depends on the version of Prettier being used.
|
|
29
|
+
// Mocking the behaviour will introduce a lot of maintenance in the tests.
|
|
30
|
+
/* c8 ignore start */
|
|
31
|
+
return prettierVersionSatisfies('^2.3.0')
|
|
32
|
+
? doc.parts // Prettier V2
|
|
33
|
+
: doc; // Prettier V3
|
|
34
|
+
/* c8 ignore stop */
|
|
35
|
+
};
|
|
26
36
|
|
|
27
37
|
module.exports = printComments;
|
package/src/parser.js
CHANGED
|
@@ -14,7 +14,7 @@ const tryHug = (node, operators) => {
|
|
|
14
14
|
return node;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
function parse(text, _parsers, options) {
|
|
17
|
+
function parse(text, _parsers, options = _parsers) {
|
|
18
18
|
const compiler = coerce(options.compiler);
|
|
19
19
|
const parsed = parser.parse(text, { loc: true, range: true });
|
|
20
20
|
parsed.comments = extractComments(text);
|
package/src/printer.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
const prettier = require('prettier');
|
|
2
|
-
const satisfies = require('semver/functions/satisfies');
|
|
3
1
|
const nodes = require('./nodes');
|
|
4
|
-
const {
|
|
2
|
+
const {
|
|
3
|
+
hasNodeIgnoreComment,
|
|
4
|
+
prettierVersionSatisfies
|
|
5
|
+
} = require('./common/util');
|
|
5
6
|
const ignoreComments = require('./comments/ignore');
|
|
6
7
|
|
|
7
8
|
let checked = false;
|
|
8
9
|
|
|
9
10
|
function prettierVersionCheck() {
|
|
10
11
|
if (checked) return;
|
|
11
|
-
if (!
|
|
12
|
+
if (!prettierVersionSatisfies('>=2.3.0 || >=3.0.0-alpha.0')) {
|
|
12
13
|
throw new Error(
|
|
13
14
|
'The version of prettier in your node-modules does not satisfy the required ">=2.3.0" constraint. Please update the version of Prettier.'
|
|
14
15
|
);
|