Skip to content

Commit 39cc037

Browse files
authored
issue-with-undefined (#36)
* add filter before join * fix lint * remove test * fix snap
1 parent 7a4d4bd commit 39cc037

4 files changed

Lines changed: 200 additions & 2 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "prettier-plugin-solidity",
3-
"version": "1.0.0-alpha.1",
3+
"version": "1.0.0-alpha.2",
44
"description": "prettier plugin for solidity",
55
"main": "src",
66
"scripts": {

src/printer.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,10 @@ function genericPrint(path, options, print) {
258258
if (node.visibility === 'default') {
259259
return join(' ', [doc, node.name]);
260260
}
261-
return join(' ', [doc, node.visibility, node.name]);
261+
return join(
262+
' ',
263+
[doc, node.visibility, node.name].filter(element => element)
264+
);
262265
case 'ArrayTypeName':
263266
return concat([
264267
path.call(print, 'baseTypeName'),

tests/Ownable.sol

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
pragma solidity ^0.4.24;
2+
3+
/**
4+
* @title Ownable
5+
* @dev The Ownable contract has an owner address, and provides basic authorization control
6+
* functions, this simplifies the implementation of "user permissions".
7+
*/
8+
contract Ownable {
9+
address private _owner;
10+
11+
event OwnershipRenounced(address indexed previousOwner);
12+
event OwnershipTransferred(
13+
address indexed previousOwner,
14+
address indexed newOwner
15+
);
16+
17+
/**
18+
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
19+
* account.
20+
*/
21+
constructor() public {
22+
_owner = msg.sender;
23+
}
24+
25+
/**
26+
* @return the address of the owner.
27+
*/
28+
function owner() public view returns(address) {
29+
return _owner;
30+
}
31+
32+
/**
33+
* @dev Throws if called by any account other than the owner.
34+
*/
35+
modifier onlyOwner() {
36+
require(isOwner());
37+
_;
38+
}
39+
40+
/**
41+
* @return true if `msg.sender` is the owner of the contract.
42+
*/
43+
function isOwner() public view returns(bool) {
44+
return msg.sender == _owner;
45+
}
46+
47+
/**
48+
* @dev Allows the current owner to relinquish control of the contract.
49+
* @notice Renouncing to ownership will leave the contract without an owner.
50+
* It will not be possible to call the functions with the `onlyOwner`
51+
* modifier anymore.
52+
*/
53+
function renounceOwnership() public onlyOwner {
54+
emit OwnershipRenounced(_owner);
55+
_owner = address(0);
56+
}
57+
58+
/**
59+
* @dev Allows the current owner to transfer control of the contract to a newOwner.
60+
* @param newOwner The address to transfer ownership to.
61+
*/
62+
function transferOwnership(address newOwner) public onlyOwner {
63+
_transferOwnership(newOwner);
64+
}
65+
66+
/**
67+
* @dev Transfers control of the contract to a newOwner.
68+
* @param newOwner The address to transfer ownership to.
69+
*/
70+
function _transferOwnership(address newOwner) internal {
71+
require(newOwner != address(0));
72+
emit OwnershipTransferred(_owner, newOwner);
73+
_owner = newOwner;
74+
}
75+
}

tests/__snapshots__/jsfmt.spec.js.snap

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,126 @@ contract Inbox {
4040
4141
`;
4242

43+
exports[`Ownable.sol 1`] = `
44+
pragma solidity ^0.4.24;
45+
46+
/**
47+
* @title Ownable
48+
* @dev The Ownable contract has an owner address, and provides basic authorization control
49+
* functions, this simplifies the implementation of "user permissions".
50+
*/
51+
contract Ownable {
52+
address private _owner;
53+
54+
event OwnershipRenounced(address indexed previousOwner);
55+
event OwnershipTransferred(
56+
address indexed previousOwner,
57+
address indexed newOwner
58+
);
59+
60+
/**
61+
* @dev The Ownable constructor sets the original \`owner\` of the contract to the sender
62+
* account.
63+
*/
64+
constructor() public {
65+
_owner = msg.sender;
66+
}
67+
68+
/**
69+
* @return the address of the owner.
70+
*/
71+
function owner() public view returns(address) {
72+
return _owner;
73+
}
74+
75+
/**
76+
* @dev Throws if called by any account other than the owner.
77+
*/
78+
modifier onlyOwner() {
79+
require(isOwner());
80+
_;
81+
}
82+
83+
/**
84+
* @return true if \`msg.sender\` is the owner of the contract.
85+
*/
86+
function isOwner() public view returns(bool) {
87+
return msg.sender == _owner;
88+
}
89+
90+
/**
91+
* @dev Allows the current owner to relinquish control of the contract.
92+
* @notice Renouncing to ownership will leave the contract without an owner.
93+
* It will not be possible to call the functions with the \`onlyOwner\`
94+
* modifier anymore.
95+
*/
96+
function renounceOwnership() public onlyOwner {
97+
emit OwnershipRenounced(_owner);
98+
_owner = address(0);
99+
}
100+
101+
/**
102+
* @dev Allows the current owner to transfer control of the contract to a newOwner.
103+
* @param newOwner The address to transfer ownership to.
104+
*/
105+
function transferOwnership(address newOwner) public onlyOwner {
106+
_transferOwnership(newOwner);
107+
}
108+
109+
/**
110+
* @dev Transfers control of the contract to a newOwner.
111+
* @param newOwner The address to transfer ownership to.
112+
*/
113+
function _transferOwnership(address newOwner) internal {
114+
require(newOwner != address(0));
115+
emit OwnershipTransferred(_owner, newOwner);
116+
_owner = newOwner;
117+
}
118+
}
119+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
120+
pragma solidity ^0.4.24;
121+
contract Ownable {
122+
address private _owner;
123+
event OwnershipRenounced(address indexed previousOwner);
124+
event OwnershipTransferred(
125+
address indexed previousOwner,
126+
address indexed newOwner
127+
);
128+
129+
constructor() public {
130+
_owner = msg.sender;
131+
}
132+
133+
function owner() public view returns(address) {
134+
return _owner;
135+
}
136+
modifier onlyOwner() {
137+
require(isOwner());
138+
_;
139+
}
140+
141+
function isOwner() public view returns(bool) {
142+
return msg.sender == _owner;
143+
}
144+
145+
function renounceOwnership() public onlyOwner {
146+
emit OwnershipRenounced(_owner);
147+
_owner = address(0);
148+
}
149+
150+
function transferOwnership(address newOwner) public onlyOwner {
151+
_transferOwnership(newOwner);
152+
}
153+
154+
function _transferOwnership(address newOwner) internal {
155+
require(newOwner != address(0));
156+
emit OwnershipTransferred(_owner, newOwner);
157+
_owner = newOwner;
158+
}
159+
}
160+
161+
`;
162+
43163
exports[`SimpleStorage.sol 1`] = `
44164
pragma solidity ^0.4.0;
45165

0 commit comments

Comments
 (0)