Skip to content

Commit fe2121a

Browse files
Traverse directories for files when type checking (luau-lang#98)
1 parent db88b93 commit fe2121a

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

cli/tc.cpp

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,57 @@ static bool reportModuleResult(Luau::Frontend& frontend, const Luau::ModuleName&
179179
return cr->errors.empty() && cr->lintResult.errors.empty();
180180
}
181181

182+
static std::string getExtension(const std::string& path)
183+
{
184+
size_t dot = path.find_last_of(".\\/");
185+
186+
if (dot == std::string::npos || path[dot] != '.')
187+
return "";
188+
189+
return path.substr(dot);
190+
}
182191

183-
int typecheck(const std::vector<std::string> sourceFiles)
192+
std::vector<std::string> processSourceFiles(const std::vector<std::string>& sourceFilesInput)
184193
{
194+
std::vector<std::string> files;
195+
196+
for (const auto& path :sourceFilesInput)
197+
{
198+
std::string normalized = normalizePath(path);
199+
200+
if (isDirectory(normalized))
201+
{
202+
traverseDirectory(
203+
normalized,
204+
[&](const std::string& name)
205+
{
206+
std::string ext = getExtension(name);
207+
208+
if (ext == ".lua" || ext == ".luau")
209+
files.push_back(name);
210+
}
211+
);
212+
}
213+
else
214+
{
215+
files.push_back(normalized);
216+
}
217+
}
218+
219+
220+
return files;
221+
}
222+
223+
int typecheck(const std::vector<std::string>& sourceFilesInput)
224+
{
225+
std::vector<std::string> sourceFiles = processSourceFiles(sourceFilesInput);
226+
227+
if (sourceFiles.empty())
228+
{
229+
fprintf(stderr, "Error: lute --check expects a file to type check.\n\n");
230+
return 1;
231+
}
232+
185233
Luau::Mode mode = Luau::Mode::Strict;
186234
bool annotate = true;
187235
std::string basePath = "";

cli/tc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
#include "Luau/Frontend.h"
55
#include "Luau/FileUtils.h"
66

7-
int typecheck(const std::vector<std::string> sourceFiles);
7+
int typecheck(const std::vector<std::string>& sourceFiles);

0 commit comments

Comments
 (0)