NatLibFi/marc-record-validators-melinda

View on GitHub

Showing 1,132 of 1,132 total issues

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

    const recordValid = new MarcRecord({
      leader: 'foo',
      fields: [
        {
          tag: '245',
Severity: Major
Found in src/field-exclusion.spec.js and 16 other locations - About 1 hr to fix
src/ending-punctuation.spec.js on lines 149..159
src/ending-punctuation.spec.js on lines 1270..1280
src/ending-punctuation.spec.js on lines 1333..1343
src/ending-punctuation.spec.js on lines 1908..1918
src/ending-punctuation.spec.js on lines 2078..2088
src/ending-punctuation.spec.js on lines 2335..2345
src/ending-punctuation.spec.js on lines 2376..2386
src/field-exclusion.spec.js on lines 274..284
src/field-exclusion.spec.js on lines 325..335
src/field-exclusion.spec.js on lines 385..395
src/field-exclusion.spec.js on lines 492..502
src/field-exclusion.spec.js on lines 585..595
src/field-exclusion.spec.js on lines 702..712
src/field-exclusion.spec.js on lines 818..828
src/field-exclusion.spec.js on lines 876..886
src/subfield-exclusion.spec.js on lines 322..332

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

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

      const recordInvalid655EngNoNoControl = new MarcRecord({
        leader: '',
        fields: [
          {
            tag: '655',
Severity: Major
Found in src/ending-punctuation.spec.js and 16 other locations - About 1 hr to fix
src/ending-punctuation.spec.js on lines 149..159
src/ending-punctuation.spec.js on lines 1270..1280
src/ending-punctuation.spec.js on lines 1333..1343
src/ending-punctuation.spec.js on lines 1908..1918
src/ending-punctuation.spec.js on lines 2335..2345
src/ending-punctuation.spec.js on lines 2376..2386
src/field-exclusion.spec.js on lines 214..224
src/field-exclusion.spec.js on lines 274..284
src/field-exclusion.spec.js on lines 325..335
src/field-exclusion.spec.js on lines 385..395
src/field-exclusion.spec.js on lines 492..502
src/field-exclusion.spec.js on lines 585..595
src/field-exclusion.spec.js on lines 702..712
src/field-exclusion.spec.js on lines 818..828
src/field-exclusion.spec.js on lines 876..886
src/subfield-exclusion.spec.js on lines 322..332

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

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 fieldIsBluray300(field) {
    if (field.tag !== '300') {
      return false;
    }
    return field.subfields.some(subfield => subfield.value.match(/(?:Blu.?ray|BD)/ui));
Severity: Major
Found in src/sync-007-and-300.js and 1 other location - About 1 hr to fix
src/sync-007-and-300.js on lines 75..80

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

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

    const recordValid = new MarcRecord({
      leader: 'foo',
      fields: [
        {
          tag: '245',
Severity: Major
Found in src/field-exclusion.spec.js and 16 other locations - About 1 hr to fix
src/ending-punctuation.spec.js on lines 149..159
src/ending-punctuation.spec.js on lines 1270..1280
src/ending-punctuation.spec.js on lines 1333..1343
src/ending-punctuation.spec.js on lines 1908..1918
src/ending-punctuation.spec.js on lines 2078..2088
src/ending-punctuation.spec.js on lines 2335..2345
src/ending-punctuation.spec.js on lines 2376..2386
src/field-exclusion.spec.js on lines 214..224
src/field-exclusion.spec.js on lines 274..284
src/field-exclusion.spec.js on lines 385..395
src/field-exclusion.spec.js on lines 492..502
src/field-exclusion.spec.js on lines 585..595
src/field-exclusion.spec.js on lines 702..712
src/field-exclusion.spec.js on lines 818..828
src/field-exclusion.spec.js on lines 876..886
src/subfield-exclusion.spec.js on lines 322..332

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

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

    const recordInvalidFixed = new MarcRecord({
      leader: 'foo',
      fields: [
        {
          tag: '245',
Severity: Major
Found in src/field-exclusion.spec.js and 16 other locations - About 1 hr to fix
src/ending-punctuation.spec.js on lines 149..159
src/ending-punctuation.spec.js on lines 1270..1280
src/ending-punctuation.spec.js on lines 1333..1343
src/ending-punctuation.spec.js on lines 1908..1918
src/ending-punctuation.spec.js on lines 2078..2088
src/ending-punctuation.spec.js on lines 2335..2345
src/ending-punctuation.spec.js on lines 2376..2386
src/field-exclusion.spec.js on lines 214..224
src/field-exclusion.spec.js on lines 274..284
src/field-exclusion.spec.js on lines 325..335
src/field-exclusion.spec.js on lines 385..395
src/field-exclusion.spec.js on lines 585..595
src/field-exclusion.spec.js on lines 702..712
src/field-exclusion.spec.js on lines 818..828
src/field-exclusion.spec.js on lines 876..886
src/subfield-exclusion.spec.js on lines 322..332

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

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

      const recordValid655EngYesNoControl = new MarcRecord({
        leader: '',
        fields: [
          {
            tag: '655',
Severity: Major
Found in src/ending-punctuation.spec.js and 16 other locations - About 1 hr to fix
src/ending-punctuation.spec.js on lines 149..159
src/ending-punctuation.spec.js on lines 1270..1280
src/ending-punctuation.spec.js on lines 1333..1343
src/ending-punctuation.spec.js on lines 2078..2088
src/ending-punctuation.spec.js on lines 2335..2345
src/ending-punctuation.spec.js on lines 2376..2386
src/field-exclusion.spec.js on lines 214..224
src/field-exclusion.spec.js on lines 274..284
src/field-exclusion.spec.js on lines 325..335
src/field-exclusion.spec.js on lines 385..395
src/field-exclusion.spec.js on lines 492..502
src/field-exclusion.spec.js on lines 585..595
src/field-exclusion.spec.js on lines 702..712
src/field-exclusion.spec.js on lines 818..828
src/field-exclusion.spec.js on lines 876..886
src/subfield-exclusion.spec.js on lines 322..332

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

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 fieldIsDvd300(field) {
    if (field.tag !== '300') {
      return false;
    }
    return field.subfields.some(subfield => subfield.value.match(/DVD/ui));
Severity: Major
Found in src/sync-007-and-300.js and 1 other location - About 1 hr to fix
src/sync-007-and-300.js on lines 68..73

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

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

function sortByOccurrenceNumber(fieldA, fieldB) { // Sort by subfield $6

  function fieldGetOccurrenceNumber(field) { // should this function be exported? (based on validator sortRelatorFields.js)
    if (!field.subfields) {
      return 0;
Severity: Minor
Found in src/sortFields.js - About 1 hr to fix

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

      function guessMissing337B(record) {
        const typeOfRecord = record.getTypeOfRecord();
    
        if (typeOfRecord === 'm') { // LDR/06=m/computer file
          return 'c'; // computer
    Severity: Minor
    Found in src/addMissingField337.js - About 1 hr to fix

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

        function keepOrDropPreventsMerge() {
          const keepOrDrop1 = baseFieldSubfields9.filter(sf => subfieldHasKeepOrDrop(sf));
          const keepOrDrop2 = sourceFieldSubfields9.filter(sf => subfieldHasKeepOrDrop(sf));
      
          if (keepOrDrop1.length === 0 && keepOrDrop2.length === 0) {
      Severity: Minor
      Found in src/merge-fields/controlSubfields.js - About 1 hr to fix

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

        function mergeOrAddSubfieldNotRequired(targetField, candSubfieldData) {
          if (catalogingSourceModifyingAgencyCandIsOriginalCatalogingSourceAgencyInTargetField(targetField, candSubfieldData) || ennakkotietoInSubfieldG(candSubfieldData)) {
            return true;
          }
        
        
        Severity: Minor
        Found in src/merge-fields/mergeOrAddSubfield.js - About 1 hr to fix

          Function getRelevant5XXFields has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

          export function getRelevant5XXFields(record, f500 = false, f594 = false) {
            const cands = actualGetFields();
            //nvdebugFieldArray(cands, 'gR5XXa: ', debugDev);
            const filtered = cands.filter(field => hasRelevantPrepubData(field));
            //nvdebugFieldArray(filtered, 'gR5XXb: ', debugDev);
          Severity: Minor
          Found in src/prepublicationUtils.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 mergeOrAddSubfield has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

          export function mergeOrAddSubfield(targetField, candSubfieldData, candFieldPairs880 = []) {
          
            const candSubfieldAsString = `${candSubfieldData.code} ${candSubfieldData.originalValue}`;
          
            nvdebug(`   Q: mergeOrAddSubfield '${candSubfieldAsString}'\n      with field '${fieldToString(targetField)}'?`, debugDev);
          Severity: Minor
          Found in src/merge-fields/mergeOrAddSubfield.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 subfieldHandleRelatorTermAbbreviation has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

          function subfieldHandleRelatorTermAbbreviation(subfield, language) {
            if (subfield.code !== 'e') {
              return;
            }
            nvdebug(`Relator cand subfield: '${subfieldToString(subfield)}', lang: ${language ? language : 'NULL'}`, debugDev);
          Severity: Minor
          Found in src/fixRelatorTerms.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 swapSubfields has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function swapSubfields(field, sortOrder) {
            if (!field.subfields) {
              return;
            }
          
          
          Severity: Minor
          Found in src/sortSubfields.js - About 1 hr to fix

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

            export default function () {
              return {
                description: 'Validates 008 06',
                validate,
                fix
            Severity: Minor
            Found in src/typeOfDate-008.js - About 1 hr to fix

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

                function projectedToField338(record) {
                  const typeOfRecord = record.getTypeOfRecord(record);
                  if (typeOfRecord !== 'g') { // must be "projected"
                    return undefined;
                  }
              Severity: Minor
              Found in src/addMissingField338.js - About 1 hr to fix

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

                function sortByRelatorTerm(fieldA, fieldB) {
                  //if (!['600', '610', '611', '630', '700', '710', '711', '730', '800', '810', '811', '830'].includes(fieldA.tag)) {
                  if (!['700', '710', '711', '730'].includes(fieldA.tag)) {
                    return 0;
                  }
                Severity: Minor
                Found in src/sortFields.js - About 1 hr to fix

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

                    function fixField(field, catalogingLanguage = 'fin') {
                      const subfieldA = getA(field);
                      if (!subfieldA) {
                        return;
                      }
                  Severity: Minor
                  Found in src/fix-33X.js - About 1 hr to fix

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

                    export function isSubfield6Pair(field, otherField) {
                      // No need to log this:
                      //nvdebug(`LOOK for $6-pair:\n ${fieldToString(field)}\n ${fieldToString(otherField)}`);
                      if (!fieldHasValidSubfield6(field) || !fieldHasValidSubfield6(otherField)) {
                        return false;
                    Severity: Minor
                    Found in src/subfield6Utils.js - About 1 hr to fix
                      Severity
                      Category
                      Status
                      Source
                      Language