translation/angular

View on GitHub
src/calls/base.js

Summary

Maintainability
D
1 day
Test Coverage
B
80%

Base has 37 functions (exceeds 20 allowed). Consider refactoring.
Open

class Base {
  constructor(configFile) {
    this.configFile = configFile || 'tio.config.json' // default config file
  }

Severity: Minor
Found in src/calls/base.js - About 4 hrs to fix

    File base.js has 313 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    const Interpolation = require('../utils/interpolation')
    
    const fs                        = require('fs')
    const path                      = require('path')
    const { XMLParser, XMLBuilder } = require('fast-xml-parser')
    Severity: Minor
    Found in src/calls/base.js - About 3 hrs to fix

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

        validateConfig(action) {
          let valid = true
      
          try {
            this.options()
      Severity: Minor
      Found in src/calls/base.js - About 1 hr to fix

        Function validateConfig has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

          validateConfig(action) {
            let valid = true
        
            try {
              this.options()
        Severity: Minor
        Found in src/calls/base.js - About 55 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 xmlUnitContext has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

          xmlUnitContext(xmlUnit) {
            const notes       = this.xmlUnitNotes(xmlUnit)
            const id          = xmlUnit['@_id']
            const contextNote = notes.find(note => note['@_from'] === 'meaning')
            const isCustomId  = (id) => !/^\d+$|^\w{40}$/.test(id) // to separate generated IDs with manual IDs
        Severity: Minor
        Found in src/calls/base.js - 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 flattenArray has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          flattenArray(array, depth = 1, stack = []) {
            for (const unit of array) {
              if (Array.isArray(unit) && depth > 0) {
                this.flattenArray(unit, depth - 1, stack);
              } else {
        Severity: Minor
        Found in src/calls/base.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

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

          escapeEntities(text) {
            return text.replace(/&/g, '&')
                       .replace(/>/g, '>')
                       .replace(/</g, '&lt;')
                       .replace(/'/g, '&apos;')
        Severity: Major
        Found in src/calls/base.js and 1 other location - About 1 hr to fix
        src/calls/base.js on lines 260..266

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

        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

          unescapeEntities(text) {
            return text.replace(/&quot;/g, '"')
                       .replace(/&apos;/g, "'")
                       .replace(/&lt;/g,   '<')
                       .replace(/&gt;/g,   '>')
        Severity: Major
        Found in src/calls/base.js and 1 other location - About 1 hr to fix
        src/calls/base.js on lines 268..274

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

        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 (! this.targetLanguages().length || this.targetLanguages().some(language => ! language.length)) {
              console.error(`\n⚠️ The "target_locales" parameter in your ${this.configFile} file is missing or invalid.`)
              console.error(`\nPlease make sure that its value is an array of locale codes (e.g.: ["fr", "it"])`)
              valid = false
            } else if (this.targetLanguages().includes(this.sourceLanguage())) {
        Severity: Minor
        Found in src/calls/base.js and 1 other location - About 50 mins to fix
        src/calls/base.js on lines 43..47

        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

            } else if (! this.targetFilesPath().includes('{lang}')) {
              console.error(`\n⚠️ The "target_files_path" parameter in your ${this.configFile} file does not contain the "{lang}" placeholder.`)
              console.error(`\nPlease update this parameter so that it contains "{lang}", in order for the process to work.`)
              valid = false
            }
        Severity: Minor
        Found in src/calls/base.js and 1 other location - About 50 mins to fix
        src/calls/base.js on lines 35..47

        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