Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint for /var/ in proc args #2064

Merged
merged 3 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Content.Tests/DMProject/Tests/Arg/ProcArgumentGlobal_lint.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// COMPILE ERROR OD2211
#pragma ProcArgumentGlobal error

/proc/foo(/var/bar)
return

/proc/RunTest()
return
1 change: 1 addition & 0 deletions DMCompiler/Compiler/CompilerError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public enum WarningCode {
FallbackBuiltinArgument = 2208, // A builtin (sin(), cos(), etc) with an invalid/fallback argument
PointlessScopeOperator = 2209,
PointlessPositionalArgument = 2210,
ProcArgumentGlobal = 2211, // Prepending "/" on a proc arg (e.g. "/proc(/var/foo)" makes the arg a global var. Ref https://www.byond.com/forum/post/2830750
ike709 marked this conversation as resolved.
Show resolved Hide resolved
MalformedRange = 2300,
InvalidRange = 2301,
InvalidSetStatement = 2302,
Expand Down
4 changes: 4 additions & 0 deletions DMCompiler/Compiler/DM/DMParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1723,6 +1723,10 @@ private List<DMASTDefinitionParameter> DefinitionParameters(out bool wasIndeterm
DMASTPath? path = Path();

if (path != null) {
if (path.Path.PathString.StartsWith("/var/")) {
Emit(WarningCode.ProcArgumentGlobal, $"Proc argument \"{path.Path.PathString}\" starting with \"/var/\" will create a global variable. Replace with \"{path.Path.PathString[1..]}\"");
}

var loc = Current().Location;
Whitespace();

Expand Down
1 change: 1 addition & 0 deletions DMCompiler/DMStandard/DefaultPragmaConfig.dm
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#pragma AmbiguousResourcePath warning
#pragma SuspiciousSwitchCase warning
#pragma PointlessPositionalArgument warning
#pragma ProcArgumentGlobal warning // Ref BYOND issue https://www.byond.com/forum/post/2830750
// NOTE: The next few pragmas are for OpenDream's experimental type checker
// This feature is still in development, elevating these pragmas outside of local testing is discouraged
// An RFC to finalize this feature is coming soon(TM)
Expand Down
Loading