Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using ... for ... supporting functions and global #683

Merged
merged 3 commits into from
May 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"solc": "^0.8.14-fixed"
},
"dependencies": {
"@solidity-parser/parser": "^0.14.1",
"@solidity-parser/parser": "^0.14.2-beta.1",
"emoji-regex": "^10.1.0",
"escape-string-regexp": "^4.0.0",
"semver": "^7.3.7",
Expand Down
2 changes: 1 addition & 1 deletion src/binary-operator-printers/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* This file was automatically generated on 1621622090.188 */
/* This file was automatically generated on 1653243394.809 */

/* eslint-disable global-require */

Expand Down
5 changes: 0 additions & 5 deletions src/nodes/TypeNameExpression.js

This file was deleted.

22 changes: 19 additions & 3 deletions src/nodes/UsingForDeclaration.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
const {
doc: {
builders: { line, softline }
}
} = require('prettier');

const printSeparatedList = require('./print-separated-list');

const UsingForDeclaration = {
print: ({ node, path, print }) => [
print: ({ node, path, print, options }) => [
'using ',
node.libraryName,
node.functions && node.functions.length
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove the .length check:

Suggested change
node.functions && node.functions.length
node.functions

Even if this is not technically allowed by the grammar, I think it's more future-proof to allow a potential result of using {} for .... The alternative is to use node.libraryName, which will be undefined and make the process fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

node.functions is always an Array even if it's an empty one :(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh 🤦‍♂️ You are right, sorry.

? [
'{',
printSeparatedList(node.functions, {
firstSeparator: options.bracketSpacing ? line : softline
}),
'}'
]
: node.libraryName,
' for ',
node.typeName ? path.call(print, 'typeName') : '*',
';'
node.isGlobal ? ' global;' : ';'
]
};

Expand Down
3 changes: 1 addition & 2 deletions src/nodes/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* This file was automatically generated on 1621622090.034 */
/* This file was automatically generated on 1653243394.65 */

/* eslint-disable global-require */

Expand Down Expand Up @@ -66,7 +66,6 @@ module.exports = {
TryStatement: require('./TryStatement'),
TupleExpression: require('./TupleExpression'),
TypeDefinition: require('./TypeDefinition'),
TypeNameExpression: require('./TypeNameExpression'),
UnaryOperation: require('./UnaryOperation'),
UncheckedStatement: require('./UncheckedStatement'),
UserDefinedTypeName: require('./UserDefinedTypeName'),
Expand Down
10 changes: 10 additions & 0 deletions tests/format/Libraries/Libraries.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Lib for uint;
using Lib for
uint global;
using { f} for uint;
using {f } for uint global;
using { a, very, long, and, complex, Function, list, with, long, names } for
uint;
using { a, very,
long, and, complex, Function,
list, with, long, names } for uint global;
102 changes: 102 additions & 0 deletions tests/format/Libraries/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Libraries.sol - {"bracketSpacing":true} format 1`] = `
====================================options=====================================
bracketSpacing: true
parsers: ["solidity-parse"]
printWidth: 80
| printWidth
=====================================input======================================
using Lib for uint;
using Lib for
uint global;
using { f} for uint;
using {f } for uint global;
using { a, very, long, and, complex, Function, list, with, long, names } for
uint;
using { a, very,
long, and, complex, Function,
list, with, long, names } for uint global;

=====================================output=====================================
using Lib for uint256;
using Lib for uint256 global;
using { f } for uint256;
using { f } for uint256 global;
using {
a,
very,
long,
and,
complex,
Function,
list,
with,
long,
names
} for uint256;
using {
a,
very,
long,
and,
complex,
Function,
list,
with,
long,
names
} for uint256 global;

================================================================================
`;

exports[`Libraries.sol format 1`] = `
====================================options=====================================
parsers: ["solidity-parse"]
printWidth: 80
| printWidth
=====================================input======================================
using Lib for uint;
using Lib for
uint global;
using { f} for uint;
using {f } for uint global;
using { a, very, long, and, complex, Function, list, with, long, names } for
uint;
using { a, very,
long, and, complex, Function,
list, with, long, names } for uint global;

=====================================output=====================================
using Lib for uint256;
using Lib for uint256 global;
using {f} for uint256;
using {f} for uint256 global;
using {
a,
very,
long,
and,
complex,
Function,
list,
with,
long,
names
} for uint256;
using {
a,
very,
long,
and,
complex,
Function,
list,
with,
long,
names
} for uint256 global;

================================================================================
`;
2 changes: 2 additions & 0 deletions tests/format/Libraries/jsfmt.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
run_spec(__dirname, ['solidity-parse']);
run_spec(__dirname, ['solidity-parse'], { bracketSpacing: true });