Skip to content
This repository was archived by the owner on Jun 30, 2022. It is now read-only.

Conversation

@epiqueras
Copy link
Contributor

This PR:

  • Adds linting and formatting to workflow.
  • Fixes linting errors.
  • Fixes some inconsistencies and duplicated or unused code (still some left).
  • Deletes unused files.
  • Organizes files.
  • Adds coverage reports.
  • Removes unused dependencies.
  • Streamlines Webpack config.

@epiqueras epiqueras requested a review from satello February 27, 2018 06:50
@epiqueras epiqueras self-assigned this Feb 27, 2018
@epiqueras epiqueras added this to the February 26 -> March 5 milestone Feb 27, 2018
satello
satello previously approved these changes Feb 27, 2018
Copy link
Contributor

@satello satello left a comment

Choose a reason for hiding this comment

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

A lot to look through but overall the consistency will be good even if I am not in love with all the linting rules. Is this the same linter we are using for our other projects?


<a name="0.0.61"></a>

## 0.0.61 (2018-02-27)
Copy link
Contributor

Choose a reason for hiding this comment

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

you should be on 0.0.62 now

Copy link
Contributor Author

@epiqueras epiqueras Feb 27, 2018

Choose a reason for hiding this comment

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

Why? Refactors don't bump versions, https://semver.org.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure but these changes weren't from 0.0.61 anyways right? Also changelogs are nice but I still think we are a little early since we really don't even have a stable v1 yet

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I'm pretty sure those changes were included in that release.

Copy link
Contributor

Choose a reason for hiding this comment

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

nvm i see whats going on


// return contract data
return await this.getData(contractInstance.address, account)
return this.getData(contractInstance.address, account)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why remove await? I think it should return the data not a Promise

Copy link
Contributor Author

Choose a reason for hiding this comment

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

async functions return a promise, you're just adding another layer of promise for no reason.

Copy link
Contributor

Choose a reason for hiding this comment

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

What do you mean? It is the difference between returning a promise (which we don't do throughout the rest of the API) and returning the resulting data

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@satello

No, async/await functions return a promise that resolves to the return value of the function body.

By adding that await, you are not accomplishing anything. You are waiting for that first promise internally before wrapping the resolve value in another promise and returning that. Either way, the consumer receives a promise that resolves to the same data.

I made this snippet to illustrate:

const getData = () =>
	new Promise(resolve => setTimeout(() => resolve('Hello World'), 1000));

async function run() {
	return getData();
}
async function runWithExtraPromise() {
	return await getData();
}

run().then(res1 => console.log('Without extra promise: ', res1));
runWithExtraPromise().then(res2 => console.log('With extra promise: ', res2));
// res1 === res2

The extra await basically turns promise into promise.then(res => res).

@@ -1,111 +1,142 @@
import PromiseQueue from '../../util/PromiseQueue'

Copy link
Contributor

Choose a reason for hiding this comment

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

what linting option is this? I don't think we need lines between every import

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/order.md.

It's a line between import 'groups'. It makes it a lot easier to see what you are importing and why.

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 parent and children imports should be in the same "group" but its ok

// key: contract address, value: true/false
this._arbitratorEventsWatcher
this._arbitrableEventsWatcher
// this._arbitratorEventsWatcher
Copy link
Contributor

Choose a reason for hiding this comment

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

It is good practice to declare class variables in the constructor even if technically it works just to use them later on


if (_.isNull(notificationIndex)) {
throw new Error(`No notification with txHash ${txHash} exists`)
throw new TypeError(`No notification with txHash ${txHash} exists`)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I would call this a TypeError. Usually TypeError refers to a variable being the wrong type. Which I guess you could argue notificationIndex is but the error is more of a Runtime "Server" Error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, we can change this. I think errors need some refactoring in general. We are just catching errors everywhere only to throw them again.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed

const txHash = event.transactionHash
const arbitrableData = await this._ArbitrableContract.getData(event.args._arbitrable)
const arbitrableData = await this._ArbitrableContract.getData(
event.args._arbitrable
Copy link
Contributor

@satello satello Feb 27, 2018

Choose a reason for hiding this comment

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

I'm not sure I really understand this linting rule. I've seen functions being rolled up onto one line with 3 params and then there is something like this doing the opposite with 1. I think I prefer new line per param for all functions including declarations

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's about line width, see https://github.com/prettier/prettier.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not my favorite one either but 👍

) => {
if (!this._eventListener) return

const defaultAccount = account
Copy link
Contributor

Choose a reason for hiding this comment

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

whats your thinking here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Something weird happens with the parser when a function param is only used as a default param in another function. It trips up for some reason.

message = '',
data = {},
read = false,
read = false
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not super picky on this linting rule because I think I am in the minority opinion in general but I prefer having extra commas at the end of every iterable. I think it is a simple way to avoid bugs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The linter will catch any missing commas. It's merely a style thing.

]
)

;[voteCounters, status] = await Promise.all([
Copy link
Contributor

Choose a reason for hiding this comment

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

extra semicolon or is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes,

In general, \n ends a statement unless:

  • The statement has an unclosed paren, array literal, or object literal or ends in some other way that is not a valid way to end a statement, (For instance, ending with . or ,.).
  • The line is -- or ++, (in which case it will decrement/increment the next token.).
  • It is a for(), while(), do, if(), or else, and there is no {.
  • The next line starts with [, (, +, *, /, -, ,, ., or some other binary operator that can only be found between two tokens in a single expression.

The last one applies here so we need the explicit line break ;.

) => {
await this._storeWrapper.setUpUserProfile(account)
this.eventListener.clearArbitratorHandlers()
await this.disputes.addDisputeEventListener(arbitratorAddress, account)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not this one too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Line width?

@clesaege
Copy link
Member

For linting, can't we use an automatic program to save time?

@satello satello force-pushed the refactor/add-kleros-scripts branch from b8d7a0b to 946d113 Compare February 27, 2018 16:10
@epiqueras
Copy link
Contributor Author

@clesaege
Yes, you should use your editor's eslint plugin with formatOnSave turned on.
You can also run yarn run lint --fix.

@satello satello merged commit 5e11e3f into develop Feb 27, 2018
@epiqueras epiqueras deleted the refactor/add-kleros-scripts branch February 27, 2018 16:49
This was referenced Feb 28, 2018
epiqueras added a commit that referenced this pull request Feb 28, 2018
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.

4 participants