Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
gurgunday committed Nov 4, 2024
1 parent 0f60f55 commit 3dec768
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1385,11 +1385,11 @@ function readdirSyncRecursive(basePath, options) {
{
encoding,
withFileTypes,
}
},
);

if (withFileTypes) {
return results.map(([path, name, type]) => getDirent(path, name, type));
return results.map(({ 0: path, 1: name, 2: type }) => getDirent(path, name, type));
}

return results;
Expand Down
31 changes: 16 additions & 15 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2082,16 +2082,16 @@ static void ReaddirRecursiveSync(const FunctionCallbackInfo<Value>& args) {
CHECK_NOT_NULL(*path);
ToNamespacedPath(env, &path);

Local<Object> options = args[1]->IsObject() ?
Local<Object> options = args[1]->IsObject() ?
args[1].As<Object>() : Object::New(isolate);

Local<Value> encoding_opt;
if (!options->Get(env->context(), env->encoding_string())
.ToLocal(&encoding_opt)) {
return;
}
const enum encoding encoding = ParseEncoding(isolate, encoding_opt, UTF8);
bool with_file_types = options->Get(env->context(),
bool with_file_types = options->Get(env->context(),
FIXED_ONE_BYTE_STRING(isolate, "withFileTypes"))
.ToLocalChecked()->IsTrue();

Expand All @@ -2107,14 +2107,14 @@ static void ReaddirRecursiveSync(const FunctionCallbackInfo<Value>& args) {
dir_queue.push_back(*path);

FSReqWrapSync req_wrap_sync("readdir_recursive");

const std::string base_path(*path);

while (!dir_queue.empty()) {
std::string current_path = std::move(dir_queue.back());
dir_queue.pop_back();

int err = uv_fs_scandir(nullptr, &req_wrap_sync.req,
int err = uv_fs_scandir(nullptr, &req_wrap_sync.req,
current_path.c_str(), 0, nullptr);
if (err < 0) {
if (err == UV_ENOENT || err == UV_ENOTDIR) {
Expand All @@ -2136,7 +2136,7 @@ static void ReaddirRecursiveSync(const FunctionCallbackInfo<Value>& args) {
full_path += kPathSeparator;
}
full_path += ent.name;

if (with_file_types) {
paths.push_back(current_path);
names.emplace_back(ent.name);
Expand All @@ -2161,22 +2161,22 @@ static void ReaddirRecursiveSync(const FunctionCallbackInfo<Value>& args) {
uv_fs_req_cleanup(&req_wrap_sync.req);
}

Local<Array> result_array = Array::New(isolate,
Local<Array> result_array = Array::New(isolate,
with_file_types ? paths.size() : relative_paths.size());

if (with_file_types) {
for (size_t i = 0; i < paths.size(); i++) {
Local<Array> entry_info = Array::New(isolate, 3);
Local<Value> error;
MaybeLocal<Value> path_value = StringBytes::Encode(isolate,

MaybeLocal<Value> path_value = StringBytes::Encode(isolate,
paths[i].c_str(), encoding, &error);
if (!error.IsEmpty()) {
isolate->ThrowException(error);
return;
}

MaybeLocal<Value> name_value = StringBytes::Encode(isolate,
MaybeLocal<Value> name_value = StringBytes::Encode(isolate,
names[i].c_str(), encoding, &error);
if (!error.IsEmpty()) {
isolate->ThrowException(error);
Expand All @@ -2185,14 +2185,15 @@ static void ReaddirRecursiveSync(const FunctionCallbackInfo<Value>& args) {

entry_info->Set(env->context(), 0, path_value.ToLocalChecked()).Check();
entry_info->Set(env->context(), 1, name_value.ToLocalChecked()).Check();
entry_info->Set(env->context(), 2, Integer::New(isolate, types[i])).Check();

entry_info->Set(env->context(), 2,
Integer::New(isolate, types[i])).Check();

result_array->Set(env->context(), i, entry_info).Check();
}
} else {
for (size_t i = 0; i < relative_paths.size(); i++) {
Local<Value> error;
MaybeLocal<Value> path_value = StringBytes::Encode(isolate,
MaybeLocal<Value> path_value = StringBytes::Encode(isolate,
relative_paths[i].c_str(), encoding, &error);
if (!error.IsEmpty()) {
isolate->ThrowException(error);
Expand Down

0 comments on commit 3dec768

Please sign in to comment.