Merge pull request #12678 from devtooligan/fix/remove-snake

Fix: remove lower_case_with_underscores and Capitalized_Words_With_Underscores
This commit is contained in:
Kamil Śliwak 2022-02-23 10:38:57 +01:00 committed by GitHub
commit e7d93f8376
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 58 additions and 60 deletions

View File

@ -89,8 +89,8 @@ For most of the topics the compiler will provide suggestions.
* Explicit data location for all variables of struct, array or mapping types is * Explicit data location for all variables of struct, array or mapping types is
now mandatory. This is also applied to function parameters and return now mandatory. This is also applied to function parameters and return
variables. For example, change ``uint[] x = m_x`` to ``uint[] storage x = variables. For example, change ``uint[] x = z`` to ``uint[] storage x =
m_x``, and ``function f(uint[][] x)`` to ``function f(uint[][] memory x)`` z``, and ``function f(uint[][] x)`` to ``function f(uint[][] memory x)``
where ``memory`` is the data location and might be replaced by ``storage`` or where ``memory`` is the data location and might be replaced by ``storage`` or
``calldata`` accordingly. Note that ``external`` functions require ``calldata`` accordingly. Note that ``external`` functions require
parameters with a data location of ``calldata``. parameters with a data location of ``calldata``.
@ -483,7 +483,7 @@ New version:
return data; return data;
} }
using address_make_payable for address; using AddressMakePayable for address;
// Data location for 'arr' must be specified // Data location for 'arr' must be specified
function g(uint[] memory /* arr */, bytes8 x, OtherContract otherContract, address unknownContract) public payable { function g(uint[] memory /* arr */, bytes8 x, OtherContract otherContract, address unknownContract) public payable {
// 'otherContract.transfer' is not provided. // 'otherContract.transfer' is not provided.
@ -500,7 +500,7 @@ New version:
// 'address payable' should be used whenever possible. // 'address payable' should be used whenever possible.
// To increase clarity, we suggest the use of a library for // To increase clarity, we suggest the use of a library for
// the conversion (provided after the contract in this example). // the conversion (provided after the contract in this example).
address payable addr = unknownContract.make_payable(); address payable addr = unknownContract.makePayable();
require(addr.send(1 ether)); require(addr.send(1 ether));
// Since uint32 (4 bytes) is smaller than bytes8 (8 bytes), // Since uint32 (4 bytes) is smaller than bytes8 (8 bytes),
@ -516,8 +516,8 @@ New version:
// We can define a library for explicitly converting ``address`` // We can define a library for explicitly converting ``address``
// to ``address payable`` as a workaround. // to ``address payable`` as a workaround.
library address_make_payable { library AddressMakePayable {
function make_payable(address x) internal pure returns (address payable) { function makePayable(address x) internal pure returns (address payable) {
return address(uint160(x)); return address(uint160(x));
} }
} }

View File

@ -45,19 +45,19 @@ Solidity language without a compiler change.
pragma solidity >=0.4.16 <0.9.0; pragma solidity >=0.4.16 <0.9.0;
library GetCode { library GetCode {
function at(address _addr) public view returns (bytes memory o_code) { function at(address _addr) public view returns (bytes memory code) {
assembly { assembly {
// retrieve the size of the code, this needs assembly // retrieve the size of the code, this needs assembly
let size := extcodesize(_addr) let size := extcodesize(_addr)
// allocate output byte array - this could also be done without assembly // allocate output byte array - this could also be done without assembly
// by using o_code = new bytes(size) // by using code = new bytes(size)
o_code := mload(0x40) code := mload(0x40)
// new "memory end" including padding // new "memory end" including padding
mstore(0x40, add(o_code, and(add(add(size, 0x20), 0x1f), not(0x1f)))) mstore(0x40, add(code, and(add(add(size, 0x20), 0x1f), not(0x1f))))
// store length in memory // store length in memory
mstore(o_code, size) mstore(code, size)
// actually retrieve the code, this needs assembly // actually retrieve the code, this needs assembly
extcodecopy(_addr, add(o_code, 0x20), 0, size) extcodecopy(_addr, add(code, 0x20), 0, size)
} }
} }
} }

View File

@ -102,10 +102,10 @@ two integers passed as function parameters, then you use something like:
function arithmetic(uint _a, uint _b) function arithmetic(uint _a, uint _b)
public public
pure pure
returns (uint o_sum, uint o_product) returns (uint sum, uint product)
{ {
o_sum = _a + _b; sum = _a + _b;
o_product = _a * _b; product = _a * _b;
} }
} }
@ -129,7 +129,7 @@ statement:
function arithmetic(uint _a, uint _b) function arithmetic(uint _a, uint _b)
public public
pure pure
returns (uint o_sum, uint o_product) returns (uint sum, uint product)
{ {
return (_a + _b, _a * _b); return (_a + _b, _a * _b);
} }

View File

