prettier-plugin-solidity 1.4.1 → 1.4.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prettier-plugin-solidity",
3
- "version": "1.4.1",
3
+ "version": "1.4.3",
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": ">=16"
87
+ "node": ">=18"
88
88
  },
89
89
  "devDependencies": {
90
- "@babel/code-frame": "^7.22.10",
91
- "c8": "^9.0.0",
90
+ "@babel/code-frame": "^7.26.2",
91
+ "c8": "^10.1.3",
92
92
  "cross-env": "^7.0.3",
93
- "eslint": "^8.47.0",
93
+ "eslint": "^8.57.1",
94
94
  "eslint-config-airbnb-base": "^15.0.0",
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",
99
- "jest": "^29.6.3",
100
- "jest-light-runner": "^0.6.0",
101
- "jest-snapshot-serializer-ansi": "^2.1.0",
95
+ "eslint-config-prettier": "^10.1.2",
96
+ "eslint-plugin-import": "^2.31.0",
97
+ "esm-utils": "^4.3.0",
98
+ "esmock": "^2.7.0",
99
+ "jest": "^29.7.0",
100
+ "jest-light-runner": "^0.7.8",
101
+ "jest-snapshot-serializer-ansi": "^2.2.1",
102
102
  "jest-snapshot-serializer-raw": "^2.0.0",
103
103
  "jest-watch-typeahead": "^2.2.2",
104
- "lines-and-columns": "^2.0.3",
105
- "prettier": "^3.1.1",
104
+ "lines-and-columns": "^2.0.4",
105
+ "prettier": "^3.5.3",
106
106
  "proxyquire": "^2.1.3",
107
- "solc": "^0.8.26",
108
- "webpack": "^5.88.2",
109
- "webpack-cli": "^5.1.4"
107
+ "solc": "^0.8.29",
108
+ "webpack": "^5.99.7",
109
+ "webpack-cli": "^6.0.1"
110
110
  },
111
111
  "dependencies": {
112
- "@solidity-parser/parser": "^0.18.0",
113
- "semver": "^7.5.4"
112
+ "@solidity-parser/parser": "^0.20.1",
113
+ "semver": "^7.7.1"
114
114
  },
115
115
  "peerDependencies": {
116
116
  "prettier": ">=2.3.0"
@@ -27,10 +27,19 @@ function handleContractDefinitionComments({
27
27
  );
28
28
 
29
29
  // The comment is behind the start of the Block `{}` or behind a base contract
30
- if (followingNode?.type === 'InheritanceSpecifier' || nextCharacter === '{') {
30
+ if (
31
+ (followingNode &&
32
+ (followingNode.type === 'InheritanceSpecifier' ||
33
+ followingNode === enclosingNode.storageLayout)) ||
34
+ nextCharacter === '{'
35
+ ) {
31
36
  // In this scenario the comment belongs to a base contract.
32
37
  // contract A is B, /* comment for B */ C /* comment for C */ {}
33
- if (precedingNode?.type === 'InheritanceSpecifier') {
38
+ if (
39
+ precedingNode &&
40
+ (precedingNode.type === 'InheritanceSpecifier' ||
41
+ precedingNode === enclosingNode.storageLayout)
42
+ ) {
34
43
  addTrailingComment(precedingNode, comment);
35
44
  return true;
36
45
  }
@@ -6,17 +6,37 @@ import {
6
6
  printSeparatedList
7
7
  } from '../common/printer-helpers.js';
8
8
 
9
- const { group, line, hardline } = doc.builders;
9
+ const { group, hardline, ifBreak, line, softline } = doc.builders;
10
10
 
11
- const inheritance = (node, path, print) =>
12
- node.baseContracts.length > 0
13
- ? [
14
- ' is',
15
- printSeparatedList(path.map(print, 'baseContracts'), {
16
- firstSeparator: line
17
- })
18
- ]
19
- : line;
11
+ const specifiers = (node, path, print) => {
12
+ const document = [];
13
+ if (node.baseContracts.length > 0) {
14
+ document.push([
15
+ 'is',
16
+ printSeparatedList(path.map(print, 'baseContracts'), {
17
+ firstSeparator: line
18
+ })
19
+ ]);
20
+ }
21
+ if (node.storageLayout) {
22
+ document.push([
23
+ 'layout at',
24
+ printSeparatedItem(path.call(print, 'storageLayout'), {
25
+ firstSeparator: line
26
+ })
27
+ ]);
28
+ }
29
+ if (document.length === 0) return line;
30
+ if (document.length === 1) return [' ', document];
31
+ const groupId = Symbol('ContractSpecifiers.inheritance');
32
+ return printSeparatedList(
33
+ [group(document[0], { id: groupId }), document[1]],
34
+ {
35
+ firstSeparator: line,
36
+ separator: ifBreak('', softline, { groupId })
37
+ }
38
+ );
39
+ };
20
40
 
21
41
  const body = (node, path, options, print) => {
22
42
  const comments = printComments(node, path, options);
@@ -34,7 +54,7 @@ export const ContractDefinition = {
34
54
  node.kind === 'abstract' ? 'abstract contract' : node.kind,
35
55
  ' ',
36
56
  node.name,
37
- inheritance(node, path, print),
57
+ specifiers(node, path, print),
38
58
  '{'
39
59
  ]),
40
60
  body(node, path, options, print),
@@ -12,8 +12,15 @@ export const ImportDirective = {
12
12
  let document;
13
13
 
14
14
  if (node.unitAlias) {
15
- // import "./Foo.sol" as Foo;
16
- document = [importPath, ' as ', node.unitAlias];
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
  ])