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

UnusedArgumentsRule should check if method is an implementation of an event #26

Open
crenan opened this issue Jul 20, 2022 · 2 comments

Comments

@crenan
Copy link

crenan commented Jul 20, 2022

I have a Code Smell "Unused argument: AMyUnusedParam at TFormTest.MyComponentMyEventImplementation" for the example below

procedure TFormTest.MyComponentMyEventImplementation(AMyUnusedParam: TSomeRandomType);
begin
  inherited;
{*
  Some code that doesn't use "AMyUnusedParam"
*}
end;

I think this rule should check if the method is a implementation of an event before mark the params as code smells.
Generally the code in events not necessarly need to use all the parameters as they exists only to comply with the event declaration.

@joachimmarder
Copy link

I don't think that this is possible. You cannot check generally if a method might get assigned to an event or not. A similar problem exists for interface implementations, where it is common that not every implementation uses every parameter. But you cannot know if a method fulfills an interface in a derived class.

@crenan
Copy link
Author

crenan commented Jul 21, 2022

@joachimmarder good point, but it is possible to reduce this false-positive by checking if the method is bound to an event in the included DFM:

  • Check if {$R *.DFM} exists
  • Open the corresponding *.DFM
  • Search for the method name

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

No branches or pull requests

2 participants