We use UPPER_CASE constants with underscores between words.
We use camelCase variable names with capitals between words.
Prefix with underscore. e.g.
private address _tradeWallet
Function arguments are camelCase.
function setRule(
address senderToken,
address signerToken,
uint256 maxSenderAmount,
uint256 priceCoef,
uint256 priceExp
) external onlyAdmin
Function arguments should be separated by newlines.
function setRule(address senderToken, address signerToken)
...becomes...
function setRules(
address senderToken,
address signerToken
)
Function names are in camelCase.
Internal and private functions are named with leading underscore.
Functions are ordered by their visibility however this is also affected by whether they are a view
, pure
or not.
- public
- external
- internal
- private
Run yarn hint
and solhint will enforce the correct ordering.
Prefix all arguments with the name of the current contract.
contract Delegate {
...
constructor(
ISwap delegateSwapContract,
address delegateContractOwner,
address delegateTradeWallet
) public
...
}
- Use the same name as the function that emits them e.g.
- e.g. function setIntent() —> emit SetIntent(...)
- If there's an interface, the event definitions go in the interface
Function documentation should follow NatSpec. Periods not required on statements. Interfaces do not need to have Natspec on them if there is only a single implemented contract from them, example ISwap.sol.
/**
* @notice Unset a Trading Rule
* @dev Only callable by the owner of the contract
* @param senderToken address The token the delegate would send
* @param signerToken address The token the consumer would send
*/
Comments in the body should use //
and be full, punctuated sentences.
// Transfer ownership to an address if specified.
2 spaces (which can be implemented as a tab in your editor)
Run from the root directory of airswap-protocols
using yarn hint
{
"extends": "solhint:default",
"rules": {
"func-param-name-mixedcase": "error", // paramName
"func-name-mixedcase": "error", // functionName
"event-name-camelcase": "error", // EventName
"var-name-mixedcase": "error", // varName
"modifier-name-mixedcase": "error", // modifierName
"contract-name-camelcase": "error", // ContractName
"const-name-snakecase": "error", // CONSTANT_NAME
"visibility-modifier-order": "error",
"func-visibility": "error",
"state-visibility": "error",
"ordering": "error",
"quotes": "error",
"max-line-length": "error",
"no-unused-vars": "error",
"no-complex-fallback": "warn",
"check-send-result": "warn",
"reentrancy": "warn"
}
}