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

refactor(api): fix eslint warnings #5366

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

chancancode
Copy link
Contributor

Which problem is this PR solving?

Fixes the following eslint warnings:

    /home/runner/work/opentelemetry-js/opentelemetry-js/api/src/diag/ComponentLogger.ts
      36:25  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
      40:25  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
      44:24  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
      48:24  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
      52:27  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
      60:9   warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any

    /home/runner/work/opentelemetry-js/opentelemetry-js/api/src/experimental/trace/SugaredTracer.ts
      80:5  warning  'context' is already declared in the upper scope on line 17 column 10  @typescript-eslint/no-shadow
      129:5  warning  'context' is already declared in the upper scope on line 17 column 10  @typescript-eslint/no-shadow
      135:5  warning  'context' is already declared in the upper scope on line 17 column 10  @typescript-eslint/no-shadow

    /home/runner/work/opentelemetry-js/opentelemetry-js/api/src/trace/NoopTracer.ts
      102:37  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any

Ref #5365

Fixing TextMapPropagator.ts is a breaking change, so that will be submitted separately.

Short description of the changes

Refactor to avoid the patterns being flagged.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • TypeScript

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated

    /home/runner/work/opentelemetry-js/opentelemetry-js/api/src/diag/ComponentLogger.ts
      36:25  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
      40:25  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
      44:24  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
      48:24  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
      52:27  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
      60:9   warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any

    /home/runner/work/opentelemetry-js/opentelemetry-js/api/src/experimental/trace/SugaredTracer.ts
      80:5  warning  'context' is already declared in the upper scope on line 17 column 10  @typescript-eslint/no-shadow
      129:5  warning  'context' is already declared in the upper scope on line 17 column 10  @typescript-eslint/no-shadow
      135:5  warning  'context' is already declared in the upper scope on line 17 column 10  @typescript-eslint/no-shadow

    /home/runner/work/opentelemetry-js/opentelemetry-js/api/src/trace/NoopTracer.ts
      102:37  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any

Ref open-telemetry#5365
@chancancode chancancode requested a review from a team as a code owner January 24, 2025 00:19
typeof spanContext['traceId'] === 'string' &&
'traceFlags' in spanContext &&
typeof spanContext['traceFlags'] === 'number'
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This imposes a very slight runtime cost from the additional check. If that is undesirable here, there are plenty of alternative factoring that would accomplish the same without runtime code, this is just the most readable IMO.

Alternatively, if we trust the types, this function can be deleted altogether. It's only ever called from L47; the input came from getSpanContext(), which is typed to return SpanContext | undefined. If that is accurate (looks like it to me), then all we really needed to check is !== undefined and it can be done inline.

@chancancode chancancode mentioned this pull request Jan 24, 2025
25 tasks
Copy link

codecov bot commented Jan 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.54%. Comparing base (0ae25f1) to head (2d7b813).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5366   +/-   ##
=======================================
  Coverage   94.54%   94.54%           
=======================================
  Files         318      318           
  Lines        8052     8055    +3     
  Branches     1694     1698    +4     
=======================================
+ Hits         7613     7616    +3     
  Misses        439      439           
Files with missing lines Coverage Δ
api/src/diag/ComponentLogger.ts 94.73% <100.00%> (-0.27%) ⬇️
api/src/experimental/trace/SugaredTracer.ts 87.23% <100.00%> (ø)
api/src/trace/NoopTracer.ts 97.67% <100.00%> (+0.23%) ⬆️

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.

1 participant