Skip to content

Commit

Permalink
Lint for /var/ in proc args (#2064)
Browse files Browse the repository at this point in the history
Co-authored-by: ike709 <[email protected]>
  • Loading branch information
ike709 and ike709 authored Oct 28, 2024
1 parent b974c59 commit bad3d7c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
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/example(/var/foo)" makes the arg a global var. Ref https://www.byond.com/forum/post/2830750
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

0 comments on commit bad3d7c

Please sign in to comment.