Skip to content

Commit

Permalink
refactor(xo): update && adapt to lints
Browse files Browse the repository at this point in the history
  • Loading branch information
EdJoPaTo committed Feb 6, 2024
1 parent d6b199a commit fa2610a
Show file tree
Hide file tree
Showing 8 changed files with 741 additions and 615 deletions.
1,295 changes: 708 additions & 587 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@
"@types/json-stable-stringify": "^1.0.32",
"@types/node": "^20.10.0",
"typescript": "^5.0.3",
"xo": "^0.56.0"
"xo": "^0.57.0"
},
"xo": {
"rules": {
"@typescript-eslint/naming-convention": "off"
"@typescript-eslint/naming-convention": "off",
"unicorn/prevent-abbreviations": "off"
}
}
}
3 changes: 1 addition & 2 deletions source/connected.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {Body} from 'grammy-inline-menu';
import {MenuTemplate} from 'grammy-inline-menu';
import {type Body, MenuTemplate} from 'grammy-inline-menu';
import {html as format} from 'telegram-format';
import * as connectedLogic from './lib/connected-logic.js';
import {timespan} from './lib/format.js';
Expand Down
5 changes: 1 addition & 4 deletions source/lib/notify-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ export function getByChat(chat: number) {

export function add(rule: Rule): void {
const {topic} = rule;
if (!rules[topic]) {
rules[topic] = [];
}

rules[topic] ??= [];
rules[topic]!.push(rule);
saveRules();
}
Expand Down
31 changes: 17 additions & 14 deletions source/lib/notify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ import stringify from 'json-stable-stringify';
import {html as format} from 'telegram-format';
import * as history from './mqtt-history.js';
import {isFalling, isRising, isUnequal} from './notify-math.js';
import type {Change, Rule} from './notify-rules.js';
import {CHANGE_TYPES, getByCompareTo, getByTopic} from './notify-rules.js';
import {
type Change,
CHANGE_TYPES,
getByCompareTo,
getByTopic,
type Rule,
} from './notify-rules.js';

let telegram: Telegram;

Expand Down Expand Up @@ -102,18 +107,16 @@ async function initiateNotification(
compareTo: number,
) {
const identifier = `${stringify(rule)}${change}`;
if (!debouncers[identifier]) {
debouncers[identifier] = debounce(
async (argsArray: ArgumentArrayArray) => {
await initiateNotificationDebounced(rule, change, argsArray);

// Fix required. See https://github.com/bjoerge/debounce-promise/pull/19
return argsArray.map(() => null);
},
rule.stableSeconds * 1000,
{accumulate: true},
);
}
debouncers[identifier] ??= debounce(
async (argsArray: ArgumentArrayArray) => {
await initiateNotificationDebounced(rule, change, argsArray);

// Fix required. See https://github.com/bjoerge/debounce-promise/pull/19
return argsArray.map(() => null);
},
rule.stableSeconds * 1000,
{accumulate: true},
);

return debouncers[identifier]!({
currentValue,
Expand Down
7 changes: 5 additions & 2 deletions source/notify.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import {StatelessQuestion} from '@grammyjs/stateless-question';
import {Composer} from 'grammy';
import type {Body} from 'grammy-inline-menu';
import {MenuTemplate, replyMenuToContext} from 'grammy-inline-menu';
import {
type Body,
MenuTemplate,
replyMenuToContext,
} from 'grammy-inline-menu';
import {html as format} from 'telegram-format';
import type {MyContext} from './context.js';
import {toggleKeyInArray} from './lib/array-helper.js';
Expand Down
3 changes: 1 addition & 2 deletions source/status.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {Body} from 'grammy-inline-menu';
import {MenuTemplate} from 'grammy-inline-menu';
import {type Body, MenuTemplate} from 'grammy-inline-menu';
import {html as format} from 'telegram-format';
import type {MyContext} from './context.js';
import {getRelatedConnectionStatus} from './lib/connected-logic.js';
Expand Down
7 changes: 5 additions & 2 deletions source/topic-filter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import {StatelessQuestion} from '@grammyjs/stateless-question';
import {Composer} from 'grammy';
import type {MenuTemplate} from 'grammy-inline-menu';
import {getMenuOfPath, replyMenuToContext} from 'grammy-inline-menu';
import {
getMenuOfPath,
type MenuTemplate,
replyMenuToContext,
} from 'grammy-inline-menu';
import type {MyContext} from './context.js';

export const bot = new Composer<MyContext>();
Expand Down

0 comments on commit fa2610a

Please sign in to comment.