Skip to content

Rules/too many required arguments #1176

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

Closed

Conversation

Lakitna
Copy link
Contributor

@Lakitna Lakitna commented Feb 18, 2025

Closes #1145

It took a while due to other priorities, but here is the addition of 2 rules:

  • too-many-required-arguments
  • too-many-optional-arguments

Please note that I disabled too-many-arguments in favor of these new rules like discussed in the issue.

Copy link

codecov bot commented Feb 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.97%. Comparing base (f62508c) to head (622fb52).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1176      +/-   ##
==========================================
- Coverage   97.02%   96.97%   -0.06%     
==========================================
  Files          37       39       +2     
  Lines        4670     5083     +413     
==========================================
+ Hits         4531     4929     +398     
- Misses        139      154      +15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Lakitna
Copy link
Contributor Author

Lakitna commented Feb 18, 2025

The failing test is caused by too-many-arguments being disabled. I'll hold off on looking for a fix until @bhirsz can chime in

Comment on lines +584 to +585
for arg in arguments.values:
if "}=" in arg:
Copy link
Member

Choose a reason for hiding this comment

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

We may want to ignore errors as well, for example:

[Arguments]    ${argument} = default

Not sure how it behaves but most likely it's parsing error, but may still come up here as 'optional' argument

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did consider variations like this, but decided it was not worth the effort to explicitly support it. I even looked through the Userguide for this :) Now that I know where it is, it's an easy find:

The syntax for default values is space sensitive. Spaces before the = sign are not allowed, and possible spaces after it are considered part of the default value itself.
Source: https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#default-values-with-user-keywords

So } = is a parsing error:

[Arguments]    ${argument} =default

And = foo sets the default value of ${argument} to ${SPACE}foo:

[Arguments]    ${argument}= foo

To me, syntax errors are out of scope while ${SPACE} is part of the value. Leading me to simply check for "}=".

Thought, writing this makes me think it can be good to add a rule to warn you about }= value 🤔 Could be called something like space-before-default-value.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it will be parsing error - but we need to test it as it night be still parsed as argument and reported by the rule (just with a parsing error attached to node).

@bhirsz
Copy link
Member

bhirsz commented Feb 24, 2025

LGTM! Only minor comments.

As for failing tests, I see it's test_all_builtin_rules_should_be_enabled_by_default - it can be ignroed (commented out even) as it will be deprecated in new robocop anyway.

@bhirsz bhirsz deleted the branch MarketSquare:master February 26, 2025 15:32
@bhirsz bhirsz closed this Feb 26, 2025
@bhirsz
Copy link
Member

bhirsz commented Feb 26, 2025

My apologies - it looks like Github closed the PR after I started clean ups in the repository. I have changed master branch to main.

Also, I have decided to keep merged Robocop inside this repository. I didn't want to lose all the stars, contributions and commit history after all! That means I will be copying the PRs from 'academy' repo into main branch here today. For your PR you have two options:

  1. Raise it againsts 'deprecated_robocop' branch (which uses current, soon to be deprecated code) and I will migrate it before releasing merged Robocop
  2. Raise it against main, but I will either update it on your branch or you can adjust the code to the new format of rules. It's not much work, so I don't mind either

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Rule] Too many arguments without default
2 participants