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

chore: fix some code style #280

Merged
merged 1 commit into from
Aug 27, 2024
Merged

chore: fix some code style #280

merged 1 commit into from
Aug 27, 2024

Conversation

lym953
Copy link
Contributor

@lym953 lym953 commented Aug 15, 2024

What does this PR do?

Make some fixes around code style

  1. remove an unused const
  2. change an if-else block to switch-case, and add a lint rule "switch-exhaustiveness-check", so that if a new value is added to RuntimeType some day, the switch-case will become non-exhaustive and lint will remind us to handle the new value in the switch-case
export enum RuntimeType {
  DOTNET,
  NODE,
  PYTHON,
  JAVA,
  CUSTOM,
  UNSUPPORTED,
}
  1. change
if (condition) {
  /* lots of code */ 
}

to

if (!condition) {
  return;
}
// lots of code

to make code more readable.

See comments on code for more.

Motivation

Testing Guidelines

npx projen build finishes successfully.

To test the link exhaustive check, I removed

      case RuntimeType.CUSTOM:
        break;

from the switch-case block, then ran npx projen build. I got an error as expected:
Pasted Graphic 4

Additional Notes

Types of Changes

  • Bug fix
  • New feature
  • Breaking change
  • Misc (docs, refactoring, dependency upgrade, etc.)

Check all that apply

  • This PR's description is comprehensive
  • This PR contains breaking changes that are documented in the description
  • This PR introduces new APIs or parameters that are documented and unlikely to change in the foreseeable future
  • This PR impacts documentation, and it has been updated (or a ticket has been logged)
  • This PR's changes are covered by the automated tests
  • This PR collects user input/sensitive content into Datadog

@@ -34,7 +34,6 @@ export const DefaultDatadogProps = {
enableMergeXrayTraces: false,
injectLogContext: true,
enableDatadogLogs: true,
architecture: "X86_64",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing unused const

log.debug("Granting read access to the provided Secret ARN for all your lambda functions.");
grantReadLambdasFromSecretArn(construct, this.props.apiKeySecretArn, extractedLambdaFunctions);
}
if (extractedLambdaFunctions.length === 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.

  1. this.props can't be undefined, so removing this check.
  2. flip the if condition and move the large chunk of code outside the if block

const isARM =
lam.architecture?.dockerPlatform !== undefined &&
lam.architecture.dockerPlatform === Architecture.ARM_64.dockerPlatform;
const isARM = lam.architecture?.dockerPlatform === Architecture.ARM_64.dockerPlatform;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consolidating the two conditions

lambdaLayerArn = getLambdaLayerArn(region, dotnetLayerVersion, runtime, isARM, accountId);
log.debug(`Using dd-trace-dotnet layer: ${lambdaLayerArn}`);
addLayer(lambdaLayerArn, false, scope, lam, runtime);
switch (lambdaRuntimeType) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changing to switch-case

@lym953 lym953 marked this pull request as ready for review August 15, 2024 21:14
@lym953 lym953 requested a review from a team as a code owner August 15, 2024 21:14
@@ -86,6 +86,7 @@ eslintConfig.addOverride("extends", [
]);

eslintConfig.addOverride("rules", {
"@typescript-eslint/switch-exhaustiveness-check": "error",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Lint rule for exhaustive switch-case

@lym953
Copy link
Contributor Author

lym953 commented Aug 27, 2024

/merge

@dd-devflow
Copy link

dd-devflow bot commented Aug 27, 2024

🚂 MergeQueue: pull request added to the queue

The median merge time in main is 4m.

Use /merge -c to cancel this operation!

@dd-mergequeue dd-mergequeue bot merged commit e0b9c14 into main Aug 27, 2024
15 checks passed
@dd-mergequeue dd-mergequeue bot deleted the yiming.luo/fix-code-style branch August 27, 2024 15:44
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.

2 participants