Skip to content

Conversation

@rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Mar 10, 2025

The CliIoHost had a number of fields that had the following pattern:

class CliIoHost {
  private _someField: string;

  /** Get someField */
  public get someField() {
    return this._someField;
  }

  /** Set someField */
  public set someField(value: string) {
    this._someField = value;
  }
}

There is no additional code in the getters and setters other than directly forwarding every access to a private field, so the above is equivalent to the following:

class CliIoHost {
  public someField: string;
}

Since the above is simpler, this PR proposed to remove the getters and setters and just expose the field mutably.

If we ever want to run additional code in a setter in some of these fields, we can refactor back to a getter and setter pair without impacting source or binary compatibility (forwards compatibility was the argument in the olden C++ and Java days for pre-emptively wrapping fields in getters and setters, but doesn't apply in JS land).

(🤖 This PR was generated using AI)


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

@rix0rrr rix0rrr requested a review from a team March 10, 2025 09:07
@aws-cdk-automation aws-cdk-automation requested a review from a team March 10, 2025 09:07
@github-actions github-actions bot added the p2 label Mar 10, 2025
@rix0rrr rix0rrr added the pr/exempt-integ-test Skips the integ test steps if set. label Mar 10, 2025
@mrgrain mrgrain changed the title refactor: replace getters and setters with a public field refactor(cli): replace getters and setters with a public field Mar 10, 2025
Copy link
Contributor

@mrgrain mrgrain left a comment

Choose a reason for hiding this comment

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

thanks!

@rix0rrr rix0rrr closed this Mar 10, 2025
auto-merge was automatically disabled March 10, 2025 09:10

Pull request was closed

@rix0rrr rix0rrr reopened this Mar 10, 2025
The `CliIoHost` had a number of fields that had the following
pattern:

```ts
class CliIoHost {
  private _someField: string;

  /** Get someField */
  public get someField() {
    return this._someField;
  }

  /** Set someField */
  public set someField(value: string) {
    this._someField = value;
  }
}
```

There is no additional code in the getters and setters other than
directly forwarding every access to a private field, so the above
is equivalent to the following:

```ts
class CliIoHost {
  public someField: string;
}
```

Since the above is simpler, this PR proposed to remove the getters
and setters and just expose the field mutably.

If we ever want to run additional code in a setter in some of these
fields, we can refactor back to a getter and setter pair without
impacting source or binary compatibility (forwards compatibility was
the argument in the olden C++ and Java days for pre-emptively wrapping
fields in getters and setters, but doesn't apply in JS land).
@rix0rrr rix0rrr force-pushed the push-okxzllktnwzr branch from 2adbcb9 to f52c851 Compare March 10, 2025 09:37
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 85.71429% with 5 lines in your changes missing coverage. Please review.

Project coverage is 84.95%. Comparing base (ac56f9b) to head (f52c851).

Files with missing lines Patch % Lines
packages/aws-cdk/lib/toolkit/cli-io-host.ts 85.71% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #215      +/-   ##
==========================================
- Coverage   85.23%   84.95%   -0.28%     
==========================================
  Files         208      208              
  Lines       35710    35657      -53     
  Branches     4654     4599      -55     
==========================================
- Hits        30437    30294     -143     
- Misses       5114     5212      +98     
+ Partials      159      151       -8     
Flag Coverage Δ
suite.unit 84.95% <85.71%> (-0.28%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@aws-cdk-automation aws-cdk-automation added this pull request to the merge queue Mar 10, 2025
Merged via the queue into main with commit 4566d8d Mar 10, 2025
11 checks passed
@aws-cdk-automation aws-cdk-automation deleted the push-okxzllktnwzr branch March 10, 2025 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p2 pr/exempt-integ-test Skips the integ test steps if set.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants