Skip to content
Merged
Show file tree
Hide file tree
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
50 changes: 49 additions & 1 deletion cli/tc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,57 @@ static bool reportModuleResult(Luau::Frontend& frontend, const Luau::ModuleName&
return cr->errors.empty() && cr->lintResult.errors.empty();
}

static std::string getExtension(const std::string& path)
{
size_t dot = path.find_last_of(".\\/");

if (dot == std::string::npos || path[dot] != '.')
return "";

return path.substr(dot);
}

int typecheck(const std::vector<std::string> sourceFiles)
std::vector<std::string> processSourceFiles(const std::vector<std::string>& sourceFilesInput)
{
std::vector<std::string> files;

for (const auto& path :sourceFilesInput)
{
std::string normalized = normalizePath(path);

if (isDirectory(normalized))
{
traverseDirectory(
normalized,
[&](const std::string& name)
{
std::string ext = getExtension(name);

if (ext == ".lua" || ext == ".luau")
files.push_back(name);
}
);
}
else
{
files.push_back(normalized);
}
}


return files;
}

int typecheck(const std::vector<std::string>& sourceFilesInput)
{
std::vector<std::string> sourceFiles = processSourceFiles(sourceFilesInput);

if (sourceFiles.empty())
{
fprintf(stderr, "Error: lute --check expects a file to type check.\n\n");
return 1;
}

Luau::Mode mode = Luau::Mode::Strict;
bool annotate = true;
std::string basePath = "";
Expand Down
2 changes: 1 addition & 1 deletion cli/tc.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
#include "Luau/Frontend.h"
#include "Luau/FileUtils.h"

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