SierraSoftworks/Iridium

View on GitHub

Showing 22 of 71 total issues

File Model.ts has 426 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import * as  MongoDB from "mongodb";
import * as Bluebird from "bluebird";
import * as util from "util";
import * as  _ from "lodash";
import * as Skmatc from "skmatc";
Severity: Minor
Found in lib/Model.ts - About 6 hrs to fix

Model has 32 functions (exceeds 20 allowed). Consider refactoring.
Open

export class Model<TDocument extends { _id?: any }, TInstance> {
    /**
     * Creates a new Iridium model representing a given ISchema and backed by a collection whose name is specified
     * @param core The Iridium core that this model should use for database access
     * @param instanceType The class which will be instantiated for each document retrieved from the database
Severity: Minor
Found in lib/Model.ts - About 4 hrs to fix

Function save has 74 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    save(...args: any[]): Bluebird<TInstance> {
        let callback: General.Callback<any>|undefined = undefined;
        let changes: any = null;
        let conditions: any = {};

Severity: Major
Found in lib/Instance.ts - About 2 hrs to fix

Omnom has 22 functions (exceeds 20 allowed). Consider refactoring.
Open

export class Omnom {
    constructor(public options: {
        atomicNumbers?: boolean;
    } = {}) {
        this._changes = {};
Severity: Minor
Found in lib/utils/Omnom.ts - About 2 hrs to fix

Function insert has 48 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    insert(objs: TDocument | TDocument[], ...args: any[]): Bluebird<any> {
        let objects: TDocument[];
        let options: ModelOptions.CreateOptions = {};
        let callback: General.Callback<any>|undefined = undefined;
        if (typeof args[0] === "function") callback = args[0];
Severity: Minor
Found in lib/Model.ts - About 1 hr to fix

Function onSomething has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    private onSomething(original: any, modified: any, changePath?: string): void {
        if (changePath) {
            if (original === undefined || original === null)
                return this.onUndefined(original, modified, changePath);

Severity: Minor
Found in lib/utils/Omnom.ts - 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 findOne has 39 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    findOne(...args: any[]): Bluebird<TInstance|null> {
        let conditions: { _id?: any, [key: string]: any }|undefined;
        let options: ModelOptions.QueryOptions|undefined;
        let callback: General.Callback<TInstance>|undefined;

Severity: Minor
Found in lib/Model.ts - About 1 hr to fix

Function remove has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    remove(conds?: any, options?: ModelOptions.RemoveOptions, callback?: General.Callback<number>): Bluebird<number> {
        let conditions: { _id?: string; } | Conditions = conds;

        if (typeof options === "function") {
            callback = <General.Callback<number>>options;
Severity: Minor
Found in lib/Model.ts - About 1 hr to fix

Function almostEqual has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    private almostEqual(o1: any, o2: any): number {
        if (!_.isPlainObject(o1) || !_.isPlainObject(o2)) return o1 == o2 ? 1 : 0;

        let object1Keys = Object.keys(o1);
        let object2Keys = Object.keys(o2);
Severity: Minor
Found in lib/utils/Omnom.ts - 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 ModelSpecificInstance has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function ModelSpecificInstance<TDocument extends { _id?: any }, TInstance>(model: Model<TDocument, TInstance>, instanceType: InstanceImplementation<TDocument, TInstance>): ModelSpecificInstanceConstructor<TDocument, TInstance> {
    const instanceTypeConstructor = <InstanceConstructor><any>instanceType;
    
    let virtualClass = class extends instanceTypeConstructor {
        constructor(...args: any[]) {
Severity: Minor
Found in lib/ModelSpecificInstance.ts - About 1 hr to fix

Function mapReduce has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    mapReduce<Key, Value>(functions: InstanceImplementation<MapReducedDocument<Key, Value>, any> |
        MapReduceFunctions<TDocument, Key, Value>, options: MapReduceOptions) {
        type fn = MapReduceFunctions<TDocument, Key, Value>;
        type instance = InstanceImplementation<MapReducedDocument<Key, Value>, any>

Severity: Minor
Found in lib/Model.ts - About 1 hr to fix

Function transformFromDB has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    transformFromDB(document: TDocument, options: TransformOptions = { properties: true }): TDocument {
        if(options.document && this.model.transforms.$document)
            document = this.model.transforms.$document.fromDB(document, "$document", this.model);
        
        if(!options.properties) return document;
Severity: Minor
Found in lib/ModelHelpers.ts - 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 transformToDB has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    transformToDB<T>(document: T, options: TransformOptions = { properties: true }): T {
        if(options.document && this.model.transforms.$document)
            document = <any>this.model.transforms.$document.toDB(document, "$document", this.model);
        
        if(!options.properties) return document;
Severity: Minor
Found in lib/ModelHelpers.ts - 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 parseRefspec has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

function parseRefspec(refSpec) {
    let properties = {
        localHead: false,
        version: false,
        tags: [],
Severity: Minor
Found in build/changelog.js - About 45 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

Function onSmallerArray has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    private onSmallerArray(original: any[], modified: any[], changePath: string): void {
      let pulls: any[] = [];
      let i = 0;
      let j = 0;
      
Severity: Minor
Found in lib/utils/Omnom.ts - About 45 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

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

    private onSimilarArray(original: any[], modified: any[], changePath: string): void {
      // Check how many manipulations would need to be performed, if it's more than half the array size
      // then rather re-create the array
      let sets: number[] = [];
      let partials: number[] = [];
Severity: Minor
Found in lib/utils/Omnom.ts - 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

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

    private pull(path: string, value: any) {
        if (!this.changes.$pull)
            this.changes.$pull = {};

        if (this.changes.$pullAll && this.changes.$pullAll[path]) {
Severity: Minor
Found in lib/utils/Omnom.ts - 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

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

    findOne(...args: any[]): Bluebird<TInstance|null> {
        let conditions: { _id?: any, [key: string]: any }|undefined;
        let options: ModelOptions.QueryOptions|undefined;
        let callback: General.Callback<TInstance>|undefined;

Severity: Minor
Found in lib/Model.ts - 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

Avoid too many return statements within this function.
Open

                return this.onScalar(original, modified, changePath);
Severity: Major
Found in lib/utils/Omnom.ts - About 30 mins to fix

Avoid too many return statements within this function.
Open

        return this.onObject(original, modified, changePath);
Severity: Major
Found in lib/utils/Omnom.ts - About 30 mins to fix
Severity
Category
Status
Source
Language