Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/Config/include/Luau/Config.h
2727 views
1
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2
#pragma once
3
4
#include "Luau/DenseHash.h"
5
#include "Luau/LinterConfig.h"
6
#include "Luau/ParseOptions.h"
7
8
#include <memory>
9
#include <optional>
10
#include <string>
11
#include <string_view>
12
#include <vector>
13
14
namespace Luau
15
{
16
17
using ModuleName = std::string;
18
19
constexpr const char* kConfigName = ".luaurc";
20
21
struct Config
22
{
23
Config();
24
Config(const Config& other);
25
Config& operator=(const Config& other);
26
Config(Config&& other) = default;
27
Config& operator=(Config&& other) = default;
28
29
Mode mode = Mode::Nonstrict;
30
31
ParseOptions parseOptions;
32
33
LintOptions enabledLint;
34
LintOptions fatalLint;
35
36
bool lintErrors = false;
37
bool typeErrors = true;
38
39
std::vector<std::string> globals;
40
41
struct AliasInfo
42
{
43
std::string value;
44
std::string_view configLocation;
45
std::string originalCase; // The alias in its original case.
46
};
47
48
DenseHashMap<std::string, AliasInfo> aliases{""};
49
50
void setAlias(std::string alias, std::string value, const std::string& configLocation);
51
52
private:
53
// Prevents making unnecessary copies of the same config location string.
54
DenseHashMap<std::string, std::unique_ptr<std::string>> configLocationCache{""};
55
};
56
57
std::optional<std::string> parseModeString(Mode& mode, const std::string& modeString, bool compat = false);
58
std::optional<std::string> parseLintRuleString(
59
LintOptions& enabledLints,
60
LintOptions& fatalLints,
61
const std::string& warningName,
62
const std::string& value,
63
bool compat = false
64
);
65
66
bool isValidAlias(const std::string& alias);
67
68
struct ConfigOptions
69
{
70
bool compat = false;
71
72
struct AliasOptions
73
{
74
std::string configLocation;
75
bool overwriteAliases;
76
};
77
std::optional<AliasOptions> aliasOptions = std::nullopt;
78
};
79
80
std::optional<std::string> parseAlias(
81
Config& config,
82
const std::string& aliasKey,
83
const std::string& aliasValue,
84
const std::optional<ConfigOptions::AliasOptions>& aliasOptions
85
);
86
87
std::optional<std::string> parseConfig(const std::string& contents, Config& config, const ConfigOptions& options = ConfigOptions{});
88
89
} // namespace Luau
90
91