luau/Config/include/Luau/Config.h
Varun Saini d1025d0029
Some checks failed
benchmark / callgrind (map[branch:main name:luau-lang/benchmark-data], ubuntu-22.04) (push) Has been cancelled
build / ${{matrix.os.name}} (map[name:macos version:macos-latest]) (push) Has been cancelled
build / ${{matrix.os.name}} (map[name:macos-arm version:macos-14]) (push) Has been cancelled
build / ${{matrix.os.name}} (map[name:ubuntu version:ubuntu-latest]) (push) Has been cancelled
build / windows (Win32) (push) Has been cancelled
build / windows (x64) (push) Has been cancelled
build / coverage (push) Has been cancelled
build / web (push) Has been cancelled
release / ${{matrix.os.name}} (map[name:macos version:macos-latest]) (push) Has been cancelled
release / ${{matrix.os.name}} (map[name:ubuntu version:ubuntu-20.04]) (push) Has been cancelled
release / ${{matrix.os.name}} (map[name:windows version:windows-latest]) (push) Has been cancelled
release / web (push) Has been cancelled
Remove noexcepts from Config (#1523)
Fixes https://github.com/luau-lang/luau/issues/1515.

By removing these `noexcept`s, we guarantee that the internal call to
`std::swap` uses move semantics when a `Config` is copy-assigned.
2024-11-12 14:25:04 -08:00

96 lines
2.2 KiB
C++

// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
#pragma once
#include "Luau/DenseHash.h"
#include "Luau/LinterConfig.h"
#include "Luau/ParseOptions.h"
#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <vector>
namespace Luau
{
using ModuleName = std::string;
constexpr const char* kConfigName = ".luaurc";
struct Config
{
Config();
Config(const Config& other);
Config& operator=(const Config& other);
Config(Config&& other) = default;
Config& operator=(Config&& other) = default;
Mode mode = Mode::Nonstrict;
ParseOptions parseOptions;
LintOptions enabledLint;
LintOptions fatalLint;
bool lintErrors = false;
bool typeErrors = true;
std::vector<std::string> globals;
struct AliasInfo
{
std::string value;
std::string_view configLocation;
};
DenseHashMap<std::string, AliasInfo> aliases{""};
void setAlias(std::string alias, const std::string& value, const std::string configLocation);
private:
// Prevents making unnecessary copies of the same config location string.
DenseHashMap<std::string, std::unique_ptr<std::string>> configLocationCache{""};
};
struct ConfigResolver
{
virtual ~ConfigResolver() {}
virtual const Config& getConfig(const ModuleName& name) const = 0;
};
struct NullConfigResolver : ConfigResolver
{
Config defaultConfig;
virtual const Config& getConfig(const ModuleName& name) const override;
};
std::optional<std::string> parseModeString(Mode& mode, const std::string& modeString, bool compat = false);
std::optional<std::string> parseLintRuleString(
LintOptions& enabledLints,
LintOptions& fatalLints,
const std::string& warningName,
const std::string& value,
bool compat = false
);
bool isValidAlias(const std::string& alias);
struct ConfigOptions
{
bool compat = false;
struct AliasOptions
{
std::string configLocation;
bool overwriteAliases;
};
std::optional<AliasOptions> aliasOptions = std::nullopt;
};
std::optional<std::string> parseConfig(const std::string& contents, Config& config, const ConfigOptions& options = ConfigOptions{});
} // namespace Luau