Skip to content

Commit fe3d26e

Browse files
committed
linted, new iobroker tests
1 parent 33babff commit fe3d26e

File tree

7 files changed

+3662
-938
lines changed

7 files changed

+3662
-938
lines changed

eslint.config.mjs

Lines changed: 31 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,35 @@
1-
import globals from "globals";
2-
import path from "node:path";
3-
import { fileURLToPath } from "node:url";
4-
import js from "@eslint/js";
5-
import { FlatCompat } from "@eslint/eslintrc";
1+
import config from '@iobroker/eslint-config';
62

7-
const __filename = fileURLToPath(import.meta.url);
8-
const __dirname = path.dirname(__filename);
9-
const compat = new FlatCompat({
10-
baseDirectory: __dirname,
11-
recommendedConfig: js.configs.recommended,
12-
allConfig: js.configs.all
13-
});
3+
export default [
4+
...config,
145

15-
export default [{
16-
ignores: ["admin/blockly.js", "**/.eslintrc.js", "admin/words.js", "node_modules", ".*"],
17-
}, ...compat.extends("eslint:recommended"), {
18-
languageOptions: {
19-
globals: {
20-
...globals.node,
21-
...globals.mocha,
22-
},
23-
24-
ecmaVersion: 2022,
25-
sourceType: "commonjs",
6+
{
7+
// specify files to exclude from linting here
8+
ignores: [
9+
'.dev-server/',
10+
'.vscode/',
11+
'**/*.test.js',
12+
'test/**/*.js',
13+
'*.config.mjs',
14+
'build',
15+
'admin/build',
16+
'admin/words.js',
17+
'admin/blockly.js',
18+
'admin/admin.d.ts',
19+
'**/adapter-config.d.ts',
20+
'lib/words.js',
21+
'admin/custom',
22+
'admin/rules',
23+
'src/', // TODO
24+
'src-admin/', // TODO
25+
]
2626
},
27-
28-
rules: {
29-
indent: ["error", 4, {
30-
SwitchCase: 1,
31-
}],
32-
33-
"no-console": "off",
34-
"no-var": "error",
35-
"prefer-const": "error",
36-
37-
quotes: ["error", "double", {
38-
avoidEscape: true,
39-
allowTemplateLiterals: true,
40-
}],
41-
42-
semi: ["error", "always"],
27+
{
28+
rules: {
29+
'jsdoc/require-jsdoc': 'off',
30+
'jsdoc/require-param-description': 'off',
31+
'jsdoc/require-returns-description': 'off',
32+
'jsdoc/require-returns-check': 'off',
33+
},
4334
},
44-
}];
35+
];

lib/actionButton.js

Lines changed: 58 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,74 @@
11
"use strict";
22

3-
class ActionButton
4-
{
5-
constructor(action, label, clear = false)
6-
{
7-
this.action = action;
8-
this.label = label;
9-
this.clear = clear;
10-
}
3+
class ActionButton {
4+
constructor(action, label, clear = false) {
5+
this.action = action;
6+
this.label = label;
7+
this.clear = clear;
8+
}
119

12-
isValidUrl(urlString)
13-
{
14-
const urlPattern = new RegExp("^(https?:\\/\\/)?"+ // validate protocol
15-
"((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|"+ // validate domain name
16-
"((\\d{1,3}\\.){3}\\d{1,3}))"+ // validate OR ip (v4) address
17-
"(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*"+ // validate port and path
18-
"(\\?[;&a-z\\d%_.~+=-]*)?"+ // validate query string
19-
"(\\#[-a-z\\d_]*)?$","i"); // validate fragment locator
20-
return !!urlPattern.test(urlString);
21-
}
10+
isValidUrl(urlString) {
11+
const urlPattern = new RegExp(
12+
"^(https?:\\/\\/)?" + // validate protocol
13+
"((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|" + // validate domain name
14+
"((\\d{1,3}\\.){3}\\d{1,3}))" + // validate OR ip (v4) address
15+
"(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*" + // validate port and path
16+
"(\\?[;&a-z\\d%_.~+=-]*)?" + // validate query string
17+
"(\\#[-a-z\\d_]*)?$",
18+
"i",
19+
); // validate fragment locator
20+
return !!urlPattern.test(urlString);
21+
}
2222
}
2323

24-
class ActionButtonView extends ActionButton
25-
{
26-
constructor(label, url, clear = false)
27-
{
28-
super("view", label, clear);
29-
30-
this.url = url;
31-
}
24+
class ActionButtonView extends ActionButton {
25+
constructor(label, url, clear = false) {
26+
super("view", label, clear);
3227

28+
this.url = url;
29+
}
3330
}
3431

35-
class ActionButtonHTTP extends ActionButton
36-
{
37-
constructor(label, url, clear = false)
38-
{
39-
super("http", label, clear);
40-
41-
this.url = url;
42-
this.method = "POST";
43-
this.headers = {};
44-
this.body = "";
45-
}
32+
class ActionButtonHTTP extends ActionButton {
33+
constructor(label, url, clear = false) {
34+
super("http", label, clear);
4635

47-
getData()
48-
{
49-
return {
50-
action: this.action,
51-
label: this.label,
52-
url: this.url,
53-
method: this.method,
54-
headers: this.headers,
55-
body: this.body,
56-
clear: this.clear
57-
};
58-
}
36+
this.url = url;
37+
this.method = "POST";
38+
this.headers = {};
39+
this.body = "";
40+
}
5941

60-
setMethod(method)
61-
{
62-
this.method = method;
63-
}
42+
getData() {
43+
return {
44+
action: this.action,
45+
label: this.label,
46+
url: this.url,
47+
method: this.method,
48+
headers: this.headers,
49+
body: this.body,
50+
clear: this.clear,
51+
};
52+
}
6453

65-
setHeaders(headers)
66-
{
67-
this.headers = headers;
68-
}
69-
70-
setBody(body)
71-
{
72-
this.body = body;
73-
}
74-
}
54+
setMethod(method) {
55+
this.method = method;
56+
}
7557

76-
class ActionButtonAB extends ActionButton
77-
{
58+
setHeaders(headers) {
59+
this.headers = headers;
60+
}
7861

62+
setBody(body) {
63+
this.body = body;
64+
}
7965
}
8066

67+
class ActionButtonAB extends ActionButton {}
8168

82-
module.exports = { ActionButton, ActionButtonView, ActionButtonHTTP, ActionButtonAB };
69+
module.exports = {
70+
ActionButton,
71+
ActionButtonView,
72+
ActionButtonHTTP,
73+
ActionButtonAB,
74+
};

0 commit comments

Comments
 (0)