Skip to content

Commit

Permalink
Merge branch 'william/update-linting'
Browse files Browse the repository at this point in the history
  • Loading branch information
swansontec committed Jul 18, 2022
2 parents de7b060 + 9b6ee5b commit 513e5e4
Show file tree
Hide file tree
Showing 12 changed files with 273 additions and 308 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/build/
/lib/
20 changes: 15 additions & 5 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
{
"extends": [
"standard-kit/prettier",
"standard-kit/prettier/node",
"standard-kit/prettier/typescript"
"standard-kit/prettier/typescript",
"standard-kit/prettier/node"
],
"overrides": [
{
"files": ["*.ts", "*.tsx"],
"rules": {
"@typescript-eslint/explicit-function-return-type": "warn",
"@typescript-eslint/no-dynamic-delete": "warn",
"@typescript-eslint/restrict-template-expressions": "warn",
"@typescript-eslint/prefer-optional-chain": "warn",
"@typescript-eslint/strict-boolean-expressions": "warn"
}
}
],
"parserOptions": {
"project": "tsconfig.json"
Expand All @@ -11,8 +23,6 @@
"simple-import-sort"
],
"rules": {
"@typescript-eslint/explicit-function-return-type": "warn",
"@typescript-eslint/strict-boolean-expressions": "warn",
"simple-import-sort/sort": "error"
"simple-import-sort/imports": "error"
}
}
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: node_js
node_js:
- 16
script:
- 'yarn verify'
21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
"scripts": {
"build": "sucrase -q -t typescript,imports -d ./lib ./src",
"clean": "rimraf lib",
"fix": "eslint . --fix",
"fix": "yarn-deduplicate && eslint . --fix",
"lint": "eslint .",
"precommit": "lint-staged && npm-run-all types prepare",
"prepare": "husky install && npm-run-all clean build",
"start-server": "node -r sucrase/register src/server/index.ts",
"start-price": "node -r sucrase/register src/price-script/index.ts",
"types": "tsc"
"types": "tsc",
"verify": "npm-run-all lint types prepare"
},
"lint-staged": {
"*.{js,ts}": "eslint"
Expand All @@ -38,21 +39,21 @@
"@types/express": "^4.17.8",
"@types/node": "^14.0.5",
"@types/node-schedule": "^1.3.0",
"@typescript-eslint/eslint-plugin": "^2.0.0",
"@typescript-eslint/parser": "^2.0.0",
"eslint": "^7.9.0",
"eslint-config-standard-kit": "^0.14.4",
"eslint-plugin-import": "^2.22.0",
"@typescript-eslint/eslint-plugin": "^4.8.2",
"@typescript-eslint/parser": "^4.8.2",
"eslint": "^7.14.0",
"eslint-config-standard-kit": "0.15.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-simple-import-sort": "^5.0.3",
"eslint-plugin-standard": "^4.0.1",
"eslint-plugin-simple-import-sort": "^6.0.1",
"husky": "^7.0.0",
"lint-staged": "^10.4.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.1.2",
"sucrase": "^3.21.0",
"typescript": "^4.7.3"
"typescript": "^4.7.3",
"yarn-deduplicate": "^5.0.0"
}
}
2 changes: 1 addition & 1 deletion src/models/CurrencyThreshold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class CurrencyThreshold extends Base implements ICurrencyThreshold {
currencyCode: string
): Promise<CurrencyThreshold> {
const threshold = new CurrencyThreshold(undefined, currencyCode)
return threshold.save()
return await threshold.save()
}

