From f1e6bc2eaa452412e8050f72ff14ad738dbe49bc Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 24 Aug 2016 15:27:46 -0400 Subject: [PATCH 1/5] Update style-guide to use new style --- docs/style-guide.rst | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/style-guide.rst b/docs/style-guide.rst index c7b13efa5..f4b419c00 100644 --- a/docs/style-guide.rst +++ b/docs/style-guide.rst @@ -273,17 +273,17 @@ No:: })); For ``if`` blocks which have an ``else`` or ``else if`` clause, the ``else`` should be -placed on it's own line following the previous closing parenthesis. The -parenthesis for the else block should follow the same rules as the other -conditional control structures. +placed on the same line as the ``if``'s closing brace. This is an exception compared +to the rules of other block-like structures. Yes:: if (x < 3) { x += 1; - } - else { + } else if (x > 7) { x -= 1; + } else { + x = 5; } @@ -296,7 +296,8 @@ No:: if (x < 3) { x += 1; - } else { + } + else { x -= 1; } From 532266b89e07d37115d160d3d1148b50e4fb1dfc Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 24 Aug 2016 15:28:07 -0400 Subject: [PATCH 2/5] Use new style for the docs --- docs/common-patterns.rst | 9 +++------ docs/control-structures.rst | 3 +-- docs/frequently-asked-questions.rst | 9 +++++---- docs/solidity-by-example.rst | 3 +-- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/docs/common-patterns.rst b/docs/common-patterns.rst index 74f9c0780..531a94ad8 100644 --- a/docs/common-patterns.rst +++ b/docs/common-patterns.rst @@ -45,8 +45,7 @@ become the new richest. richest = msg.sender; mostSent = msg.value; return true; - } - else { + } else { return false; } } @@ -58,8 +57,7 @@ become the new richest. pendingWithdrawals[msg.sender] = 0; if (msg.sender.send(amount)) { return true; - } - else { + } else { pendingWithdrawals[msg.sender] = amount; return false; } @@ -90,8 +88,7 @@ This is as opposed to the more intuitive sending pattern. richest = msg.sender; mostSent = msg.value; return true; - } - else { + } else { return false; } } diff --git a/docs/control-structures.rst b/docs/control-structures.rst index b3940f723..0e430b6b0 100644 --- a/docs/control-structures.rst +++ b/docs/control-structures.rst @@ -275,8 +275,7 @@ As a result, the following code is legal, despite being poorly written:: uint bar = 5; if (true) { bar += baz; - } - else { + } else { uint baz = 10;// never executes } return bar;// returns 5 diff --git a/docs/frequently-asked-questions.rst b/docs/frequently-asked-questions.rst index c28b4ab79..7e69093f7 100644 --- a/docs/frequently-asked-questions.rst +++ b/docs/frequently-asked-questions.rst @@ -461,16 +461,17 @@ If you do not want to throw, you can return a pair:: function getCounter(uint index) returns (uint counter, bool error) { - if (index >= counters.length) return (0, true); - else return (counters[index], false); + if (index >= counters.length) + return (0, true); + else + return (counters[index], false); } function checkCounter(uint index) { var (counter, error) = getCounter(index); if (error) { ... - } - else { + } else { ... } } diff --git a/docs/solidity-by-example.rst b/docs/solidity-by-example.rst index 61589b2ee..8e23dafd5 100644 --- a/docs/solidity-by-example.rst +++ b/docs/solidity-by-example.rst @@ -133,8 +133,7 @@ of votes. // If the delegate already voted, // directly add to the number of votes proposals[delegate.vote].voteCount += sender.weight; - } - else { + } else { // If the delegate did not vote yet, // add to her weight. delegate.weight += sender.weight; From d2144b03c7ef6f7189ba289f5df1a445c68f3b68 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 24 Aug 2016 15:20:59 -0400 Subject: [PATCH 3/5] Make std contracts use new style --- std/StandardToken.sol | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/std/StandardToken.sol b/std/StandardToken.sol index db4534920..41f2d709a 100644 --- a/std/StandardToken.sol +++ b/std/StandardToken.sol @@ -17,8 +17,7 @@ contract StandardToken is Token { balanceOf[_to] += _value; Transfer(msg.sender, _to, _value); return true; - } - else { + } else { return false; } } @@ -29,8 +28,7 @@ contract StandardToken is Token { balanceOf[_to] += _value; Transfer(_from, _to, _value); return true; - } - else { + } else { return false; } } From ff756bc94d7129844f8f3492cc07807a78b973bc Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 24 Aug 2016 15:31:59 -0400 Subject: [PATCH 4/5] Make tests more consistent in style --- test/contracts/AuctionRegistrar.cpp | 8 ++------ test/libsolidity/SolidityEndToEndTest.cpp | 3 ++- test/libsolidity/SolidityParser.cpp | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/test/contracts/AuctionRegistrar.cpp b/test/contracts/AuctionRegistrar.cpp index 3b1d1165d..6eba27065 100644 --- a/test/contracts/AuctionRegistrar.cpp +++ b/test/contracts/AuctionRegistrar.cpp @@ -130,9 +130,7 @@ contract GlobalRegistrar is Registrar, AuctionSystem { if (previousOwner != 0) { if (!record.owner.send(auction.sumOfBids - auction.highestBid / 100)) throw; - } - else - { + } else { if (!auction.highestBidder.send(auction.highestBid - auction.secondHighestBid)) throw; } @@ -147,9 +145,7 @@ contract GlobalRegistrar is Registrar, AuctionSystem { if (now < m_toRecord[_name].renewalDate) throw; bid(_name, msg.sender, msg.value); - } - else - { + } else { Record record = m_toRecord[_name]; if (record.owner != 0) throw; diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 8a61907ac..8f645170b 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -2549,8 +2549,9 @@ BOOST_AUTO_TEST_CASE(event) if (_manually) { bytes32 s = 0x19dacbf83c5de6658e14cbf7bcae5c15eca2eedecf1c66fbca928e4d351bea0f; log3(bytes32(msg.value), s, bytes32(msg.sender), _id); - } else + } else { Deposit(msg.sender, _id, msg.value); + } } } )"; diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp index 909d18c9d..07cb07519 100644 --- a/test/libsolidity/SolidityParser.cpp +++ b/test/libsolidity/SolidityParser.cpp @@ -540,7 +540,7 @@ BOOST_AUTO_TEST_CASE(if_statement) { char const* text = "contract test {\n" " function fun(uint256 a) {\n" - " if (a >= 8) return 2; else { var b = 7; }\n" + " if (a >= 8) { return 2 }; else { var b = 7; }\n" " }\n" "}\n"; BOOST_CHECK(successParse(text)); From a8c5d2bbde73e13dc2fc2e002bab0bd39536f162 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 31 Aug 2016 09:55:28 -0400 Subject: [PATCH 5/5] Fix syntax error --- test/libsolidity/SolidityParser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp index 07cb07519..92f5a1424 100644 --- a/test/libsolidity/SolidityParser.cpp +++ b/test/libsolidity/SolidityParser.cpp @@ -540,7 +540,7 @@ BOOST_AUTO_TEST_CASE(if_statement) { char const* text = "contract test {\n" " function fun(uint256 a) {\n" - " if (a >= 8) { return 2 }; else { var b = 7; }\n" + " if (a >= 8) { return 2; } else { var b = 7; }\n" " }\n" "}\n"; BOOST_CHECK(successParse(text));