@ -204,7 +204,7 @@ Yes:
.. code-block:: solidity .. code-block:: solidity
thisIsALongNestedMapping[being][set][to_some_value] = someFunction( thisIsALongNestedMapping[being][set][toSomeValue] = someFunction(
argument1, argument1,
argument2, argument2,
argument3, argument3,
@ -215,7 +215,7 @@ No:
.. code-block:: solidity .. code-block:: solidity
thisIsALongNestedMapping[being][set][to_some_value] = someFunction(argument1, thisIsALongNestedMapping[being][set][toSomeValue] = someFunction(argument1,
argument2, argument2,
argument3, argument3,
argument4); argument4);
@ -439,15 +439,15 @@ Yes:
x = 1; x = 1;
y = 2; y = 2;
long_variable = 3; longVariable = 3;
No: No:
.. code-block:: solidity .. code-block:: solidity
x = 1; x = 1;
y = 2; y = 2;
long_variable = 3; longVariable = 3;
Don't include a whitespace in the receive and fallback functions: Don't include a whitespace in the receive and fallback functions:
@ -1092,12 +1092,10 @@ naming styles.
* ``b`` (single lowercase letter) * ``b`` (single lowercase letter)
* ``B`` (single uppercase letter) * ``B`` (single uppercase letter)
* ``lowercase`` * ``lowercase``
* ``lower_case_with_underscores``
* ``UPPERCASE`` * ``UPPERCASE``
* ``UPPER_CASE_WITH_UNDERSCORES`` * ``UPPER_CASE_WITH_UNDERSCORES``
* ``CapitalizedWords`` (or CapWords) * ``CapitalizedWords`` (or CapWords)
* ``mixedCase`` (differs from CapitalizedWords by initial lowercase character!) * ``mixedCase`` (differs from CapitalizedWords by initial lowercase character!)
* ``Capitalized_Words_With_Underscores``
.. note:: When using initialisms in CapWords, capitalize all the letters of the initialisms. Thus HTTPServerError is better than HttpServerError. When using initialisms in mixedCase, capitalize all the letters of the initialisms, except keep the first one lower case if it is the beginning of the name. Thus xmlHTTPRequest is better than XMLHTTPRequest. .. note:: When using initialisms in CapWords, capitalize all the letters of the initialisms. Thus HTTPServerError is better than HttpServerError. When using initialisms in mixedCase, capitalize all the letters of the initialisms, except keep the first one lower case if it is the beginning of the name. Thus xmlHTTPRequest is better than XMLHTTPRequest.
@ -1256,7 +1254,7 @@ Enums, in the style of simple type declarations, should be named using the CapWo
Avoiding Naming Collisions Avoiding Naming Collisions
========================== ==========================
* ``single_trailing_underscore_`` * ``singleTrailingUnderscore_``
This convention is suggested when the desired name collides with that of a This convention is suggested when the desired name collides with that of a
built-in or otherwise reserved name. built-in or otherwise reserved name.

View File

@ -166,22 +166,22 @@ the ``sum`` function iterates over to sum all the values.
return self.data[key].keyIndex > 0; return self.data[key].keyIndex > 0;
} }
function iterate_start(itmap storage self) internal view returns (uint keyIndex) { function iterateStart(itmap storage self) internal view returns (uint keyIndex) {
return iterate_next(self, type(uint).max); return iterateNext(self, type(uint).max);
} }
function iterate_valid(itmap storage self, uint keyIndex) internal view returns (bool) { function iterateValid(itmap storage self, uint keyIndex) internal view returns (bool) {
return keyIndex < self.keys.length; return keyIndex < self.keys.length;
} }
function iterate_next(itmap storage self, uint keyIndex) internal view returns (uint r_keyIndex) { function iterateNext(itmap storage self, uint keyIndex) internal view returns (uint r_keyIndex) {
keyIndex++; keyIndex++;
while (keyIndex < self.keys.length && self.keys[keyIndex].deleted) while (keyIndex < self.keys.length && self.keys[keyIndex].deleted)
keyIndex++; keyIndex++;
return keyIndex; return keyIndex;
} }
function iterate_get(itmap storage self, uint keyIndex) internal view returns (uint key, uint value) { function iterateGet(itmap storage self, uint keyIndex) internal view returns (uint key, uint value) {
key = self.keys[keyIndex].key; key = self.keys[keyIndex].key;
value = self.data[key].value; value = self.data[key].value;
} }
@ -206,11 +206,11 @@ the ``sum`` function iterates over to sum all the values.
// Computes the sum of all stored data. // Computes the sum of all stored data.
function sum() public view returns (uint s) { function sum() public view returns (uint s) {
for ( for (
uint i = data.iterate_start(); uint i = data.iterateStart();
data.iterate_valid(i); data.iterateValid(i);
i = data.iterate_next(i) i = data.iterateNext(i)
) { ) {
(, uint value) = data.iterate_get(i); (, uint value) = data.iterateGet(i);
s += value; s += value;
} }
} }

View File

