Skip to content

Commit

Permalink
chore(github CI):add prettier check (#326)
Browse files Browse the repository at this point in the history
* chore(github CI):add prettier check

* minor

* add eslint

* fix

* separate

* format codes

* clean up
  • Loading branch information
0xmountaintop authored Sep 14, 2021
1 parent 19a62f0 commit 5ed5ca2
Show file tree
Hide file tree
Showing 16 changed files with 126 additions and 120 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
path: ./examples/js/node_modules
key: node_modules-${{ hashFiles('examples/js/package-lock.json') }}

- name: NPM ci
- name: npm ci
if: steps.npm_cache.outputs.cache-hit != 'true'
run: |
cd ./examples/js/
Expand Down
23 changes: 22 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
- release/*

jobs:
lint:
rust-lint:
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down Expand Up @@ -62,3 +62,24 @@ jobs:
with:
command: clippy
args: -- -D warnings

js-lint:
runs-on: ubuntu-latest

steps:
- name: Checkout sources
uses: actions/checkout@v2

- name: Install Node.js 16
uses: actions/setup-node@v2
with:
node-version: '16'
# cache: 'npm'
# cache-dependency-path: examples/js/package-lock.json

- name: Prettify js/ts code
uses: creyD/prettier_action@v4.0
with:
dry: True
prettier_options: --check examples/js/*
# github_token: ${{ secrets.GITHUB_TOKEN }}
32 changes: 16 additions & 16 deletions examples/js/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"env": {
"browser": true,
"es6": true
},
"extends": ["eslint:recommended", "plugin:prettier/recommended"],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
"no-unused-vars": "off"
}
"env": {
"browser": true,
"es6": true
},
"extends": ["eslint:recommended", "plugin:prettier/recommended"],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
"no-unused-vars": "off"
}
}
6 changes: 3 additions & 3 deletions examples/js/RESTClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class RESTClient {
console.log("using REST API server: ", server);
this.client = axios.create({
baseURL: server,
timeout: 1000
timeout: 1000,
});
}

Expand All @@ -27,7 +27,7 @@ class RESTClient {
console.log("error:", resp.data);
return null;
}
let userInfo = (resp.data as unknown) as UserInfo;
let userInfo = resp.data as unknown as UserInfo;
//console.log('raw', resp.data, 'result', userInfo);
return userInfo;
}
Expand All @@ -44,7 +44,7 @@ class RESTClient {
}
) {
let resp = await this.client.get(`/internal_txs/${user_id}`, {
params: _.pickBy(params, _.identity)
params: _.pickBy(params, _.identity),
});
if (resp.status === 200) {
return resp.data;
Expand Down
34 changes: 15 additions & 19 deletions examples/js/bots/run_bots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { defaultRESTClient, RESTClient } from "../RESTClient";
import {
defaultClient as defaultGrpcClient,
Client as grpcClient,
defaultClient
defaultClient,
} from "../client";
import { sleep, depositAssets, getPriceOfCoin } from "../util";
import {
ORDER_SIDE_BID,
ORDER_SIDE_ASK,
ORDER_TYPE_LIMIT,
VERBOSE
VERBOSE,
} from "../config";

// TODO: add a similar function using quoteAmount. "i want to sell some eth to get 5000 usdt"
Expand Down Expand Up @@ -44,7 +44,7 @@ async function estimateMarketOrderSell(
quote: quoteAcc,
avgPrice: quoteAcc / baseAcc,
bestPrice,
worstPrice
worstPrice,
};
//console.log("estimateMarketOrderSell:", estimateResult);
return estimateResult;
Expand Down Expand Up @@ -79,7 +79,7 @@ async function estimateMarketOrderBuy(
quote: quoteAcc,
avgPrice: quoteAcc / tradeAmount,
bestPrice,
worstPrice
worstPrice,
};
//console.log("estimateMarketOrderBuy:", estimateResult);
return estimateResult;
Expand Down Expand Up @@ -153,7 +153,7 @@ async function initUser(): Promise<number> {
let resp = await defaultGrpcClient.registerUser({
user_id: 0, // discard in server side
l1_address: acc.ethAddr,
l2_pubkey: acc.bjjPubKey
l2_pubkey: acc.bjjPubKey,
});
const t = Date.now();
console.log("register resp", resp);
Expand Down Expand Up @@ -259,13 +259,13 @@ async function main() {
console.log("------- BALANCE1:", {
quote: allQuote,
base: res.quote,
total: allQuote + res.quote
total: allQuote + res.quote,
});
console.log("------- BALANCE2:", {
quote: allQuote,
base: allBase * externalPrice,
total: allQuote + allBase * externalPrice,
totalInB: allQuote / externalPrice + allBase
totalInB: allQuote / externalPrice + allBase,
});
}

Expand All @@ -285,10 +285,10 @@ async function main() {
console.log("oldOrders", oldOrders);
}
const oldAskOrder = oldOrders.orders.find(
elem => elem.order_side == "ASK"
(elem) => elem.order_side == "ASK"
);
const oldBidOrder = oldOrders.orders.find(
elem => elem.order_side == "BID"
(elem) => elem.order_side == "BID"
);

// await defaultGrpcClient.orderCancelAll(user_id, market);
Expand All @@ -313,14 +313,10 @@ async function main() {
let bidPriceRaw = price * (1 - spread);
let bidAmountRaw = (allQuote * ratio) / bidPriceRaw;
let askAmountRaw = allBase * ratio;
let {
price: askPrice,
amount: askAmount
} = defaultGrpcClient.roundOrderInput(market, askAmountRaw, askPriceRaw);
let {
price: bidPrice,
amount: bidAmount
} = defaultGrpcClient.roundOrderInput(market, bidAmountRaw, bidPriceRaw);
let { price: askPrice, amount: askAmount } =
defaultGrpcClient.roundOrderInput(market, askAmountRaw, askPriceRaw);
let { price: bidPrice, amount: bidAmount } =
defaultGrpcClient.roundOrderInput(market, bidAmountRaw, bidPriceRaw);
let minAmount = 0.001;
if (askAmountRaw < minAmount) {
askAmount = "";
Expand Down Expand Up @@ -357,15 +353,15 @@ async function main() {
order_side: ORDER_SIDE_BID,
order_type: ORDER_TYPE_LIMIT,
amount: bidAmount,
price: bidPrice
price: bidPrice,
};
const ask_order = {
user_id,
market,
order_side: ORDER_SIDE_ASK,
order_type: ORDER_TYPE_LIMIT,
amount: askAmount,
price: askPrice
price: askPrice,
};
await defaultGrpcClient.orderCancelAll(user_id, market);

Expand Down
41 changes: 25 additions & 16 deletions examples/js/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ORDER_SIDE_BID,
ORDER_SIDE_ASK,
ORDER_TYPE_LIMIT,
VERBOSE
VERBOSE,
} from "./config";

const file = "../../orchestra/proto/exchange/matchengine.proto";
Expand All @@ -14,7 +14,7 @@ const load = {
longs: String,
enums: String,
defaults: true,
oneofs: true
oneofs: true,
};

function fullPrec(d, p): Decimal {
Expand Down Expand Up @@ -57,7 +57,7 @@ class Client {
const allBalances = (
await this.client.BalanceQuery({ user_id: user_id, assets: [asset] })
).balances;
const balance = allBalances.find(item => item.asset_id == asset);
const balance = allBalances.find((item) => item.asset_id == asset);
let available = new Decimal(balance.available);
let frozen = new Decimal(balance.frozen);
let total = available.add(frozen);
Expand All @@ -76,7 +76,7 @@ class Client {
business_id,
delta,
detail: JSON.stringify(detail),
signature: ""
signature: "",
});
}
roundOrderInput(market, amount, price) {
Expand Down Expand Up @@ -130,7 +130,7 @@ class Client {
tokenSell,
tokenBuy,
totalSell,
totalBuy
totalBuy,
});
signature = this.accounts.get(user_id).signHashPacked(orderInput.hash());
}
Expand All @@ -143,7 +143,7 @@ class Client {
price: priceRounded,
taker_fee,
maker_fee,
signature
signature,
};
}
async orderPut(
Expand Down Expand Up @@ -183,7 +183,7 @@ class Client {
amount,
price,
taker_fee,
maker_fee
maker_fee,
} = o;
order_reqs.push(
await this.createOrder(
Expand All @@ -201,7 +201,7 @@ class Client {
return await this.client.batchOrderPut({
market,
reset,
orders: order_reqs
orders: order_reqs,
});
}

Expand Down Expand Up @@ -233,7 +233,7 @@ class Client {
}
let resp = (await this.client.MarketSummary({ markets })).market_summaries;
if (typeof req === "string") {
return resp.find(item => item.name === req);
return resp.find((item) => item.name === req);
}
return resp;
}
Expand Down Expand Up @@ -265,7 +265,7 @@ class Client {
amount: delta,
from,
from_nonce: nonce,
to
to,
});
signature = this.accounts.get(user_id).signHashPacked(tx.hash());
}
Expand All @@ -275,7 +275,7 @@ class Client {
asset,
delta,
memo,
signature
signature,
};
}

Expand All @@ -287,7 +287,7 @@ class Client {
token_id: this.assets.get(asset).inner_id,
amount: delta,
nonce: 0,
old_balance: 0 // TODO: Update `old_balance` with precision.
old_balance: 0, // TODO: Update `old_balance` with precision.
});
signature = this.accounts.get(account_id).signHashPacked(tx.hash());
}
Expand All @@ -298,7 +298,7 @@ class Client {
business_id,
delta: -delta,
detail: JSON.stringify(detail),
signature: signature
signature: signature,
};
}

Expand All @@ -309,9 +309,18 @@ class Client {

async withdraw(user_id, asset, business, business_id, delta, detail) {
if (delta < 0) {
throw new Error("Parameter `delta` must be positive in `withdraw` function");
throw new Error(
"Parameter `delta` must be positive in `withdraw` function"
);
}
let tx = this.createWithdrawTx(user_id, asset, business, business_id, delta, detail);
let tx = this.createWithdrawTx(
user_id,
asset,
business,
business_id,
delta,
detail
);
return await this.client.BalanceUpdate(tx);
}

Expand All @@ -331,7 +340,7 @@ class Client {
return await this.client.RegisterUser({
user_id: user.id || user.user_id, // legacy reasons
l1_address: user.l1_address,
l2_pubkey: user.l2_pubkey
l2_pubkey: user.l2_pubkey,
});
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/js/kafka_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class KafkaConsumer {
const brokers = process.env.KAFKA_BROKERS;
const kafka = new Kafka.Kafka({
brokers: (brokers || "127.0.0.1:9092").split(","),
logLevel: Kafka.logLevel.WARN
logLevel: Kafka.logLevel.WARN,
});
const consumer = kafka.consumer({ groupId: "test-group" });
this.consumer = consumer;
Expand All @@ -31,11 +31,11 @@ export class KafkaConsumer {
partition,
offset: message.offset,
key: message.key.toString(),
value: message.value.toString()
value: message.value.toString(),
});
}
this.messages.get(topic).push(message.value.toString());
}
},
});
}
Reset() {
Expand Down
Loading

0 comments on commit 5ed5ca2

Please sign in to comment.