Skip to content

Commit ba45e35

Browse files
committed
Fix ESLint errors
1 parent afec3fd commit ba45e35

File tree

6 files changed

+82
-62
lines changed

6 files changed

+82
-62
lines changed

lib/actions/splitOnJsonata.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ async function processAction(msg, cfg) {
2222
const results = [];
2323
split.forEach((elem) => results.push(elem));
2424
debug('%s parts to emit found', results.length);
25-
for (const value of results) {
26-
if (value) {
27-
await this.emit('data', messages.newMessageWithBody(value));
25+
results.forEach(async (result) => {
26+
if (result) {
27+
await this.emit('data', messages.newMessageWithBody(result));
2828
}
29-
}
29+
});
3030
await this.emit('end');
3131
}
3232

spec/split/data/index.js

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
1+
const arrayOfObjects = require('./splitArrayOfObjects.json');
2+
const splitArrayOfArrays = require('./splitArrayOfArrays.json');
3+
const arrayOfArraysOfObjects = require('./arrayOfArraysOfObjects.json');
4+
const arrayOfArraysOfPrimitives = require('./arrayOfArraysOfPrimitives.json');
5+
const rootArray = require('./rootArray.json');
6+
const nothingToSplit = require('./nothingToSplit.json');
7+
const noSuchPropertySplitting = require('./noSuchPropertySplitting.json');
8+
const arrayOfPrimitives = require('./arrayOfPrimitives.json');
9+
const primitiveValue = require('./primitiveValue.json');
10+
const objectValue = require('./objectValue.json');
11+
112
module.exports = {
2-
'should split array of objects users': require('./splitArrayOfObjects.json'),
3-
'should split array of arrays users.friends': require('./splitArrayOfArrays.json'),
4-
'should split array of arrays of objects users.friends': require('./arrayOfArraysOfObjects.json'),
5-
'should split array of arrays of primitives userNames': require('./arrayOfArraysOfPrimitives.json'),
6-
'should split root array': require('./rootArray.json'),
7-
'should emit only "end" with empty array userNames': require('./nothingToSplit.json'),
8-
'should emit error no such property users.emails': require('./noSuchPropertySplitting.json'),
9-
'should emit error for array of primitives userNames': require('./arrayOfPrimitives.json'),
10-
'should emit error when users is primitive': require('./primitiveValue.json'),
11-
'should emit object when users is object': require('./objectValue.json'),
13+
'should split array of objects users': arrayOfObjects,
14+
'should split array of arrays users.friends': splitArrayOfArrays,
15+
'should split array of arrays of objects users.friends': arrayOfArraysOfObjects,
16+
'should split array of arrays of primitives userNames': arrayOfArraysOfPrimitives,
17+
'should split root array': rootArray,
18+
'should emit only "end" with empty array userNames': nothingToSplit,
19+
'should emit error no such property users.emails': noSuchPropertySplitting,
20+
'should emit error for array of primitives userNames': arrayOfPrimitives,
21+
'should emit error when users is primitive': primitiveValue,
22+
'should emit object when users is object': objectValue,
1223
};

spec/split/split.spec.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,31 @@ describe('Splitter ', () => {
1212
};
1313
});
1414

15-
for (const key of Object.keys(data)) {
15+
Object.keys(data).forEach((key) => {
1616
it(key, async () => {
1717
const { message, config, results } = data[key];
1818
await splitter.process.call(self, message, config);
19-
for (let i = 0; i < results.length; i++) {
19+
for (let i = 0; i < results.length; i += 1) {
2020
const { args } = self.emit.getCall(i);
2121

2222
const expectedEventType = results[i][0];
2323
const actualEventType = args[0];
2424
expect(actualEventType).to.equal(expectedEventType);
2525

2626
const expected = results[i][1];
27-
if (!expected) {
28-
continue;
29-
}
27+
if (expected) {
28+
let actual = expectedEventType === 'data'
29+
? args[1].body
30+
: args[1];
3031

31-
let actual = expectedEventType === 'data'
32-
? args[1].body
33-
: args[1];
32+
if (expectedEventType === 'error') {
33+
expect(actual).instanceOf(Error);
34+
actual = actual.message;
35+
}
3436

35-
if (expectedEventType === 'error') {
36-
expect(actual).instanceOf(Error);
37-
actual = actual.message;
37+
expect(actual).to.deep.equal(expected);
3838
}
39-
40-
expect(actual).to.deep.equal(expected);
4139
}
4240
});
43-
}
41+
});
4442
});