public async update(
Expand Down
2 changes: 1 addition & 1 deletion src/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class User extends Base implements ReturnType<typeof asUser> {
currencyCode: string,
hours: string
) {
return User.table.view<IDevicesByCurrencyHoursViewResponse>(
return await User.table.view<IDevicesByCurrencyHoursViewResponse>(
'filter',
'by-currency',
{ key: [currencyCode, hours] }
Expand Down
10 changes: 5 additions & 5 deletions src/models/User/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ export const views = {
filter: {
// @ts-expect-error
byCurrency(doc) {
var notifs = doc.notifications
const notifs = doc.notifications
if (notifs && notifs.enabled && notifs.currencyCodes) {
var codes = notifs.currencyCodes
for (var currencyCode in codes) {
for (var hours in codes[currencyCode]) {
var enabled = codes[currencyCode][hours]
const codes = notifs.currencyCodes
for (const currencyCode in codes) {
for (const hours in codes[currencyCode]) {
const enabled = codes[currencyCode][hours]
if (enabled) {
emit([currencyCode, hours], doc.devices)
}
Expand Down
6 changes: 2 additions & 4 deletions src/models/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class Base implements ReturnType<typeof asModelData> {
}

public processAPIResponse(response: Nano.DocumentInsertResponse) {
if (response.ok === true) {
if (response.ok) {
this._id = response.id
this._rev = response.rev
}
Expand Down Expand Up @@ -85,7 +85,6 @@ export class Base implements ReturnType<typeof asModelData> {
): Promise<Array<InstanceType<T>>> {
const response = await this.table.list({ include_docs: true })
return response.rows.map(row => {
// @ts-ignore
const item: InstanceType<T> = new this(row.doc)
item.validate()
return item
Expand All @@ -98,7 +97,6 @@ export class Base implements ReturnType<typeof asModelData> {
): Promise<Array<InstanceType<T>>> {
const response = await this.table.find(where)
return response.docs.map(doc => {
// @ts-ignore
const item: InstanceType<T> = new this(doc)
item.validate()
return item
Expand Down Expand Up @@ -151,7 +149,7 @@ export class Base implements ReturnType<typeof asModelData> {
'Document already exists. Fetching current `_rev` and resaving.'
)
const { _rev } = await ItemClass.fetch(this._id)
return this.save('_rev', _rev)
return await this.save('_rev', _rev)
}
default:
throw err
Expand Down
4 changes: 2 additions & 2 deletions src/price-script/checkPriceChanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function checkPriceChanges(manager: NotificationManager) {
const body = `${currencyCode} is ${direction} ${symbol}${priceChange}% to $${displayPrice} in the last ${time}.`
const data = {}

return manager.send(title, body, deviceTokens, data)
return await manager.send(title, body, deviceTokens, data)
}

// Fetch list of threshold items and their prices
Expand All @@ -60,7 +60,7 @@ export async function checkPriceChanges(manager: NotificationManager) {
defaultThresholds[hours],
anomalyPercent
)
if (!priceData) continue
if (priceData == null) continue

const { rows: usersDevices } = await User.devicesByCurrencyHours(
currencyCode,
Expand Down
4 changes: 2 additions & 2 deletions src/price-script/fetchThresholdPrices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Counter = ReturnType<typeof io.counter>
const processMetrics: { [id: string]: Counter | undefined } = {}

async function sleep(ms = SLEEP_TIMEOUT) {
return new Promise(resolve => setTimeout(resolve, ms))
return await new Promise(resolve => setTimeout(resolve, ms))
}
export async function fetchThresholdPrice(
currencyThreshold: CurrencyThreshold,
Expand Down Expand Up @@ -87,7 +87,7 @@ export async function fetchThresholdPrice(

const counterId = `threshold:crossed:${currencyCode}:${hours}`
let counter = processMetrics[counterId]
if (!counter) {
if (counter == null) {
counter = processMetrics[counterId] = io.counter({
id: counterId,
name: `Threshold Crossed for ${currencyCode} - ${hours} Hour`
Expand Down
4 changes: 2 additions & 2 deletions src/price-script/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ async function main(): Promise<void> {

// Read the API keys from settings:
const managers = await Promise.all(
syncedSettings.doc.apiKeys.map(async partner =>
NotificationManager.init(partner.apiKey)
syncedSettings.doc.apiKeys.map(
async partner => await NotificationManager.init(partner.apiKey)
)
)

Expand Down
Loading

0 comments on commit 513e5e4

Please sign in to comment.