Showing 37 of 77 total issues
Function clone
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
static async clone(id, widget, userId, apiKey) {
logger.debug(`[WidgetService]: Getting widget with id: ${id}`);
logger.debug(`[WidgetService]: New user id: ${userId}`);
const currentWidget = await Widget.findById(id).exec() || await Widget.findOne({
slug: id
Function loadAPI
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
const loadAPI = (app, path, pathApi) => {
const routesFiles = fs.readdirSync(path);
let existIndexRouter = false;
routesFiles.forEach((file) => {
const newPath = path ? (`${path}/${file}`) : file;
Function serializeElement
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
static serializeElement(el) {
return {
id: el._id,
type: 'widget',
attributes: {
Function validationMiddleware
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
const validationMiddleware = async (ctx, next) => {
logger.debug(`[WidgetRouter] Validating the widget`);
if (ctx.request.body.widget) {
ctx.request.body = Object.assign(ctx.request.body, ctx.request.body.widget);
delete ctx.request.body.widget;
Function getAll
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
static async getAll(user, apiKey, query = {}, dataset = null) {
const sort = query.sort || '';
const page = query['page[number]'] ? parseInt(query['page[number]'], 10) : 1;
logger.debug(`pageNumber param: ${page}`);
const limit = query['page[size]'] ? parseInt(query['page[size]'], 10) : 10;
Function serialize
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
static serialize(data, link = null) {
const result = {};
if (data) {
if (data.docs) {
result.data = data.docs.map((el) => WidgetSerializer.serializeElement(el));
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function get
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
static async get(id, dataset, apiKey, includes = [], user = null) {
logger.debug(`[WidgetService]: Getting widget with id: ${id}`);
const widget = await Widget.findById(id).exec();
if (widget) {
if (dataset && dataset !== widget.dataset) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function exports
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
module.exports = (() => {
const loadAPI = (app, path, pathApi) => {
const routesFiles = fs.readdirSync(path);
let existIndexRouter = false;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid deeply nested control flow statements. Open
if (widget.widgetConfig.data.url.indexOf('?') >= 0) {
widget.widgetConfig.data.url += `&${params}`;
} else {
widget.widgetConfig.data.url += `?${params}`;
}
Function getFilteredQuery
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
static getFilteredQuery(query, ids = []) {
const { collection, favourite } = query;
if (!query.application && query.app) {
query.application = query.app;
if (favourite) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function validationMiddleware
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
const validationMiddleware = async (ctx, next) => {
logger.debug(`[WidgetRouter] Validating the widget`);
if (ctx.request.body.widget) {
ctx.request.body = Object.assign(ctx.request.body, ctx.request.body.widget);
delete ctx.request.body.widget;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this function. Open
return;
Avoid too many return
statements within this function. Open
return;
Function getByDataset
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
static async getByDataset(resource) {
logger.debug(`[WidgetService] Getting widgets for datasets with ids ${resource.ids}`);
if (resource.app) {
if (resource.app.indexOf('@') >= 0) {
resource.app = {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function delete
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
static async delete(ctx) {
const id = ctx.params.widget;
logger.info(`[WidgetRouter] Deleting widget with id: ${id}`);
try {
let { dataset } = ctx.params;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function getAll
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
static async getAll(user, apiKey, query = {}, dataset = null) {
const sort = query.sort || '';
const page = query['page[number]'] ? parseInt(query['page[number]'], 10) : 1;
logger.debug(`pageNumber param: ${page}`);
const limit = query['page[size]'] ? parseInt(query['page[size]'], 10) : 10;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function checkDataset
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
static async checkDataset(ctx) {
if (ctx.params.dataset || ctx.request.body.dataset) {
const datasetId = ctx.params.dataset || ctx.request.body.dataset;
logger.info(`[DatasetService] Validating presence of dataset with id: ${datasetId}`);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"