tom-weatherhead/thaw-grammar

View on GitHub
src/languages/lisp/domain-object-model/macro-definition.ts

Summary

Maintainability
F
3 days
Test Coverage

Function objectToString_ApostrophesToQuoteKeywords has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
Open

    public objectToString_ApostrophesToQuoteKeywords(expr: unknown): string {
        if (isFunctionDefinition<ISExpression>(expr)) {
            return `(define ${expr.functionName} (${expr.argList
                .map((a) => a.name)
                .join(' ')}) ${this.objectToString_ApostrophesToQuoteKeywords(expr.body)})`;
Severity: Minor
Found in src/languages/lisp/domain-object-model/macro-definition.ts - About 6 hrs 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 objectToString_ApostrophesToQuoteKeywords has 94 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public objectToString_ApostrophesToQuoteKeywords(expr: unknown): string {
        if (isFunctionDefinition<ISExpression>(expr)) {
            return `(define ${expr.functionName} (${expr.argList
                .map((a) => a.name)
                .join(' ')}) ${this.objectToString_ApostrophesToQuoteKeywords(expr.body)})`;
Severity: Major
Found in src/languages/lisp/domain-object-model/macro-definition.ts - About 3 hrs to fix

    Avoid too many return statements within this function.
    Open

                return `(call/cc ${this.objectToString_ApostrophesToQuoteKeywords(expr.body)})`;
    Severity: Major
    Found in src/languages/lisp/domain-object-model/macro-definition.ts - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

                      return `(${expr.operatorName})`;
      Severity: Major
      Found in src/languages/lisp/domain-object-model/macro-definition.ts - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                    return `(cond ${exprPairListString})`;
        Severity: Major
        Found in src/languages/lisp/domain-object-model/macro-definition.ts - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                      return `(begin ${this.objectToString_ApostrophesToQuoteKeywords(
                          expr.firstExpression
                      )} ${expr.expressionList
                          .map((e) => this.objectToString_ApostrophesToQuoteKeywords(e))
                          .join(' ')})`;
          Severity: Major
          Found in src/languages/lisp/domain-object-model/macro-definition.ts - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                            return `(${feAsString})`;
            Severity: Major
            Found in src/languages/lisp/domain-object-model/macro-definition.ts - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                          return `${expr}`;
              Severity: Major
              Found in src/languages/lisp/domain-object-model/macro-definition.ts - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                            return `(define-macro ${expr.macroName} ${
                                expr.argList
                            } ${this.objectToString_ApostrophesToQuoteKeywords(expr.body)})`;
                Severity: Major
                Found in src/languages/lisp/domain-object-model/macro-definition.ts - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                              return `(lambda ${expr.argList} ${this.objectToString_ApostrophesToQuoteKeywords(
                                  expr.body
                              )})`;
                  Severity: Major
                  Found in src/languages/lisp/domain-object-model/macro-definition.ts - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                return `(${feAsString} ${expr.expressionList
                                    .map((x) => this.objectToString_ApostrophesToQuoteKeywords(x))
                                    .join(' ')})`;
                    Severity: Major
                    Found in src/languages/lisp/domain-object-model/macro-definition.ts - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                  return `(${expr.operatorName} ${exprListString})`;
                      Severity: Major
                      Found in src/languages/lisp/domain-object-model/macro-definition.ts - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                    return `(quote ${expr.sexpression})`;
                        Severity: Major
                        Found in src/languages/lisp/domain-object-model/macro-definition.ts - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                      return `(letrec (${bindingsAsString}) ${this.objectToString_ApostrophesToQuoteKeywords(
                                          expr.expression
                                      )})`;
                          Severity: Major
                          Found in src/languages/lisp/domain-object-model/macro-definition.ts - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                        return `(let (${bindingsString}) ${this.objectToString_ApostrophesToQuoteKeywords(
                                            expr.expression
                                        )})`;
                            Severity: Major
                            Found in src/languages/lisp/domain-object-model/macro-definition.ts - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                          return `(let* (${bindingsString}) ${this.objectToString_ApostrophesToQuoteKeywords(
                                              expr.expression
                                          )})`;
                              Severity: Major
                              Found in src/languages/lisp/domain-object-model/macro-definition.ts - About 30 mins to fix

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

                                    private expressionToSExpression(
                                        expr: IExpression<ISExpression>,
                                        globalInfo: IGlobalInfo<ISExpression>
                                    ): ISExpression {
                                        if (typeof globalInfo.tokenizer === 'undefined') {
                                Severity: Minor
                                Found in src/languages/lisp/domain-object-model/macro-definition.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

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

                                        } else if (isLetUsage<ISExpression>(expr)) {
                                            const bindingsString = expr.bindings
                                                .map(
                                                    ([v, e]: [IVariable<ISExpression>, IExpression<ISExpression>]) =>
                                                        `(${v} ${this.objectToString_ApostrophesToQuoteKeywords(e)})`
                                Severity: Major
                                Found in src/languages/lisp/domain-object-model/macro-definition.ts and 1 other location - About 3 hrs to fix
                                src/languages/lisp/domain-object-model/macro-definition.ts on lines 144..206

                                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 110.

                                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

                                        } else if (isLetStarUsage<ISExpression>(expr)) {
                                            const bindingsString = expr.bindings
                                                .map(
                                                    ([v, e]: [IVariable<ISExpression>, IExpression<ISExpression>]) =>
                                                        `(${v} ${this.objectToString_ApostrophesToQuoteKeywords(e)})`
                                Severity: Major
                                Found in src/languages/lisp/domain-object-model/macro-definition.ts and 1 other location - About 3 hrs to fix
                                src/languages/lisp/domain-object-model/macro-definition.ts on lines 133..206

                                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 110.

                                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 12 locations. Consider refactoring.
                                Open

                                export function isMacroDefinition(obj: unknown): obj is MacroDefinition {
                                    const md = obj as MacroDefinition;
                                
                                    return typeof md !== 'undefined' && md.typename === typenameMacroDefinition;
                                }
                                src/languages/clu/utilities/type-guards.ts on lines 7..11
                                src/languages/lambda-calculus/type-guards.ts on lines 14..21
                                src/languages/lambda-calculus/type-guards.ts on lines 23..30
                                src/languages/lambda-calculus/type-guards.ts on lines 32..38
                                src/languages/lisp/domain-object-model/quoted-constant-with-apostrophe.ts on lines 11..15
                                src/languages/lisp/domain-object-model/quoted-constant-with-quote-keyword.ts on lines 11..17
                                src/languages/prolog/domain-object-model/prolog-goal.ts on lines 14..18
                                src/languages/prolog/domain-object-model/prolog-integer-literal.ts on lines 14..18
                                src/languages/scheme/domain-object-model/call-cc-usage.ts on lines 20..24
                                src/languages/scheme/domain-object-model/evaluable-expression.ts on lines 19..23
                                src/languages/scheme/domain-object-model/lambda-expression.ts on lines 15..19

                                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 62.

                                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

                                        if (typeof globalInfo.tokenizer === 'undefined') {
                                            throw new Error('expressionToSExpression() : this.tokenizer is undefined.');
                                        } else if (typeof globalInfo.parser === 'undefined') {
                                            throw new Error('expressionToSExpression() : this.parser is undefined.');
                                        }
                                Severity: Minor
                                Found in src/languages/lisp/domain-object-model/macro-definition.ts and 1 other location - About 40 mins to fix
                                src/languages/lisp/domain-object-model/macro-definition.ts on lines 308..312

                                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 49.

                                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

                                        if (typeof globalInfo.tokenizer === 'undefined') {
                                            throw new Error('invokeMacro() : this.tokenizer is undefined.');
                                        } else if (typeof globalInfo.parser === 'undefined') {
                                            throw new Error('invokeMacro() : this.parser is undefined.');
                                        }
                                Severity: Minor
                                Found in src/languages/lisp/domain-object-model/macro-definition.ts and 1 other location - About 40 mins to fix
                                src/languages/lisp/domain-object-model/macro-definition.ts on lines 213..217

                                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 49.

                                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