CIDARLAB / 3DuF

Prefer that for-in loops should include an if statement JS-0051
Anti-pattern
Minor
15 days ago3 years old
Wrap the body of a for-in loop in an if statement with a hasOwnProperty guard
131            // Get the corresponding the definitions object from the componentAPI, convert to a spec object and return
132            let definition = ComponentAPI.getDefinitionForMINT(minttype);
133            let spec = [];
134            for (let key in definition.heritable) {135                let item = {136                    min: definition.minimum[key],137                    max: definition.maximum[key],138                    value: definition.defaults[key],139                    units: definition.units[key],140                    steps: (definition.maximum[key] - definition.minimum[key]) / 10,141                    name: key142                };143                spec.push(item);144            }145            return spec;
146        }
147    }
Wrap the body of a for-in loop in an if statement with a hasOwnProperty guard
217            // Get the corresponding the definitions object from the componentAPI, convert to a spec object and return
218            let definition = ComponentAPI.getDefinition(threeduftype);
219            let spec = [];
220            for (let key in definition.heritable) {221                console.log(definition.units[key]);222                // const unittext = definition.units[key] !== "" ? he.htmlDecode(definition.units[key]) : "";223                let item = {224                    mint: key,225                    min: definition.minimum[key],226                    max: definition.maximum[key],227                    value: definition.defaults[key],228                    units: definition.units[key],229                    steps: (definition.maximum[key] - definition.minimum[key]) / 10,230                    name: key231                };232                spec.push(item);233            }234            return spec;
235        },
236        showProperties() {
Wrap the body of a for-in loop in an if statement with a hasOwnProperty guard
164            const heritable = def.heritable;
165            const defaults = def.defaults;
166
167            for (const key in heritable) {168                Registry.viewManager.adjustParams(typeString, setString, key, defaults[key]);169            }170        },
171
172        deleteButton() {
Wrap the body of a for-in loop in an if statement with a hasOwnProperty guard
 82            // Get the corresponding the definitions object from the componentAPI, convert to a spec object and return
 83            let spec = [];
 84            const definition = ComponentAPI.getDefinitionForMINT(mint);
 85            for (let i in params.heritable) { 86                let key = params.heritable[i]; 87                let item = { 88                    min: definition.minimum[key], 89                    max: definition.maximum[key], 90                    value: params.getValue(key), 91                    units: definition.units[key], 92                    steps: (definition.maximum[key] - definition.minimum[key]) / 10, 93                    name: key 94                }; 95                spec.push(item); 96            } 97            console.log("Spec: ", spec);
 98            return spec;
 99        },
Wrap the body of a for-in loop in an if statement with a hasOwnProperty guard
69            // Get the corresponding the definitions object from the componentAPI, convert to a spec object and return
70            let definition = ComponentAPI.getDefinition(threeduftype);
71            let spec = [];
72            for (let key in definition.heritable) {73                // const unittext = definition.units[key] !== "" ? he.htmlDecode(definition.units[key]) : "";74                let item = {75                    mint: key,76                    min: definition.minimum[key],77                    max: definition.maximum[key],78                    value: definition.defaults[key],79                    units: definition.units[key],80                    steps: (definition.maximum[key] - definition.minimum[key]) / 10,81                    name: key82                };83                spec.push(item);84            }85            return spec;
86        }
87    }