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 redundant positional arguments. #1770

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

moonheart08
Copy link
Contributor

Fixes #1768, adds a new lint.

Warning OD2210 at code/modules/gamemaster/actions/atmos_leak.dm:20:45: The argument at index 1 is a positional argument with a redundant index (`1 = value` at argument 1). This does not function like a named argument and is likely a mistake.
Warning OD2210 at code/modules/gamemaster/actions/atmos_leak.dm:21:24: The argument at index 2 is a positional argument with a redundant index (`2 = value` at argument 2). This does not function like a named argument and is likely a mistake.
Warning OD2210 at code/modules/gamemaster/actions/atmos_leak.dm:22:21: The argument at index 3 is a positional argument with a redundant index (`3 = value` at argument 3). This does not function like a named argument and is likely a mistake.

@boring-cyborg boring-cyborg bot added the Compiler Involves the OpenDream compiler label May 6, 2024
@github-actions github-actions bot added the size/S label May 6, 2024
@moonheart08
Copy link
Contributor Author

this accidentally depends on #1767 and im too lazy to fix it merge that first.

@ike709
Copy link
Collaborator

ike709 commented May 6, 2024

Unit tests plz

Copy link
Member

@wixoaGit wixoaGit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also like for there to be unit tests. You can make one by #pragma-ing the lint to an error and purposefully triggering it.

@@ -129,6 +136,7 @@ sealed class ArgumentList {
_isKeyed = true;

Expressions[argIndex] = (name, value);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary empty line

Suggested change

Comment on lines +206 to +207

if ((!expr.ValType.IsAnything && !paramType.MatchesType(expr.ValType))) {
Copy link
Member

@wixoaGit wixoaGit May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary empty line & parentheses

Suggested change
if ((!expr.ValType.IsAnything && !paramType.MatchesType(expr.ValType))) {
if (!expr.ValType.IsAnything && !paramType.MatchesType(expr.ValType)) {


if (newIdx == argIndex) {
DMCompiler.Emit(WarningCode.PointlessPositionalArgument, key.Location,
$"The argument at index {argIndex + 1} is a positional argument with a redundant index (`{argIndex + 1} = value` at argument {argIndex + 1}). This does not function like a named argument and is likely a mistake.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We avoid using backticks in compiler messages due to it causing formatting issues when pasted elsewhere

Suggested change
$"The argument at index {argIndex + 1} is a positional argument with a redundant index (`{argIndex + 1} = value` at argument {argIndex + 1}). This does not function like a named argument and is likely a mistake.");
$"The argument at index {argIndex + 1} is a positional argument with a redundant index (\"{argIndex + 1} = value\" at argument {argIndex + 1}). This does not function like a named argument and is likely a mistake.");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compiler Involves the OpenDream compiler size/S
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lint for pointless/bad positional arguments.
3 participants