Microsoft/fast-dna

View on GitHub
packages/web-components/fast-foundation/src/design-token/core/design-token-node.ts

Summary

Maintainability
F
3 days
Test Coverage

File design-token-node.ts has 520 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import type { Disposable, ExpressionNotifier, Subscriber } from "@microsoft/fast-element";
import { Observable } from "@microsoft/fast-element";
import type { DesignToken } from "./design-token.js";

/**

    Function dispatch has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
    Open

        private dispatch<T>(record: DesignTokenChangeRecordImpl<T>) {
            if (this !== record.target) {
                const { token } = record;
                // If the node is assigned the token being dispatched and the assigned value does not depend on the token
                // (circular token reference) then terminate the dispatch.

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

        private dispatch<T>(record: DesignTokenChangeRecordImpl<T>) {
            if (this !== record.target) {
                const { token } = record;
                // If the node is assigned the token being dispatched and the assigned value does not depend on the token
                // (circular token reference) then terminate the dispatch.

      DesignTokenNode has 23 functions (exceeds 20 allowed). Consider refactoring.
      Open

      export class DesignTokenNode {
          private _parent: DesignTokenNode | null = null;
          private _children: Set<DesignTokenNode> = new Set();
          private _values: Map<DesignToken<any>, DesignTokenValue<any>> = new Map();
          private _derived: Map<DesignToken<any>, DerivedValue<any>> = new Map();

        Function setTokenValue has 54 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public setTokenValue<T>(token: DesignToken<T>, value: DesignTokenValue<T>) {
                const changeType =
                    DesignTokenNode.isAssigned(this, token) ||
                    DesignTokenNode.isDerivedFor(this, token)
                        ? DesignTokenMutationType.change

          Function appendChild has 40 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public appendChild(child: DesignTokenNode) {
                  let prevContext: DesignToken<any>[] | null = null;
          
                  // If this node is already attached, get it's context so change record
                  // types can be determined

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

                public appendChild(child: DesignTokenNode) {
                    let prevContext: DesignToken<any>[] | null = null;
            
                    // If this node is already attached, get it's context so change record
                    // types can be determined

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

                private setupDerivedTokenValue<T>(
                    token: DesignToken<any>,
                    value: DerivedDesignTokenValue<T>,
                    subscribeNode = false
                ) {

              Function deleteTokenValue has 28 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public deleteTokenValue<T>(token: DesignToken<T>): void {
                      if (DesignTokenNode.isAssigned(this, token)) {
                          const prev = DesignTokenNode.getLocalTokenValue(this, token);
                          this._values.delete(token);
                          this.tearDownDerivedTokenValue(token);

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

                    public getTokenValue<T>(token: DesignToken<T>): T {
                        /* eslint-disable-next-line */
                        let node: DesignTokenNode | null = this;
                        let value;
                
                

                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 collectDerivedContext has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                    private static collectDerivedContext(
                        node: DesignTokenNode
                    ): Map<DesignToken<any>, DerivedValue<any>> {
                        const collected = new Map<DesignToken<any>, DerivedValue<any>>();
                        // Exit early if  there is no parent

                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 setTokenValue has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    public setTokenValue<T>(token: DesignToken<T>, value: DesignTokenValue<T>) {
                        const changeType =
                            DesignTokenNode.isAssigned(this, token) ||
                            DesignTokenNode.isDerivedFor(this, token)
                                ? DesignTokenMutationType.change

                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 notifyChildren has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    private notifyChildren(...records: DesignTokenChangeRecordImpl<any>[]) {
                        if (this.children.length) {
                            for (let i = 0, l = this.children.length; i < l; i++) {
                                for (let j = 0; j < records.length; j++) {
                                    this.children[i].dispatch(records[j]);

                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 evaluate has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    public evaluate(node: DesignTokenNode, tokenContext: DesignToken<any>): T {
                        const resolve = <T>(token: DesignToken<T>): T => {
                            this.dependencies.add(token);
                            if (tokenContext === token) {
                                if (node.parent) {

                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

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                    private static isDerivedFor<T>(node: DesignTokenNode, token: DesignToken<T>) {
                        return node._derived.has(token);
                    }
                packages/web-components/fast-foundation/src/design-token/core/design-token-node.ts on lines 297..299

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 51.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                    public static isAssigned<T>(node: DesignTokenNode, token: DesignToken<T>) {
                        return node._values.has(token);
                    }
                packages/web-components/fast-foundation/src/design-token/core/design-token-node.ts on lines 171..173

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 51.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                There are no issues that match your filters.

                Category
                Status