superdesk/superdesk-client-core

View on GitHub
scripts/apps/authoring-react/toolbar/template-helpers.ts

Summary

Maintainability
A
3 hrs
Test Coverage

Function applyMiddleware has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function applyMiddleware(_item: IArticle): Promise<IArticle> {
    // Custom field types with `onTemplateCreate` defined. From all extensions.
    const fieldTypes: {[id: string]: ICustomFieldType<any, any, any, any>} = {};

    Object.values(extensions).forEach((ext) => {
Severity: Minor
Found in scripts/apps/authoring-react/toolbar/template-helpers.ts - About 1 hr to fix

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

    export function cleanData<T>(data: Partial<T>): Partial<T> {
        [
            '_type',
            '_status',
            '_updated',
    Severity: Minor
    Found in scripts/apps/authoring-react/toolbar/template-helpers.ts - About 1 hr to fix

      Avoid too many return statements within this function.
      Open

              return privileges.userHasPrivileges({personal_template: 1}); // can edit templates of other users
      Severity: Major
      Found in scripts/apps/authoring-react/toolbar/template-helpers.ts - About 30 mins to fix

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

        export function canEdit(template: ITemplate, isPublic: boolean): boolean {
            const privileges = ng.get('privileges');
        
            if (template == null) {
                return false;
        Severity: Minor
        Found in scripts/apps/authoring-react/toolbar/template-helpers.ts - 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

        There are no issues that match your filters.

        Category
        Status