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

UIP-1590: Deprecate the Required annotation (Includes UIP-1835) #51

Conversation

jacehensley-wf
Copy link
Contributor

Ultimate problem:

The Required annotation used by the over_react transformer collides with the annotation from package:meta.

How it was fixed:

  • Deprecate Required, and add more options to the Accessor annotation.
  • Update logic around the transformer to support the new options on an Accessor annotation.
  • Added shorthand consts for Accessor(isRequired: true) and Accessor(isRequired: true, isNullable: true).

Testing suggestions:

  • Verify tests pass
  • On one of the example components, make a prop required via the new options on an Accessor annotation.
    • Verify that when you don't set it, the component throws an error.

Potential areas of regression:

  • Required annotation support.

FYA: @greglittlefield-wf @aaronlademann-wf @jacehensley-wf @clairesarsam-wf @joelleibow-wf

@aviary2-wf
Copy link

Raven

Number of Findings: 0

@codecov-io
Copy link

codecov-io commented Feb 24, 2017

Codecov Report

Merging #51 into master will increase coverage by 0.03%.
The diff coverage is 63.16%.

@@            Coverage Diff            @@
##           master     #51      +/-   ##
=========================================
+ Coverage   97.67%   97.7%   +0.03%     
=========================================
  Files          28      28              
  Lines        1329    1344      +15     
=========================================
+ Hits         1298    1313      +15     
  Misses         31      31

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 11188e2...6247b19. Read the comment docs.

Copy link
Contributor

@aaronlademann-wf aaronlademann-wf left a comment

Choose a reason for hiding this comment

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

Couple of nits... looks good otherwise.

/// Whether setting a prop to null is allowed.
final bool isNullable;

/// The erro message displayed when the accessor is not set.
Copy link
Contributor

Choose a reason for hiding this comment

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

#nit s/erro/error

/// @Required()
/// String bar;
/// }
/// Deprecated use [Accessor], [requiredProp], or [nullableRequiredProp] instead.
Copy link
Contributor

Choose a reason for hiding this comment

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

#nit

/// Deprecated.
///
/// Use [Accessor], [requiredProp] or [nullableRequiredProp] instead.

@jacehensley-wf
Copy link
Contributor Author

@aaronlademann-wf Feedback has been addressed

@aaronlademann-wf
Copy link
Contributor

+1

/// Annotation used with the `over_react` transformer to customize individual accessors (props/state fields).
///
/// Validation occurs in `UiComponent.validateRequiredProps` which requires super calls into `componentWillMount` and
/// `componentWillReceiveProps`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice. #nit might be nice to have this message on the aliases as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed

this.key,
this.keyNamespace,
this.isRequired = false,
this.isNullable = false,
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh man this looks weird lol

class ComponentTestComponent extends UiComponent<ComponentTestProps> {
@override
render() => Dom.div()();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We should have integration tests for the alias/shorthand consts as well.

I actually don't think that they're getting picked up right now...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed

@@ -402,10 +402,6 @@ class ImplGenerator {
annotations.Accessor accessorMeta = instantiateAnnotation(field, annotations.Accessor);
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I don't think this will pick up the constants.

You'll probably have to just match them by name, like so:

T getConstantAnnotation<T>(AnnotatedNode member, String name, T value) =>
    member.metadata.any((annotation) => annotation.name?.name == name)) ? value : null;


annotations.Accessor requiredProp = instantiateAnnotation(field, 'requiredProp', annotations.requiredProp);
annotations.Accessor nullableRequiredProp = instantiateAnnotation(field, 'nullableRequiredProp', annotations.nullableRequiredProp);

if (requiredProp != null) {
  // ...
}
if (nullableRequiredProp != null) {
  // ...
}

Copy link
Contributor

Choose a reason for hiding this comment

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

We should also probably emit a warning if they try to use @requiredProp/nullableRequiredProp/@Accessor together.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I thought it would pick up on that sort of thing too. What happens if a consumers has there own const shorthand for some reason, should we be supporting that?

Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately we can't support that without performing a full analysis 😢

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed

@jacehensley-wf
Copy link
Contributor Author

@greglittlefield-wf Feedback has been addressed. The requiredProp and nullableRequiredProp are now actually being picked up by the transformer.

}

if (annotationCount > 1) {
logger.error('At most only a single annotation can be applied to an accessor.', span: getSpan(sourceFile, field));
Copy link
Contributor

Choose a reason for hiding this comment

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

This message might be a little misleading, since other annotations like @deprecated are also allowed.

What about something like:

@requiredProp/@nullableProp/@Accessor cannot be used together.
You can use `@Accessor(required: true)` or `isNullable: true` instead of the shorthand versions.

@greglittlefield-wf
Copy link
Contributor

  • Code looks good
  • Tests pass in CI (Dart)
  • Tests pass locally in dart2js
  • Transformer fails gracefully w/ error message when multiple conflicting annotations are used

+10

@leviwith-wf leviwith-wf changed the title UIP-1590: Deprecate the Required annotation UIP-1590: Deprecate the Required annotation (Includes UIP-1835) Feb 28, 2017
@leviwith-wf
Copy link
Contributor

QA +1

  • Testing instruction
  • Dev +1's
  • Dev/QA +10
  • Unit tests created/updated
  • All unit tests pass
  • Rosie ran/Rosie comment displays expected info
  • Dependency Scan Clean

Merging.

@leviwith-wf leviwith-wf merged commit 8c403e5 into Workiva:master Feb 28, 2017
greglittlefield-wf added a commit that referenced this pull request Jun 23, 2020
[DIAGNOSTIC] hint for `consumedProps` returning a list literal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants