-
Notifications
You must be signed in to change notification settings - Fork 14
refactor: project wide clean up #83
Conversation
satello
left a comment
There was a problem hiding this 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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 === res2The extra await basically turns promise into promise.then(res => res).
| @@ -1,111 +1,142 @@ | |||
| import PromiseQueue from '../../util/PromiseQueue' | |||
|
|
|||
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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`) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whats your thinking here?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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([ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line width?
|
For linting, can't we use an automatic program to save time? |
b8d7a0b to
946d113
Compare
|
@clesaege |
This PR: