Skip to content

Commit 90fa4c0

Browse files
authored
only break import deconstruction if the list of items is longer than 1 (#1178)
* adding tests for import directives * only break import deconstruction if the list of items is longer than 1 * update `antlr` parser
1 parent 2a140f3 commit 90fa4c0

File tree

5 files changed

+121
-5
lines changed

5 files changed

+121
-5
lines changed

src/nodes/ImportDirective.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ export const ImportDirective = {
3030
let firstSeparator;
3131
let separator;
3232

33-
if (compiler && satisfies(compiler, '>=0.7.4')) {
33+
if (
34+
compiler &&
35+
satisfies(compiler, '>=0.7.4') &&
36+
symbolAliases.length > 1
37+
) {
3438
// if the compiler exists and is greater than or equal to 0.7.4 we will
3539
// split the ImportDirective.
3640
firstSeparator = options.bracketSpacing ? line : softline;

src/slang-nodes/ImportDeconstructionSymbols.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class ImportDeconstructionSymbols implements SlangNode {
4343
const compiler = coerce(options.compiler);
4444
return printSeparatedList(
4545
path.map(print, 'items'),
46-
compiler && satisfies(compiler, '>=0.7.4')
46+
compiler && satisfies(compiler, '>=0.7.4') && this.items.length > 1
4747
? {
4848
// if the compiler exists and is greater than or equal to 0.7.4 we will
4949
// split the ImportDirective.

tests/format/ImportDirective/ImportDirectives.sol

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,19 @@ import "SomeFile.sol" as SomeOtherFile;
33
import * as SomeSymbol from "AnotherFile.sol";
44
import {symbol1 as alias1, symbol2} from "File.sol";
55
import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol";
6+
import {
7+
GovernorVotesSuperQuorumFraction
8+
} from "../../../contracts/governance/extensions/GovernorVotesSuperQuorumFraction.sol";
9+
import {
10+
IAccessControl
11+
} from "@openzeppelin/contracts/access/IAccessControl.sol";
12+
import {
13+
IERC7579Module,
14+
IERC7579Validator,
15+
IERC7579Execution,
16+
IERC7579AccountConfig,
17+
IERC7579ModuleConfig,
18+
MODULE_TYPE_VALIDATOR,
19+
MODULE_TYPE_EXECUTOR,
20+
MODULE_TYPE_FALLBACK
21+
} from "../../interfaces/draft-IERC7579.sol";

tests/format/ImportDirective/__snapshots__/format.test.js.snap

Lines changed: 98 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`ImportDirectives.sol - {"bracketSpacing":true} format 1`] = `
44
====================================options=====================================
@@ -12,7 +12,22 @@ import "SomeFile.sol" as SomeOtherFile;
1212
import * as SomeSymbol from "AnotherFile.sol";
1313
import {symbol1 as alias1, symbol2} from "File.sol";
1414
import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol";
15-
15+
import {
16+
GovernorVotesSuperQuorumFraction
17+
} from "../../../contracts/governance/extensions/GovernorVotesSuperQuorumFraction.sol";
18+
import {
19+
IAccessControl
20+
} from "@openzeppelin/contracts/access/IAccessControl.sol";
21+
import {
22+
IERC7579Module,
23+
IERC7579Validator,
24+
IERC7579Execution,
25+
IERC7579AccountConfig,
26+
IERC7579ModuleConfig,
27+
MODULE_TYPE_VALIDATOR,
28+
MODULE_TYPE_EXECUTOR,
29+
MODULE_TYPE_FALLBACK
30+
} from "../../interfaces/draft-IERC7579.sol";
1631
=====================================output=====================================
1732
import "SomeFile.sol";
1833
import "SomeFile.sol" as SomeOtherFile;
@@ -24,12 +39,25 @@ import {
2439
symbol3 as alias3,
2540
symbol4
2641
} from "File2.sol";
42+
import { GovernorVotesSuperQuorumFraction } from "../../../contracts/governance/extensions/GovernorVotesSuperQuorumFraction.sol";
43+
import { IAccessControl } from "@openzeppelin/contracts/access/IAccessControl.sol";
44+
import {
45+
IERC7579Module,
46+
IERC7579Validator,
47+
IERC7579Execution,
48+
IERC7579AccountConfig,
49+
IERC7579ModuleConfig,
50+
MODULE_TYPE_VALIDATOR,
51+
MODULE_TYPE_EXECUTOR,
52+
MODULE_TYPE_FALLBACK
53+
} from "../../interfaces/draft-IERC7579.sol";
2754
2855
================================================================================
2956
`;
3057

31-
exports[`ImportDirectives.sol format 1`] = `
58+
exports[`ImportDirectives.sol - {"compiler":"0.7.3"} format 1`] = `
3259
====================================options=====================================
60+
compiler: "0.7.3"
3361
parsers: ["slang"]
3462
printWidth: 80
3563
| printWidth
@@ -39,7 +67,62 @@ import "SomeFile.sol" as SomeOtherFile;
3967
import * as SomeSymbol from "AnotherFile.sol";
4068
import {symbol1 as alias1, symbol2} from "File.sol";
4169
import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol";
70+
import {
71+
GovernorVotesSuperQuorumFraction
72+
} from "../../../contracts/governance/extensions/GovernorVotesSuperQuorumFraction.sol";
73+
import {
74+
IAccessControl
75+
} from "@openzeppelin/contracts/access/IAccessControl.sol";
76+
import {
77+
IERC7579Module,
78+
IERC7579Validator,
79+
IERC7579Execution,
80+
IERC7579AccountConfig,
81+
IERC7579ModuleConfig,
82+
MODULE_TYPE_VALIDATOR,
83+
MODULE_TYPE_EXECUTOR,
84+
MODULE_TYPE_FALLBACK
85+
} from "../../interfaces/draft-IERC7579.sol";
86+
=====================================output=====================================
87+
import "SomeFile.sol";
88+
import "SomeFile.sol" as SomeOtherFile;
89+
import * as SomeSymbol from "AnotherFile.sol";
90+
import {symbol1 as alias1, symbol2} from "File.sol";
91+
import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol";
92+
import {GovernorVotesSuperQuorumFraction} from "../../../contracts/governance/extensions/GovernorVotesSuperQuorumFraction.sol";
93+
import {IAccessControl} from "@openzeppelin/contracts/access/IAccessControl.sol";
94+
import {IERC7579Module, IERC7579Validator, IERC7579Execution, IERC7579AccountConfig, IERC7579ModuleConfig, MODULE_TYPE_VALIDATOR, MODULE_TYPE_EXECUTOR, MODULE_TYPE_FALLBACK} from "../../interfaces/draft-IERC7579.sol";
4295
96+
================================================================================
97+
`;
98+
99+
exports[`ImportDirectives.sol format 1`] = `
100+
====================================options=====================================
101+
parsers: ["slang"]
102+
printWidth: 80
103+
| printWidth
104+
=====================================input======================================
105+
import "SomeFile.sol";
106+
import "SomeFile.sol" as SomeOtherFile;
107+
import * as SomeSymbol from "AnotherFile.sol";
108+
import {symbol1 as alias1, symbol2} from "File.sol";
109+
import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol";
110+
import {
111+
GovernorVotesSuperQuorumFraction
112+
} from "../../../contracts/governance/extensions/GovernorVotesSuperQuorumFraction.sol";
113+
import {
114+
IAccessControl
115+
} from "@openzeppelin/contracts/access/IAccessControl.sol";
116+
import {
117+
IERC7579Module,
118+
IERC7579Validator,
119+
IERC7579Execution,
120+
IERC7579AccountConfig,
121+
IERC7579ModuleConfig,
122+
MODULE_TYPE_VALIDATOR,
123+
MODULE_TYPE_EXECUTOR,
124+
MODULE_TYPE_FALLBACK
125+
} from "../../interfaces/draft-IERC7579.sol";
43126
=====================================output=====================================
44127
import "SomeFile.sol";
45128
import "SomeFile.sol" as SomeOtherFile;
@@ -51,6 +134,18 @@ import {
51134
symbol3 as alias3,
52135
symbol4
53136
} from "File2.sol";
137+
import {GovernorVotesSuperQuorumFraction} from "../../../contracts/governance/extensions/GovernorVotesSuperQuorumFraction.sol";
138+
import {IAccessControl} from "@openzeppelin/contracts/access/IAccessControl.sol";
139+
import {
140+
IERC7579Module,
141+
IERC7579Validator,
142+
IERC7579Execution,
143+
IERC7579AccountConfig,
144+
IERC7579ModuleConfig,
145+
MODULE_TYPE_VALIDATOR,
146+
MODULE_TYPE_EXECUTOR,
147+
MODULE_TYPE_FALLBACK
148+
} from "../../interfaces/draft-IERC7579.sol";
54149
55150
================================================================================
56151
`;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
runFormatTest(import.meta, ['slang']);
22
runFormatTest(import.meta, ['slang'], { bracketSpacing: true });
3+
runFormatTest(import.meta, ['slang'], { compiler: '0.7.3' });

0 commit comments

Comments
 (0)