Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit ccf27cf

Browse files
committed
Fix lint errors found by eslint
1 parent 0e709b6 commit ccf27cf

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

lib/parser.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const parse = function (trace) {
2-
let data;
3-
let dir = function (ident) {
2+
const dir = function (ident) {
43
if (ident === '=>') {
54
return 'request';
65
}
@@ -31,36 +30,35 @@ const parse = function (trace) {
3130

3231
const dataMatch = dataPattern.exec(line);
3332
if (dataMatch !== null) {
34-
data = dataMatch[1].trim();
33+
const data = dataMatch[1].trim();
3534
asciiHexSets.push([lastDir, data]);
3635
}
3736
}
3837

3938

4039
// split lines by spaces and make array of ASCII hex bytes
4140
const asciiHexBuffer = { request: [], response: [] };
42-
for (const set of asciiHexSets) {
43-
data = set[1];
41+
for (const [direction, data] of asciiHexSets) {
4442
for (const byte of data.split(' ')) {
45-
asciiHexBuffer[dir(set[0])].push(byte);
43+
asciiHexBuffer[dir(direction)].push(byte);
4644
}
4745
}
4846

4947
// convert ASCII hex to ASCII integers codes
5048
const asciiIntBuffer = { request: [], response: [] };
51-
for (dir in asciiHexBuffer) {
52-
const hexs = asciiHexBuffer[dir];
49+
for (const key of Object.keys(asciiHexBuffer)) {
50+
const hexs = asciiHexBuffer[key];
5351
for (const hex of hexs) {
54-
asciiIntBuffer[dir].push(parseInt(`0x${hex}`));
52+
asciiIntBuffer[key].push(parseInt(hex, 16));
5553
}
5654
}
5755

5856
// convert ACII codes to charactes
5957
const stringBuffer = { request: [], response: [] };
60-
for (dir in asciiIntBuffer) {
61-
const codes = asciiIntBuffer[dir];
58+
for (const key of Object.keys(asciiIntBuffer)) {
59+
const codes = asciiIntBuffer[key];
6260
for (const code of codes) {
63-
stringBuffer[dir].push(String.fromCharCode(code));
61+
stringBuffer[key].push(String.fromCharCode(code));
6462
}
6563
}
6664

@@ -77,15 +75,15 @@ const parseToString = function (trace) {
7775

7876
const request = [];
7977
const requestLines = message.request.split('\r\n');
80-
for (var line of requestLines) {
78+
for (const line of requestLines) {
8179
request.push(`> ${line}`);
8280
}
8381
output += request.join('\r\n');
8482
output += '\n';
8583
output += '\r\n';
8684
const response = [];
8785
const responseLines = message.response.split('\r\n');
88-
for (line of responseLines) {
86+
for (const line of responseLines) {
8987
response.push(`< ${line}`);
9088
}
9189
output += response.join('\r\n');
@@ -99,15 +97,15 @@ const parseBackRequestAndResponseFromString = function (string) {
9997

10098
const request = [];
10199
const stringLines = string.split('\r\n');
102-
for (var line of stringLines) {
100+
for (const line of stringLines) {
103101
if (/^> /.test(line)) { request.push(line.replace(/^> /, '')); }
104102
}
105103

106104
// removing trailing LF
107105
output.request = request.join('\r\n').replace(/\n$/, '');
108106

109107
const response = [];
110-
for (line of stringLines) {
108+
for (const line of stringLines) {
111109
if (/^< /.test(line)) { response.push(line.replace(/^< /, '')); }
112110
}
113111

0 commit comments

Comments
 (0)