@ -190,11 +190,11 @@ If you want to use string parameters or other types that are not implicitly conv
contract C { contract C {
string s = "Storage"; string s = "Storage";
function f(bytes calldata bc, string memory sm, bytes16 b) public view { function f(bytes calldata bc, string memory sm, bytes16 b) public view {
string memory concat_string = string.concat(s, string(bc), "Literal", sm); string memory concatString = string.concat(s, string(bc), "Literal", sm);
assert((bytes(s).length + bc.length + 7 + bytes(sm).length) == bytes(concat_string).length); assert((bytes(s).length + bc.length + 7 + bytes(sm).length) == bytes(concatString).length);
bytes memory concat_bytes = bytes.concat(bytes(s), bc, bc[:2], "Literal", bytes(sm), b); bytes memory concatBytes = bytes.concat(bytes(s), bc, bc[:2], "Literal", bytes(sm), b);
assert((bytes(s).length + bc.length + 2 + 7 + bytes(sm).length + b.length) == concat_bytes.length); assert((bytes(s).length + bc.length + 2 + 7 + bytes(sm).length + b.length) == concatBytes.length);
} }
} }
@ -376,20 +376,20 @@ Array Members
pragma solidity >=0.6.0 <0.9.0; pragma solidity >=0.6.0 <0.9.0;
contract ArrayContract { contract ArrayContract {
uint[2**20] m_aLotOfIntegers; uint[2**20] aLotOfIntegers;
// Note that the following is not a pair of dynamic arrays but a // Note that the following is not a pair of dynamic arrays but a
// dynamic array of pairs (i.e. of fixed size arrays of length two). // dynamic array of pairs (i.e. of fixed size arrays of length two).
// Because of that, T[] is always a dynamic array of T, even if T // Because of that, T[] is always a dynamic array of T, even if T
// itself is an array. // itself is an array.
// Data location for all state variables is storage. // Data location for all state variables is storage.
bool[2][] m_pairsOfFlags; bool[2][] pairsOfFlags;
// newPairs is stored in memory - the only possibility // newPairs is stored in memory - the only possibility
// for public contract function arguments // for public contract function arguments
function setAllFlagPairs(bool[2][] memory newPairs) public { function setAllFlagPairs(bool[2][] memory newPairs) public {
// assignment to a storage array performs a copy of ``newPairs`` and // assignment to a storage array performs a copy of ``newPairs`` and
// replaces the complete array ``m_pairsOfFlags``. // replaces the complete array ``pairsOfFlags``.
m_pairsOfFlags = newPairs; pairsOfFlags = newPairs;
} }
struct StructType { struct StructType {
@ -411,45 +411,45 @@ Array Members
function setFlagPair(uint index, bool flagA, bool flagB) public { function setFlagPair(uint index, bool flagA, bool flagB) public {
// access to a non-existing index will throw an exception // access to a non-existing index will throw an exception
m_pairsOfFlags[index][0] = flagA; pairsOfFlags[index][0] = flagA;
m_pairsOfFlags[index][1] = flagB; pairsOfFlags[index][1] = flagB;
} }
function changeFlagArraySize(uint newSize) public { function changeFlagArraySize(uint newSize) public {
// using push and pop is the only way to change the // using push and pop is the only way to change the
// length of an array // length of an array
if (newSize < m_pairsOfFlags.length) { if (newSize < pairsOfFlags.length) {
while (m_pairsOfFlags.length > newSize) while (pairsOfFlags.length > newSize)
m_pairsOfFlags.pop(); pairsOfFlags.pop();
} else if (newSize > m_pairsOfFlags.length) { } else if (newSize > pairsOfFlags.length) {
while (m_pairsOfFlags.length < newSize) while (pairsOfFlags.length < newSize)
m_pairsOfFlags.push(); pairsOfFlags.push();
} }
} }
function clear() public { function clear() public {
// these clear the arrays completely // these clear the arrays completely
delete m_pairsOfFlags; delete pairsOfFlags;
delete m_aLotOfIntegers; delete aLotOfIntegers;
// identical effect here // identical effect here
m_pairsOfFlags = new bool[2][](0); pairsOfFlags = new bool[2][](0);
} }
bytes m_byteData; bytes byteData;
function byteArrays(bytes memory data) public { function byteArrays(bytes memory data) public {
// byte arrays ("bytes") are different as they are stored without padding, // byte arrays ("bytes") are different as they are stored without padding,
// but can be treated identical to "uint8[]" // but can be treated identical to "uint8[]"
m_byteData = data; byteData = data;
for (uint i = 0; i < 7; i++) for (uint i = 0; i < 7; i++)
m_byteData.push(); byteData.push();
m_byteData[3] = 0x08; byteData[3] = 0x08;
delete m_byteData[2]; delete byteData[2];
} }
function addFlag(bool[2] memory flag) public returns (uint) { function addFlag(bool[2] memory flag) public returns (uint) {
m_pairsOfFlags.push(flag); pairsOfFlags.push(flag);
return m_pairsOfFlags.length; return pairsOfFlags.length;
} }
function createMemoryArray(uint size) public pure returns (bytes memory) { function createMemoryArray(uint size) public pure returns (bytes memory) {