prettier-plugin-solidity 1.1.3 → 1.1.4-dev
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/README.md +48 -9
- package/dist/standalone.cjs +3 -0
- package/dist/standalone.cjs.map +1 -0
- package/package.json +42 -33
- package/src/binary-operator-printers/arithmetic.js +12 -14
- package/src/binary-operator-printers/assignment.js +4 -6
- package/src/binary-operator-printers/bit.js +2 -2
- package/src/binary-operator-printers/comparison.js +11 -13
- package/src/binary-operator-printers/exponentiation.js +4 -6
- package/src/binary-operator-printers/index.js +7 -13
- package/src/binary-operator-printers/logical.js +12 -14
- package/src/binary-operator-printers/shift.js +2 -2
- package/src/clean.js +1 -1
- package/src/comments/handler.js +7 -15
- package/src/comments/handlers/handleContractDefinitionComments.js +9 -11
- package/src/comments/handlers/handleModifierInvocationComments.js +9 -11
- package/src/comments/handlers/index.js +5 -3
- package/src/comments/ignore.js +1 -1
- package/src/comments/index.js +2 -4
- package/src/comments/printer.js +5 -10
- package/src/common/printer-helpers.js +15 -28
- package/src/common/util.js +30 -20
- package/src/index.js +14 -12
- package/src/loc.js +1 -1
- package/src/nodes/ArrayTypeName.js +1 -3
- package/src/nodes/AssemblyAssignment.js +4 -8
- package/src/nodes/AssemblyBlock.js +6 -11
- package/src/nodes/AssemblyCall.js +2 -4
- package/src/nodes/AssemblyCase.js +1 -3
- package/src/nodes/AssemblyFor.js +4 -8
- package/src/nodes/AssemblyFunctionDefinition.js +6 -11
- package/src/nodes/AssemblyIf.js +1 -3
- package/src/nodes/AssemblyLocalDefinition.js +4 -9
- package/src/nodes/AssemblyMemberAccess.js +1 -3
- package/src/nodes/AssemblyStackAssignment.js +1 -3
- package/src/nodes/AssemblySwitch.js +4 -8
- package/src/nodes/BinaryOperation.js +2 -5
- package/src/nodes/Block.js +6 -11
- package/src/nodes/BooleanLiteral.js +1 -3
- package/src/nodes/Break.js +1 -3
- package/src/nodes/BreakStatement.js +1 -3
- package/src/nodes/CatchClause.js +2 -4
- package/src/nodes/Conditional.js +4 -8
- package/src/nodes/Continue.js +1 -3
- package/src/nodes/ContinueStatement.js +1 -3
- package/src/nodes/ContractDefinition.js +11 -17
- package/src/nodes/CustomErrorDefinition.js +2 -4
- package/src/nodes/DecimalNumber.js +1 -3
- package/src/nodes/DoWhileStatement.js +4 -9
- package/src/nodes/ElementaryTypeName.js +1 -3
- package/src/nodes/EmitStatement.js +1 -3
- package/src/nodes/EnumDefinition.js +4 -9
- package/src/nodes/EnumValue.js +1 -3
- package/src/nodes/EventDefinition.js +2 -4
- package/src/nodes/ExpressionStatement.js +4 -9
- package/src/nodes/FileLevelConstant.js +1 -3
- package/src/nodes/ForStatement.js +4 -9
- package/src/nodes/FunctionCall.js +4 -9
- package/src/nodes/FunctionDefinition.js +11 -18
- package/src/nodes/FunctionTypeName.js +4 -9
- package/src/nodes/HexLiteral.js +4 -9
- package/src/nodes/HexNumber.js +1 -3
- package/src/nodes/Identifier.js +1 -3
- package/src/nodes/IfStatement.js +6 -11
- package/src/nodes/ImportDirective.js +12 -17
- package/src/nodes/IndexAccess.js +4 -8
- package/src/nodes/IndexRangeAccess.js +1 -3
- package/src/nodes/InheritanceSpecifier.js +2 -4
- package/src/nodes/InlineAssemblyStatement.js +3 -4
- package/src/nodes/LabelDefinition.js +4 -8
- package/src/nodes/Mapping.js +17 -18
- package/src/nodes/MemberAccess.js +6 -10
- package/src/nodes/ModifierDefinition.js +4 -9
- package/src/nodes/ModifierInvocation.js +3 -5
- package/src/nodes/NameValueExpression.js +1 -3
- package/src/nodes/NameValueList.js +4 -9
- package/src/nodes/NewExpression.js +1 -3
- package/src/nodes/NumberLiteral.js +1 -3
- package/src/nodes/PragmaDirective.js +1 -3
- package/src/nodes/ReturnStatement.js +4 -8
- package/src/nodes/RevertStatement.js +1 -3
- package/src/nodes/SourceUnit.js +4 -9
- package/src/nodes/StateVariableDeclaration.js +4 -8
- package/src/nodes/StringLiteral.js +5 -9
- package/src/nodes/StructDefinition.js +13 -22
- package/src/nodes/ThrowStatement.js +1 -3
- package/src/nodes/TryStatement.js +6 -11
- package/src/nodes/TupleExpression.js +4 -9
- package/src/nodes/TypeDefinition.js +1 -3
- package/src/nodes/UnaryOperation.js +1 -3
- package/src/nodes/UncheckedStatement.js +4 -8
- package/src/nodes/UserDefinedTypeName.js +1 -3
- package/src/nodes/UsingForDeclaration.js +28 -44
- package/src/nodes/VariableDeclaration.js +4 -9
- package/src/nodes/VariableDeclarationStatement.js +6 -11
- package/src/nodes/WhileStatement.js +4 -9
- package/src/nodes/index.js +72 -78
- package/src/options.js +1 -1
- package/src/parser.js +5 -12
- package/src/prettier-comments/language-js/comments.js +13 -23
- package/src/printer.js +6 -6
- package/dist/standalone.js +0 -3
- package/dist/standalone.js.map +0 -1
- package/src/prettier-comments/index.js +0 -3
- /package/dist/{standalone.js.LICENSE.txt → standalone.cjs.LICENSE.txt} +0 -0
package/package.json
CHANGED
|
@@ -1,28 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prettier-plugin-solidity",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4-dev",
|
|
4
4
|
"description": "A Prettier Plugin for automatically formatting your Solidity code.",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "./src/index.js",
|
|
6
|
-
"browser": "./dist/standalone.
|
|
7
|
-
"unpkg": "./dist/standalone.
|
|
7
|
+
"browser": "./dist/standalone.cjs",
|
|
8
|
+
"unpkg": "./dist/standalone.cjs",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./src/index.js",
|
|
12
|
+
"require": "./dist/standalone.cjs"
|
|
13
|
+
},
|
|
14
|
+
"./standalone": {
|
|
15
|
+
"default": "./dist/standalone.cjs"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
8
18
|
"scripts": {
|
|
9
19
|
"build": "webpack --env production",
|
|
10
20
|
"build:dev": "webpack --env development",
|
|
11
|
-
"
|
|
12
|
-
"
|
|
21
|
+
"build:test": "webpack --config test.config.js",
|
|
22
|
+
"eslint": "eslint 'src/**' 'tests/**'",
|
|
13
23
|
"lint": "npm run eslint && npm run prettier -- --list-different",
|
|
14
24
|
"lint:fix": "npm run eslint -- --fix && npm run prettier -- --write",
|
|
15
25
|
"prepublishOnly": "npm run build",
|
|
16
|
-
"prettier": "prettier './*.{js,json,md,yml}' '{
|
|
17
|
-
"test": "jest",
|
|
18
|
-
"test:all": "cross-env FULL_TEST=1 c8 jest",
|
|
26
|
+
"prettier": "prettier './*.{js,json,md,yml}' '{src,tests}/**/*.js'",
|
|
27
|
+
"test": "NODE_OPTIONS=--loader=esmock jest",
|
|
28
|
+
"test:all": "cross-env FULL_TEST=1 NODE_OPTIONS=--loader=esmock c8 jest",
|
|
19
29
|
"test:standalone": "cross-env TEST_STANDALONE=1 FULL_TEST=1 jest"
|
|
20
30
|
},
|
|
21
31
|
"files": [
|
|
22
32
|
"src",
|
|
23
|
-
"dist
|
|
24
|
-
"dist/standalone.js.LICENSE.txt",
|
|
25
|
-
"dist/standalone.js.map",
|
|
33
|
+
"dist/**/*",
|
|
26
34
|
"LICENSE",
|
|
27
35
|
"README.md"
|
|
28
36
|
],
|
|
@@ -76,43 +84,44 @@
|
|
|
76
84
|
},
|
|
77
85
|
"homepage": "https://github.com/prettier-solidity/prettier-plugin-solidity#readme",
|
|
78
86
|
"engines": {
|
|
79
|
-
"node": ">=
|
|
87
|
+
"node": ">=16"
|
|
80
88
|
},
|
|
81
89
|
"devDependencies": {
|
|
82
|
-
"@babel/code-frame": "^7.
|
|
83
|
-
"c8": "^
|
|
90
|
+
"@babel/code-frame": "^7.22.10",
|
|
91
|
+
"c8": "^8.0.1",
|
|
84
92
|
"cross-env": "^7.0.3",
|
|
85
|
-
"
|
|
86
|
-
"eslint": "^8.31.0",
|
|
93
|
+
"eslint": "^8.47.0",
|
|
87
94
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
88
|
-
"eslint-config-prettier": "^
|
|
89
|
-
"eslint-plugin-import": "^2.
|
|
95
|
+
"eslint-config-prettier": "^9.0.0",
|
|
96
|
+
"eslint-plugin-import": "^2.28.1",
|
|
97
|
+
"esm-utils": "^4.1.2",
|
|
98
|
+
"esmock": "^2.3.8",
|
|
90
99
|
"exports-loader": "^4.0.0",
|
|
91
|
-
"jest": "^29.3
|
|
92
|
-
"jest-light-runner": "^0.
|
|
93
|
-
"jest-
|
|
94
|
-
"jest-snapshot-serializer-
|
|
95
|
-
"jest-
|
|
96
|
-
"jest-watch-typeahead": "^2.2.1",
|
|
100
|
+
"jest": "^29.6.3",
|
|
101
|
+
"jest-light-runner": "^0.5.0",
|
|
102
|
+
"jest-snapshot-serializer-ansi": "^2.1.0",
|
|
103
|
+
"jest-snapshot-serializer-raw": "^2.0.0",
|
|
104
|
+
"jest-watch-typeahead": "^2.2.2",
|
|
97
105
|
"lines-and-columns": "^2.0.3",
|
|
98
|
-
"prettier": "^
|
|
106
|
+
"prettier": "^3.0.2",
|
|
99
107
|
"proxyquire": "^2.1.3",
|
|
100
|
-
"solc": "^0.8.
|
|
101
|
-
"webpack": "^5.
|
|
102
|
-
"webpack-cli": "^5.
|
|
108
|
+
"solc": "^0.8.21",
|
|
109
|
+
"webpack": "^5.88.2",
|
|
110
|
+
"webpack-cli": "^5.1.4"
|
|
103
111
|
},
|
|
104
112
|
"dependencies": {
|
|
105
|
-
"@solidity-parser/parser": "^0.16.
|
|
106
|
-
"semver": "^7.
|
|
113
|
+
"@solidity-parser/parser": "^0.16.1",
|
|
114
|
+
"semver": "^7.5.4",
|
|
107
115
|
"solidity-comments-extractor": "^0.0.7"
|
|
108
116
|
},
|
|
109
117
|
"peerDependencies": {
|
|
110
|
-
"prettier": ">=2.3.0
|
|
118
|
+
"prettier": ">=2.3.0"
|
|
111
119
|
},
|
|
112
120
|
"browserslist": {
|
|
113
121
|
"production": [
|
|
114
|
-
">0.
|
|
115
|
-
"not
|
|
122
|
+
">0.5%",
|
|
123
|
+
"not ie 11",
|
|
124
|
+
"not safari 5.1",
|
|
116
125
|
"not op_mini all"
|
|
117
126
|
],
|
|
118
127
|
"development": [
|
|
@@ -1,38 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} = require('prettier');
|
|
6
|
-
const comparison = require('./comparison');
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
import { comparison } from './comparison.js';
|
|
3
|
+
|
|
4
|
+
const { group, line, indent } = doc.builders;
|
|
7
5
|
|
|
8
|
-
const groupIfNecessaryBuilder = (path) => (
|
|
6
|
+
const groupIfNecessaryBuilder = (path) => (document) => {
|
|
9
7
|
const parentNode = path.getParentNode();
|
|
10
8
|
if (
|
|
11
9
|
parentNode.type === 'BinaryOperation' &&
|
|
12
10
|
!comparison.match(parentNode.operator)
|
|
13
11
|
) {
|
|
14
|
-
return
|
|
12
|
+
return document;
|
|
15
13
|
}
|
|
16
|
-
return group(
|
|
14
|
+
return group(document);
|
|
17
15
|
};
|
|
18
16
|
|
|
19
|
-
const indentIfNecessaryBuilder = (path) => (
|
|
17
|
+
const indentIfNecessaryBuilder = (path) => (document) => {
|
|
20
18
|
let node = path.getNode();
|
|
21
19
|
for (let i = 0; ; i += 1) {
|
|
22
20
|
const parentNode = path.getParentNode(i);
|
|
23
|
-
if (parentNode.type === 'ReturnStatement') return
|
|
21
|
+
if (parentNode.type === 'ReturnStatement') return document;
|
|
24
22
|
if (
|
|
25
23
|
parentNode.type !== 'BinaryOperation' ||
|
|
26
24
|
comparison.match(parentNode.operator)
|
|
27
25
|
) {
|
|
28
|
-
return indent(
|
|
26
|
+
return indent(document);
|
|
29
27
|
}
|
|
30
|
-
if (node === parentNode.right) return
|
|
28
|
+
if (node === parentNode.right) return document;
|
|
31
29
|
node = parentNode;
|
|
32
30
|
}
|
|
33
31
|
};
|
|
34
32
|
|
|
35
|
-
|
|
33
|
+
export const arithmetic = {
|
|
36
34
|
match: (op) => ['+', '-', '*', '/', '%'].includes(op),
|
|
37
35
|
print: (node, path, print) => {
|
|
38
36
|
const groupIfNecessary = groupIfNecessaryBuilder(path);
|
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
} = require('prettier');
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
|
|
3
|
+
const { group, indent, line } = doc.builders;
|
|
6
4
|
|
|
7
|
-
const indentIfNecessaryBuilder = (path) => (
|
|
5
|
+
const indentIfNecessaryBuilder = (path) => (document) => {
|
|
8
6
|
let node = path.getNode();
|
|
9
7
|
for (let i = 0; ; i += 1) {
|
|
10
8
|
const parentNode = path.getParentNode(i);
|
|
11
|
-
if (parentNode.type === 'ReturnStatement') return
|
|
12
|
-
if (parentNode.type === 'IfStatement') return
|
|
13
|
-
if (parentNode.type === 'ForStatement') return
|
|
14
|
-
if (parentNode.type === 'WhileStatement') return
|
|
15
|
-
if (parentNode.type !== 'BinaryOperation') return indent(
|
|
16
|
-
if (node === parentNode.right) return
|
|
9
|
+
if (parentNode.type === 'ReturnStatement') return document;
|
|
10
|
+
if (parentNode.type === 'IfStatement') return document;
|
|
11
|
+
if (parentNode.type === 'ForStatement') return document;
|
|
12
|
+
if (parentNode.type === 'WhileStatement') return document;
|
|
13
|
+
if (parentNode.type !== 'BinaryOperation') return indent(document);
|
|
14
|
+
if (node === parentNode.right) return document;
|
|
17
15
|
node = parentNode;
|
|
18
16
|
}
|
|
19
17
|
};
|
|
20
18
|
|
|
21
|
-
|
|
19
|
+
export const comparison = {
|
|
22
20
|
match: (op) => ['<', '>', '<=', '>=', '==', '!='].includes(op),
|
|
23
21
|
print: (node, path, print) => {
|
|
24
22
|
const indentIfNecessary = indentIfNecessaryBuilder(path);
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
} = require('prettier');
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
|
|
3
|
+
const { group, indent, line } = doc.builders;
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
export const exponentiation = {
|
|
8
6
|
match: (op) => op === '**',
|
|
9
7
|
print: (node, path, print) => {
|
|
10
8
|
const right = [' ', node.operator, line, path.call(print, 'right')];
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
bit: require('./bit'),
|
|
9
|
-
comparison: require('./comparison'),
|
|
10
|
-
exponentiation: require('./exponentiation'),
|
|
11
|
-
logical: require('./logical'),
|
|
12
|
-
shift: require('./shift')
|
|
13
|
-
};
|
|
1
|
+
export * from './arithmetic.js';
|
|
2
|
+
export * from './assignment.js';
|
|
3
|
+
export * from './bit.js';
|
|
4
|
+
export * from './comparison.js';
|
|
5
|
+
export * from './exponentiation.js';
|
|
6
|
+
export * from './logical.js';
|
|
7
|
+
export * from './shift.js';
|
|
@@ -1,26 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
} = require('prettier');
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
|
|
3
|
+
const { group, line, indent } = doc.builders;
|
|
6
4
|
|
|
7
|
-
const groupIfNecessaryBuilder = (path) => (
|
|
8
|
-
path.getParentNode().type === 'BinaryOperation' ?
|
|
5
|
+
const groupIfNecessaryBuilder = (path) => (document) =>
|
|
6
|
+
path.getParentNode().type === 'BinaryOperation' ? document : group(document);
|
|
9
7
|
|
|
10
|
-
const indentIfNecessaryBuilder = (path) => (
|
|
8
|
+
const indentIfNecessaryBuilder = (path) => (document) => {
|
|
11
9
|
let node = path.getNode();
|
|
12
10
|
for (let i = 0; ; i += 1) {
|
|
13
11
|
const parentNode = path.getParentNode(i);
|
|
14
|
-
if (parentNode.type === 'ReturnStatement') return
|
|
15
|
-
if (parentNode.type === 'IfStatement') return
|
|
16
|
-
if (parentNode.type === 'WhileStatement') return
|
|
17
|
-
if (parentNode.type !== 'BinaryOperation') return indent(
|
|
18
|
-
if (node === parentNode.right) return
|
|
12
|
+
if (parentNode.type === 'ReturnStatement') return document;
|
|
13
|
+
if (parentNode.type === 'IfStatement') return document;
|
|
14
|
+
if (parentNode.type === 'WhileStatement') return document;
|
|
15
|
+
if (parentNode.type !== 'BinaryOperation') return indent(document);
|
|
16
|
+
if (node === parentNode.right) return document;
|
|
19
17
|
node = parentNode;
|
|
20
18
|
}
|
|
21
19
|
};
|
|
22
20
|
|
|
23
|
-
|
|
21
|
+
export const logical = {
|
|
24
22
|
match: (op) => ['&&', '||'].includes(op),
|
|
25
23
|
print: (node, path, print) => {
|
|
26
24
|
const groupIfNecessary = groupIfNecessaryBuilder(path);
|
package/src/clean.js
CHANGED
package/src/comments/handler.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import {
|
|
2
2
|
handleOwnLineComment,
|
|
3
3
|
handleEndOfLineComment,
|
|
4
4
|
handleRemainingComment
|
|
5
|
-
}
|
|
5
|
+
} from '../prettier-comments/language-js/comments.js';
|
|
6
|
+
import handlers from './handlers/index.js';
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
function solidityHandleOwnLineComment(
|
|
8
|
+
export function solidityHandleOwnLineComment(
|
|
10
9
|
comment,
|
|
11
10
|
text,
|
|
12
11
|
options,
|
|
@@ -32,7 +31,7 @@ function solidityHandleOwnLineComment(
|
|
|
32
31
|
return false;
|
|
33
32
|
}
|
|
34
33
|
|
|
35
|
-
function solidityHandleEndOfLineComment(
|
|
34
|
+
export function solidityHandleEndOfLineComment(
|
|
36
35
|
comment,
|
|
37
36
|
text,
|
|
38
37
|
options,
|
|
@@ -58,7 +57,7 @@ function solidityHandleEndOfLineComment(
|
|
|
58
57
|
return false;
|
|
59
58
|
}
|
|
60
59
|
|
|
61
|
-
function solidityHandleRemainingComment(
|
|
60
|
+
export function solidityHandleRemainingComment(
|
|
62
61
|
comment,
|
|
63
62
|
text,
|
|
64
63
|
options,
|
|
@@ -84,13 +83,6 @@ function solidityHandleRemainingComment(
|
|
|
84
83
|
return false;
|
|
85
84
|
}
|
|
86
85
|
|
|
87
|
-
function isBlockComment(comment) {
|
|
86
|
+
export function isBlockComment(comment) {
|
|
88
87
|
return comment.type === 'BlockComment';
|
|
89
88
|
}
|
|
90
|
-
|
|
91
|
-
module.exports = {
|
|
92
|
-
handleOwnLineComment: solidityHandleOwnLineComment,
|
|
93
|
-
handleEndOfLineComment: solidityHandleEndOfLineComment,
|
|
94
|
-
handleRemainingComment: solidityHandleRemainingComment,
|
|
95
|
-
isBlockComment
|
|
96
|
-
};
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
addDanglingComment,
|
|
6
|
-
getNextNonSpaceNonCommentCharacterIndex
|
|
7
|
-
}
|
|
8
|
-
} = require('prettier');
|
|
1
|
+
import { util } from 'prettier';
|
|
2
|
+
import { getNextNonSpaceNonCommentCharacter } from '../../common/util.js';
|
|
3
|
+
|
|
4
|
+
const { addLeadingComment, addTrailingComment, addDanglingComment } = util;
|
|
9
5
|
|
|
10
6
|
function handleContractDefinitionComments({
|
|
11
7
|
text,
|
|
@@ -24,8 +20,10 @@ function handleContractDefinitionComments({
|
|
|
24
20
|
// contract a is abc /* comment */ {}
|
|
25
21
|
// The only workaround I found is to look at the next character to see if
|
|
26
22
|
// it is a {}.
|
|
27
|
-
const nextCharacter =
|
|
28
|
-
|
|
23
|
+
const nextCharacter = getNextNonSpaceNonCommentCharacter(
|
|
24
|
+
text,
|
|
25
|
+
comment,
|
|
26
|
+
options.locEnd
|
|
29
27
|
);
|
|
30
28
|
|
|
31
29
|
// The comment is behind the start of the Block `{}` or behind a base contract
|
|
@@ -57,4 +55,4 @@ function handleContractDefinitionComments({
|
|
|
57
55
|
return false;
|
|
58
56
|
}
|
|
59
57
|
|
|
60
|
-
|
|
58
|
+
export default handleContractDefinitionComments;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
addDanglingComment,
|
|
6
|
-
getNextNonSpaceNonCommentCharacterIndex
|
|
7
|
-
}
|
|
8
|
-
} = require('prettier');
|
|
1
|
+
import { util } from 'prettier';
|
|
2
|
+
import { getNextNonSpaceNonCommentCharacter } from '../../common/util.js';
|
|
3
|
+
|
|
4
|
+
const { addLeadingComment, addTrailingComment, addDanglingComment } = util;
|
|
9
5
|
|
|
10
6
|
function handleModifierInvocationComments({
|
|
11
7
|
text,
|
|
@@ -23,8 +19,10 @@ function handleModifierInvocationComments({
|
|
|
23
19
|
// function a() public modifier /* comment 1 */ ( /* comment 2 */ ) /* comment 3 */
|
|
24
20
|
// The only workaround I found is to look at the next character to see if
|
|
25
21
|
// it is a ().
|
|
26
|
-
const nextCharacter =
|
|
27
|
-
|
|
22
|
+
const nextCharacter = getNextNonSpaceNonCommentCharacter(
|
|
23
|
+
text,
|
|
24
|
+
comment,
|
|
25
|
+
options.locEnd
|
|
28
26
|
);
|
|
29
27
|
|
|
30
28
|
// The comment is behind the start of the Parentheses `()`
|
|
@@ -66,4 +64,4 @@ function handleModifierInvocationComments({
|
|
|
66
64
|
return false;
|
|
67
65
|
}
|
|
68
66
|
|
|
69
|
-
|
|
67
|
+
export default handleModifierInvocationComments;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/* eslint-disable global-require */
|
|
2
|
+
import handleContractDefinitionComments from './handleContractDefinitionComments.js';
|
|
3
|
+
import handleModifierInvocationComments from './handleModifierInvocationComments.js';
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
export default [
|
|
6
|
+
handleContractDefinitionComments,
|
|
7
|
+
handleModifierInvocationComments
|
|
6
8
|
];
|
package/src/comments/ignore.js
CHANGED
package/src/comments/index.js
CHANGED
package/src/comments/printer.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
},
|
|
5
|
-
util: { hasNewline }
|
|
6
|
-
} = require('prettier');
|
|
1
|
+
import { doc, util } from 'prettier';
|
|
2
|
+
|
|
3
|
+
const { hardline, join } = doc.builders;
|
|
7
4
|
|
|
8
5
|
function isIndentableBlockComment(comment) {
|
|
9
6
|
// If the comment has multiple lines and every line starts with a star
|
|
@@ -31,7 +28,7 @@ function printIndentableBlockComment(comment) {
|
|
|
31
28
|
];
|
|
32
29
|
}
|
|
33
30
|
|
|
34
|
-
function printComment(commentPath, options) {
|
|
31
|
+
export function printComment(commentPath, options) {
|
|
35
32
|
const comment = commentPath.getValue();
|
|
36
33
|
|
|
37
34
|
switch (comment.type) {
|
|
@@ -43,7 +40,7 @@ function printComment(commentPath, options) {
|
|
|
43
40
|
// interleaved. See https://github.com/prettier/prettier/issues/4412
|
|
44
41
|
if (
|
|
45
42
|
comment.trailing &&
|
|
46
|
-
!hasNewline(options.originalText, options.locStart(comment), {
|
|
43
|
+
!util.hasNewline(options.originalText, options.locStart(comment), {
|
|
47
44
|
backwards: true
|
|
48
45
|
})
|
|
49
46
|
) {
|
|
@@ -60,5 +57,3 @@ function printComment(commentPath, options) {
|
|
|
60
57
|
throw new Error(`Not a comment: ${JSON.stringify(comment)}`);
|
|
61
58
|
}
|
|
62
59
|
}
|
|
63
|
-
|
|
64
|
-
module.exports = printComment;
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
builders: { group, indent, join, line, softline, hardline }
|
|
4
|
-
},
|
|
5
|
-
util: { isNextLineEmptyAfterIndex }
|
|
6
|
-
} = require('prettier');
|
|
7
|
-
const { prettierVersionSatisfies } = require('./util');
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
import { isNextLineEmpty, isPrettier2 } from './util.js';
|
|
8
3
|
|
|
9
|
-
const
|
|
4
|
+
const { group, indent, join, line, softline, hardline } = doc.builders;
|
|
5
|
+
|
|
6
|
+
export const printComments = (node, path, options, filter = () => true) => {
|
|
10
7
|
if (!node.comments) return '';
|
|
11
|
-
const
|
|
8
|
+
const document = join(
|
|
12
9
|
line,
|
|
13
10
|
path
|
|
14
11
|
.map((commentPath) => {
|
|
@@ -29,13 +26,13 @@ const printComments = (node, path, options, filter = () => true) => {
|
|
|
29
26
|
// since it depends on the version of Prettier being used.
|
|
30
27
|
// Mocking the behaviour will introduce a lot of maintenance in the tests.
|
|
31
28
|
/* c8 ignore start */
|
|
32
|
-
return
|
|
33
|
-
?
|
|
34
|
-
:
|
|
29
|
+
return isPrettier2()
|
|
30
|
+
? document.parts // Prettier V2
|
|
31
|
+
: document; // Prettier V3
|
|
35
32
|
/* c8 ignore stop */
|
|
36
33
|
};
|
|
37
34
|
|
|
38
|
-
function printPreservingEmptyLines(path, key, options, print) {
|
|
35
|
+
export function printPreservingEmptyLines(path, key, options, print) {
|
|
39
36
|
const parts = [];
|
|
40
37
|
path.each((childPath, index) => {
|
|
41
38
|
const node = childPath.getValue();
|
|
@@ -63,10 +60,7 @@ function printPreservingEmptyLines(path, key, options, print) {
|
|
|
63
60
|
parts.push(print(childPath));
|
|
64
61
|
|
|
65
62
|
if (
|
|
66
|
-
|
|
67
|
-
options.originalText,
|
|
68
|
-
options.locEnd(node) + 1
|
|
69
|
-
) ||
|
|
63
|
+
isNextLineEmpty(options.originalText, options.locEnd(node) + 1) ||
|
|
70
64
|
nodeType === 'FunctionDefinition'
|
|
71
65
|
) {
|
|
72
66
|
parts.push(hardline);
|
|
@@ -82,7 +76,7 @@ function printPreservingEmptyLines(path, key, options, print) {
|
|
|
82
76
|
|
|
83
77
|
// This function will add an indentation to the `item` and separate it from the
|
|
84
78
|
// rest of the `doc` in most cases by a `softline`.
|
|
85
|
-
const printSeparatedItem = (
|
|
79
|
+
export const printSeparatedItem = (
|
|
86
80
|
item,
|
|
87
81
|
{
|
|
88
82
|
firstSeparator = softline,
|
|
@@ -90,15 +84,15 @@ const printSeparatedItem = (
|
|
|
90
84
|
grouped = true
|
|
91
85
|
} = {}
|
|
92
86
|
) => {
|
|
93
|
-
const
|
|
94
|
-
return grouped ? group(
|
|
87
|
+
const document = [indent([firstSeparator, item]), lastSeparator];
|
|
88
|
+
return grouped ? group(document) : document;
|
|
95
89
|
};
|
|
96
90
|
|
|
97
91
|
// This function will add an indentation to the `list` and separate it from the
|
|
98
92
|
// rest of the `doc` in most cases by a `softline`.
|
|
99
93
|
// the list itself will be printed with a separator that in most cases is a
|
|
100
94
|
// comma (,) and a `line`
|
|
101
|
-
const printSeparatedList = (
|
|
95
|
+
export const printSeparatedList = (
|
|
102
96
|
list,
|
|
103
97
|
{ firstSeparator, separator = [',', line], lastSeparator, grouped } = {}
|
|
104
98
|
) =>
|
|
@@ -107,10 +101,3 @@ const printSeparatedList = (
|
|
|
107
101
|
lastSeparator,
|
|
108
102
|
grouped
|
|
109
103
|
});
|
|
110
|
-
|
|
111
|
-
module.exports = {
|
|
112
|
-
printComments,
|
|
113
|
-
printPreservingEmptyLines,
|
|
114
|
-
printSeparatedList,
|
|
115
|
-
printSeparatedItem
|
|
116
|
-
};
|