diff options
author | chriseth <chris@ethereum.org> | 2016-09-01 04:34:44 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-01 04:34:44 +0800 |
commit | 18abafe029a2eb4628136f7a944c80265da3ece4 (patch) | |
tree | 010c8a38e9541bf0d0bf5a3e29ae046931267402 | |
parent | 58dbd162ab369e9dd69af0b2a45a386527ed7b58 (diff) | |
parent | a8c5d2bbde73e13dc2fc2e002bab0bd39536f162 (diff) | |
download | dexon-solidity-18abafe029a2eb4628136f7a944c80265da3ece4.tar dexon-solidity-18abafe029a2eb4628136f7a944c80265da3ece4.tar.gz dexon-solidity-18abafe029a2eb4628136f7a944c80265da3ece4.tar.bz2 dexon-solidity-18abafe029a2eb4628136f7a944c80265da3ece4.tar.lz dexon-solidity-18abafe029a2eb4628136f7a944c80265da3ece4.tar.xz dexon-solidity-18abafe029a2eb4628136f7a944c80265da3ece4.tar.zst dexon-solidity-18abafe029a2eb4628136f7a944c80265da3ece4.zip |
Merge pull request #960 from Denton-L/change-else-style
Change else style
-rw-r--r-- | docs/common-patterns.rst | 9 | ||||
-rw-r--r-- | docs/control-structures.rst | 3 | ||||
-rw-r--r-- | docs/frequently-asked-questions.rst | 9 | ||||
-rw-r--r-- | docs/solidity-by-example.rst | 3 | ||||
-rw-r--r-- | docs/style-guide.rst | 13 | ||||
-rw-r--r-- | std/StandardToken.sol | 6 | ||||
-rw-r--r-- | test/contracts/AuctionRegistrar.cpp | 8 | ||||
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 3 | ||||
-rw-r--r-- | test/libsolidity/SolidityParser.cpp | 2 |
9 files changed, 24 insertions, 32 deletions
diff --git a/docs/common-patterns.rst b/docs/common-patterns.rst index 74f9c078..531a94ad 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 b3940f72..0e430b6b 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 c28b4ab7..7e69093f 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 61589b2e..8e23dafd 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; diff --git a/docs/style-guide.rst b/docs/style-guide.rst index c7b13efa..f4b419c0 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; } diff --git a/std/StandardToken.sol b/std/StandardToken.sol index db453492..41f2d709 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; } } diff --git a/test/contracts/AuctionRegistrar.cpp b/test/contracts/AuctionRegistrar.cpp index 3b1d1165..6eba2706 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 a370aafa..35b7078d 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -2563,8 +2563,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 909d18c9..92f5a142 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)); |