sisoe24 / Nuke-Tools

Use for-of loop for array JS-0361
Anti-pattern
Minor
5 months ago5 months old
Expected a for-of loop instead of a for loop with this simple iteration
276        );
277
278        const files = osWalk(KNOBS_DIR);
279        for (let i = 0; i < files.length; i++) {280            const file = files[i];281282            // Get the knob name file parts without the id to check if the knob already exists.283            const knobFileName = knobFile.filename.split("_").slice(0, 3).join("_");284285            if (path.basename(file).startsWith(knobFileName)) {286                vscode.window.showErrorMessage("Knob already exists");287                return;288            }289        }290
291        fs.writeFileSync(knobFile.path, "");
292        vscode.window.showTextDocument(vscode.Uri.file(knobFile.path), { preview: false });
Expected a for-of loop instead of a for loop with this simple iteration
206
207        // TODO: send all the code at once and then rename the files. 
208
209        for (let i = 0; i < files.length; i++) {210            const file = files[i];211            if (!file.endsWith(".py")) {212                continue;213            }214215            const knobFile = new KnobFile(file);216            const result = await sendToNuke(syncNodeSnippet(knobFile));217            if (result.error) {218                vscode.window.showErrorMessage(`Failed to sync ${file}: ${result.errorMessage}`);219                continue;220            }221            const newName = knobFile.newName(result.message);222223            try {224                fs.renameSync(file, path.join(KNOBS_DIR, newName));225            } catch (error) {226                vscode.window.showErrorMessage(`Failed to rename ${file} to ${newName}: ${error}`);227            }228229            sleep(1000);230        }231
232        this.refresh();
233    }