src/subfield6Utils.js
File subfield6Utils.js
has 298 lines of code (exceeds 250 allowed). Consider refactoring. Open
Open
// import createDebugLogger from 'debug';
// const debug = createDebugLogger('@natlibfi/marc-record-validator-melinda/subfield6Utils');
import {add8s, fieldsGetAllSubfield8LinkingNumbers, getSubfield8LinkingNumber, isValidSubfield8} from './subfield8Utils';
import {fieldHasSubfield, fieldToString, fieldsToString, nvdebug, subfieldToString} from './utils';
Function isSubfield6Pair
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
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;
- Read upRead up
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 isSubfield6Pair
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
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;
Function subfieldToNormalizedString
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
Open
function subfieldToNormalizedString(sf, tag, targetLinkingNumber = 0, normalizeOccurrenceNumber = false, normalizeEntryTagBoolean = false) {
// targetLinkingNumber refers to $8.
// normalizeEntryTagBoolean refers to 1XX/7XX tag values in subfield $6 value.
if (isValidSubfield6(sf)) { // && targetLinkingNumber === 0) {
// 1XX/7XX (entry tag) normalization:
- Read upRead up
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 subfieldToNormalizedString
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
function subfieldToNormalizedString(sf, tag, targetLinkingNumber = 0, normalizeOccurrenceNumber = false, normalizeEntryTagBoolean = false) {
Avoid too many return
statements within this function. Open
Open
return false;
Avoid too many return
statements within this function. Open
Open
return true;