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

feat(jsii): added warnings for usage of deprecated elements #3051

Merged
merged 19 commits into from
Oct 14, 2021
Merged

Conversation

otaviomacedo
Copy link
Contributor

General idea:

First, DeprecationWarningsInjector.process() consumes the assembly. For each complex type in the assembly, it generates a function responsible for calling the print function if the type is deprecated. For each struct property or enum member, it also generates a call to the function corresponding to the type of that property or member. This creates a call tree that mirrors the type tree (including recursive functions that mirror recursive types).

Then Transformer traverses the AST and for each parameter of a method, it injects into that method a call to the function corresponding to the type of that parameter.

For example, for the types:

/** @deprecated Use something else */
interface Foo {
  readonly bar: Bar;
}

interface Bar {
  readonly bar: Bar;
}

we get:

module_name_Foo(p) {
  if (p) { // <-- this if is to make sure we only print a warning if the user assigned it a value
    print(p, "module_name.Foo", "Use something else");
    module_name_Bar(p.bar);
  }
}

module_name_Bar(p) {
  if (p) {
    module_name_Bar(p.bar);
  }
}

Then, if we have a method like:

/** @deprecated Do something else */
doSomething(foo: Foo, bar: Bar) {}

the following calls will be injected into doSomething:

print("", "module_name.SomeClass#doSomething", "Do something else");
module_name_Foo(foo);
module_name_Bar(bar);

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@otaviomacedo otaviomacedo requested a review from a team October 11, 2021 10:41
…tion warnings and handling of types from other assemblies
@mergify
Copy link
Contributor

mergify bot commented Oct 12, 2021

The title of this Pull Request does not conform with [Conventional Commits] guidelines. It will need to be adjusted before the PR can be merged.
[Conventional Commits]: https://www.conventionalcommits.org

packages/jsii/test/deprecation-warnings.test.ts Outdated Show resolved Hide resolved
packages/jsii/test/deprecation-warnings.test.ts Outdated Show resolved Hide resolved
@otaviomacedo otaviomacedo requested a review from rix0rrr October 12, 2021 16:25
rix0rrr
rix0rrr previously approved these changes Oct 13, 2021
Copy link
Contributor

@rix0rrr rix0rrr left a comment

Choose a reason for hiding this comment

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

I think I'd prefer AssertionError to be called something else (DeprecationError seems logical?).

Other than that, I think we thought of most things that could become a problem. Let's make sure we try it out on an actual CDK build and poke at it (integration test), and then let's go ahead and merge!

@rix0rrr rix0rrr added the pr/do-not-merge This PR should not be merged at this time. label Oct 13, 2021
@mergify mergify bot dismissed rix0rrr’s stale review October 13, 2021 09:30

Pull request has been modified.

@otaviomacedo otaviomacedo removed the pr/do-not-merge This PR should not be merged at this time. label Oct 13, 2021
@otaviomacedo otaviomacedo requested review from RomainMuller and rix0rrr and removed request for RomainMuller and njlynch October 14, 2021 08:29
@otaviomacedo otaviomacedo requested review from rix0rrr and RomainMuller and removed request for RomainMuller and rix0rrr October 14, 2021 09:45
@mergify
Copy link
Contributor

mergify bot commented Oct 14, 2021

Thank you for contributing! ❤️ I will now look into making sure the PR is up-to-date, then proceed to try and merge it!

@mergify mergify bot added the pr/ready-to-merge This PR is ready to be merged. label Oct 14, 2021
@mergify
Copy link
Contributor

mergify bot commented Oct 14, 2021

Merging (with squash)...

@mergify
Copy link
Contributor

mergify bot commented Oct 14, 2021

Merging (with squash)...

@mergify mergify bot merged commit 8c0dd3b into main Oct 14, 2021
@mergify mergify bot deleted the warnings-tmp branch October 14, 2021 10:57
@mergify mergify bot removed the pr/ready-to-merge This PR is ready to be merged. label Oct 14, 2021
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

Successfully merging this pull request may close these issues.

3 participants