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] avoid_unused_parameters #59955

Open
stephane-archer opened this issue Jan 22, 2025 · 6 comments
Open

[lint] avoid_unused_parameters #59955

stephane-archer opened this issue Jan 22, 2025 · 6 comments
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. linter-lint-request

Comments

@stephane-archer
Copy link

class LutFoldersState {
  final int _lutFolders;

  const LutFoldersState(this._lutFolders);

  LutFoldersState copyWith({
    int? lutFolders,
    bool? uselessbool,
  }) {
    return LutFoldersState(
      lutFolders ?? _lutFolders,
    );
  }
}

uselessbool is an unused parameters

@stephane-archer stephane-archer added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Jan 22, 2025
@julemand101
Copy link
Contributor

Just to make sure we have covered the details, I guess this rule should not apply when you override a method?

What about scenarios where we have a default implementation not using the parameter but we want the parameter to be available for sub-classes?

@stephane-archer
Copy link
Author

this rule should not apply when you override a method

yes

is this a valid design to have unused parameters for people who might extend you?
If you implement an interface and you have unused parameters that make sense (here you override),
but having unused parameters on a base class? I'm not sure it makes any sense.

@stephane-archer
Copy link
Author

top-level function and static function, this linter will always make sense right?

@RohitSaily
Copy link
Contributor

It is reasonable to have unused parameters for a method of the base class.

The Template Method Pattern may involve defining methods in a base class with unused parameters. The idea is that the base class provides a partial implementation using some parameters and the extenders can make use of that implementation by calling super while also adding implementation involving the unused parameters.

class ErrorProcessor
{	void process({required String severity, required String message, Object? error})
	{	print('[$severity] $message');//<Parent class implements logging
	}
}
final class DatabaseErrorProcessor extends ErrorProcessor
{	@override void process({required String severity, required String message, Object? error})
	{	super.process(severity: severity, message: message, error: error);//<Allow parent processing to occur
		//<Can make decisions of other things to do based on the error, like
		// attempting recovery
	}
}

@stephane-archer
Copy link
Author

@RohitSaily I would be happy personally with false positive on that case and the need to explicitly say these parameters are meat for extenders by silencing the linter there.

@RohitSaily
Copy link
Contributor

I agree. I think it is better to have it cautious by default because, as you have said, the linter can be silenced when it is intentional design.

@bwilkerson bwilkerson added analyzer-linter Issues with the analyzer's support for the linter package linter-lint-request labels Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. linter-lint-request
Projects
None yet
Development

No branches or pull requests

4 participants