Skip to content

Commit

Permalink
HCK-7056: fix sonar issues (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
serhii-filonenko authored Jul 12, 2024
1 parent 4101399 commit dd309db
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 44 deletions.
20 changes: 11 additions & 9 deletions forward_engineering/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ module.exports = {
this.setProperties(schema, fieldProperties, data);

if (type === 'alias') {
return Object.assign({}, schema, this.getAliasSchema(field, data));
return { ...schema, ...this.getAliasSchema(field, data) };
} else if (type === 'join') {
return Object.assign({}, schema, this.getJoinSchema(field));
return { ...schema, ...this.getJoinSchema(field) };
} else if (
[
'completion',
Expand All @@ -105,7 +105,7 @@ module.exports = {
arrData = field.items[0];
}

schema = Object.assign(schema, this.getField(arrData, data));
schema = { ...schema, ...this.getField(arrData, data) };
}

return schema;
Expand Down Expand Up @@ -267,14 +267,16 @@ module.exports = {
}

if (item.children.length === 1) {
return Object.assign({}, result, {
[item.parent]: (item.children[0] || {}).name,
});
return {
...result,
[item.parent]: item.children?.[0]?.name
};
}

return Object.assign({}, result, {
[item.parent]: item.children.map(item => item.name || ''),
});
return {
...result,
[item.parent]: item.children.map(item => item.name || '')
};
}, {});

return { relations };
Expand Down
16 changes: 8 additions & 8 deletions helper/schemaHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const getNameByPath = (schema, path) => {
return ['[' + i + ']'];
}

return ['[' + i + ']', ...getNameByPath(property, path.slice(1), '[' + i + ']')];
return ['[' + i + ']', ...getNameByPath(property, path.slice(1))];
}, []);
} else if (Object(schema.items) === schema.items) {
const property = schema.items;
Expand All @@ -77,7 +77,7 @@ const getNameByPath = (schema, path) => {
return ['[0]'];
}

return ['[0]', ...getNameByPath(property, path.slice(1), '[0]')];
return ['[0]', ...getNameByPath(property, path.slice(1))];
}
};

Expand All @@ -95,7 +95,7 @@ const findFieldNameById = (id, source) => {
let path = getPathById(source, id, []);

if (path) {
const name = joinIndex(getNameByPath(source, path, ''));
const name = joinIndex(getNameByPath(source, path));

return name[name.length - 1] || '';
} else {
Expand All @@ -104,11 +104,11 @@ const findFieldNameById = (id, source) => {
};

const getPathName = (id, sources) => {
for (let i = 0; i < sources.length; i++) {
let path = getPathById(sources[i], id, []);
for (const source of sources) {
let path = getPathById(source, id, []);

if (path) {
const name = getNameByPath(sources[i], path, '');
const name = getNameByPath(source, path);

return name
.slice(1)
Expand All @@ -122,8 +122,8 @@ const getPathName = (id, sources) => {

const getNamesByIds = (ids, sources) => {
return ids.reduce((names, id) => {
for (let i = 0; i < sources.length; i++) {
const name = findFieldNameById(id, sources[i]);
for (const source of sources) {
const name = findFieldNameById(id, source);

if (name) {
return [...names, name];
Expand Down
38 changes: 18 additions & 20 deletions reverse_engineering/SchemaCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ module.exports = {
}
const hasProperties = !!fieldData.properties;

schema = Object.assign(schema, this.getType(fieldData.type, sample, hasProperties));
schema = {
...schema,
...this.getType(fieldData.type, sample, hasProperties),
};

let isArrayType = ['nested', 'array', 'geo-point'].indexOf(schema.type) !== -1;

Expand Down Expand Up @@ -242,15 +245,14 @@ module.exports = {
type: scalar,
};
}
} else {
if (hasProperties) {
return { type: 'object' };
} else {
return {};
}
} else if (hasProperties) {
return { type: 'object' };
}

return {};
}
},
}
},

getScalar(value) {
return typeof value;
Expand Down Expand Up @@ -367,17 +369,13 @@ module.exports = {
},

handleCompletionSnippet(schema) {
return Object.assign(
{},
this.handleSnippet(
Object.assign({}, schema, {
subType: schema.subType === 'array' ? 'completionArray' : 'completionObject',
}),
),
{
subType: schema.subType,
},
);
const subType = schema.subType === 'array' ? 'completionArray' : 'completionObject';
const snippetSchema = this.handleSnippet({ ...schema, subType });

return {
...snippetSchema,
subType: schema.subType,
};
},

handleSnippet(schema) {
Expand Down Expand Up @@ -428,7 +426,7 @@ module.exports = {
},

setProperties(schema, fieldData) {
const properties = helper.getFieldProperties(schema.type, Object.assign({ mode: fieldData.type }, fieldData), {
const properties = helper.getFieldProperties(schema.type, { mode: fieldData.type, ...fieldData}, {
'stringfields': 'fields',
});

Expand Down
15 changes: 8 additions & 7 deletions reverse_engineering/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ module.exports = {
async.map(
indices,
(indexName, nextIndex) => {
let bucketInfo = Object.assign(
getBucketData(jsonSchemas[indexName] || {}),
defaultBucketInfo,
);
let bucketInfo = {
...getBucketData(jsonSchemas[indexName] || {}),
...defaultBucketInfo,
};

if (!indexTypes[indexName]) {
if (includeEmptyCollection) {
Expand Down Expand Up @@ -439,7 +439,7 @@ const getTypesByVersion = (version, types, indexes) => {
indexes = Array.isArray(indexes) ? indexes : [];

return indexes.reduce((result, indexName) => {
return Object.assign({}, result, { [indexName]: [] });
return {...result, [indexName]: [] };
}, {});
};

Expand All @@ -454,9 +454,10 @@ const getIndexes = (client, includeSystemCollection) => {
}
})
.reduce((result, indexName) => {
return Object.assign({}, result, {
return {
...result,
[indexName]: data[indexName],
});
};
}, {});
});
};
Expand Down

0 comments on commit dd309db

Please sign in to comment.