From 366f760d9b5f7a2afcba933c56232836bf4bd4b2 Mon Sep 17 00:00:00 2001 From: simatec Date: Tue, 3 Dec 2024 12:13:19 +0100 Subject: [PATCH] (simatec) Code fix --- README.md | 1 + eslint.config.mjs | 16 +++++++++++++++- lib/tools.js | 41 +++++++++++++++++++++++------------------ main.js | 23 ++++++++++++----------- 4 files changed, 51 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 4349205..98beab5 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ When the adapter crashes or an other Code error happens, this error message that ### __WORK IN PROGRESS__ * (simatec) eslint-config fix +* (simatec) Code fix ### 0.6.4 (2024-11-24) * (simatec) json5 added diff --git a/eslint.config.mjs b/eslint.config.mjs index 1221f34..32ba58c 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -25,7 +25,21 @@ export default [ // you may disable some 'jsdoc' warnings - but using jsdoc is highly recommended // as this improves maintainability. jsdoc warnings will not block buiuld process. rules: { - // 'jsdoc/require-jsdoc': 'off', + 'jsdoc/require-jsdoc': 'off', + 'no-async-promise-executor': 'off', + 'prettier/prettier': 'off', + '@typescript-eslint/no-unused-vars': 'off', + 'curly': 'off', + 'jsdoc/require-returns-description': 'off', + 'no-else-return': 'off', + '@typescript-eslint/ban-ts-comment': 'off', + //'no-prototype-builtins': 'off', + //'no-case-declarations': 'off', + //'no-useless-escape': 'off', + //'jsdoc/require-param': 'off', + //'@typescript-eslint/no-require-imports': 'off', + //'jsdoc/no-types': 'off', + //'jsdoc/tag-lines': 'off', }, }, diff --git a/lib/tools.js b/lib/tools.js index 172d48b..531668d 100644 --- a/lib/tools.js +++ b/lib/tools.js @@ -2,8 +2,9 @@ const axios = require('axios'); /** * Tests whether the given variable is a real object and not an Array - * @param {any} it The variable to test - * @returns {it is Record} + * + * @param it The variable to test + * @returns */ function isObject(it) { // This is necessary because: @@ -15,8 +16,9 @@ function isObject(it) { /** * Tests whether the given variable is really an Array - * @param {any} it The variable to test - * @returns {it is any[]} + * + * @param it The variable to test + * @returns */ function isArray(it) { if (typeof Array.isArray === 'function') return Array.isArray(it); @@ -25,10 +27,11 @@ function isArray(it) { /** * Translates text to the target language. Automatically chooses the right translation API. - * @param {string} text The text to translate - * @param {string} targetLang The target languate - * @param {string} [yandexApiKey] The yandex API key. You can create one for free at https://translate.yandex.com/developers - * @returns {Promise} + * + * @param text The text to translate + * @param targetLang The target languate + * @param [yandexApiKey] The yandex API key. You can create one for free at https://translate.yandex.com/developers + * @returns */ async function translateText(text, targetLang, yandexApiKey) { if (targetLang === 'en') { @@ -45,10 +48,11 @@ async function translateText(text, targetLang, yandexApiKey) { /** * Translates text with Yandex API - * @param {string} text The text to translate - * @param {string} targetLang The target languate - * @param {string} apiKey The yandex API key. You can create one for free at https://translate.yandex.com/developers - * @returns {Promise} + * + * @param text The text to translate + * @param targetLang The target languate + * @param apiKey The yandex API key. You can create one for free at https://translate.yandex.com/developers + * @returns */ async function translateYandex(text, targetLang, apiKey) { if (targetLang === 'zh-cn') { @@ -57,7 +61,7 @@ async function translateYandex(text, targetLang, apiKey) { try { const url = `https://translate.yandex.net/api/v1.5/tr.json/translate?key=${apiKey}&text=${encodeURIComponent(text)}&lang=en-${targetLang}`; // @ts-ignore - const response = await axios({url, timeout: 15000}); + const response = await axios({ url, timeout: 15000 }); if (response.data && response.data.text && isArray(response.data.text)) { return response.data.text[0]; } @@ -69,15 +73,16 @@ async function translateYandex(text, targetLang, apiKey) { /** * Translates text with Google API - * @param {string} text The text to translate - * @param {string} targetLang The target languate - * @returns {Promise} + * + * @param text The text to translate + * @param targetLang The target languate + * @returns */ async function translateGoogle(text, targetLang) { try { const url = `http://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=${targetLang}&dt=t&q=${encodeURIComponent(text)}&ie=UTF-8&oe=UTF-8`; // @ts-ignore - const response = await axios({url, timeout: 15000}); + const response = await axios({ url, timeout: 15000 }); if (isArray(response.data)) { // we got a valid response return response.data[0][0][0]; @@ -101,7 +106,7 @@ function _(word, systemLang) { if (translations[word]) { return translations[word]; } else { - console.warn('Please translate in translations.json: ' + word); + console.warn(`Please translate in translations.json: ${word}`); return word; } } diff --git a/main.js b/main.js index 2408306..1b79bd4 100644 --- a/main.js +++ b/main.js @@ -17,6 +17,7 @@ const adapterName = require('./package.json').name.split('.').pop(); /** * Starts the adapter instance + * * @param {Partial} [options] */ @@ -50,16 +51,16 @@ function getSystemData() { if (obj) { systemLang = obj.common.language; - adapter.log.debug('System language: ' + systemLang); + adapter.log.debug(`System language: ${systemLang}`); if (adapter.config.systemGeoData) { longitude = obj.common.longitude; latitude = obj.common.latitude; - adapter.log.debug('System longitude: ' + longitude + ' System latitude: ' + latitude); + adapter.log.debug(`System longitude: ${longitude} System latitude: ${latitude}`); } else { longitude = adapter.config.longitude; latitude = adapter.config.latitude; - adapter.log.debug('longitude: ' + longitude + ' latitude: ' + latitude); + adapter.log.debug(`longitude: ${longitude} latitude: ${latitude}`); } // @ts-ignore @@ -114,12 +115,12 @@ async function requestAPI() { // created json let json = ({ - "uv": Math.round(openUVRequest.data.result.uv * 100) / 100, - "uv_time": new Date(openUVRequest.data.result.uv_time).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }), - "uv_max": Math.round(openUVRequest.data.result.uv_max * 100) / 100, - "uv_max_time": new Date(openUVRequest.data.result.uv_max_time).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }), - "ozone": openUVRequest.data.result.ozone, - "ozone_time": new Date(openUVRequest.data.result.ozone_time).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }) + uv: Math.round(openUVRequest.data.result.uv * 100) / 100, + uv_time: new Date(openUVRequest.data.result.uv_time).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }), + uv_max: Math.round(openUVRequest.data.result.uv_max * 100) / 100, + uv_max_time: new Date(openUVRequest.data.result.uv_max_time).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }), + ozone: openUVRequest.data.result.ozone, + ozone_time: new Date(openUVRequest.data.result.ozone_time).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }) }); await adapter.setStateAsync('uv_json', JSON.stringify(json), true); @@ -188,7 +189,7 @@ async function requestAPI() { adapter.log.warn('API is not reachable'); } } catch (err) { - adapter.log.warn('Request error: ' + err); + adapter.log.warn(`Request error: ${err}`); } // @ts-ignore resolve(); @@ -211,7 +212,7 @@ async function main() { } } -// @ts-ignore parent is a valid property on module +// @ts-expect-error parent is a valid property on module if (module.parent) { // Export startAdapter in compact mode module.exports = startAdapter;