GSA/code-gov-api

View on GitHub

Showing 5 of 29 total issues

Function getApiRoutes has 176 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function getApiRoutes(config, router) {

  const logger = new Logger({ name: 'routes.index', level: config.LOGGER_LEVEL });
  const adapter = new ElasticsearchAdapter({ hosts: config.ES_HOST, logger: Logger, mappings, settings });

Severity: Major
Found in routes/routes.js - About 7 hrs to fix

File utils.js has 330 lines of code (exceeds 250 allowed). Consider refactoring.
Open

const _ = require('lodash');
const fs = require('fs');
const git = require("git-rev");
const pkg = require("../package.json");
const Jsonfile = require("jsonfile");
Severity: Minor
Found in routes/utils.js - About 3 hrs to fix

Function getFlattenedMappingPropertiesByType has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

  static getFlattenedMappingPropertiesByType(mapping) {
    let props = {};

    const _recurseMappingTree = (mappingTree, pathArr) => {
      if (mappingTree["properties"]) {
Severity: Minor
Found in utils/index.js - About 1 hr to fix

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 constructor has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  constructor(config) {
    if(!config || !config.name) {
      config = {
        name: this.DEFAULT_LOGGER_NAME
      };
Severity: Minor
Found in utils/logger.js - About 1 hr to fix

Function omitPrivateKeys has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  static omitPrivateKeys(collection) {
    const omitFn = (value) => {
      if (value && typeof value === 'object') {
        Object.keys(value).forEach((key) => {
          if (key[0] === "_") {
Severity: Minor
Found in utils/index.js - About 35 mins to fix

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

Severity
Category
Status
Source
Language