Showing 16 of 24 total issues
Function xmlToJson
has a Cognitive Complexity of 50 (exceeds 5 allowed). Consider refactoring. Open
export function xmlToJson(parent: Node, depth: number = 0): any {
// Create the return object
let obj: any = {}; // TODO formalize type?
if (parent.nodeType === 1) { // element Node.ELEMENT_NODE
- 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 refineMetadata2
has 107 lines of code (exceeds 25 allowed). Consider refactoring. Open
function refineMetadata2(meta: any): RechtspraakMetadata {
if (typeof meta !== "object") throw new Error("Expected meta to be of type 'object'");
const _id = throwIfNotString(meta["dcterms:identifier"]);
Function xmlToJson
has 91 lines of code (exceeds 25 allowed). Consider refactoring. Open
export function xmlToJson(parent: Node, depth: number = 0): any {
// Create the return object
let obj: any = {}; // TODO formalize type?
if (parent.nodeType === 1) { // element Node.ELEMENT_NODE
Function mergeDescriptionTags
has 79 lines of code (exceeds 25 allowed). Consider refactoring. Open
function mergeDescriptionTags(rdf: any) {
let description = rdf["rdf:Description"];
if (Object.prototype.toString.call(description) !== "[object Array]") description = [description, {}];
if (description.length !== 2) throw new Error("Expected 2 descriptions");
const description0 = description[0];
Function refineMetadata2
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
function refineMetadata2(meta: any): RechtspraakMetadata {
if (typeof meta !== "object") throw new Error("Expected meta to be of type 'object'");
const _id = throwIfNotString(meta["dcterms:identifier"]);
- 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
File convert-to-typed.ts
has 260 lines of code (exceeds 250 allowed). Consider refactoring. Open
import {
Creator,
Date,
RechtspraakMetadata,
UriWithProtocol
Function resourceObject
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
function resourceObject(idIsUri = true,
hasLabels = true,
extraMandatoryProperties: any = {}, // todo
extraOptionalProperties: any = {} // todo
): SchemaTypeDefinition {
Function getResourceId
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
export function getResourceId(attrz: any/*todo*/, key?: string): string {
if (!attrz)
throw new Error("No attributes found!" + (key ? " (" + key + ")" : ""));
if (attrz["resourceIdentifier"])
if (!!attrz["psi:resourceIdentifier"])
- 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 getGevolg
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
function getGevolg(gevolgUri?: string, label?: string): Gevolg | undefined {
if (!gevolgUri)
return undefined;
else {
const id = gevolgUri.replace(/^http:\/\/psi\.rechtspraak\.nl\//, "");
- 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
Avoid deeply nested control flow statements. Open
if (typeof(obj[childNodeName]) === "undefined") {
// child doesn't exist yet
obj[childNodeName] = xmlToJson(item, depth + 1);
} else {
// Add child to array
Function getRelation
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
export const getRelation = (arr: any[]): Relation[] | undefined => arr ? arr.map((rel: any) => {
const attrs = [
"rdfs:label",
["ecli:resourceIdentifier"/*, "bwb:resourceIdentifier"*/],
"psi:type",
- 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
Avoid deeply nested control flow statements. Open
if (!!item.textContent)
obj.textContent = item.textContent.trim().replace(/\s\s+/g, " ");
Function mergeDescriptionTags
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
function mergeDescriptionTags(rdf: any) {
let description = rdf["rdf:Description"];
if (Object.prototype.toString.call(description) !== "[object Array]") description = [description, {}];
if (description.length !== 2) throw new Error("Expected 2 descriptions");
const description0 = description[0];
- 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 mustHaveTextAndAttributes
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
export function mustHaveTextAndAttributes(object: any/*todo*/, mustHaveText: boolean, ...attrs: (string | string[])[]) {
if (attrs.length > 0) {
if (!object["@attributes"])
throw new Error("Expected object to have " + attrs.length + " attributes: " + JSON.stringify(object));
if (attrs.length != Object.keys(object["@attributes"]).length)
- 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 getTitle
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
export function getTitle(t: any, id: string, creator: Creator, issued: string): LabelWithLanguage {
if (!t) {
const title = [id];
const creatorLabels = creator['rdfs:label'];
- 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
Avoid too many return
statements within this function. Open
else return "nl";