Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/Config/include/Luau/LinterConfig.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/Location.h"
5
6
#include <string>
7
#include <vector>
8
9
#include <stdint.h>
10
11
namespace Luau
12
{
13
14
struct HotComment;
15
16
struct LintWarning
17
{
18
// Make sure any new lint codes are documented here: https://luau.org/lint
19
// Note that in Studio, the active set of lint warnings is determined by FStringStudioLuauLints
20
enum Code
21
{
22
Code_Unknown = 0,
23
24
Code_UnknownGlobal = 1, // superseded by type checker
25
Code_DeprecatedGlobal = 2,
26
Code_GlobalUsedAsLocal = 3,
27
Code_LocalShadow = 4, // disabled in Studio
28
Code_SameLineStatement = 5, // disabled in Studio
29
Code_MultiLineStatement = 6,
30
Code_LocalUnused = 7, // disabled in Studio
31
Code_FunctionUnused = 8, // disabled in Studio
32
Code_ImportUnused = 9, // disabled in Studio
33
Code_BuiltinGlobalWrite = 10,
34
Code_PlaceholderRead = 11,
35
Code_UnreachableCode = 12,
36
Code_UnknownType = 13,
37
Code_ForRange = 14,
38
Code_UnbalancedAssignment = 15,
39
Code_ImplicitReturn = 16, // disabled in Studio, superseded by type checker in strict mode
40
Code_DuplicateLocal = 17,
41
Code_FormatString = 18,
42
Code_TableLiteral = 19,
43
Code_UninitializedLocal = 20,
44
Code_DuplicateFunction = 21,
45
Code_DeprecatedApi = 22,
46
Code_TableOperations = 23,
47
Code_DuplicateCondition = 24,
48
Code_MisleadingAndOr = 25,
49
Code_CommentDirective = 26,
50
Code_IntegerParsing = 27,
51
Code_ComparisonPrecedence = 28,
52
Code_RedundantNativeAttribute = 29,
53
54
Code__Count
55
};
56
57
Code code;
58
Location location;
59
std::string text;
60
61
static const char* getName(Code code);
62
static Code parseName(const char* name);
63
static uint64_t parseMask(const std::vector<HotComment>& hotcomments);
64
};
65
66
struct LintOptions
67
{
68
uint64_t warningMask = 0;
69
70
void enableWarning(LintWarning::Code code)
71
{
72
warningMask |= 1ull << code;
73
}
74
void disableWarning(LintWarning::Code code)
75
{
76
warningMask &= ~(1ull << code);
77
}
78
79
bool isEnabled(LintWarning::Code code) const
80
{
81
return 0 != (warningMask & (1ull << code));
82
}
83
84
void setDefaults();
85
};
86
87
// clang-format off
88
inline constexpr const char* kWarningNames[] = {
89
"Unknown",
90
91
"UnknownGlobal",
92
"DeprecatedGlobal",
93
"GlobalUsedAsLocal",
94
"LocalShadow",
95
"SameLineStatement",
96
"MultiLineStatement",
97
"LocalUnused",
98
"FunctionUnused",
99
"ImportUnused",
100
"BuiltinGlobalWrite",
101
"PlaceholderRead",
102
"UnreachableCode",
103
"UnknownType",
104
"ForRange",
105
"UnbalancedAssignment",
106
"ImplicitReturn",
107
"DuplicateLocal",
108
"FormatString",
109
"TableLiteral",
110
"UninitializedLocal",
111
"DuplicateFunction",
112
"DeprecatedApi",
113
"TableOperations",
114
"DuplicateCondition",
115
"MisleadingAndOr",
116
"CommentDirective",
117
"IntegerParsing",
118
"ComparisonPrecedence",
119
"RedundantNativeAttribute",
120
};
121
// clang-format on
122
123
static_assert(std::size(kWarningNames) == unsigned(LintWarning::Code__Count), "did you forget to add warning to the list?");
124
125
} // namespace Luau
126
127