2021-10-29 21:25:12 +01:00
|
|
|
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
|
|
#pragma once
|
|
|
|
|
2024-11-08 21:41:45 +00:00
|
|
|
#include "Luau/DenseHash.h"
|
2023-08-11 15:42:37 +01:00
|
|
|
#include "Luau/LinterConfig.h"
|
2021-10-29 21:25:12 +01:00
|
|
|
#include "Luau/ParseOptions.h"
|
|
|
|
|
2024-11-08 21:41:45 +00:00
|
|
|
#include <memory>
|
2021-10-29 21:25:12 +01:00
|
|
|
#include <optional>
|
2023-12-02 07:46:57 +00:00
|
|
|
#include <string>
|
2024-11-08 21:41:45 +00:00
|
|
|
#include <string_view>
|
2021-10-29 21:25:12 +01:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace Luau
|
|
|
|
{
|
|
|
|
|
|
|
|
using ModuleName = std::string;
|
|
|
|
|
|
|
|
constexpr const char* kConfigName = ".luaurc";
|
|
|
|
|
|
|
|
struct Config
|
|
|
|
{
|
2022-09-29 23:23:10 +01:00
|
|
|
Config();
|
2024-11-12 22:25:04 +00:00
|
|
|
Config(const Config& other);
|
|
|
|
Config& operator=(const Config& other);
|
|
|
|
Config(Config&& other) = default;
|
|
|
|
Config& operator=(Config&& other) = default;
|
2021-10-29 21:25:12 +01:00
|
|
|
|
2023-07-28 16:13:53 +01:00
|
|
|
Mode mode = Mode::Nonstrict;
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
ParseOptions parseOptions;
|
|
|
|
|
|
|
|
LintOptions enabledLint;
|
|
|
|
LintOptions fatalLint;
|
|
|
|
|
|
|
|
bool lintErrors = false;
|
|
|
|
bool typeErrors = true;
|
|
|
|
|
|
|
|
std::vector<std::string> globals;
|
2023-12-02 07:46:57 +00:00
|
|
|
|
2024-11-08 21:41:45 +00:00
|
|
|
struct AliasInfo
|
|
|
|
{
|
|
|
|
std::string value;
|
|
|
|
std::string_view configLocation;
|
|
|
|
};
|
|
|
|
|
|
|
|
DenseHashMap<std::string, AliasInfo> aliases{""};
|
|
|
|
|
2024-11-22 21:00:51 +00:00
|
|
|
void setAlias(std::string alias, std::string value, const std::string& configLocation);
|
2024-11-08 21:41:45 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Prevents making unnecessary copies of the same config location string.
|
|
|
|
DenseHashMap<std::string, std::unique_ptr<std::string>> configLocationCache{""};
|
2021-10-29 21:25:12 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
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(
|
2024-08-02 15:30:04 +01:00
|
|
|
LintOptions& enabledLints,
|
|
|
|
LintOptions& fatalLints,
|
|
|
|
const std::string& warningName,
|
|
|
|
const std::string& value,
|
|
|
|
bool compat = false
|
|
|
|
);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
2023-12-02 07:46:57 +00:00
|
|
|
bool isValidAlias(const std::string& alias);
|
|
|
|
|
2024-11-08 21:41:45 +00:00
|
|
|
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{});
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
} // namespace Luau
|