packages/miew/src/io/parsers/CMLParser.js

Summary

Maintainability
F
1 wk
Test Coverage

File CMLParser.js has 631 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import Parser from './Parser'
import chem from '../../chem'
import { isString } from 'lodash'
import { Vector3 } from 'three'

Severity: Major
Found in packages/miew/src/io/parsers/CMLParser.js - About 1 day to fix

    Function _parseSet has a Cognitive Complexity of 63 (exceeds 5 allowed). Consider refactoring.
    Open

      _parseSet(varData) {
        const complex = (this._complex = new Complex())
        const data = varData
        const currentLabel = data.curr
        const { atoms, labels } = data
    Severity: Minor
    Found in packages/miew/src/io/parsers/CMLParser.js - About 1 day 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 _selectComponents has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring.
    Open

      _selectComponents(text) {
        const parser = new DOMParser()
        const doc = parser.parseFromString(text, 'application/xml')
        const traversedData = this._traverseData(doc)
        let rawData
    Severity: Minor
    Found in packages/miew/src/io/parsers/CMLParser.js - About 7 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 _parseSet has 165 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      _parseSet(varData) {
        const complex = (this._complex = new Complex())
        const data = varData
        const currentLabel = data.curr
        const { atoms, labels } = data
    Severity: Major
    Found in packages/miew/src/io/parsers/CMLParser.js - About 6 hrs to fix

      Function _selectComponents has 110 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        _selectComponents(text) {
          const parser = new DOMParser()
          const doc = parser.parseFromString(text, 'application/xml')
          const traversedData = this._traverseData(doc)
          let rawData
      Severity: Major
      Found in packages/miew/src/io/parsers/CMLParser.js - About 4 hrs to fix

        Function _findSuitableMolecule has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
        Open

          _findSuitableMolecule(data, molSet) {
            for (const key in data) {
              if (key === 'xmlNode') {
                continue
              } else if (key === 'molecule') {
        Severity: Minor
        Found in packages/miew/src/io/parsers/CMLParser.js - About 4 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 _extractSGroups has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
        Open

          _extractSGroups(molecule, atoms) {
            const moleculeArr = this._extractSGroup(molecule)
        
            const count = atoms.length
            let i
        Severity: Minor
        Found in packages/miew/src/io/parsers/CMLParser.js - About 3 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 prepareComponentCompound has 85 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            function prepareComponentCompound(data) {
              let atoms = []
              if (
                data.molecule &&
                data.molecule.atomArray &&
        Severity: Major
        Found in packages/miew/src/io/parsers/CMLParser.js - About 3 hrs to fix

          Function _extractSGroups has 79 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            _extractSGroups(molecule, atoms) {
              const moleculeArr = this._extractSGroup(molecule)
          
              const count = atoms.length
              let i
          Severity: Major
          Found in packages/miew/src/io/parsers/CMLParser.js - About 3 hrs to fix

            Function _breadWidthSearch has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
            Open

              _breadWidthSearch(atoms, molID) {
                const atomLabels = new Array(atoms.length)
            
                let id
                for (id = 0; id < atomLabels.length; id++) {
            Severity: Minor
            Found in packages/miew/src/io/parsers/CMLParser.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 _extractSGroup has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
            Open

              _extractSGroup(molecule, moleculeArr) {
                if (!Array.isArray(moleculeArr)) {
                  moleculeArr = []
                }
            
            
            Severity: Minor
            Found in packages/miew/src/io/parsers/CMLParser.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 _traverseData has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
            Open

              _traverseData(dom) {
                function isArray(o) {
                  return Object.prototype.toString.apply(o) === '[object Array]'
                }
            
            
            Severity: Minor
            Found in packages/miew/src/io/parsers/CMLParser.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 _breadWidthSearch has 41 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              _breadWidthSearch(atoms, molID) {
                const atomLabels = new Array(atoms.length)
            
                let id
                for (id = 0; id < atomLabels.length; id++) {
            Severity: Minor
            Found in packages/miew/src/io/parsers/CMLParser.js - About 1 hr to fix

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

                _traverseData(dom) {
                  function isArray(o) {
                    return Object.prototype.toString.apply(o) === '[object Array]'
                  }
              
              
              Severity: Minor
              Found in packages/miew/src/io/parsers/CMLParser.js - About 1 hr to fix

                Function parseSync has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  parseSync() {
                    const complexes = []
                    const self = this
                    const moleculaSet = this._selectComponents(this._data)
                    moleculaSet.forEach((molSet) => {
                Severity: Minor
                Found in packages/miew/src/io/parsers/CMLParser.js - About 1 hr to fix

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

                      function parseNode(xmlNode, result) {
                        if (xmlNode.nodeName === '#text' && xmlNode.nodeValue.trim() === '') {
                          return
                        }
                  
                  
                  Severity: Minor
                  Found in packages/miew/src/io/parsers/CMLParser.js - About 1 hr to fix

                    Function _findSuitableMolecule has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      _findSuitableMolecule(data, molSet) {
                        for (const key in data) {
                          if (key === 'xmlNode') {
                            continue
                          } else if (key === 'molecule') {
                    Severity: Minor
                    Found in packages/miew/src/io/parsers/CMLParser.js - About 1 hr to fix

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

                        _extractSGroup(molecule, moleculeArr) {
                          if (!Array.isArray(moleculeArr)) {
                            moleculeArr = []
                          }
                      
                      
                      Severity: Minor
                      Found in packages/miew/src/io/parsers/CMLParser.js - About 1 hr to fix

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

                          _rebuidBondIndexes(atoms, bonds) {
                            const count = atoms.length
                            for (let i = 0; i < count; i++) {
                              const atomId = atoms[i].id
                        
                        
                        Severity: Minor
                        Found in packages/miew/src/io/parsers/CMLParser.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

                        Avoid deeply nested control flow statements.
                        Open

                                    for (let i = 0; i < data.molecule.length; i++) {
                                      if (
                                        data.molecule[i].atomArray &&
                                        data.molecule[i].atomArray.atom
                                      ) {
                        Severity: Major
                        Found in packages/miew/src/io/parsers/CMLParser.js - About 45 mins to fix

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

                            _fixBondsArray() {
                              const serialAtomMap = (this._serialAtomMap = {})
                              const complex = this._complex
                          
                              const atoms = complex._atoms
                          Severity: Major
                          Found in packages/miew/src/io/parsers/CMLParser.js and 1 other location - About 1 day to fix
                          packages/miew/src/io/parsers/PDBParser.js on lines 131..151

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

                          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 (data.molecule.bondArray && data.molecule.bondArray.bond) {
                                  if (!Array.isArray(data.molecule.bondArray.bond)) {
                                    localBond.push(data.molecule.bondArray.bond)
                                  } else {
                                    localBond = data.molecule.bondArray.bond
                          Severity: Major
                          Found in packages/miew/src/io/parsers/CMLParser.js and 1 other location - About 2 hrs to fix
                          packages/miew/src/io/parsers/CMLParser.js on lines 279..294

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

                          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 (
                                  data.molecule &&
                                  data.molecule.atomArray &&
                                  data.molecule.atomArray.atom
                                ) {
                          Severity: Major
                          Found in packages/miew/src/io/parsers/CMLParser.js and 1 other location - About 2 hrs to fix
                          packages/miew/src/io/parsers/CMLParser.js on lines 308..314

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

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

                                  bHight.set(
                                    Math.max(bHight.x, mapEntry.x),
                                    Math.max(bHight.y, mapEntry.y),
                                    Math.max(bHight.z, mapEntry.z)
                                  )
                          Severity: Major
                          Found in packages/miew/src/io/parsers/CMLParser.js and 3 other locations - About 1 hr to fix
                          packages/miew/src/chem/SGroup.js on lines 53..57
                          packages/miew/src/chem/SGroup.js on lines 58..62
                          packages/miew/src/io/parsers/CMLParser.js on lines 139..143

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

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

                                  bLow.set(
                                    Math.min(bLow.x, mapEntry.x),
                                    Math.min(bLow.y, mapEntry.y),
                                    Math.min(bLow.z, mapEntry.z)
                                  )
                          Severity: Major
                          Found in packages/miew/src/io/parsers/CMLParser.js and 3 other locations - About 1 hr to fix
                          packages/miew/src/chem/SGroup.js on lines 53..57
                          packages/miew/src/chem/SGroup.js on lines 58..62
                          packages/miew/src/io/parsers/CMLParser.js on lines 144..148

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

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

                                if (atoms[i].y3) {
                                  atomMap[atoms[i].id].y = atoms[i].y3
                                }
                          Severity: Minor
                          Found in packages/miew/src/io/parsers/CMLParser.js and 2 other locations - About 35 mins to fix
                          packages/miew/src/io/parsers/CMLParser.js on lines 156..158
                          packages/miew/src/io/parsers/CMLParser.js on lines 166..168

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

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

                                if (atoms[i].z3) {
                                  atomMap[atoms[i].id].z = atoms[i].z3
                                }
                          Severity: Minor
                          Found in packages/miew/src/io/parsers/CMLParser.js and 2 other locations - About 35 mins to fix
                          packages/miew/src/io/parsers/CMLParser.js on lines 156..158
                          packages/miew/src/io/parsers/CMLParser.js on lines 161..163

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

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

                                if (atoms[i].x3) {
                                  atomMap[atoms[i].id].x = atoms[i].x3
                                }
                          Severity: Minor
                          Found in packages/miew/src/io/parsers/CMLParser.js and 2 other locations - About 35 mins to fix
                          packages/miew/src/io/parsers/CMLParser.js on lines 161..163
                          packages/miew/src/io/parsers/CMLParser.js on lines 166..168

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

                          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