prettier-plugin-solidity 1.1.3 → 1.2.0
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/backward-compatibility.js +46 -0
- package/src/common/printer-helpers.js +63 -41
- package/src/common/util.js +6 -22
- 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/src/parser.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import extractComments from 'solidity-comments-extractor';
|
|
2
2
|
// https://prettier.io/docs/en/plugins.html#parsers
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import parser from '@solidity-parser/parser';
|
|
4
|
+
import coerce from 'semver/functions/coerce.js';
|
|
5
|
+
import satisfies from 'semver/functions/satisfies.js';
|
|
6
6
|
|
|
7
7
|
const tryHug = (node, operators) => {
|
|
8
8
|
if (node.type === 'BinaryOperation' && operators.includes(node.operator))
|
|
@@ -61,13 +61,6 @@ function parse(text, _parsers, options = _parsers) {
|
|
|
61
61
|
? `hex'${ctx.value.slice(4, -1)}'`
|
|
62
62
|
: `hex"${ctx.value.slice(4, -1)}"`;
|
|
63
63
|
},
|
|
64
|
-
ElementaryTypeName(ctx) {
|
|
65
|
-
// if the compiler is below 0.8.0 we will recognize the type 'byte' as an
|
|
66
|
-
// alias of 'bytes1'. Otherwise we will ignore this and enforce always
|
|
67
|
-
// 'bytes1'.
|
|
68
|
-
const pre080 = compiler && satisfies(compiler, '<0.8.0');
|
|
69
|
-
if (!pre080 && ctx.name === 'byte') ctx.name = 'bytes1';
|
|
70
|
-
},
|
|
71
64
|
BinaryOperation(ctx) {
|
|
72
65
|
switch (ctx.operator) {
|
|
73
66
|
case '+':
|
|
@@ -184,4 +177,4 @@ function parse(text, _parsers, options = _parsers) {
|
|
|
184
177
|
return parsed;
|
|
185
178
|
}
|
|
186
179
|
|
|
187
|
-
|
|
180
|
+
export default parse;
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import { util } from "prettier";
|
|
2
|
+
import { getNextNonSpaceNonCommentCharacter } from "../../common/backward-compatibility.js";
|
|
2
3
|
|
|
3
4
|
const {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} = require('prettier');
|
|
13
|
-
const { getNextNonSpaceNonCommentCharacter } = require("../../common/util");
|
|
14
|
-
|
|
15
|
-
function handleOwnLineComment(comment, text, options, ast, isLastComment) {
|
|
5
|
+
addLeadingComment,
|
|
6
|
+
addTrailingComment,
|
|
7
|
+
addDanglingComment,
|
|
8
|
+
hasNewline,
|
|
9
|
+
hasNewlineInRange
|
|
10
|
+
} = util
|
|
11
|
+
|
|
12
|
+
export function handleOwnLineComment(comment, text, options, ast, isLastComment) {
|
|
16
13
|
const { precedingNode, enclosingNode, followingNode } = comment;
|
|
17
14
|
if (
|
|
18
15
|
handleLastFunctionArgComments(
|
|
@@ -77,7 +74,7 @@ function handleOwnLineComment(comment, text, options, ast, isLastComment) {
|
|
|
77
74
|
return false;
|
|
78
75
|
}
|
|
79
76
|
|
|
80
|
-
function handleEndOfLineComment(comment, text, options, ast, isLastComment) {
|
|
77
|
+
export function handleEndOfLineComment(comment, text, options, ast, isLastComment) {
|
|
81
78
|
const { precedingNode, enclosingNode, followingNode } = comment;
|
|
82
79
|
if (
|
|
83
80
|
handleLastFunctionArgComments(
|
|
@@ -132,7 +129,7 @@ function handleEndOfLineComment(comment, text, options, ast, isLastComment) {
|
|
|
132
129
|
return false;
|
|
133
130
|
}
|
|
134
131
|
|
|
135
|
-
function handleRemainingComment(comment, text, options, ast, isLastComment) {
|
|
132
|
+
export function handleRemainingComment(comment, text, options, ast, isLastComment) {
|
|
136
133
|
const { precedingNode, enclosingNode, followingNode } = comment;
|
|
137
134
|
|
|
138
135
|
if (
|
|
@@ -834,13 +831,6 @@ function handleTSMappedTypeComments(
|
|
|
834
831
|
return false;
|
|
835
832
|
}
|
|
836
833
|
|
|
837
|
-
function isBlockComment(comment) {
|
|
834
|
+
export function isBlockComment(comment) {
|
|
838
835
|
return comment.type === "Block" || comment.type === "CommentBlock";
|
|
839
836
|
}
|
|
840
|
-
|
|
841
|
-
module.exports = {
|
|
842
|
-
handleOwnLineComment,
|
|
843
|
-
handleEndOfLineComment,
|
|
844
|
-
handleRemainingComment,
|
|
845
|
-
isBlockComment
|
|
846
|
-
};
|
package/src/printer.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import * as nodes from './nodes/index.js';
|
|
2
|
+
import {
|
|
3
3
|
hasNodeIgnoreComment,
|
|
4
4
|
prettierVersionSatisfies
|
|
5
|
-
}
|
|
6
|
-
|
|
5
|
+
} from './common/util.js';
|
|
6
|
+
import ignoreComments from './comments/ignore.js';
|
|
7
7
|
|
|
8
8
|
let checked = false;
|
|
9
9
|
|
|
10
10
|
function prettierVersionCheck() {
|
|
11
11
|
if (checked) return;
|
|
12
|
-
if (!prettierVersionSatisfies('>=2.3.0
|
|
12
|
+
if (!prettierVersionSatisfies('>=2.3.0')) {
|
|
13
13
|
throw new Error(
|
|
14
14
|
'The version of prettier in your node-modules does not satisfy the required ">=2.3.0" constraint. Please update the version of Prettier.'
|
|
15
15
|
);
|
|
@@ -41,4 +41,4 @@ function genericPrint(path, options, print) {
|
|
|
41
41
|
return nodes[node.type].print({ node, options, path, print });
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
export default genericPrint;
|