spec/splitOnJsonata/data/index.js

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
1+
const arrayConstructors = require('./arrayConstructors.json');
2+
const arrayOfArraysOfObjects = require('./arrayOfArraysOfObjects.json');
3+
const arrayOfArraysOfPrimitives = require('./arrayOfArraysOfPrimitives.json');
4+
const arrayOfPrimitives = require('./arrayOfPrimitives.json');
5+
const nothingToSplit = require('./nothingToSplit.json');
6+
const objectConstructors = require('./objectConstructors.json');
7+
const objectValue = require('./objectValue.json');
8+
const primitiveValue = require('./primitiveValue.json');
9+
const rangeQuery = require('./rangeQuery.json');
10+
const rootArray = require('./rootArray.json');
11+
const splitArrayOfArrays = require('./splitArrayOfArrays.json');
12+
const splitArrayOfObjects = require('./splitArrayOfObjects.json');
13+
114
module.exports = {
2-
'should split array from an array constructor expression': require('./arrayConstructors.json'),
3-
'should split array of arrays of objects users.friends': require('./arrayOfArraysOfObjects.json'),
4-
'should emit error for array of primitives': require('./arrayOfArraysOfPrimitives.json'),
5-
'should emit error for array of primitives usernames': require('./arrayOfPrimitives.json'),
6-
'should emit only "end" with empty array usernames': require('./nothingToSplit.json'),
7-
'should split array from an object constructor expression': require('./objectConstructors.json'),
8-
'should emit error for non-array object': require('./objectValue.json'),
9-
'should emit error for non-array primitive': require('./primitiveValue.json'),
10-
'should split array from a range query expression': require('./objectConstructors.json'),
11-
'should split root array': require('./rootArray.json'),
12-
'should split array of arrays': require('./splitArrayOfArrays.json'),
13-
'should split array of objects users': require('./splitArrayOfObjects.json'),
15+
'should split array from an array constructor expression': arrayConstructors,
16+
'should split array of arrays of objects users.friends': arrayOfArraysOfObjects,
17+
'should emit error for array of primitives': arrayOfArraysOfPrimitives,
18+
'should emit error for array of primitives usernames': arrayOfPrimitives,
19+
'should emit only "end" with empty array usernames': nothingToSplit,
20+
'should split array from an object constructor expression': objectConstructors,
21+
'should emit error for non-array object': objectValue,
22+
'should emit error for non-array primitive': primitiveValue,
23+
'should split array from a range query expression': rangeQuery,
24+
'should split root array': rootArray,
25+
'should split array of arrays': splitArrayOfArrays,
26+
'should split array of objects users': splitArrayOfObjects,
1427
};

spec/splitOnJsonata/splitOnJsonata.spec.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,31 @@ describe('Split on JSONata ', () => {
1212
};
1313
});
1414

15-
for (const key of Object.keys(data)) {
15+
Object.keys(data).forEach((key) => {
1616
it(key, async () => {
1717
const { message, config, results } = data[key];
1818
await splitter.process.call(self, message, config);
19-
for (let i = 0; i < results.length; i++) {
19+
for (let i = 0; i < results.length; i += 1) {
2020
const { args } = self.emit.getCall(i);
2121

2222
const expectedEventType = results[i][0];
2323
const actualEventType = args[0];
2424
expect(actualEventType).to.equal(expectedEventType);
2525

2626
const expected = results[i][1];
27-
if (!expected) {
28-
continue;
29-
}
27+
if (expected) {
28+
let actual = expectedEventType === 'data'
29+
? args[1].body
30+
: args[1];
3031

31-
let actual = expectedEventType === 'data'
32-
? args[1].body
33-
: args[1];
32+
if (expectedEventType === 'error') {
33+
expect(actual).instanceOf(Error);
34+
actual = actual.message;
35+
}
3436

35-
if (expectedEventType === 'error') {
36-
expect(actual).instanceOf(Error);
37-
actual = actual.message;
37+
expect(actual).to.deep.equal(expected);
3838
}
39-
40-
expect(actual).to.deep.equal(expected);
4139
}
4240
});
43-
}
41+
});
4442
});

split.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,21 @@ async function processAction(msg, conf) {
2727
return;
2828
}
2929

30-
const result = [];
30+
const results = [];
3131

3232
if (_.isArray(split)) {
33-
split.forEach((elem) => result.push(elem));
33+
split.forEach((elem) => results.push(elem));
3434
} else if (_.isObject(split)) {
3535
debug(`"${splitting}" is not an array. Returning the original object`);
36-
result.push(split);
36+
results.push(split);
3737
}
3838

39-
debug('%s parts to emit found', result.length);
40-
for (const value of result) {
41-
if (value) {
42-
await this.emit('data', messages.newMessageWithBody(value));
39+
debug('%s parts to emit found', results.length);
40+
results.forEach(async (result) => {
41+
if (result) {
42+
await this.emit('data', messages.newMessageWithBody(result));
4343
}
44-
}
44+
});
4545
await this.emit('end');
4646
}
4747

0 commit comments

Comments
 (0)