Skip to content

Commit 5cd1bb8

Browse files
committed
Update eslint-config-standard-kit
1 parent 2792e06 commit 5cd1bb8

53 files changed

Lines changed: 936 additions & 407 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.eslintrc.json

Lines changed: 0 additions & 34 deletions
This file was deleted.

bin/testRates.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ const test4 = {
454454
]
455455
}
456456

457-
const fetchem = async (test: object): Promise<void> => {
457+
const fetchem = async (test: object): Promise<any> => {
458458
const response = await fetch('http://127.0.0.1:8087/v3/rates', {
459459
method: 'POST',
460460
headers: {
@@ -463,18 +463,18 @@ const fetchem = async (test: object): Promise<void> => {
463463
body: JSON.stringify(test)
464464
})
465465
const json = await response.json()
466-
console.log(JSON.stringify(json, null, 2))
466+
return json
467467
}
468468

469469
const main = async (): Promise<void> => {
470-
console.log('test1')
471-
console.log(JSON.stringify(await fetchem(test1), null, 2))
472-
console.log('test2')
473-
console.log(JSON.stringify(await fetchem(test2), null, 2))
474-
console.log('test3')
475-
console.log(JSON.stringify(await fetchem(test3), null, 2))
476-
console.log('test4')
477-
console.log(JSON.stringify(await fetchem(test4), null, 2))
470+
const test1Result = await fetchem(test1)
471+
console.log('test1', JSON.stringify(test1Result, null, 2))
472+
const test2Result = await fetchem(test2)
473+
console.log('test2', JSON.stringify(test2Result, null, 2))
474+
const test3Result = await fetchem(test3)
475+
console.log('test3', JSON.stringify(test3Result, null, 2))
476+
const test4Result = await fetchem(test4)
477+
console.log('test4', JSON.stringify(test4Result, null, 2))
478478
}
479479

480480
main().catch(e => {

eslint.config.mjs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import standardConfig from 'eslint-config-standard-kit'
2+
3+
export default [
4+
...standardConfig({
5+
prettier: true,
6+
sortImports: true,
7+
node: true,
8+
typescript: true
9+
}),
10+
11+
// Turn several TypeScript lint errors into warnings:
12+
{
13+
files: ['**/*.ts', '**/*.tsx'],
14+
languageOptions: {
15+
parserOptions: {
16+
projectService: true,
17+
tsconfigRootDir: import.meta.dirname
18+
}
19+
},
20+
rules: {
21+
'@typescript-eslint/ban-ts-comment': 'warn',
22+
'@typescript-eslint/default-param-last': 'warn',
23+
'@typescript-eslint/explicit-function-return-type': 'warn',
24+
'@typescript-eslint/no-dynamic-delete': 'warn',
25+
'@typescript-eslint/no-misused-promises': 'warn',
26+
'@typescript-eslint/prefer-nullish-coalescing': 'warn',
27+
'@typescript-eslint/prefer-optional-chain': 'warn',
28+
'@typescript-eslint/require-array-sort-compare': 'warn',
29+
'@typescript-eslint/restrict-plus-operands': 'warn',
30+
'@typescript-eslint/restrict-template-expressions': 'warn',
31+
'@typescript-eslint/strict-boolean-expressions': 'warn',
32+
'@typescript-eslint/use-unknown-in-catch-callback-variable': 'warn',
33+
34+
// Allow snake_case until we remove the legacy code
35+
camelcase: 'off',
36+
'@typescript-eslint/naming-convention': [
37+
'warn',
38+
{
39+
selector: 'variableLike',
40+
format: ['camelCase', 'PascalCase', 'snake_case'], // allow all three
41+
leadingUnderscore: 'allow'
42+
},
43+
{
44+
selector: 'typeLike',
45+
format: ['PascalCase']
46+
}
47+
]
48+
}
49+
},
50+
51+
// Global ignores need to be in their own block:
52+
{
53+
ignores: ['lib/*', 'node_modules/*', '.vscode/*']
54+
}
55+
]

package.json

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,8 @@
4444
"compression": "^1.7.4",
4545
"cors": "^2.8.5",
4646
"edge-server-tools": "^0.2.22",
47-
"eslint-config-standard-kit": "0.15.1",
48-
"eslint-plugin-import": "^2.22.1",
49-
"eslint-plugin-node": "^11.1.0",
50-
"eslint-plugin-prettier": "^3.1.4",
51-
"eslint-plugin-promise": "^4.2.1",
52-
"eslint-plugin-simple-import-sort": "^6.0.1",
53-
"eslint": "^8.57.0",
47+
"eslint": "^9.31.0",
48+
"eslint-config-standard-kit": "1.0.0",
5449
"express": "^4.21.2",
5550
"husky": "^5.2.0",
5651
"lint-staged": ">=9.0.0",
@@ -64,7 +59,7 @@
6459
"redis": "^4.0.4",
6560
"rimraf": "^6.0.1",
6661
"serverlet": "^0.1.3",
67-
"sucrase": "^3.12.1",
62+
"sucrase": "^3.35.0",
6863
"typescript": "5.0.4"
6964
},
7065
"dependencies": {

src/coinrankEngine.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import fetch from 'node-fetch'
22

33
import { config } from './config'
44
import { REDIS_COINRANK_KEY_PREFIX } from './constants'
5-
import { asCoingeckoMarkets, CoinrankMarkets, CoinrankRedis } from './types'
5+
import {
6+
asCoingeckoMarkets,
7+
type CoinrankMarkets,
8+
type CoinrankRedis
9+
} from './types'
610
import { setAsync, slackMessage } from './utils/dbUtils'
711
import { getDelay, logger, snooze } from './utils/utils'
812

@@ -65,9 +69,11 @@ export const coinrankEngine = async (): Promise<void> => {
6569
)
6670
} catch (e) {
6771
const err: any = e // Weird TS issue causing :any to get removed from above line
68-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
72+
6973
const message = `coinrankEngine failure: ${err.message}`
70-
slackMessage(message).catch(e => logger(e))
74+
slackMessage(message).catch(e => {
75+
logger(e)
76+
})
7177
logger(message)
7278
}
7379
}

src/exchangeRateRouter.ts

Lines changed: 61 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
import { mul } from 'biggystring'
2-
import { asArray, asMaybe, asObject, asOptional, asString } from 'cleaners'
2+
import { asArray, asMaybe, asObject, asString } from 'cleaners'
33
import express from 'express'
44
import nano from 'nano'
55
import fetch from 'node-fetch'
66
import promisify from 'promisify-node'
77

88
import { config } from './config'
99
import { REDIS_COINRANK_KEY_PREFIX } from './constants'
10-
import { asReturnGetRate, getExchangeRates } from './rates'
10+
import { getExchangeRates, type ReturnGetRate } from './rates'
1111
import {
1212
asCoinrankAssetReq,
1313
asCoinrankReq,
1414
asExchangeRateResponse,
15-
CoinrankAssetReq,
16-
CoinrankRedis,
17-
CoinrankReq
15+
type CoinrankAssetReq,
16+
type CoinrankRedis,
17+
type CoinrankReq
1818
} from './types'
19-
import { asExtendedReq } from './utils/asExtendedReq'
2019
import {
21-
DbDoc,
20+
type DbDoc,
2221
getAsync,
2322
hgetallAsync,
2423
hmgetAsync,
@@ -87,14 +86,16 @@ const asExchangeRatesReq = asObject({
8786
data: asArray(asExchangeRateReq)
8887
})
8988

90-
const asRatesRequest = asExtendedReq({
91-
requestedRates: asOptional(asExchangeRatesReq),
92-
requestedRatesResult: asOptional(asReturnGetRate)
93-
})
89+
interface RatesRequest {
90+
requestedRates?: {
91+
data: ExchangeRateReq[]
92+
}
93+
requestedRatesResult?: ReturnGetRate
94+
}
9495

9596
// Hack to add type definitions for middleware
9697
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
97-
type ExpressRequest = ReturnType<typeof asRatesRequest> | void
98+
type ExpressRequest = RatesRequest | void
9899

99100
const { couchUri, fiatCurrencyCodes: FIAT_CODES } = config
100101
const EXCHANGE_RATES_BATCH_LIMIT = 100
@@ -128,7 +129,10 @@ const v1ExchangeRateIsoAdder: express.RequestHandler = (
128129
next
129130
): void => {
130131
const exReq = req as ExpressRequest
131-
if (exReq?.requestedRates == null) return next(500)
132+
if (exReq?.requestedRates == null) {
133+
next(500)
134+
return
135+
}
132136

133137
exReq.requestedRates.data = exReq.requestedRates.data.map(req => ({
134138
currency_pair: maybeAddIsoToPair(req.currency_pair),
@@ -144,7 +148,10 @@ const v1ExchangeRateIsoSubtractor: express.RequestHandler = (
144148
next
145149
): void => {
146150
const exReq = req as ExpressRequest
147-
if (exReq?.requestedRatesResult == null) return next(500)
151+
if (exReq?.requestedRatesResult == null) {
152+
next(500)
153+
return
154+
}
148155

149156
exReq.requestedRatesResult.data = exReq.requestedRatesResult.data.map(
150157
rate => ({
@@ -158,7 +165,10 @@ const v1ExchangeRateIsoSubtractor: express.RequestHandler = (
158165

159166
const v1IsoChecker: express.RequestHandler = (req, res, next): void => {
160167
const exReq = req as ExpressRequest
161-
if (exReq?.requestedRates == null) return next(500)
168+
if (exReq?.requestedRates == null) {
169+
next(500)
170+
return
171+
}
162172

163173
if (exReq.requestedRates.data.every(pair => isIsoPair(pair.currency_pair))) {
164174
res.status(400).send(`Please use v2 of this API to query with ISO codes`)
@@ -174,7 +184,10 @@ const v1IsoChecker: express.RequestHandler = (req, res, next): void => {
174184

175185
const exchangeRateCleaner: express.RequestHandler = (req, res, next): void => {
176186
const exReq = req as ExpressRequest
177-
if (exReq == null) return next(500)
187+
if (exReq == null) {
188+
next(500)
189+
return
190+
}
178191

179192
const { currency_pair, date } = req.query
180193
try {
@@ -196,10 +209,12 @@ const exchangeRateCleaner: express.RequestHandler = (req, res, next): void => {
196209

197210
const exchangeRatesCleaner: express.RequestHandler = (req, res, next): void => {
198211
const exReq = req as ExpressRequest
199-
if (exReq == null) return next(500)
200-
212+
if (exReq == null) {
213+
next(500)
214+
return
215+
}
201216
try {
202-
exReq.requestedRates = asExchangeRatesReq(exReq.body)
217+
exReq.requestedRates = asExchangeRatesReq(req.body)
203218
} catch (e) {
204219
res
205220
.status(400)
@@ -221,13 +236,16 @@ const queryRedis: express.RequestHandler = async (
221236
next
222237
): Promise<void> => {
223238
const exReq = req as ExpressRequest
224-
if (exReq?.requestedRates == null) return next(500)
239+
if (exReq?.requestedRates == null) {
240+
next(500)
241+
return
242+
}
225243

226244
// Redis will store all crypto code rates in USD and USD to all fiat codes
227245
// This middleware splits up incoming pairs into two rates, crypto_USD and USD_fiat,
228246
// so each unique timestamp only requires a single query to redis to get all applicable rates.
229247

230-
const reqMap: { [date: string]: string[] } = {}
248+
const reqMap: Record<string, string[]> = {}
231249
for (const req of exReq.requestedRates.data) {
232250
const [cryptoCode, fiatCode] = req.currency_pair.split('_')
233251
if (reqMap[req.date] == null) reqMap[req.date] = []
@@ -287,10 +305,14 @@ const queryExchangeRates: express.RequestHandler = async (
287305
next
288306
): Promise<void> => {
289307
const exReq = req as ExpressRequest
290-
if (exReq?.requestedRates == null) return next(500)
308+
if (exReq?.requestedRates == null) {
309+
next(500)
310+
return
311+
}
291312

292313
if (exReq.requestedRates.data.length === 0) {
293-
return next()
314+
next()
315+
return
294316
}
295317

296318
try {
@@ -311,14 +333,20 @@ const queryExchangeRates: express.RequestHandler = async (
311333

312334
const sendExchangeRate: express.RequestHandler = (req, res, next): void => {
313335
const exReq = req as ExpressRequest
314-
if (exReq?.requestedRatesResult == null) return next(500)
336+
if (exReq?.requestedRatesResult == null) {
337+
next(500)
338+
return
339+
}
315340

316341
res.json(exReq.requestedRatesResult.data[0])
317342
}
318343

319344
const sendExchangeRates: express.RequestHandler = (req, res, next): void => {
320345
const exReq = req as ExpressRequest
321-
if (exReq?.requestedRatesResult == null) return next(500)
346+
if (exReq?.requestedRatesResult == null) {
347+
next(500)
348+
return
349+
}
322350

323351
res.json({ data: exReq.requestedRatesResult.data })
324352
}
@@ -456,7 +484,10 @@ const sendCoinrankAsset: express.RequestHandler = async (
456484
next
457485
): Promise<void> => {
458486
const exReq = req as ExpressRequest
459-
if (exReq == null) return next(500)
487+
if (exReq == null) {
488+
next(500)
489+
return
490+
}
460491

461492
let query: CoinrankAssetReq
462493
try {
@@ -499,7 +530,10 @@ const sendCoinranks: express.RequestHandler = async (
499530
next
500531
): Promise<void> => {
501532
const exReq = req as ExpressRequest
502-
if (exReq == null) return next(500)
533+
if (exReq == null) {
534+
next(500)
535+
return
536+
}
503537

504538
let query: CoinrankReq
505539
try {

0 commit comments

Comments
 (0)