app/javascript/alchemy_admin/components/element_editor.js
ElementEditor
has 41 functions (exceeds 20 allowed). Consider refactoring. Open
Open
export class ElementEditor extends HTMLElement {
constructor() {
super()
// Add event listeners
File element_editor.js
has 331 lines of code (exceeds 250 allowed). Consider refactoring. Open
Open
import ImageLoader from "alchemy_admin/image_loader"
import fileEditors from "alchemy_admin/file_editors"
import pictureEditors from "alchemy_admin/picture_editors"
import SortableElements from "alchemy_admin/sortable_elements"
import IngredientAnchorLink from "alchemy_admin/ingredient_anchor_link"
Function expand
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
expand() {
if (this.expanded && !this.compact) {
return Promise.resolve("Element is already expanded.")
}
Function collapse
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
collapse() {
if (this.collapsed || this.compact || this.fixed) {
return Promise.resolve("Element is already collapsed.")
}
Function onSaveElement
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Wontfix
Wontfix
onSaveElement(data) {
// JS event bubbling will also update the parents element quote.
this.setClean()
// Reset errors that might be visible from last save attempt
this.errorsDisplay.innerHTML = ""
Function handleEvent
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
handleEvent(event) {
switch (event.type) {
case "click":
const elementEditor = event.target.closest("alchemy-element-editor")
if (elementEditor === this) {
Function handleEvent
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
Open
handleEvent(event) {
switch (event.type) {
case "click":
const elementEditor = event.target.closest("alchemy-element-editor")
if (elementEditor === this) {
- 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"