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

Analyzer should report on various parameter/argument situations of private API #44570

Open
srawlins opened this issue Dec 30, 2020 · 0 comments
Labels
analyzer-warning Issues with the analyzer's Warning codes area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P4 type-enhancement A request for a change that isn't a bug

Comments

@srawlins
Copy link
Member

For functions and methods which are not publicly accessible ("private"), there are some additional analyses that the analyzer could do:

  • If every call to a private function omits an argument for a given optional parameter, report that the optional parameter can be removed.
  • If every call to a private function includes an argument for a given optional parameter, report that the optional parameter can be made required.
  • If every call to a private function uses the same (literal? const?) value as an argument for a given parameter, report that the parameter can be removed. I think you'd see this a lot with boolean parameters which at one time served a purpose.
  • If every call to a private function uses the same "value" (expression?) as an argument for a given parameter, and that value is visible to the function, report that the parameter can be removed. There may be some false positives in here, and it may be hard to compute... but I've seen code in which a method is always given a field as an argument, which is obviously already in-scope to the method, or a local function is always given a local variable as an argument, which was declared above the function, as so is already in-scope to the local function.

I don't think any of these have a lot of opportunity to shrink code bloat; mostly to simplify and improve maintainability of existing code.

As with other analyses of "private" elements, this amounts to:

  • private top-level functions
  • private instance methods, constructors on classes and mixins
  • public static methods on private classes, mixins, and extensions
  • methods on private or unnamed extensions
  • local functions

TODO: gather related requests from this repo and from the linter repo.

@srawlins srawlins added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. analyzer-warning Issues with the analyzer's Warning codes P4 labels Dec 30, 2020
@srawlins srawlins added the type-enhancement A request for a change that isn't a bug label Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-warning Issues with the analyzer's Warning codes area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P4 type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

1 participant