Skip to content

Commit 1922226

Browse files
committed
Fixing comments from PR
- Use `` instead of ''to concatenate strings with variables - Change variable called inden to intent - Fix indentation and variable definitions style
1 parent cdb24be commit 1922226

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

lib/xmlSchemaFaker.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* eslint-disable */
22
const _ = require('lodash');
33

4-
function convertSchemaToXML(name, schema, attribute, indentChar, inden) {
4+
function convertSchemaToXML(name, schema, attribute, indentChar, indent) {
55
var tagPrefix = '',
6-
cInden = _.times(inden, _.constant(indentChar)).join('');
6+
cIndent = _.times(indent, _.constant(indentChar)).join('');
77
name = _.get(schema, 'xml.name', name || 'element');
88
if (_.get(schema, 'xml.prefix')) {
99
tagPrefix = schema.xml.prefix ? `${schema.xml.prefix}:` : '';
@@ -25,26 +25,26 @@ function convertSchemaToXML(name, schema, attribute, indentChar, inden) {
2525
return actualValue;
2626
}
2727
else {
28-
var retVal = '\n' + cInden + '<' + tagPrefix+name;
28+
var retVal = `\n${cIndent}<${tagPrefix+name}`;
2929
if (_.get(schema, 'xml.namespace')) {
30-
retVal += ' xmlns:' + tagPrefix.slice(0,-1) + '="'+schema.xml.namespace+'"'
30+
retVal += ` xmlns:${tagPrefix.slice(0,-1)}="${schema.xml.namespace}"`
3131
}
32-
retVal += '>' + actualValue + '</' + tagPrefix+name + '>';
32+
retVal += `>${actualValue}</${tagPrefix}${name}>`;
3333
}
3434
}
3535
else if (schema.type === 'object') {
3636
// go through all properties
37-
var retVal = '\n' + cInden + `<${tagPrefix}${name}`, propVal, attributes = [], childNodes = '';
37+
var retVal = '\n' + cIndent + `<${tagPrefix}${name}`, propVal, attributes = [], childNodes = '';
3838
if (_.get(schema, 'xml.namespace')) {
3939
let formattedTagPrefix = tagPrefix ?
4040
`:${tagPrefix.slice(0,-1)}` :
4141
'';
4242
retVal += ` xmlns${formattedTagPrefix}="${schema.xml.namespace}"`
4343
}
4444
_.forOwn(schema.properties, (value, key) => {
45-
propVal = convertSchemaToXML(key, value, _.get(value, 'xml.attribute'), indentChar, inden + 1);
45+
propVal = convertSchemaToXML(key, value, _.get(value, 'xml.attribute'), indentChar, indent + 1);
4646
if (_.get(value, 'xml.attribute')) {
47-
attributes.push(key + '="' + propVal + '"');
47+
attributes.push(`${key}="${propVal}"`);
4848
}
4949
else {
5050
childNodes += propVal;
@@ -55,19 +55,21 @@ function convertSchemaToXML(name, schema, attribute, indentChar, inden) {
5555
}
5656
retVal += '>';
5757
retVal += childNodes;
58-
retVal += `\n${cInden}</${tagPrefix+name}>`;
58+
retVal += `\n${cIndent}</${tagPrefix}${name}>`;
5959
}
6060
else if (schema.type === 'array') {
6161
// schema.items must be an object
6262
var isWrapped = _.get(schema, 'xml.wrapped'),
63-
extraIndent = isWrapped ? 1 : 0;
64-
var arrayElemName = _.get(schema, 'items.xml.name', name, 'arrayItem');
65-
var schemaItemsWithXmlProps = _.cloneDeep(schema.items);
63+
extraIndent = isWrapped ? 1 : 0,
64+
arrayElemName = _.get(schema, 'items.xml.name', name, 'arrayItem'),
65+
schemaItemsWithXmlProps = _.cloneDeep(schema.items),
66+
contents;
67+
6668
schemaItemsWithXmlProps.xml = schema.xml;
67-
var contents = convertSchemaToXML(arrayElemName, schemaItemsWithXmlProps, false, indentChar, inden + extraIndent) +
68-
convertSchemaToXML(arrayElemName, schemaItemsWithXmlProps, false, indentChar, inden + extraIndent);
69+
contents = convertSchemaToXML(arrayElemName, schemaItemsWithXmlProps, false, indentChar, indent + extraIndent) +
70+
convertSchemaToXML(arrayElemName, schemaItemsWithXmlProps, false, indentChar, indent + extraIndent);
6971
if (isWrapped) {
70-
return `\n${cInden}<${tagPrefix}${name}>${contents}\n${cInden}</${tagPrefix}${name}>`;
72+
return `\n${cIndent}<${tagPrefix}${name}>${contents}\n${cIndent}</${tagPrefix}${name}>`;
7173
}
7274
else {
7375
return contents;

0 commit comments

Comments
 (0)