Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -1142,15 +1142,14 @@ function complete(line, callback) {
paths = module.paths.concat(CJSModule.globalPaths);
}

for (let i = 0; i < paths.length; i++) {
dir = path.resolve(paths[i], subdir);
for (const pathEntry of paths) {
dir = path.resolve(pathEntry, subdir);
try {
files = fs.readdirSync(dir);
} catch {
continue;
}
for (let f = 0; f < files.length; f++) {
const name = files[f];
for (const name of files) {
const ext = path.extname(name);
const base = name.slice(0, -ext.length);
if (versionedFileNamesRe.test(base) || name === '.npm') {
Expand All @@ -1170,8 +1169,8 @@ function complete(line, callback) {
} catch {
continue;
}
for (let s = 0; s < subfiles.length; s++) {
if (indexRe.test(subfiles[s])) {
for (const subfile of subfiles) {
if (indexRe.test(subfile)) {
group.push(subdir + name);
}
}
Expand Down Expand Up @@ -1295,9 +1294,9 @@ function complete(line, callback) {
}

if (memberGroups.length) {
for (let i = 0; i < memberGroups.length; i++) {
for (const memberGroup of memberGroups) {
completionGroups.push(
memberGroups[i].map((member) => `${expr}.${member}`));
memberGroup.map((member) => `${expr}.${member}`));
}
if (filter) {
filter = `${expr}.${filter}`;
Expand All @@ -1316,8 +1315,8 @@ function complete(line, callback) {
// Filter, sort (within each group), uniq and merge the completion groups.
if (completionGroups.length && filter) {
const newCompletionGroups = [];
for (let i = 0; i < completionGroups.length; i++) {
group = completionGroups[i]
for (const completionGroup of completionGroups) {
group = completionGroup
.filter((elem) => elem.indexOf(filter) === 0);
if (group.length) {
newCompletionGroups.push(group);
Expand Down Expand Up @@ -1516,8 +1515,7 @@ function defineDefaultCommands(repl) {
(max, name) => MathMax(max, name.length),
0
);
for (let n = 0; n < names.length; n++) {
const name = names[n];
for (const name of names) {
const cmd = this.commands[name];
const spaces = ' '.repeat(longestNameLength - name.length + 3);
const line = `.${name}${cmd.help ? spaces + cmd.help : ''}\n`;
Expand Down