Skip to content

Commit

Permalink
push eslint to version 9
Browse files Browse the repository at this point in the history
  • Loading branch information
PLCHome committed Aug 16, 2024
1 parent 63ff201 commit 87226df
Show file tree
Hide file tree
Showing 7 changed files with 628 additions and 1,324 deletions.
9 changes: 0 additions & 9 deletions .eslintignore

This file was deleted.

21 changes: 0 additions & 21 deletions .eslintrc.js

This file was deleted.

56 changes: 56 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import globals from 'globals';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import js from '@eslint/js';
import { FlatCompat } from '@eslint/eslintrc';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});

export default [
{
ignores: ['**/admin', '**/test', 'lib/env/tools.js', '**/gulpfile.js', 'eslint.config.mjs', 'test.js', 'test2.js'],
},
...compat.extends('eslint:recommended', 'plugin:prettier/recommended'),
{
languageOptions: {
globals: {
...globals.browser,
...globals.node,
...globals.mocha,
},

ecmaVersion: 2018,
sourceType: 'module',

parserOptions: {
ecmaFeatures: {
impliedStrict: true,
},
},
},

rules: {
'no-use-before-define': [
'error',
{
functions: false,
},
],

'no-continue': 'off',

'no-param-reassign': [
'error',
{
props: false,
},
],
},
},
];
18 changes: 6 additions & 12 deletions lib/growatt.js
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,6 @@ module.exports = class growatt {
});
}

// eslint-disable-next-line class-methods-use-this
getInverterCommunication(type) {
debugApi('getInverterCommunication:', 'type', type);
const ret = {};
Expand Down Expand Up @@ -736,13 +735,12 @@ module.exports = class growatt {
reject(e);
});
if (plants) {
// eslint-disable-next-line no-restricted-syntax
for (const plant of plants) {
let res = {};
let curPage = 0;
do {
curPage += 1;
// eslint-disable-next-line no-await-in-loop

res = await this.getDataLogger(plant.id, curPage).catch(e => {
debugApi('getDataLoggers getDataLogger err:', e);
reject(e);
Expand Down Expand Up @@ -791,7 +789,6 @@ module.exports = class growatt {
});
}

/* eslint-disable-next-line class-methods-use-this */
correctTime(struct) {
function makeTime(time) {
if (
Expand Down Expand Up @@ -892,7 +889,7 @@ module.exports = class growatt {
result[plant.id] = plant;
if (options.plantData) {
result[plant.id].plantData = {};
/* eslint-disable-next-line no-await-in-loop */

const plantData = await this.getPlantData(plant.id).catch(e => {
debugApi('getAllPlantData getPlantData err:', e);
reject(e);
Expand All @@ -903,7 +900,7 @@ module.exports = class growatt {
}
if (options.weather) {
result[plant.id].weather = {};
/* eslint-disable-next-line no-await-in-loop */

const weather = await this.getWeatherByPlantId(plant.id).catch(e => {
debugApi('getAllPlantData getWeatherByPlantId err:', e);
reject(e);
Expand All @@ -914,7 +911,7 @@ module.exports = class growatt {
}
if (options.faultlog) {
result[plant.id].faultlog = {};
/* eslint-disable-next-line no-await-in-loop */

const faultlog = await this.getNewPlantFaultLog(plant.id, options.faultlogdate).catch(e => {
debugApi('getAllPlantData getNewPlantFaultLog err:', e);
reject(e);
Expand All @@ -940,22 +937,20 @@ module.exports = class growatt {
}
}
}
/* eslint-disable-next-line no-await-in-loop */

result[plant.id].devices = await this.getAllPlantDeviceData(plant.id, options).catch(e => {
debugApi('getAllPlantData getAllPlantDeviceData err:', e);
reject(e);
});

if (options.deviceData) {
/* eslint-disable-next-line no-await-in-loop */
const devices = await this.getDevicesByPlantList(plant.id, 1).catch(e => {
debugApi('getAllPlantData getDevicesByPlantList err:', e);
reject(e);
});
if (devices && devices.obj && devices.obj.datas) {
if (devices.obj.pages && devices.obj.pages > 1) {
for (let p = 1; p < devices.obj.pages; p += 1) {
/* eslint-disable-next-line no-await-in-loop */
const devicesPlus = await this.getDevicesByPlantList(plant.id, p).catch(e => {
debugApi('getAllPlantData getDevicesByPlantList err:', e);
reject(e);
Expand All @@ -969,7 +964,6 @@ module.exports = class growatt {
result[plant.id].devices = {};
}
if (!result[plant.id].devices[devData.sn] && devData.plantId) {
/* eslint-disable-next-line no-await-in-loop */
result[plant.id].devices[devData.sn] = await this.getPlantDeviceData(
devData.plantId,
devData.deviceTypeName,
Expand Down Expand Up @@ -1026,7 +1020,7 @@ module.exports = class growatt {
if (GROWATTTYPE[growattType].atIndex) {
serialNr += `@${device.obj[growattType][a][GROWATTTYPE[growattType].atIndex]}`;
}
/* eslint-disable-next-line no-await-in-loop */

result[serialNr] = await this.getPlantDeviceData(plantId, growattType, serialNr, invId, options).catch(e => {
debugApi(`getAllPlantDeviceData getPlantDeviceData ${growattType} err:`, e);
reject(e);
Expand Down
1 change: 1 addition & 0 deletions lib/parsein.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ module.exports = class {
const secunde = `0${d.getSeconds()}`.slice(-2);
const res = `${year}-${month}-${day} ${hour}:${minute}:${secunde}`;
return [res, /^[0-9][0-9][0-9][0-9]-(1[0-2]|0[1-9])-(3[0-1]|[0-2][0-9]) (2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])$/.test(res)];
/* eslint-disable-next-line no-unused-vars */
} catch (Error) {
return [0, false];
}
Expand Down
5 changes: 3 additions & 2 deletions lib/parseret.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ const debugApi = require('debug')('growatt:api');

function fTime(val, ok) {
debugApi('fTime:', 'val', val, 'ok', ok);
// eslint-disable-next-line no-bitwise

const H = val >> 8;
// eslint-disable-next-line no-bitwise

const M = val & 255;

return [`${`00${H}`.slice(-2)}:${`00${M}`.slice(-2)}`, ok && ((H >= 0 && H <= 23) || M >= 0 || M <= 59)];
Expand All @@ -49,6 +49,7 @@ function fDate(val, ok) {
.map(n => parseInt(n, 10));
try {
return [new Date(ar[0], ar[1] - 1, ar[2], ar[3], ar[4], ar[5]).getTime(), ok];
/* eslint-disable-next-line no-unused-vars */
} catch (Error) {
return [0, false];
}
Expand Down
Loading

0 comments on commit 87226df

Please sign in to comment.