translation/angular

View on GitHub

Showing 19 of 19 total issues

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

        static substitution(extraction, existingSubstitutions) {
          let substitution, name, number
      
          if (extraction.includes('id="INTERPOLATION_') && ! extraction.includes('equiv-text=')) {        // {x2}, {x3}, ... // Interpolations in HTML templates
            number       = parseInt(extraction.split('id="INTERPOLATION_', 2)[1].split('"', 2)[0]) + 1
      Severity: Minor
      Found in src/utils/interpolation.js - About 2 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 run has 54 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        run() {
          console.log("\n🏁 Starting Translation.io Init process, please wait 🏁")
      
          if (! this.validateConfig('Init')) {
            return false
      Severity: Major
      Found in src/calls/init.js - About 2 hrs to fix

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

                   error => {
                     console.error('HTTP REQUEST ERROR')
                     console.error(error.message)
                     if (error.response) {
                       console.error(error.response.data)
        Severity: Major
        Found in src/calls/sync.js and 1 other location - About 1 hr to fix
        src/calls/init.js on lines 74..82

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

        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

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

                   error => {
                     console.error('HTTP REQUEST ERROR')
                     console.error(error.message)
                     if (error.response) {
                       console.error(error.response.data)
        Severity: Major
        Found in src/calls/init.js and 1 other location - About 1 hr to fix
        src/calls/sync.js on lines 53..61

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

        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

        Function substitution has 43 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          static substitution(extraction, existingSubstitutions) {
            let substitution, name, number
        
            if (extraction.includes('id="INTERPOLATION_') && ! extraction.includes('equiv-text=')) {        // {x2}, {x3}, ... // Interpolations in HTML templates
              number       = parseInt(extraction.split('id="INTERPOLATION_', 2)[1].split('"', 2)[0]) + 1
        Severity: Minor
        Found in src/utils/interpolation.js - About 1 hr to fix

          Function run has 38 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            run() {
              console.log("\n🏁 Starting Translation.io Sync process, please wait 🏁")
          
              if (! this.validateConfig('Sync')) {
                return false
          Severity: Minor
          Found in src/calls/sync.js - About 1 hr to fix

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

                } else if (this.includesAll(extraction, ['id="PH_', 'equiv-text='])) {                          // {x2}, {x3}, ... // Interpolations (placeholders) in components, using $localize
                  number       = parseInt(extraction.split('id="PH_', 2)[1].split('"', 2)[0]) + 1
                  substitution = `{x${number}}`
                } else if (this.includesAll(extraction, ['id="PH"', 'equiv-text='])) {                          // {x1} - May be converted later to {x} if only 1
                  substitution = `{x1}`
            Severity: Major
            Found in src/utils/interpolation.js and 1 other location - About 1 hr to fix
            src/utils/interpolation.js on lines 54..95

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

            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 (extraction.includes('id="INTERPOLATION_') && ! extraction.includes('equiv-text=')) {        // {x2}, {x3}, ... // Interpolations in HTML templates
                  number       = parseInt(extraction.split('id="INTERPOLATION_', 2)[1].split('"', 2)[0]) + 1
                  substitution = `{x${number}}`
                } else if (extraction.includes('id="INTERPOLATION"') && ! extraction.includes('equiv-text=')) { // {x1} - May be converted later to {x} if only 1
                  substitution = `{x1}`
            Severity: Major
            Found in src/utils/interpolation.js and 1 other location - About 1 hr to fix
            src/utils/interpolation.js on lines 72..95

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

            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

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

                static angularIdToHtmlTag(id) {
                  return {
                    'LINK':               'a',
                    'BOLD_TEXT':          'b',
                    'EMPHASISED_TEXT':    'em',
              Severity: Minor
              Found in src/utils/html-tag-extraction.js - About 1 hr to fix

                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

                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

                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

                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

                Severity
                Category
                Status
                Source
                Language