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(otlp-exporter-base): fix eslint warnigns #5391

Merged

Conversation

chancancode
Copy link
Contributor

Which problem is this PR solving?

Fix the following eslint warnings:

/home/runner/work/opentelemetry-js/opentelemetry-js/experimental/packages/otlp-exporter-base/src/transport/http-exporter-transport.ts
  55:9  warning  Forbidden non-null assertion  @typescript-eslint/no-non-null-assertion

/home/runner/work/opentelemetry-js/opentelemetry-js/experimental/packages/otlp-exporter-base/src/transport/http-transport-utils.ts
  95:35  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any

Ref #5365

Short description of the changes

The first was that we know we already checked and initialized a related variable, but TypeScript has no idea they are related. We can better communicate that, both to TypeScript and to humans, by groupping the related variables into a single one, that is either set or not.

The second was a little strange, and I don't really see what the any is doing there. res.on('end') is already typed to have an Error type on the callback argument (maybe that wasn't always the case?). If we trust the type, then there is nothing more we need to do. If we don't trust the type, widening it to any without other runtime checks isn't going to do anything for us either. So I just removed it and everything was still fine.

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

  • eslint

Checklist:

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

Fix the following eslint warnings:

```
/home/runner/work/opentelemetry-js/opentelemetry-js/experimental/packages/otlp-exporter-base/src/transport/http-exporter-transport.ts
  55:9  warning  Forbidden non-null assertion  @typescript-eslint/no-non-null-assertion

/home/runner/work/opentelemetry-js/opentelemetry-js/experimental/packages/otlp-exporter-base/src/transport/http-transport-utils.ts
  95:35  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
```

The first was that we know we already checked and initialized a
related variable, but TypeScript has no idea they are related. We
can better communicate that, both to TypeScript and to humans, by
groupping the related variables into a single one, that is either
set or not.

The second was a little strange, and I don't really see what the
`any` is doing there. `res.on('end')` is already typed to have an
`Error` type on the callback argument (maybe that wasn't always the
case?). If we trust the type, then there is nothing more we need to
do. If we don't trust the type, widening it to `any` without other
runtime checks isn't going to do anything for us either. So I just
removed it and everything was still fine.

Ref open-telemetry#5365
@chancancode chancancode requested a review from a team as a code owner January 29, 2025 01:53
sendWithHttp,
createHttpAgent,
// eslint-disable-next-line @typescript-eslint/no-var-requires
} = require('./http-transport-utils');
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 should be updated to use dynamic import, but @pichlermarc is working on that elsewhere and needed to change the TS settings first. Conveniently, this is already used in an async context.

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

codecov bot commented Jan 29, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.64%. Comparing base (29d0da5) to head (260b233).
Report is 7 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5391   +/-   ##
=======================================
  Coverage   94.64%   94.64%           
=======================================
  Files         318      318           
  Lines        8033     8035    +2     
  Branches     1688     1687    -1     
=======================================
+ Hits         7603     7605    +2     
  Misses        430      430           
Files with missing lines Coverage Δ
...rter-base/src/transport/http-exporter-transport.ts 94.44% <100.00%> (+0.69%) ⬆️
...xporter-base/src/transport/http-transport-utils.ts 100.00% <100.00%> (ø)

@david-luna david-luna added this pull request to the merge queue Feb 5, 2025
Merged via the queue into open-telemetry:main with commit 39e9a09 Feb 5, 2025
15 of 16 checks passed
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