Skip to content

Commit 33368a1

Browse files
authored
Merge pull request #392 from prettier-solidity/change-comments-extractor
Use solidity-comments-extractor
2 parents f3a25da + bdd2b9c commit 33368a1

5 files changed

Lines changed: 52 additions & 27 deletions

File tree

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@
7575
"dir-to-object": "^2.0.0",
7676
"emoji-regex": "^9.0.0",
7777
"escape-string-regexp": "^4.0.0",
78-
"extract-comments": "^1.1.0",
7978
"prettier": "^2.0.5",
8079
"semver": "^7.3.2",
80+
"solidity-comments-extractor": "^0.0.4",
8181
"string-width": "^4.2.0"
8282
}
8383
}

src/parser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const extract = require('extract-comments');
1+
const extractComments = require('solidity-comments-extractor');
22
// https://prettier.io/docs/en/plugins.html#parsers
33
const parser = require('@solidity-parser/parser');
44

@@ -14,7 +14,7 @@ const tryHug = (node, operators) => {
1414

1515
function parse(text, parsers, options) {
1616
const parsed = parser.parse(text, { loc: true, range: true });
17-
parsed.comments = extract(text);
17+
parsed.comments = extractComments(text);
1818

1919
parser.visit(parsed, {
2020
ForStatement(ctx) {

tests/Issues/Issue355.sol

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
pragma solidity 0.6.12;
2+
3+
contract Bug {
4+
// This is a comment
5+
uint public hello;
6+
7+
// Another comment
8+
uint public bigNum = 100_000;
9+
10+
// This will disappear
11+
uint public magic;
12+
}

tests/Issues/__snapshots__/jsfmt.spec.js.snap

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,35 @@ contract Issue289 {
5151
5252
`;
5353

54+
exports[`Issue355.sol 1`] = `
55+
pragma solidity 0.6.12;
56+
57+
contract Bug {
58+
// This is a comment
59+
uint public hello;
60+
61+
// Another comment
62+
uint public bigNum = 100_000;
63+
64+
// This will disappear
65+
uint public magic;
66+
}
67+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
68+
pragma solidity 0.6.12;
69+
70+
contract Bug {
71+
// This is a comment
72+
uint256 public hello;
73+
74+
// Another comment
75+
uint256 public bigNum = 100_000;
76+
77+
// This will disappear
78+
uint256 public magic;
79+
}
80+
81+
`;
82+
5483
exports[`Issue385.sol 1`] = `
5584
contract Issue385 {
5685
function emptyTryCatch() {

0 commit comments

Comments
 (0)