Remove filesystem access

This commit is contained in:
HawDevelopment 2022-07-06 14:56:56 +02:00
parent 67afc373c9
commit 7633ff83f0
2 changed files with 8 additions and 32 deletions

View file

@ -4,8 +4,6 @@
#include "Luau/Lexer.h" #include "Luau/Lexer.h"
#include "Luau/StringUtils.h" #include "Luau/StringUtils.h"
#include <filesystem>
namespace namespace
{ {
@ -109,15 +107,6 @@ Error parseLintRuleString(LintOptions& enabledLints, LintOptions& fatalLints, co
return std::nullopt; return std::nullopt;
} }
Error parseFilePath(std::vector<std::string>& paths, const std::string& value) {
// The exists check could be invalid, since we use the frontend file resolver to read the contents.
if (value.empty() || !std::filesystem::exists(value))
return Error{"Unkown file path: " + value};
paths.push_back(value);
return std::nullopt;
}
static void next(Lexer& lexer) static void next(Lexer& lexer)
{ {
lexer.next(); lexer.next();
@ -272,7 +261,10 @@ Error parseConfig(const std::string& contents, Config& config, bool compat)
return std::nullopt; return std::nullopt;
} }
else if (keys.size() == 1 && keys[0] == "globalTypePaths") else if (keys.size() == 1 && keys[0] == "globalTypePaths")
return parseFilePath(config.globalTypePaths, value); {
config.globalTypePaths.push_back(value);
return std::nullopt;
}
else if (compat && keys.size() == 2 && keys[0] == "language" && keys[1] == "mode") else if (compat && keys.size() == 2 && keys[0] == "language" && keys[1] == "mode")
return parseModeString(config.mode, value, compat); return parseModeString(config.mode, value, compat);
else else

View file

@ -8,7 +8,6 @@
#include "doctest.h" #include "doctest.h"
#include <iostream> #include <iostream>
#include <fstream>
using namespace Luau; using namespace Luau;
@ -137,35 +136,20 @@ TEST_CASE("extra_globals")
TEST_CASE("global_type_paths") TEST_CASE("global_type_paths")
{ {
// This could be done with a temp file!
std::ofstream file("./globalTypePathsTest.lua");
file.close();
Config config; Config config;
auto err = parseConfig(R"( auto err = parseConfig(R"(
{"globalTypePaths": ["./globalTypePathsTest.lua"]} {
)", "globalTypePaths": ["./globalTypePathsTest.lua"]
}
)",
config); config);
std::remove("./globalTypePathsTest.lua");
REQUIRE(!err); REQUIRE(!err);
CHECK(config.globalTypePaths.size() == 1); CHECK(config.globalTypePaths.size() == 1);
CHECK(config.globalTypePaths[0] == "./globalTypePathsTest.lua"); CHECK(config.globalTypePaths[0] == "./globalTypePathsTest.lua");
} }
TEST_CASE("global_type_paths_unable_to_find_file") {
Config config;
auto err = parseConfig(R"(
{"globalTypePaths": ["./THIS_FILE_SHOULD_NOT_EXIST.lua"]}
)",
config);
REQUIRE(err);
CHECK(err.value() == "Unkown file path: ./THIS_FILE_SHOULD_NOT_EXIST.lua");
}
TEST_CASE("lint_rules_compat") TEST_CASE("lint_rules_compat")
{ {
Config config; Config config;