Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.

Solidity and JS linters #328

Merged
merged 16 commits into from Mar 30, 2020
Merged

Solidity and JS linters #328

merged 16 commits into from Mar 30, 2020

Conversation

nkuba
Copy link
Member

@nkuba nkuba commented Mar 26, 2020

In this PR we:

  • configured linters for Solidity and JavaScript code,
  • added a pre-commit hook to enforce correct code formatting,
  • added CircleCI job to execute linters on git push
  • fixed formating of JS and Solidity files.

Closes #42

@nkuba nkuba requested a review from Shadowfiend March 26, 2020 23:16
@nkuba nkuba mentioned this pull request Mar 26, 2020
- run:
name: Install dependencies
working_directory: ~/project/solidity
command: npm install
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm ci is the jam here.

lint:
jobs:
- setup_github_package_registry:
context: github-package-registry
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably don't need this anymore since the repo is open, though not certain about that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, Unable to authenticate, need: Basic realm="GitHub Package Registry" 😞

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this happened for a couple of reasons:

  • You need to update package-lock by running npm i.
  • You need to drop .npmrc.
  • You need to drop the publishConfig.

However, I'll do all of this stuff in one step when I handle deployment later today.

Copy link
Contributor

@Shadowfiend Shadowfiend left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few comments around the prettier config for JS.

@@ -0,0 +1,2 @@
semi: false
trailingComma: "all"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't have a custom .prettierrc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I just copy-pasted it from tbtc 😉

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it predates my adding prettier to eslint and I haven't migrated it yet 😬

"security/no-call-value": "off",
"security/no-inline-assembly": "off"
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should consider unifying these rules at the keep level, as a side note. Haven't peeked into this yet, so not a blocking note or anything.

@@ -1,3 +1,4 @@
/* solium-disable function-order */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason for this? I would kind of rather just go with the function order in our linter. Fewer toggles is better.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We tried to place the functions in a logical order as they may be used in the flow. But yeah, sure I can rearrange the functions order to satisfy solium.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually get this and it tends to be my first preference during initial dev, but there are some strong arguments for function ordering for visibility. Diligence also flagged this possibility. My main thing is I'd rather either go all in on ignoring this, or not ignore it ever heh. I'm already twitchy over the other exceptions we have to solium.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I like the idea to conform to the rules and order the functions accordingly, there is one place where IMO it would be better to disable the check.
It's in BondedECDSAKeepVendor contract where we have a long list of getters/setters pairs where getters are public and setters internal:

/// @dev Returns the current implementation. Implements function from `Proxy`
/// contract.
/// @return Address of the current implementation
function _implementation() internal view returns (address impl) {
bytes32 slot = IMPLEMENTATION_SLOT;
/* solium-disable-next-line */
assembly {
impl := sload(slot)
}
}
/// @notice Sets the address of the current implementation.
/// @param _implementation Address representing the new implementation to
/// be set.
function setImplementation(address _implementation) internal {
bytes32 slot = IMPLEMENTATION_SLOT;
/* solium-disable-next-line */
assembly {
sstore(slot, _implementation)
}
}
function upgradeTimeDelay()
public
view
returns (uint256 _upgradeTimeDelay)
{
bytes32 position = UPGRADE_TIME_DELAY_SLOT;
/* solium-disable-next-line */
assembly {
_upgradeTimeDelay := sload(position)
}
}
function setUpgradeTimeDelay(uint256 _upgradeTimeDelay) internal {
bytes32 position = UPGRADE_TIME_DELAY_SLOT;
/* solium-disable-next-line */
assembly {
sstore(position, _upgradeTimeDelay)
}
}
function newImplementation()
public
view
returns (address _newImplementation)
{
bytes32 position = UPGRADE_IMPLEMENTATION_SLOT;
/* solium-disable-next-line */
assembly {
_newImplementation := sload(position)
}
}
function setNewImplementation(address _newImplementation) internal {
bytes32 position = UPGRADE_IMPLEMENTATION_SLOT;
/* solium-disable-next-line */
assembly {
sstore(position, _newImplementation)
}
}
function upgradeInitiatedTimestamp()
public
view
returns (uint256 _upgradeInitiatedTimestamp)
{
bytes32 position = UPGRADE_INIT_TIMESTAMP_SLOT;
/* solium-disable-next-line */
assembly {
_upgradeInitiatedTimestamp := sload(position)
}
}
function setUpgradeInitiatedTimestamp(uint256 _upgradeInitiatedTimestamp)
internal
{
bytes32 position = UPGRADE_INIT_TIMESTAMP_SLOT;
/* solium-disable-next-line */
assembly {
sstore(position, _upgradeInitiatedTimestamp)
}
}
/// @notice The admin slot.
/// @return The contract owner's address.
function admin() public view returns (address adm) {
bytes32 slot = ADMIN_SLOT;
/* solium-disable-next-line */
assembly {
adm := sload(slot)
}
}
/// @dev Sets the address of the proxy admin.
/// @param _newAdmin Address of the new proxy admin.
function setAdmin(address _newAdmin) internal {
bytes32 slot = ADMIN_SLOT;
/* solium-disable-next-line */
assembly {
sstore(slot, _newAdmin)
}
}

