csblogs/api-server

View on GitHub

Showing 6 of 20 total issues

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

function formatValidationErrors(ajvErrors) {
  const normalizedErrors = {};

  for (let i = 0; i < ajvErrors.length; ++i) {
    const err = ajvErrors[i];
Severity: Minor
Found in src/errors/schema-validation-error.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 formatValidationErrors has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function formatValidationErrors(ajvErrors) {
  const normalizedErrors = {};

  for (let i = 0; i < ajvErrors.length; ++i) {
    const err = ajvErrors[i];
Severity: Minor
Found in src/errors/schema-validation-error.js - About 1 hr to fix

    Function getManyByIds has 32 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function getManyByIds(ids) {
      return new Promise((resolve, reject) => {
        User.findAll({
          attributes: PUBLIC_API_ATTRIBUTES,
          where: {
    Severity: Minor
    Found in src/components/user/user-controller.js - About 1 hr to fix

      Function startServer has 30 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function startServer() {
        initDbLogger(log);
      
        database.sync()
          .then(() => {
      Severity: Minor
      Found in src/server.js - About 1 hr to fix

        Function value has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            const value = ((keyword) => {
              switch (keyword) {
                case 'required':
                  return 'cannot be blank';
                case 'minLength':
        Severity: Minor
        Found in src/errors/schema-validation-error.js - About 1 hr to fix

          Function validateUniqueConstraints has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          function validateUniqueConstraints(error) {
            if (error.name === 'SequelizeUniqueConstraintError') {
              const errorInfo = {};
          
              if (error.fields.vanity_name) {
          Severity: Minor
          Found in src/components/user/user-controller.js - About 25 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