From cb34ae5041afa47017ee757becdf4825ec229cf6 Mon Sep 17 00:00:00 2001 From: Juergen Kunz Date: Thu, 29 Jan 2026 17:46:23 +0000 Subject: [PATCH] fix(core): fix lint/type issues and small refactors --- bin/nupst-wrapper.js | 1 + changelog.md | 10 ++++++++++ scripts/install-binary.js | 4 +++- ts/00_commitinfo_data.ts | 2 +- ts/actions/script-action.ts | 2 +- ts/actions/webhook-action.ts | 4 ++-- ts/cli.ts | 2 +- ts/cli/feature-handler.ts | 1 - ts/cli/group-handler.ts | 1 - ts/cli/service-handler.ts | 2 +- ts/cli/ups-handler.ts | 2 +- ts/daemon.ts | 4 ++-- ts/logger.ts | 3 ++- ts/snmp/manager.ts | 19 +++++++++++++------ ts/systemd.ts | 2 +- 15 files changed, 39 insertions(+), 20 deletions(-) diff --git a/bin/nupst-wrapper.js b/bin/nupst-wrapper.js index e11dfd1..d84137f 100644 --- a/bin/nupst-wrapper.js +++ b/bin/nupst-wrapper.js @@ -10,6 +10,7 @@ import { fileURLToPath } from 'url'; import { dirname, join } from 'path'; import { existsSync } from 'fs'; import { arch, platform } from 'os'; +import process from "node:process"; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); diff --git a/changelog.md b/changelog.md index a0d40a0..71f1eaf 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,15 @@ # Changelog +## 2026-01-29 - 5.2.3 - fix(core) +fix lint/type issues and small refactors + +- Add missing node:process imports in bin and scripts to ensure process is available +- Remove unused imports and unused type imports (e.g. writeFileSync, IActionConfig) to reduce noise +- Make some methods synchronous (service update, webhook call) to match actual usage +- Tighten SNMP typings and linting: added deno-lint-ignore comments, renamed unused params with leading underscore, and use `as const` for securityLevel fallbacks +- Improve error handling variable naming in systemd (use error instead of _error) +- Annotate ANSI regex with deno-lint-ignore no-control-regex and remove unused color/symbol imports across CLI/daemon/logger + ## 2026-01-29 - 5.2.2 - fix(core) tidy formatting and minor fixes across CLI, SNMP, HTTP server, migrations and packaging diff --git a/scripts/install-binary.js b/scripts/install-binary.js index d92cef9..7001865 100644 --- a/scripts/install-binary.js +++ b/scripts/install-binary.js @@ -1,4 +1,5 @@ #!/usr/bin/env node +// deno-lint-ignore-file no-unused-vars /** * NUPST npm postinstall script @@ -6,13 +7,14 @@ */ import { arch, platform } from 'os'; -import { chmodSync, existsSync, mkdirSync, unlinkSync, writeFileSync } from 'fs'; +import { chmodSync, existsSync, mkdirSync, unlinkSync } from 'fs'; import { dirname, join } from 'path'; import { fileURLToPath } from 'url'; import https from 'https'; import { pipeline } from 'stream'; import { promisify } from 'util'; import { createWriteStream } from 'fs'; +import process from "node:process"; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index cc3c519..c404c70 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@serve.zone/nupst', - version: '5.2.2', + version: '5.2.3', description: 'Network UPS Shutdown Tool - Monitor SNMP-enabled UPS devices and orchestrate graceful system shutdowns during power emergencies' } diff --git a/ts/actions/script-action.ts b/ts/actions/script-action.ts index 695c442..28b8a1a 100644 --- a/ts/actions/script-action.ts +++ b/ts/actions/script-action.ts @@ -3,7 +3,7 @@ import * as fs from 'node:fs'; import process from 'node:process'; import { exec } from 'node:child_process'; import { promisify } from 'node:util'; -import { Action, type IActionConfig, type IActionContext } from './base-action.ts'; +import { Action, type IActionContext } from './base-action.ts'; import { logger } from '../logger.ts'; const execAsync = promisify(exec); diff --git a/ts/actions/webhook-action.ts b/ts/actions/webhook-action.ts index 5840695..f01b9b4 100644 --- a/ts/actions/webhook-action.ts +++ b/ts/actions/webhook-action.ts @@ -1,7 +1,7 @@ import * as http from 'node:http'; import * as https from 'node:https'; import { URL } from 'node:url'; -import { Action, type IActionConfig, type IActionContext } from './base-action.ts'; +import { Action, type IActionContext } from './base-action.ts'; import { logger } from '../logger.ts'; import { WEBHOOK } from '../constants.ts'; @@ -81,7 +81,7 @@ export class WebhookAction extends Action { * @param method HTTP method (GET or POST) * @param timeout Request timeout in milliseconds */ - private async callWebhook( + private callWebhook( context: IActionContext, method: 'GET' | 'POST', timeout: number, diff --git a/ts/cli.ts b/ts/cli.ts index 3b7f106..e87de8e 100644 --- a/ts/cli.ts +++ b/ts/cli.ts @@ -1,7 +1,7 @@ import { execSync } from 'node:child_process'; import { Nupst } from './nupst.ts'; import { type ITableColumn, logger } from './logger.ts'; -import { symbols, theme } from './colors.ts'; +import { theme } from './colors.ts'; /** * Class for handling CLI commands diff --git a/ts/cli/feature-handler.ts b/ts/cli/feature-handler.ts index 49aba77..e0fa7f1 100644 --- a/ts/cli/feature-handler.ts +++ b/ts/cli/feature-handler.ts @@ -1,4 +1,3 @@ -import process from 'node:process'; import { execSync } from 'node:child_process'; import { Nupst } from '../nupst.ts'; import { logger } from '../logger.ts'; diff --git a/ts/cli/group-handler.ts b/ts/cli/group-handler.ts index a5781db..ebb8de2 100644 --- a/ts/cli/group-handler.ts +++ b/ts/cli/group-handler.ts @@ -1,4 +1,3 @@ -import process from 'node:process'; import { Nupst } from '../nupst.ts'; import { type ITableColumn, logger } from '../logger.ts'; import { theme } from '../colors.ts'; diff --git a/ts/cli/service-handler.ts b/ts/cli/service-handler.ts index 5888ddf..36aea07 100644 --- a/ts/cli/service-handler.ts +++ b/ts/cli/service-handler.ts @@ -126,7 +126,7 @@ export class ServiceHandler { /** * Update NUPST from repository and refresh systemd service */ - public async update(): Promise { + public update(): void { try { // Check if running as root this.checkRootAccess( diff --git a/ts/cli/ups-handler.ts b/ts/cli/ups-handler.ts index 8efedaa..4c46944 100644 --- a/ts/cli/ups-handler.ts +++ b/ts/cli/ups-handler.ts @@ -5,7 +5,7 @@ import { type ITableColumn, logger } from '../logger.ts'; import { theme } from '../colors.ts'; import * as helpers from '../helpers/index.ts'; import type { ISnmpConfig, IUpsStatus as ISnmpUpsStatus, TUpsModel } from '../snmp/types.ts'; -import type { INupstConfig, IUpsConfig, IUpsStatus } from '../daemon.ts'; +import type { INupstConfig, IUpsConfig } from '../daemon.ts'; import type { IActionConfig } from '../actions/base-action.ts'; /** diff --git a/ts/daemon.ts b/ts/daemon.ts index 3329bdf..f9dbc2e 100644 --- a/ts/daemon.ts +++ b/ts/daemon.ts @@ -5,9 +5,9 @@ import { exec, execFile } from 'node:child_process'; import { promisify } from 'node:util'; import { NupstSnmp } from './snmp/manager.ts'; import type { ISnmpConfig, IUpsStatus as ISnmpUpsStatus } from './snmp/types.ts'; -import { type ITableColumn, logger } from './logger.ts'; +import { logger } from './logger.ts'; import { MigrationRunner } from './migrations/index.ts'; -import { formatPowerStatus, getBatteryColor, getRuntimeColor, symbols, theme } from './colors.ts'; +import { formatPowerStatus, getBatteryColor, getRuntimeColor, theme } from './colors.ts'; import type { IActionConfig } from './actions/base-action.ts'; import { ActionManager, type IActionContext, type TPowerStatus } from './actions/index.ts'; import { NupstHttpServer } from './http-server.ts'; diff --git a/ts/logger.ts b/ts/logger.ts index 55c029e..2c620a5 100644 --- a/ts/logger.ts +++ b/ts/logger.ts @@ -230,7 +230,8 @@ export class Logger { * Strip ANSI color codes from string for accurate length calculation */ private stripAnsi(text: string): string { - // Remove ANSI escape codes + // Remove ANSI escape codes (intentional control character regex) + // deno-lint-ignore no-control-regex return text.replace(/\x1b\[[0-9;]*m/g, ''); } diff --git a/ts/snmp/manager.ts b/ts/snmp/manager.ts index 3473e1e..93e41c8 100644 --- a/ts/snmp/manager.ts +++ b/ts/snmp/manager.ts @@ -94,7 +94,8 @@ export class NupstSnmp { public snmpGet( oid: string, config = this.DEFAULT_CONFIG, - retryCount = 0, + _retryCount = 0, + // deno-lint-ignore no-explicit-any ): Promise { return new Promise((resolve, reject) => { if (this.debug) { @@ -105,6 +106,7 @@ export class NupstSnmp { } // Create SNMP options based on configuration + // deno-lint-ignore no-explicit-any const options: any = { port: config.port, retries: SNMP.RETRIES, // Number of retries @@ -132,6 +134,7 @@ export class NupstSnmp { const securityLevel = config.securityLevel || 'noAuthNoPriv'; // Create the user object with required structure for net-snmp + // deno-lint-ignore no-explicit-any const user: any = { name: config.username || '', }; @@ -214,7 +217,8 @@ export class NupstSnmp { const oids = [oid]; // Send the GET request - session.get(oids, (error: any, varbinds: any[]) => { + // deno-lint-ignore no-explicit-any + session.get(oids, (error: Error | null, varbinds: any[]) => { // Close the session to release resources session.close(); @@ -428,6 +432,7 @@ export class NupstSnmp { oid: string, description: string, config: ISnmpConfig, + // deno-lint-ignore no-explicit-any ): Promise { if (oid === '') { if (this.debug) { @@ -482,6 +487,7 @@ export class NupstSnmp { oid: string, description: string, config: ISnmpConfig, + // deno-lint-ignore no-explicit-any ): Promise { if (this.debug) { logger.dim(`Retrying ${description} with fallback security level...`); @@ -489,7 +495,7 @@ export class NupstSnmp { // Try with authNoPriv if current level is authPriv if (config.securityLevel === 'authPriv') { - const retryConfig = { ...config, securityLevel: 'authNoPriv' as 'authNoPriv' }; + const retryConfig = { ...config, securityLevel: 'authNoPriv' as const }; try { if (this.debug) { logger.dim(`Retrying with authNoPriv security level`); @@ -512,7 +518,7 @@ export class NupstSnmp { // Try with noAuthNoPriv as a last resort if (config.securityLevel === 'authPriv' || config.securityLevel === 'authNoPriv') { - const retryConfig = { ...config, securityLevel: 'noAuthNoPriv' as 'noAuthNoPriv' }; + const retryConfig = { ...config, securityLevel: 'noAuthNoPriv' as const }; try { if (this.debug) { logger.dim(`Retrying with noAuthNoPriv security level`); @@ -538,15 +544,16 @@ export class NupstSnmp { /** * Try standard OIDs as fallback - * @param oid OID to query + * @param _oid Original OID (unused, kept for method signature consistency) * @param description Description of the value for logging * @param config SNMP configuration * @returns Promise resolving to the SNMP value */ private async tryStandardOids( - oid: string, + _oid: string, description: string, config: ISnmpConfig, + // deno-lint-ignore no-explicit-any ): Promise { try { // Try RFC 1628 standard UPS MIB OIDs diff --git a/ts/systemd.ts b/ts/systemd.ts index 997e84c..658ef18 100644 --- a/ts/systemd.ts +++ b/ts/systemd.ts @@ -174,7 +174,7 @@ WantedBy=multi-user.target }`, ); } - } catch (_error) { + } catch (error) { // If version check fails, show at least the current version try { const nupst = this.daemon.getNupstSnmp().getNupst();