@@ -43,7 +52,14 @@
"@truffle/hdwallet-provider": "^1.0.25",
"bn-chai": "^1.0.1",
"chai": "^4.2.0",
"eslint": "^6.8.0",
"eslint-config-keep": "github:keep-network/eslint-config-keep",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's anchor this to a version tag.

@@ -43,7 +52,14 @@
"@truffle/hdwallet-provider": "^1.0.25",
"bn-chai": "^1.0.1",
"chai": "^4.2.0",
"eslint": "^6.8.0",
"eslint-config-keep": "github:keep-network/eslint-config-keep",
"eslint-config-prettier": "^6.10.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Burn it please :) eslint-config-keep should handle this. I realize it doesn't currently deal with the Solidity plugin, but we still need to explicitly include the prettier dependency here anyway.

My suggestion:

  • Kill eslint-config-prettier. Let eslint-config-keep#0.3.0 handle the JS side of prettier. You still need the prettier dependency below for this, but you lose the explicit prettier invocation for lint:js and lint:fix:js.
  • Continue to pull in prettier-plugin-solidity and run prettier in the :sol scripts.

I also want to see if I can pull prettier into solium's config, but that seems unlikely. There may be room to set something up with our core eslint config and Solidity though, TBD.

@nkuba nkuba requested a review from Shadowfiend March 26, 2020 23:33
/// @param _keepBonding Address of the KeepBonding contract.
/// @param _keepFactory Address of the BondedECDSAKeepFactory that created
/// this keep.
function initialize(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving this function below external ones hurts me because this is like a constructor that we use in the factory pattern.

const RegistryAddress = "0x9aF7d664E6d7DB318c6BdE54ED77A7D99361F539"
const TokenStakingAddress = "0x602c5f7d11eb786E14cDfBafe34E70c0b6717a8c"
const RandomBeaconAddress = "0xB901EDDE70EcB59c1243f404a238fd97B78f1F54"
const TBTCSystemAddress = "0x065c3Ab1D2cb67c70dAC17Cf3BD4B8A165ffceFa"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this on purpose? <_<

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh boy, no! It's fixed in 43bfb27.
Thanks for noticing that!

Copy link
Contributor

@Shadowfiend Shadowfiend left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok… Let's do this crazy thing.

@Shadowfiend Shadowfiend merged commit 8f22080 into master Mar 30, 2020
@Shadowfiend Shadowfiend deleted the linting branch March 30, 2020 18:35
@pdyraga pdyraga added this to the v0.11.0 milestone Mar 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Solidity and JS linters
3 participants