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

enable lint avoid_private_typedef_functions #16356

Closed
wants to merge 1 commit into from

Conversation

a14n
Copy link
Contributor

@a14n a14n commented Apr 8, 2018

No description provided.

@Hixie
Copy link
Contributor

Hixie commented Apr 10, 2018

I don't understand the value of this one. What's wrong with private typedefs, so long as they don't leak into the public API?

@a14n
Copy link
Contributor Author

a14n commented Apr 10, 2018

Lint requested by dart-lang/linter#884 .

@@ -295,5 +299,3 @@ T _interpolate<T>(List<T> values, double progress, _Interpolator<T> interpolator
final double t = targetIdx - lowIdx;
return interpolator(values[lowIdx], values[highIdx], t);
}

typedef T _Interpolator<T>(T a, T b, double progress);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a great example of why I don't think this is a helpful lint. "Interpolator" tells me what this is. T Function(T a, T b, double progress) just looks arbitrary.

It happens to be private here, but we could easily (well, @amirh would surely stop us, but aside from that :-P) make it public, at which point we'd add lots of documentation to this typedef.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The lint only occurs on private typedefs that are only used once.

Here I agree you loose that this typedef is an Interpolator but IMHO this sort of documentation is still there in the signature of _interpolate with the name of the parameter (interpolator).

T _interpolate<T>(
  List<T> values,
  double progress,
  T Function(T a, T b, double progress) interpolator,
) {

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah but in that version it's buried in syntax and hard to spot.

@@ -480,7 +478,7 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
double _getIntrinsicSize({
Axis sizingDirection,
double extent, // the extent in the direction that isn't the sizing direction
_ChildSizingFunction childSize // a method to find the size in the sizing direction
double Function(RenderBox child, double extent) childSize, // a method to find the size in the sizing direction
Copy link
Contributor

Choose a reason for hiding this comment

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

similarly here. the very name of the typedef is documentation. I don't see the value of inlining the type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One advantage is that you don't have to jump in the source to see what the real signature is.

Perhaps renaming childSize to getChildSize?

class _ImageProviderResolver {
_ImageProviderResolver({
@required this.state,
@required this.listener,
});

final _FadeInImageState state;
final _ImageProviderResolverListener listener;
final void Function() listener;
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

@Hixie
Copy link
Contributor

Hixie commented Apr 10, 2018

Yeah, looking at the patch here I don't think this improves the code.

Copy link
Contributor Author

@a14n a14n left a comment

Choose a reason for hiding this comment

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

The lint only occurs on private typedefs that are only used once. One advantage is that you don't have to jump in the source to see what the real signature is.

Most of the time the name of the typedef is really close to the name of the parameter. A good name parameter (and dart-doc) can do the job.

I'm ambivalent about typedefs with dart-doc but one can argument that the doc can be moved to the only place the typedef is used.

@@ -284,7 +284,11 @@ class _PathClose extends _PathCommand {
// not be smooth enough we can try applying spline instead.
//
// [progress] is expected to be between 0.0 and 1.0.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Side question: is it intentional to have simple comments instead of doc-comments?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the link. I need to read it again since it seems to have received several changed since I read it.

@@ -295,5 +299,3 @@ T _interpolate<T>(List<T> values, double progress, _Interpolator<T> interpolator
final double t = targetIdx - lowIdx;
return interpolator(values[lowIdx], values[highIdx], t);
}

typedef T _Interpolator<T>(T a, T b, double progress);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The lint only occurs on private typedefs that are only used once.

Here I agree you loose that this typedef is an Interpolator but IMHO this sort of documentation is still there in the signature of _interpolate with the name of the parameter (interpolator).

T _interpolate<T>(
  List<T> values,
  double progress,
  T Function(T a, T b, double progress) interpolator,
) {

@@ -480,7 +478,7 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
double _getIntrinsicSize({
Axis sizingDirection,
double extent, // the extent in the direction that isn't the sizing direction
_ChildSizingFunction childSize // a method to find the size in the sizing direction
double Function(RenderBox child, double extent) childSize, // a method to find the size in the sizing direction
Copy link
Contributor Author

Choose a reason for hiding this comment

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

One advantage is that you don't have to jump in the source to see what the real signature is.

Perhaps renaming childSize to getChildSize?

@a14n
Copy link
Contributor Author

a14n commented Apr 12, 2018

Closing this PR. I'll do another one to explain why we keep this lint commented in analysis_options.yaml

@a14n a14n closed this Apr 12, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants