NatLibFi/marc-record-validators-melinda

View on GitHub

Showing 830 of 830 total issues

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

      const record = new MarcRecord({
        fields: [
          {tag: '001', value: '1234567'},
          {tag: '500', ind1: ' ', ind2: ' ',
            subfields: [
Severity: Major
Found in src/empty-fields.spec.js and 2 other locations - About 1 hr to fix
src/item-language.spec.js on lines 142..155
src/item-language.spec.js on lines 219..237

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

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

    const data = {tag: '337', ind1: ' ', ind2: ' ', subfields: [
      {code: 'a', value: a},
      {code: 'b', value: b},
      {code: '2', value: 'rdamedia'}
    ]};
Severity: Major
Found in src/addMissingField337.js and 1 other location - About 1 hr to fix
src/addMissingField336.js on lines 238..242

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

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

  const f337nonElectronic = {
    tag: '337',
    ind1: ' ',
    ind2: ' ',
    subfields: [
Severity: Major
Found in src/access-rights.spec.js and 3 other locations - About 1 hr to fix
src/urn.spec.js on lines 27..36
src/urn.spec.js on lines 38..47
src/urn.spec.js on lines 49..58

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

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

  function fix(record) {
    record.fields.forEach(field => {
      normalizeQualifyingInformationField(field);
    });

Severity: Major
Found in src/normalize-qualifying-information.js and 1 other location - About 1 hr to fix
src/field-505-separators.js on lines 13..20

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

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

  function recordMatchesConfigElement(record, searchedField, confObj, dependencies) {
    const foundFields = record.get(searchedField);
    // If field has dependencies and fields matching configuration is not found
    if (foundFields.length === 0 && confObj.dependencies) {
      return false;
Severity: Minor
Found in src/field-structure.js - About 1 hr to fix

    Function sortByIndexTerms has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    function sortByIndexTerms(fieldA, fieldB) { // eslint-disable-line complexity, max-statements
    
      const indexTermFields = ['600', '610', '611', '630', '648', '650', '651', '652', '653', '654', '655', '656', '657', '658', '659', '662'];
    
      function scoreInd2(val) {
    Severity: Minor
    Found in src/sortFields.js - About 1 hr 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 getNormalizedValue has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    function getNormalizedValue(subfield, field) {
      return uppercaseLanguage(handleMovies(handleInitials(subfield.value, subfield.code, field)));
    
    
      function handleMovies(value) {
    Severity: Minor
    Found in src/subfieldValueNormalizations.js - About 1 hr 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 default has 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export default function (tagPattern) {
    
      return {
        description: 'Swap adjacent subfields',
        validate, fix
    Severity: Minor
    Found in src/sortSubfields.js - About 1 hr to fix

      Function excludeFields has 35 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        function excludeFields(record, conf, fix) {
          const res = {message: [], valid: true};
      
          // Parse trough every element of config array
          forEach(conf, ([, confObj]) => {
      Severity: Minor
      Found in src/field-exclusion.js - About 1 hr to fix

        Function mergePrintData has 35 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function mergePrintData(value1, value2) {
          const [index1, print1, year1] = value1.split(' ');
          const [index2, print2, year2] = value2.split(' ');
        
          const betterIndex = index1 ? index1 : index2; // just to cheat eslint...
        Severity: Minor
        Found in src/mergeField500Lisapainokset.js - About 1 hr to fix

          Function default has 34 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export default function () {
          
            return {
              description: 'Justify left and sort character groups within 008/18-24',
              validate, fix
          Severity: Minor
          Found in src/field-008-18-34-character-groups.js - About 1 hr to fix

            Function validateField has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                function validateField(value, spec, tag) {
                  const messagePrefix = tag ? `Field ${tag}` : 'Leader';
            
                  if (typeof spec.length === 'number') {
                    if (value.length !== spec.length) {
            Severity: Minor
            Found in src/fixed-fields.js - About 1 hr to fix

              Function getRelevantFields has 33 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                function getRelevantFields(record) {
                  //return record.get(/^(?:020|022)$/u).filter(field => {
                  return record.fields.filter(field => {
                    if (!field.subfields) {
                      return false;
              Severity: Minor
              Found in src/isbn-issn.js - About 1 hr to fix

                Function default has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                export default function (tagPattern) {
                  if (tagPattern instanceof RegExp) {
                    return {
                      description:
                        'Handles data fields that only differ in the first indicator',
                Severity: Minor
                Found in src/duplicates-ind1.js - About 1 hr to fix

                  Function processCharacterGroup has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  function processCharacterGroup(field, group) {
                    const originalContent = field.value.substring(group.start, group.end + 1);
                    const content = removeDuplicateValues(fixBlanks(originalContent));
                    //console.info(`008/${group.start}-${group.end}: '${originalContent}'`); // eslint-disable-line no-console
                    const charArray = content.split('');
                  Severity: Minor
                  Found in src/field-008-18-34-character-groups.js - About 1 hr to fix

                    Function default has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    export default function () {
                      const PATTERN = Object.keys(MAP_CONVERSION).reduce((result, key, index, list) => index === list.length - 1 ? new RegExp(`${result}${key})`, 'u') : `${result}${key}|`, '(');
                    
                      return {
                        description: 'Unicode decomposer',
                    Severity: Minor
                    Found in src/unicode-decomposition.js - About 1 hr to fix

                      Function default has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      export default function () {
                        return {
                          description: 'Handles subfields that contains non-breaking space character',
                          validate,
                          fix
                      Severity: Minor
                      Found in src/non-breaking-space.js - About 1 hr to fix

                        Function default has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                        export default function () {
                        
                          // NB! We should and could handle ISNIs here as well.
                          return {
                            description: 'Normalizes identifiers such as subfield $0 values',
                        Severity: Minor
                        Found in src/normalize-identifiers.js - About 1 hr to fix

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

                          function normalizeNonFilingIndicator2(field, languages = []) {
                            if (!hasNonFilingIndicator2(field) || !modifiableIndicatorValue(field.ind2)) {
                              return;
                            }
                          
                          
                          Severity: Major
                          Found in src/indicator-fixes.js and 1 other location - About 1 hr to fix
                          src/indicator-fixes.js on lines 131..137

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

                          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

                          function normalizeNonFilingIndicator1(field, languages = []) {
                            if (!hasNonFilingIndicator1(field) || !modifiableIndicatorValue(field.ind1)) {
                              return;
                            }
                          
                          
                          Severity: Major
                          Found in src/indicator-fixes.js and 1 other location - About 1 hr to fix
                          src/indicator-fixes.js on lines 139..145

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

                          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

                          Severity
                          Category
                          Status
                          Source
                          Language