From 0cbb82fef4d841f515b12a9b3317bba21bad60ce Mon Sep 17 00:00:00 2001 From: foxriver76 Date: Fri, 27 Sep 2024 09:53:09 +0200 Subject: [PATCH] also fix lint warnings --- eslint.config.mjs | 18 ------------------ src/controllerTools.ts | 13 +++++++++++++ src/exitCodes.ts | 36 ++++++++++++++++++++++++++++++++++++ src/helpers.ts | 6 ++++++ src/index.ts | 2 ++ src/utils.ts | 3 ++- 6 files changed, 59 insertions(+), 19 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 6ebb11f..c83a179 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -1,23 +1,5 @@ import config from '@iobroker/eslint-config'; -// disable temporary the rule 'jsdoc/require-param' and enable 'jsdoc/require-jsdoc' -config.forEach(rule => { - if (rule?.plugins?.jsdoc) { - rule.rules['jsdoc/require-jsdoc'] = 'off'; - rule.rules['jsdoc/require-param'] = 'off'; - } -}); - export default [ ...config, - { - languageOptions: { - parserOptions: { - projectService: { - allowDefaultProject: ['*.js', '*.mjs'], - }, - tsconfigRootDir: import.meta.dirname, - }, - }, - }, ]; diff --git a/src/controllerTools.ts b/src/controllerTools.ts index a27f040..3132481 100644 --- a/src/controllerTools.ts +++ b/src/controllerTools.ts @@ -118,18 +118,31 @@ function getAdapterDir(adapter: string): string | null { return controllerToolsInternal.getAdapterDir(adapter); } +/** Information about Host */ export interface InstalledInfo { + /** If it is the js-controller */ controller?: boolean; + /** Version of adapter */ version?: string; + /** Path to adapter icon */ icon?: string; + /** Title of adapter */ title?: string; + /** I18n title of adapter */ titleLang?: ioBroker.Translated; + /** I18n adapter description */ desc?: ioBroker.Translated; + /** Supported adapter platform */ platform?: string; + /** The keywords */ keywords?: string[]; + /** Path to ReadMe */ readme?: string; + /** Running version of adapter */ runningVersion?: string; + /** The license */ license?: string; + /** The url of the license */ licenseUrl?: string; } /** diff --git a/src/exitCodes.ts b/src/exitCodes.ts index b27c668..a7df266 100644 --- a/src/exitCodes.ts +++ b/src/exitCodes.ts @@ -2,40 +2,76 @@ // Keep this in sync when a new exit code is added export type ExitCodes = Readonly<{ + /** Exit without error */ NO_ERROR: number; + /** Exit because js-controller is stopped */ JS_CONTROLLER_STOPPED: number; + /** Exit because Adapter config is invalid */ INVALID_ADAPTER_CONFIG: number; + /** Exit because no adapter config was found */ NO_ADAPTER_CONFIG_FOUND: number; + /** Exit because the config is invalid */ INVALID_CONFIG_OBJECT: number; + /** Exit because the adapter id is invalid */ INVALID_ADAPTER_ID: number; + /** Exit because an uncaught exception occurred */ UNCAUGHT_EXCEPTION: number; + /** Exit because the adapter is already running */ ADAPTER_ALREADY_RUNNING: number; + /** Exit because instance is disabled */ INSTANCE_IS_DISABLED: number; + /** Exit because directory cannot be compressed */ CANNOT_GZIP_DIRECTORY: number; + /** Exit because adapter directory could not be found */ CANNOT_FIND_ADAPTER_DIR: number; + /** Exit because adapter requested it */ ADAPTER_REQUESTED_TERMINATION: number; + /** Exit because the packet name is not known */ UNKNOWN_PACKET_NAME: number; + /** Exit because the adapters requested a rebuild */ ADAPTER_REQUESTED_REBUILD: number; + /** Exit because instances could not be read */ CANNOT_READ_INSTANCES: number; + /** Exit because only one instance is allowed globally */ NO_MULTIPLE_INSTANCES_ALLOWED: number; + /** Exit because only one instance is allowed on this host */ NO_MULTIPLE_INSTANCES_ALLOWED_ON_HOST: number; + /** Exit because no connection to objects database could be established */ NO_CONNECTION_TO_OBJ_DB: number; + /** Exit because no connection to states database could be established */ NO_CONNECTION_TO_STATES_DB: number; + /** Exit because the instance already exists */ INSTANCE_ALREADY_EXISTS: number; + /** Exit because the npm package could not be installed */ CANNOT_INSTALL_NPM_PACKET: number; + /** Exit because the zip could not be extracted */ CANNOT_EXTRACT_FROM_ZIP: number; + /** Exit because the io-package.json is invalid */ INVALID_IO_PACKAGE_JSON: number; + /** Exit because directory could not be copied */ CANNOT_COPY_DIR: number; + /** Exit because adapter files are missing */ MISSING_ADAPTER_FILES: number; + /** Exit because the npm version is invalid */ INVALID_NPM_VERSION: number; + /** Exit because the node version is invalid */ INVALID_NODE_VERSION: number; + /** Exit because the operating system is invalid */ INVALID_OS: number; + /** Exit because the dependency version is invalid */ INVALID_DEPENDENCY_VERSION: number; + /** Exit because the passed arguments are invalid */ INVALID_ARGUMENTS: number; + /** Exit because the password is invalid */ INVALID_PASSWORD: number; + /** Exit because the iobroker.json is missing */ MISSING_CONFIG_JSON: number; + /** Exit because a non-deletable object cannot be deleted */ CANNOT_DELETE_NON_DELETABLE: number; + /** Exit because states could not be retrieved */ CANNOT_GET_STATES: number; + /** Exit because repository list could not be retrieved */ CANNOT_GET_REPO_LIST: number; + /** Exit because direct restart is requested after stop */ START_IMMEDIATELY_AFTER_STOP: number; }>; diff --git a/src/helpers.ts b/src/helpers.ts index 100a2b2..4f80452 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -9,6 +9,9 @@ const thisDir = fileURLToPath(new URL('.', import.meta.url || `file://${__filena /** * Tries to resolve a package using Node.js resolution. * Directory names differing from the package name and alternate lookup paths can be passed. + * + * @param possiblePaths all possible paths the package can be resolved from + * @param lookupPaths lookup paths passed to `require.resolve` */ export function tryResolvePackage(possiblePaths: string[], lookupPaths?: string[]): string | undefined { for (const pkg of possiblePaths) { @@ -31,6 +34,9 @@ export function tryResolvePackage(possiblePaths: string[], lookupPaths?: string[ /** * Scans for a package by walking up the directory tree and inspecting package.json * Directory names differing from the package name and an alternate start dir can be passed. + * + * @param possiblePaths All possible paths to check + * @param startDir Optional start directory where we scan for the package */ export function scanForPackage(possiblePaths: string[], startDir: string = thisDir): string | undefined { // We start in the node_modules subfolder of adapter-core, diff --git a/src/index.ts b/src/index.ts index 0fcaf87..d029194 100644 --- a/src/index.ts +++ b/src/index.ts @@ -19,6 +19,8 @@ export function getAbsoluteDefaultDataDir(): string { /** * Returns the absolute path of the data directory for the current adapter instance. * On linux, this is usually `/opt/iobroker/iobroker-data/.` + * + * @param adapterObject The adapter instance */ export function getAbsoluteInstanceDataDir(adapterObject: ioBroker.Adapter): string { return join(getAbsoluteDefaultDataDir(), adapterObject.namespace); diff --git a/src/utils.ts b/src/utils.ts index 37670db..d3b25cd 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -101,7 +101,6 @@ function resolveAdapterConstructor(): any { } throw new Error('Cannot resolve adapter class'); - return process.exit(10); } /** Reads the configuration file of JS-Controller */ @@ -116,7 +115,9 @@ export interface AdapterInstance< HasObjectsCache extends boolean | undefined = undefined, HasStatesCache extends boolean | undefined = undefined, > extends ioBroker.Adapter { + /** Objects cache */ oObjects: HasObjectsCache extends true ? Exclude : undefined; + /** States cache */ oStates: HasStatesCache extends true ? Exclude : undefined; }