cognitive-complexity-ts
Version:
This program analyses TypeScript and JavaScript code according to the [Cognitive Complexity metric](https://www.sonarsource.com/docs/CognitiveComplexity.pdf). It produces a JSON summary and a GUI for exploring the complexity of your codebase.
39 lines • 1.3 kB
JavaScript
import { CopyText } from "../controls/CopyText.js";
import { ToggleableBox } from "../box/ToggleableBox.js";
import { Score } from "../text/Score.js";
import { showInTree, StickyTitle } from "./StickyTitle.js";
export class Container {
constructor(complexity, children) {
this.children = children;
this.depth = complexity.depth;
this.title = new StickyTitle([
complexity.name,
CopyText(`${complexity.path}:${complexity.line}:${complexity.column}`),
], complexity.depth);
this.box = new ToggleableBox([
this.title.dom,
Score(complexity.score),
], false, () => this.scrollIntoView());
this.box.changeHideableContent(() => this.children.map(child => child.dom));
}
get dom() {
return this.box.dom;
}
scrollIntoView() {
showInTree(this.dom, this.depth);
}
setChildren(children) {
this.children = children;
this.box.changeHideableContent(() => this.children.map(child => child.dom));
}
setDepth(depth) {
if (this.depth !== depth) {
this.depth = depth;
this.title.setDepth(depth);
}
}
setOpenness(open) {
this.box.setOpenness(open);
}
}
//# sourceMappingURL=Container.js.map