From 7633ff83f00be372f2c7f5950e6c0c8c5bdc44af Mon Sep 17 00:00:00 2001 From: HawDevelopment <70876593+HawDevelopment@users.noreply.github.com> Date: Wed, 6 Jul 2022 14:56:56 +0200 Subject: [PATCH] Remove filesystem access --- Analysis/src/Config.cpp | 16 ++++------------ tests/Config.test.cpp | 24 ++++-------------------- 2 files changed, 8 insertions(+), 32 deletions(-) diff --git a/Analysis/src/Config.cpp b/Analysis/src/Config.cpp index 03854c61..a9a399cf 100644 --- a/Analysis/src/Config.cpp +++ b/Analysis/src/Config.cpp @@ -4,8 +4,6 @@ #include "Luau/Lexer.h" #include "Luau/StringUtils.h" -#include - namespace { @@ -109,15 +107,6 @@ Error parseLintRuleString(LintOptions& enabledLints, LintOptions& fatalLints, co return std::nullopt; } -Error parseFilePath(std::vector& 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) { lexer.next(); @@ -272,7 +261,10 @@ Error parseConfig(const std::string& contents, Config& config, bool compat) return std::nullopt; } 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") return parseModeString(config.mode, value, compat); else diff --git a/tests/Config.test.cpp b/tests/Config.test.cpp index 52d48e5f..4849cf35 100644 --- a/tests/Config.test.cpp +++ b/tests/Config.test.cpp @@ -8,7 +8,6 @@ #include "doctest.h" #include -#include using namespace Luau; @@ -137,35 +136,20 @@ TEST_CASE("extra_globals") TEST_CASE("global_type_paths") { - // This could be done with a temp file! - std::ofstream file("./globalTypePathsTest.lua"); - file.close(); - Config config; auto err = parseConfig(R"( - {"globalTypePaths": ["./globalTypePathsTest.lua"]} - )", +{ + "globalTypePaths": ["./globalTypePathsTest.lua"] +} +)", config); - std::remove("./globalTypePathsTest.lua"); - REQUIRE(!err); CHECK(config.globalTypePaths.size() == 1); 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") { Config config;