Update ESLint and Prettier

This commit is contained in:
Zaid Abdulla committed 2020-07-27 20:30:13 -07:00
1 parent 5a9e03db2c
commit ac980116bd
110 files changed
+2993 -2794

No files matched your search

+2 -2
View File
@@ -2,7 +2,7 @@ import ava from "ava";
import { randomBytes } from "crypto";
import * as auth from "../lib/auth";
ava("digest", t => {
ava("digest", (t) => {
const username = "test";
const password = "test";
const uri = "/";
@@ -14,7 +14,7 @@ ava("digest", t => {
const challenges = [
`Digest realm="${realm}",nonce="${nonce}"`,
`Digest realm="${realm}",nonce="${nonce}",qop="auth"`,
`Digest realm="${realm}",nonce="${nonce}",qop="auth-int"`
`Digest realm="${realm}",nonce="${nonce}",qop="auth-int"`,
];
t.plan(challenges.length);
+11 -38
View File
@@ -1,35 +1,7 @@
import ava from "ava";
import * as common from "../lib/common";
ava("typeOf", t => {
const cases = [
[undefined, common.UNDEFINED_TYPE],
[null, common.NULL_TYPE],
[true, common.BOOLEAN_TYPE],
[false, common.BOOLEAN_TYPE],
[0, common.NUMBER_TYPE],
[1, common.NUMBER_TYPE],
[-1, common.NUMBER_TYPE],
[0.0, common.NUMBER_TYPE],
[1.0, common.NUMBER_TYPE],
[1.1, common.NUMBER_TYPE],
[-1.0, common.NUMBER_TYPE],
[-1.1, common.NUMBER_TYPE],
["", common.STRING_TYPE],
["TEST", common.STRING_TYPE],
[[], common.ARRAY_TYPE],
[[1, 2, 3], common.ARRAY_TYPE],
[{}, common.OBJECT_TYPE],
[{ test: 1 }, common.OBJECT_TYPE],
[/[^A-Za-z0-9_]/g, common.REGEXP_TYPE],
[new RegExp("//"), common.REGEXP_TYPE],
[new Date(), common.DATE_TYPE]
];
t.plan(cases.length);
for (const c of cases) t.is(common.typeOf(c[0]), c[1]);
});
ava("generateDeviceId", t => {
ava("generateDeviceId", (t) => {
const space = [" ", "%20"];
const special = [";", "%3B"];
const cases = [
@@ -37,30 +9,31 @@ ava("generateDeviceId", t => {
{
ProductClass: "TestProductClass",
OUI: "TestOUI",
SerialNumber: "TestSerialNumber"
SerialNumber: "TestSerialNumber",
},
"TestOUI-TestProductClass-TestSerialNumber"
"TestOUI-TestProductClass-TestSerialNumber",
],
[
{
OUI: "TestOUI",
SerialNumber: "TestSerialNumber"
SerialNumber: "TestSerialNumber",
},
"TestOUI-TestSerialNumber"
"TestOUI-TestSerialNumber",
],
[
{
OUI: `TestOUIWith${space[0]}_${special[0]}2912`,
SerialNumber: `TestSerialNumberWith${space[0]}_${special[0]}2912`
SerialNumber: `TestSerialNumberWith${space[0]}_${special[0]}2912`,
},
`TestOUIWith${space[1]}_${special[1]}2912-TestSerialNumberWith${space[1]}_${special[1]}2912`
]
`TestOUIWith${space[1]}_${special[1]}2912-TestSerialNumberWith${space[1]}_${special[1]}2912`,
],
];
t.plan(cases.length);
for (const c of cases) t.is(common.generateDeviceId(c[0]), c[1]);
for (const c of cases)
t.is(common.generateDeviceId(c[0] as Record<string, string>), c[1]);
});
ava("escapeRegExp", t => {
ava("escapeRegExp", (t) => {
t.is(
common.escapeRegExp("\\ ^ $ * + ? . ( ) | { } [ ]"),
"\\\\ \\^ \\$ \\* \\+ \\? \\. \\( \\) \\| \\{ \\} \\[ \\]"
+19 -19
View File
@@ -5,7 +5,7 @@ import PathSet from "../lib/common/path-set";
import VersionedMap from "../lib/versioned-map";
import { Attributes } from "../lib/types";
ava("getAliasDeclarations", t => {
ava("getAliasDeclarations", (t) => {
const path = Path.parse("a.[aa:10,bb.[aaa:100].cc:1].b");
const decs = device.getAliasDeclarations(path, 99);
@@ -22,64 +22,64 @@ ava("getAliasDeclarations", t => {
}
});
ava("unpack", t => {
ava("unpack", (t) => {
const now = Date.now();
const deviceData = {
paths: new PathSet(),
timestamps: new VersionedMap<Path, number>(),
attributes: new VersionedMap<Path, Attributes>(),
trackers: new Map<Path, { [name: string]: number }>(),
changes: new Set<string>()
changes: new Set<string>(),
};
device.set(deviceData, Path.parse("a.1.b"), now, {
value: [now, ["b", "xsd:string"]]
value: [now, ["b", "xsd:string"]],
});
device.set(deviceData, Path.parse("a.1.c"), now, {
value: [now, ["c", "xsd:string"]]
value: [now, ["c", "xsd:string"]],
});
device.set(deviceData, Path.parse("a.1.a.1.a"), now, {
value: [now, ["", "xsd:string"]]
value: [now, ["", "xsd:string"]],
});
device.set(deviceData, Path.parse("a.1.a.1.b"), now, {
value: [now, ["b1", "xsd:string"]]
value: [now, ["b1", "xsd:string"]],
});
device.set(deviceData, Path.parse("a.1.a.1.c"), now, {
value: [now, ["c1", "xsd:string"]]
value: [now, ["c1", "xsd:string"]],
});
device.set(deviceData, Path.parse("a.1.a.2.a"), now, {
value: [now, ["", "xsd:string"]]
value: [now, ["", "xsd:string"]],
});
device.set(deviceData, Path.parse("a.1.a.2.b"), now, {
value: [now, ["b2", "xsd:string"]]
value: [now, ["b2", "xsd:string"]],
});
device.set(deviceData, Path.parse("a.1.a.2.c"), now, {
value: [now, ["c2", "xsd:string"]]
value: [now, ["c2", "xsd:string"]],
});
device.set(deviceData, Path.parse("a.2.b"), now, {
value: [now, ["b", "xsd:string"]]
value: [now, ["b", "xsd:string"]],
});
device.set(deviceData, Path.parse("a.2.c"), now, {
value: [now, ["c", "xsd:string"]]
value: [now, ["c", "xsd:string"]],
});
device.set(deviceData, Path.parse("a.2.a.1.a"), now, {
value: [now, ["", "xsd:string"]]
value: [now, ["", "xsd:string"]],
});
device.set(deviceData, Path.parse("a.2.a.1.b"), now, {
value: [now, ["b1", "xsd:string"]]
value: [now, ["b1", "xsd:string"]],
});
device.set(deviceData, Path.parse("a.2.a.1.c"), now, {
value: [now, ["c1", "xsd:string"]]
value: [now, ["c1", "xsd:string"]],
});
device.set(deviceData, Path.parse("a.2.a.2.a"), now, {
value: [now, ["", "xsd:string"]]
value: [now, ["", "xsd:string"]],
});
device.set(deviceData, Path.parse("a.2.a.2.b"), now, {
value: [now, ["c1", "xsd:string"]]
value: [now, ["c1", "xsd:string"]],
});
device.set(deviceData, Path.parse("a.2.a.2.c"), now, {
value: [now, ["b1", "xsd:string"]]
value: [now, ["b1", "xsd:string"]],
});
let unpacked: Path[];
+8 -8
View File
@@ -2,7 +2,7 @@ import ava from "ava";
import * as mongodbFunctions from "../lib/mongodb-functions";
import { stringify } from "../lib/common/expression-parser";
ava("mongoQueryToFilter", t => {
ava("mongoQueryToFilter", (t) => {
const tests = [
[{}, "true"],
[{ test: "test" }, 'test = "test"'],
@@ -22,21 +22,21 @@ ava("mongoQueryToFilter", t => {
[{ _tags: { $eq: "test" } }, "Tags.test IS NOT NULL"],
[
{ $and: [{ test: "test" }, { test: { $ne: "test" } }] },
'test = "test" AND test <> "test"'
'test = "test" AND test <> "test"',
],
[{ test: "test", test2: "test2" }, 'test = "test" AND test2 = "test2"'],
[
{ $or: [{ test: "test" }, { test: { $ne: "test" } }] },
'test = "test" OR test <> "test"'
'test = "test" OR test <> "test"',
],
[
{ test: { $gte: "test1", $ne: "test2" } },
'test >= "test1" AND test <> "test2"'
'test >= "test1" AND test <> "test2"',
],
[
{ test: "test", test2: { $ne: "test2" } },
'test = "test" AND test2 <> "test2"'
]
'test = "test" AND test2 <> "test2"',
],
];
const shouldFailTests = [
@@ -45,7 +45,7 @@ ava("mongoQueryToFilter", t => {
[{ "Tags.test": { $gt: true } }, "Invalid tag query"],
[{ _tags: [] }, "Invalid type"],
[{ _tags: { $gt: "test" } }, "Invalid tag query"],
[{ $nor: [] }, "Operator $nor not supported"]
[{ $nor: [] }, "Operator $nor not supported"],
];
t.plan(tests.length + 2 * shouldFailTests.length);
@@ -54,7 +54,7 @@ ava("mongoQueryToFilter", t => {
for (const test of shouldFailTests) {
const func = (): void => {
mongodbFunctions.mongoQueryToFilter(test[0]);
mongodbFunctions.mongoQueryToFilter(test[0] as Record<string, unknown>);
};
const error = t.throws(func, Error);
t.is(error.message, test[1]);
+10 -10
View File
@@ -2,7 +2,7 @@ import ava from "ava";
import Path from "../lib/common/path";
import PathSet from "../lib/common/path-set";
ava("depth", t => {
ava("depth", (t) => {
const pathSet = new PathSet();
t.is(pathSet.depth, 0);
pathSet.add(Path.parse(""));
@@ -11,14 +11,14 @@ ava("depth", t => {
t.is(pathSet.depth, 2);
});
ava("add", t => {
ava("add", (t) => {
const pathSet = new PathSet();
pathSet.add(Path.parse("a"));
pathSet.add(Path.parse("a"));
t.is(pathSet.find(Path.parse("a"), true, true, 99).length, 1);
});
ava("get", t => {
ava("get", (t) => {
const pathSet = new PathSet();
pathSet.add(Path.parse("a.*"));
pathSet.add(Path.parse("a.a"));
@@ -28,7 +28,7 @@ ava("get", t => {
t.is(pathSet.get(Path.parse("*.a")), null);
});
ava("find", t => {
ava("find", (t) => {
const pathSet = new PathSet();
pathSet.add(Path.parse("a"));
pathSet.add(Path.parse("a.*"));
@@ -37,32 +37,32 @@ ava("find", t => {
pathSet.add(Path.parse("*.*"));
t.deepEqual(
pathSet.find(Path.parse(""), true, true, 1).map(p => p.toString()),
pathSet.find(Path.parse(""), true, true, 1).map((p) => p.toString()),
["a"]
);
t.deepEqual(
pathSet.find(Path.parse(""), false, false, 2).map(p => p.toString()),
pathSet.find(Path.parse(""), false, false, 2).map((p) => p.toString()),
["a", "a.*", "a.a", "*.a", "*.*"]
);
t.deepEqual(
pathSet.find(Path.parse("a.*"), false, false).map(p => p.toString()),
pathSet.find(Path.parse("a.*"), false, false).map((p) => p.toString()),
["a.*"]
);
t.deepEqual(
pathSet.find(Path.parse("a.*"), false, true).map(p => p.toString()),
pathSet.find(Path.parse("a.*"), false, true).map((p) => p.toString()),
["a.*", "a.a"]
);
t.deepEqual(
pathSet.find(Path.parse("a.*"), true, false).map(p => p.toString()),
pathSet.find(Path.parse("a.*"), true, false).map((p) => p.toString()),
["a.*", "*.*"]
);
t.deepEqual(
pathSet.find(Path.parse("a.*"), true, true).map(p => p.toString()),
pathSet.find(Path.parse("a.*"), true, true).map((p) => p.toString()),
["a.*", "a.a", "*.a", "*.*"]
);
});
+3 -3
View File
@@ -1,13 +1,13 @@
import ava from "ava";
import Path from "../lib/common/path";
ava("toString", t => {
ava("toString", (t) => {
const path1 = Path.parse('abc.[ abc : 123 , 123 : abc , 123: " abc "].123');
const path2 = Path.parse('abc.[123: " abc ",abc:123,123:abc].123');
t.is(path1.toString(), path2.toString());
});
ava("slice", t => {
ava("slice", (t) => {
const path = Path.parse("a.*.b.[x:y].c");
const sliced = path.slice(1, -1);
t.is(sliced.toString(), '*.b.[x:"y"]');
@@ -15,7 +15,7 @@ ava("slice", t => {
t.is(sliced.wildcard, 0b1);
});
ava("concat", t => {
ava("concat", (t) => {
const path1 = Path.parse("a");
const path2 = Path.parse("*.[a:b]");
const concat = path1.concat(path2);
+13 -13
View File
@@ -2,10 +2,10 @@ import ava from "ava";
import {
parseXmlDeclaration,
decodeEntities,
parseXml
parseXml,
} from "../lib/xml-parser";
ava("parseXmlDeclaration", t => {
ava("parseXmlDeclaration", (t) => {
const buf = Buffer.from(
'<?xml version="1.0" encoding="UTF-8"?>\n<soap-env:Envelope />'
);
@@ -15,25 +15,25 @@ ava("parseXmlDeclaration", t => {
name: "version",
namespace: "",
localName: "version",
value: "1.0"
value: "1.0",
},
{
name: "encoding",
namespace: "",
localName: "encoding",
value: "UTF-8"
}
value: "UTF-8",
},
]);
});
ava("decodeEntities", t => {
ava("decodeEntities", (t) => {
t.is(
decodeEntities("&&amp;&lt;&gt;&quot;&apos;&gt;&#167;&#xd842;&#xDFB7;;"),
"&&<>\"'>§𠮷;"
);
});
ava("parse", t => {
ava("parse", (t) => {
const xml =
'<?xml version="1.0"?>\n<a-b:c><d f="1<g>"/><!-- comment --><h >i</h></a-b:c>';
const parsed = parseXml(xml);
@@ -60,7 +60,7 @@ ava("parse", t => {
attrs: 'f="1<g>"',
text: "",
bodyIndex: 42,
children: []
children: [],
},
{
name: "h",
@@ -69,10 +69,10 @@ ava("parse", t => {
attrs: "",
text: "i",
bodyIndex: 62,
children: []
}
]
}
]
children: [],
},
],
},
],
});
});