Skip to content

Commit

Permalink
chore(code-style): run prettier (#1705)
Browse files Browse the repository at this point in the history
  • Loading branch information
afharo authored Apr 3, 2023
1 parent 113cb46 commit 4b46b85
Show file tree
Hide file tree
Showing 14 changed files with 114 additions and 120 deletions.
14 changes: 7 additions & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -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',
},
};
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ dist/
ws-messages/
package-lock.json
package.json
.vscode/
.vscode/
src/i18n/locales/
10 changes: 5 additions & 5 deletions .release-it.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"git": {
"commitMessage": "chore(deploy): release v${version}"
},
"npm": false
}
"git": {
"commitMessage": "chore(deploy): release v${version}"
},
"npm": false
}
2 changes: 1 addition & 1 deletion commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = { extends: ["@commitlint/config-conventional"] };
module.exports = { extends: ['@commitlint/config-conventional'] };
37 changes: 15 additions & 22 deletions i18n-z2m-exporter.js
Original file line number Diff line number Diff line change
@@ -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 = {};
Expand All @@ -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));
fs.writeFileSync(enTranslationFile, JSON.stringify(enTranslations, null, 4));
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require("path");
const path = require('path');

module.exports = {
getPath: () => path.join(__dirname, "dist"),
getPath: () => path.join(__dirname, 'dist'),
};
4 changes: 1 addition & 3 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:base"
]
"extends": ["config:base"]
}
12 changes: 6 additions & 6 deletions src/components/extensions-editor/example-extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' }));
}
}
}
Expand Down
15 changes: 13 additions & 2 deletions src/components/settings/uiSchema.json
Original file line number Diff line number Diff line change
@@ -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", "*"]
Expand Down
59 changes: 29 additions & 30 deletions src/initialState.json
Original file line number Diff line number Diff line change
@@ -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": ""
}
38 changes: 16 additions & 22 deletions trim-locales.js
Original file line number Diff line number Diff line change
@@ -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));
}
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"strictNullChecks": true,
"resolveJsonModule": true,
"resolveJsonModule": true
},
"suppressImplicitAnyIndexErrors": true,
"lib": ["dom", "esnext"],
Expand Down
18 changes: 9 additions & 9 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -14,7 +14,7 @@ export default defineConfig(async ({ command }) => {
base: '',
build: {
emptyOutDir: true,
outDir: '../dist'
outDir: '../dist',
},
plugins: [
react({
Expand All @@ -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
}
}
}
}
});
target: process.env.Z2M_API_URI ? process.env.Z2M_API_URI : 'ws://localhost:8579',
ws: true,
},
},
},
};
});
Loading

0 comments on commit 4b46b85

Please sign in to comment.