From 4b46b857a0a17ef2032faf1bd60c25e3c42c3e5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Fern=C3=A1ndez=20Haro?= Date: Mon, 3 Apr 2023 15:15:14 +0200 Subject: [PATCH] chore(code-style): run prettier (#1705) --- .eslintrc.js | 14 ++--- .prettierignore | 3 +- .release-it.json | 10 ++-- commitlint.config.js | 2 +- i18n-z2m-exporter.js | 37 +++++------- index.js | 4 +- renovate.json | 4 +- .../extensions-editor/example-extension.js | 12 ++-- src/components/settings/uiSchema.json | 15 ++++- src/initialState.json | 59 +++++++++---------- trim-locales.js | 38 +++++------- tsconfig.json | 2 +- vite.config.js | 18 +++--- ws.js | 16 +++-- 14 files changed, 114 insertions(+), 120 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 20f2fe18f..f06c0eb80 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,26 +1,26 @@ module.exports = { - parser: "@typescript-eslint/parser", // Specifies the ESLint parser + parser: '@typescript-eslint/parser', // Specifies the ESLint parser parserOptions: { ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features - sourceType: "module", // Allows for the use of imports + sourceType: 'module', // Allows for the use of imports ecmaFeatures: { jsx: true, // Allows for the parsing of JSX }, }, settings: { react: { - version: "detect", // Tells eslint-plugin-react to automatically detect the version of React to use + version: 'detect', // Tells eslint-plugin-react to automatically detect the version of React to use }, }, extends: [ - "plugin:react/recommended", // Uses the recommended rules from @eslint-plugin-react - "plugin:@typescript-eslint/recommended", // Uses the recommended rules from the @typescript-eslint/eslint-plugin + 'plugin:react/recommended', // Uses the recommended rules from @eslint-plugin-react + 'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin // "prettier/@typescript-eslint", // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier // "plugin:prettier/recommended", // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array. ], rules: { // Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs - "@typescript-eslint/explicit-function-return-type": "off", - "react/prop-types": "off" + '@typescript-eslint/explicit-function-return-type': 'off', + 'react/prop-types': 'off', }, }; diff --git a/.prettierignore b/.prettierignore index fa078796e..67475dd4f 100644 --- a/.prettierignore +++ b/.prettierignore @@ -2,4 +2,5 @@ dist/ ws-messages/ package-lock.json package.json -.vscode/ \ No newline at end of file +.vscode/ +src/i18n/locales/ diff --git a/.release-it.json b/.release-it.json index 179dd6799..b84c23ac8 100644 --- a/.release-it.json +++ b/.release-it.json @@ -1,6 +1,6 @@ { - "git": { - "commitMessage": "chore(deploy): release v${version}" - }, - "npm": false -} \ No newline at end of file + "git": { + "commitMessage": "chore(deploy): release v${version}" + }, + "npm": false +} diff --git a/commitlint.config.js b/commitlint.config.js index 5073c20db..422b19445 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -1 +1 @@ -module.exports = { extends: ["@commitlint/config-conventional"] }; +module.exports = { extends: ['@commitlint/config-conventional'] }; diff --git a/i18n-z2m-exporter.js b/i18n-z2m-exporter.js index 9572ac5a5..ceae69327 100644 --- a/i18n-z2m-exporter.js +++ b/i18n-z2m-exporter.js @@ -1,9 +1,8 @@ const { devices } = require('zigbee-herdsman-converters'); -const settingsSchema = require('../zigbee2mqtt/lib/util/settings.schema.json') +const settingsSchema = require('../zigbee2mqtt/lib/util/settings.schema.json'); const fs = require('fs'); -const camelCase = require("lodash/camelCase"); -const startCase = require("lodash/startCase"); - +const camelCase = require('lodash/camelCase'); +const startCase = require('lodash/startCase'); let featureDescriptions = {}; let featureNames = {}; @@ -12,45 +11,39 @@ const exportDescriptions = ({ features = [], description, name }) => { featureNames[name] = startCase(camelCase(name)); featureDescriptions[description] = description; if (Array.isArray(features)) { - features.forEach(exportDescriptions) + features.forEach(exportDescriptions); } else { - features().forEach(exportDescriptions) + features().forEach(exportDescriptions); } -} +}; -devices.forEach(device => { - exportDescriptions({ features: device.exposes }) -}) +devices.forEach((device) => { + exportDescriptions({ features: device.exposes }); +}); const enTranslationFile = './src/i18n/locales/en.json'; const enTranslations = require(enTranslationFile); enTranslations.featureDescriptions = featureDescriptions; enTranslations.featureNames = featureNames; - - - let settingsSchemaDescriptions = {}; let settingsSchemaTitles = {}; -const isObject = (value) => value !== null && typeof value === 'object' +const isObject = (value) => value !== null && typeof value === 'object'; const exportSettingsSchemaDescriptions = (obj) => { Object.entries(obj).forEach(([key, value]) => { - if (isObject(value)) { - exportSettingsSchemaDescriptions(value) + exportSettingsSchemaDescriptions(value); } else if (key === 'description') { settingsSchemaDescriptions[value] = value; } else if (key === 'title') { settingsSchemaTitles[value] = value; } - }) -} - -exportSettingsSchemaDescriptions(settingsSchema) + }); +}; +exportSettingsSchemaDescriptions(settingsSchema); enTranslations.settingsSchemaDescriptions = settingsSchemaDescriptions; enTranslations.settingsSchemaTitles = settingsSchemaTitles; - -fs.writeFileSync(enTranslationFile, JSON.stringify(enTranslations, null, 4)); \ No newline at end of file +fs.writeFileSync(enTranslationFile, JSON.stringify(enTranslations, null, 4)); diff --git a/index.js b/index.js index 303bf617a..05c89a191 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ -const path = require("path"); +const path = require('path'); module.exports = { - getPath: () => path.join(__dirname, "dist"), + getPath: () => path.join(__dirname, 'dist'), }; diff --git a/renovate.json b/renovate.json index f9c2c3270..5d39e8b85 100644 --- a/renovate.json +++ b/renovate.json @@ -1,6 +1,4 @@ { "$schema": "https://docs.renovatebot.com/renovate-schema.json", - "extends": [ - "config:base" - ] + "extends": ["config:base"] } diff --git a/src/components/extensions-editor/example-extension.js b/src/components/extensions-editor/example-extension.js index 75865487e..af6a5eba8 100644 --- a/src/components/extensions-editor/example-extension.js +++ b/src/components/extensions-editor/example-extension.js @@ -9,16 +9,16 @@ class MyExampleExtension_TS_ { } async onStateChange(data) { - console.log("State changed", data); // comment this out if clutters logs - + console.log('State changed', data); // comment this out if clutters logs + const { entity, update } = data; - - + //example how to toggle state - if (entity.ID === '0x00158d000224154d') { //state changed for some device (example: clicked a button) + if (entity.ID === '0x00158d000224154d') { + //state changed for some device (example: clicked a button) if (update.action === 'single') { const myLampIeeAddr = '0x00124b001e73227f'; // change this - this.mqtt.onMessage(`${this.mqttBaseTopic}/${myLampIeeAddr}/set`, JSON.stringify({state: 'toggle'})); + this.mqtt.onMessage(`${this.mqttBaseTopic}/${myLampIeeAddr}/set`, JSON.stringify({ state: 'toggle' })); } } } diff --git a/src/components/settings/uiSchema.json b/src/components/settings/uiSchema.json index 3b983be25..90a9677af 100644 --- a/src/components/settings/uiSchema.json +++ b/src/components/settings/uiSchema.json @@ -1,7 +1,18 @@ { "mqtt": { - "ui:order": ["base_topic", "server", "user", "password", "client_id", "version", - "ca", "key", "cert", "reject_unauthorized", "*"] + "ui:order": [ + "base_topic", + "server", + "user", + "password", + "client_id", + "version", + "ca", + "key", + "cert", + "reject_unauthorized", + "*" + ] }, "serial": { "ui:order": ["port", "adapter", "disable_led", "*"] diff --git a/src/initialState.json b/src/initialState.json index b5f186a14..b5ff370bb 100644 --- a/src/initialState.json +++ b/src/initialState.json @@ -1,33 +1,32 @@ { - "devices": {}, - "deviceStates": {}, - "touchlinkDevices": [], - "touchlinkScanInProgress": false, - "touchlinkIdentifyInProgress": false, - "touchlinkResetInProgress": false, - "networkGraph": { - "links": [], - "nodes": [] - }, - "networkGraphIsLoading": false, - "groups": [], - "bridgeState": "online", - "bridgeConfig": { - }, - "bridgeInfo": { - "configSchema": { - "properties": {}, - "required": [] + "devices": {}, + "deviceStates": {}, + "touchlinkDevices": [], + "touchlinkScanInProgress": false, + "touchlinkIdentifyInProgress": false, + "touchlinkResetInProgress": false, + "networkGraph": { + "links": [], + "nodes": [] }, - "config": { - "advanced": {} - } - }, - "logs": [], - "extensions": [], - "theme": "light", - "missingTranslations": {}, - "availability": {}, - "prepearingBackup": false, - "backup": "" + "networkGraphIsLoading": false, + "groups": [], + "bridgeState": "online", + "bridgeConfig": {}, + "bridgeInfo": { + "configSchema": { + "properties": {}, + "required": [] + }, + "config": { + "advanced": {} + } + }, + "logs": [], + "extensions": [], + "theme": "light", + "missingTranslations": {}, + "availability": {}, + "prepearingBackup": false, + "backup": "" } diff --git a/trim-locales.js b/trim-locales.js index 64e9f0780..8602f8f44 100644 --- a/trim-locales.js +++ b/trim-locales.js @@ -1,51 +1,45 @@ - -var diff = require('deep-diff') +var diff = require('deep-diff'); const _ = require('lodash'); -const fs = require('fs') +const fs = require('fs'); -let isObject = function(a) { - return (!!a) && (a.constructor === Object); +let isObject = function (a) { + return !!a && a.constructor === Object; }; function removeEmpty(obj) { return Object.entries(obj) - .filter(([_, v]) => v != null && v != "") - .reduce( - (acc, [k, v]) => ({ ...acc, [k]: isObject(v) ? removeEmpty(v) : v }), - {} - ); + .filter(([_, v]) => v != null && v != '') + .reduce((acc, [k, v]) => ({ ...acc, [k]: isObject(v) ? removeEmpty(v) : v }), {}); } const enTranslationFile = './src/i18n/locales/en.json'; const enTranslations = require(enTranslationFile); - const ignoredFiles = ['localeNames.json', 'en.json']; -const localesDir = './src/i18n/locales' +const localesDir = './src/i18n/locales'; const files = []; -const dir = fs.opendirSync(localesDir) -let dirent +const dir = fs.opendirSync(localesDir); +let dirent; while ((dirent = dir.readSync()) !== null) { if (!ignoredFiles.includes(dirent.name)) { - files.push(dirent.name) + files.push(dirent.name); } } -dir.closeSync() +dir.closeSync(); for (const file of files) { const localeFileName = `./src/i18n/locales/${file}`; const translations = require(localeFileName); - const diffR = diff(enTranslations, translations) + const diffR = diff(enTranslations, translations); let newTranslation = {}; - diffR.forEach(d => { + diffR.forEach((d) => { switch (d.kind) { case 'E': _.set(newTranslation, d.path, d.rhs); break; } - - }) + }); newTranslation = removeEmpty(newTranslation); - console.log(`Trimmed ${localeFileName}`) + console.log(`Trimmed ${localeFileName}`); fs.writeFileSync(localeFileName, JSON.stringify(newTranslation, null, 4)); -} \ No newline at end of file +} diff --git a/tsconfig.json b/tsconfig.json index 54b7a5639..e851046b1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,7 +12,7 @@ "allowSyntheticDefaultImports": true, "esModuleInterop": true, "strictNullChecks": true, - "resolveJsonModule": true, + "resolveJsonModule": true }, "suppressImplicitAnyIndexErrors": true, "lib": ["dom", "esnext"], diff --git a/vite.config.js b/vite.config.js index 20425ee5f..ad4407c4d 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,6 +1,6 @@ import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; -import sassDts from "vite-plugin-sass-dts"; +import sassDts from 'vite-plugin-sass-dts'; import viteCompression from 'vite-plugin-compression'; import { startServer } from './ws'; @@ -14,7 +14,7 @@ export default defineConfig(async ({ command }) => { base: '', build: { emptyOutDir: true, - outDir: '../dist' + outDir: '../dist', }, plugins: [ react({ @@ -27,10 +27,10 @@ export default defineConfig(async ({ command }) => { proxy: { '/api': { changeOrigin: true, - target: process.env.Z2M_API_URI ? process.env.Z2M_API_URI : "ws://localhost:8579", - ws: true - } - } - } - } -}); \ No newline at end of file + target: process.env.Z2M_API_URI ? process.env.Z2M_API_URI : 'ws://localhost:8579', + ws: true, + }, + }, + }, + }; +}); diff --git a/ws.js b/ws.js index 2c17dc410..09fa681ac 100644 --- a/ws.js +++ b/ws.js @@ -1,24 +1,23 @@ -const WebSocket = require("ws"); +const WebSocket = require('ws'); const lineReader = require('line-reader'); -const fs = require("fs"); +const fs = require('fs'); function startServer() { const wss = new WebSocket.Server({ port: 8579, }); - wss.on("connection", (ws) => { - + wss.on('connection', (ws) => { lineReader.eachLine('./ws-messages/onConnect.json', (line) => { ws.send(line); }); - ws.addEventListener("message", (message) => { + ws.addEventListener('message', (message) => { const msg = JSON.parse(message.data); switch (msg.topic) { - case "bridge/request/networkmap": + case 'bridge/request/networkmap': ws.send(fs.readFileSync('./ws-messages/networkMapRequest.json', 'utf8')); break; - case "bridge/request/touchlink/scan": + case 'bridge/request/touchlink/scan': ws.send(fs.readFileSync('./ws-messages/onTouchlink.json', 'utf8')); break; default: @@ -29,9 +28,8 @@ function startServer() { console.log('started ws server'); } - if (require.main === module) { startServer(); } -module.exports = { startServer }; \ No newline at end of file +module.exports = { startServer };