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: remove unused code #1252

Merged
merged 4 commits into from
Feb 6, 2023
Merged

Conversation

incendial
Copy link
Contributor

@incendial incendial commented Jan 30, 2023

๐Ÿ“œ Description

This PR removes some unused code.
#skip-changelog

๐Ÿ’ก Motivation and Context

Hello! I'm one of the authors of DCM package and I'm currently testing new unused code check that also checks for methods, fields, etc.

I've noticed that you have an opened issue #949, so decide to submit this PR.

Here is full report for dart/ folder:

โœ” Analysis is completed. Preparing the results: 18.3s

dart/lib/src/noop_sentry_client.dart:
    โš  unused constructor NoOpSentryClient
      at /Users/dimannich/Desktop/code/sentry-dart/dart/lib/src/noop_sentry_client.dart:15:3

dart/lib/src/protocol/max_body_size.dart:
    โš  unused method shouldAddBody
      at /Users/dimannich/Desktop/code/sentry-dart/dart/lib/src/protocol/max_body_size.dart:61:3
    โš  unused extension MaxResponseBodySizeX
      at /Users/dimannich/Desktop/code/sentry-dart/dart/lib/src/protocol/max_body_size.dart:60:1

dart/lib/src/sentry_client_stub.dart:
    โš  unused function createSentryClient
      at /Users/dimannich/Desktop/code/sentry-dart/dart/lib/src/sentry_client_stub.dart:8:1

dart/lib/src/sentry_item_type.dart:
    โš  unused field unknown
      at /Users/dimannich/Desktop/code/sentry-dart/dart/lib/src/sentry_item_type.dart:7:3

dart/lib/src/transport/encode.dart:
    โš  unused function compressBody
      at /Users/dimannich/Desktop/code/sentry-dart/dart/lib/src/transport/encode.dart:3:1

dart/lib/src/transport/noop_encode.dart:
    โš  unused function compressBody
      at /Users/dimannich/Desktop/code/sentry-dart/dart/lib/src/transport/noop_encode.dart:1:1

dart/test/mocks/mock_hub.dart:
    โš  unused method reset
      at /Users/dimannich/Desktop/code/sentry-dart/dart/test/mocks/mock_hub.dart:27:3
    โš  unused field stackTrace
      at /Users/dimannich/Desktop/code/sentry-dart/dart/test/mocks/mock_hub.dart:138:3
    โš  unused field hint
      at /Users/dimannich/Desktop/code/sentry-dart/dart/test/mocks/mock_hub.dart:139:3
    โš  unused field throwable
      at /Users/dimannich/Desktop/code/sentry-dart/dart/test/mocks/mock_hub.dart:145:3
    โš  unused field stackTrace
      at /Users/dimannich/Desktop/code/sentry-dart/dart/test/mocks/mock_hub.dart:146:3
    โš  unused field hint
      at /Users/dimannich/Desktop/code/sentry-dart/dart/test/mocks/mock_hub.dart:147:3
    โš  unused field message
      at /Users/dimannich/Desktop/code/sentry-dart/dart/test/mocks/mock_hub.dart:157:3
    โš  unused field level
      at /Users/dimannich/Desktop/code/sentry-dart/dart/test/mocks/mock_hub.dart:158:3
    โš  unused field template
      at /Users/dimannich/Desktop/code/sentry-dart/dart/test/mocks/mock_hub.dart:159:3
    โš  unused field params
      at /Users/dimannich/Desktop/code/sentry-dart/dart/test/mocks/mock_hub.dart:160:3
    โš  unused field hint
      at /Users/dimannich/Desktop/code/sentry-dart/dart/test/mocks/mock_hub.dart:161:3
    โš  unused field hint
      at /Users/dimannich/Desktop/code/sentry-dart/dart/test/mocks/mock_hub.dart:174:3

dart/test/mocks/mock_sentry_client.dart:
    โš  unused field hint
      at /Users/dimannich/Desktop/code/sentry-dart/dart/test/mocks/mock_sentry_client.dart:98:3
    โš  unused field throwable
      at /Users/dimannich/Desktop/code/sentry-dart/dart/test/mocks/mock_sentry_client.dart:109:3
    โš  unused field stackTrace
      at /Users/dimannich/Desktop/code/sentry-dart/dart/test/mocks/mock_sentry_client.dart:110:3
    โš  unused field scope
      at /Users/dimannich/Desktop/code/sentry-dart/dart/test/mocks/mock_sentry_client.dart:111:3
    โš  unused field hint
      at /Users/dimannich/Desktop/code/sentry-dart/dart/test/mocks/mock_sentry_client.dart:112:3
    โš  unused field template
      at /Users/dimannich/Desktop/code/sentry-dart/dart/test/mocks/mock_sentry_client.dart:125:3
    โš  unused field params
      at /Users/dimannich/Desktop/code/sentry-dart/dart/test/mocks/mock_sentry_client.dart:126:3
    โš  unused field hint
      at /Users/dimannich/Desktop/code/sentry-dart/dart/test/mocks/mock_sentry_client.dart:128:3
    โš  unused field envelope
      at /Users/dimannich/Desktop/code/sentry-dart/dart/test/mocks/mock_sentry_client.dart:141:3

โœ– total unused code (classes, functions, variables, extensions, enums, mixins and type aliases) - 28

Here is full report for flutter/ folder:

โœ” Analysis is completed. Preparing the results: 10.9s

flutter/lib/src/jvm/jvm_exception.dart:
    โš  unused method tryParse
      at /Users/dimannich/Desktop/code/sentry-dart/flutter/lib/src/jvm/jvm_exception.dart:22:3

flutter/lib/src/jvm/jvm_frame.dart:
    โš  unused method tryParse
      at /Users/dimannich/Desktop/code/sentry-dart/flutter/lib/src/jvm/jvm_frame.dart:24:3
    โš  unused getter unparsed
      at /Users/dimannich/Desktop/code/sentry-dart/flutter/lib/src/jvm/jvm_frame.dart:67:3

flutter/test/integrations/flutter_error_integration_test.dart:
    โš  unused method getIntegration
      at /Users/dimannich/Desktop/code/sentry-dart/flutter/test/integrations/flutter_error_integration_test.dart:219:3

flutter/test/integrations/load_contexts_integration_test.dart:
    โš  unused method getIntegration
      at /Users/dimannich/Desktop/code/sentry-dart/flutter/test/integrations/load_contexts_integration_test.dart:46:3

flutter/test/integrations/native_sdk_integration_test.dart:
    โš  unused method getIntegration
      at /Users/dimannich/Desktop/code/sentry-dart/flutter/test/integrations/native_sdk_integration_test.dart:101:3

flutter/test/integrations/widgets_flutter_binding_integration_test.dart:
    โš  unused method getIntegration
      at /Users/dimannich/Desktop/code/sentry-dart/flutter/test/integrations/widgets_flutter_binding_integration_test.dart:53:3

flutter/test/mocks.dart:
    โš  unused constructor MockPlatform.fuchsia
      at /Users/dimannich/Desktop/code/sentry-dart/flutter/test/mocks.dart:77:3

flutter/test/mocks.mocks.dart:
    โš  unused constructor MockSentryNative
      at /Users/dimannich/Desktop/code/sentry-dart/flutter/test/mocks.mocks.dart:494:3
    โš  unused class MockSentryNative
      at /Users/dimannich/Desktop/code/sentry-dart/flutter/test/mocks.mocks.dart:490:1

flutter/test/sentry_navigator_observer_test.dart:
    โš  unused method mockContext
      at /Users/dimannich/Desktop/code/sentry-dart/flutter/test/sentry_navigator_observer_test.dart:750:3

โœ– total unused code (classes, functions, variables, extensions, enums, mixins and type aliases) - 11

Note: I've removed only some reported code, anything above is not touched. If you consider anything above worth removing, please let me know and I'll update the PR.

๐Ÿ’š How did you test it?

With dcm.

๐Ÿ“ Checklist

  • I reviewed submitted code
  • I added tests to verify changes
  • No new PII added or SDK only sends newly added PII if sendDefaultPii is enabled
  • I updated the docs if needed
  • All tests passing
  • No breaking changes

๐Ÿ”ฎ Next steps

Waiting for your feedback / comments ๐Ÿ™‚.

@marandaneto
Copy link
Contributor

@incendial thank you for the PR, it does make sense.
There are likely false positives in the report as well just because if the SDK itself doesn't use eg a ctor, it does not mean that users don't in their code, so before going ahead and removing everything, it has to be case by case but besides that, all in for PRs like this :)

@codecov
Copy link

codecov bot commented Jan 30, 2023

Codecov Report

Base: 89.72% // Head: 76.45% // Decreases project coverage by -13.28% โš ๏ธ

Coverage data is based on head (b0f9f1e) compared to base (e893df5).
Patch has no changes to coverable lines.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1252       +/-   ##
===========================================
- Coverage   89.72%   76.45%   -13.28%     
===========================================
  Files         155       11      -144     
  Lines        5034      327     -4707     
===========================================
- Hits         4517      250     -4267     
+ Misses        517       77      -440     
Impacted Files Coverage ฮ”
flutter/lib/src/jvm/jvm_exception.dart
dart/lib/src/protocol/sentry_request.dart
dart/lib/src/transport/data_category.dart
dart/lib/src/sentry_sampling_context.dart
flutter/lib/src/renderer/io_renderer.dart
...or/android_platform_exception_event_processor.dart
dart/lib/src/protocol/sentry_gpu.dart
...art/lib/src/http_client/failed_request_client.dart
dart/lib/src/client_reports/client_report.dart
dart/lib/src/protocol/sentry_baggage_header.dart
... and 134 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

โ˜” View full report at Codecov.
๐Ÿ“ข Do you have feedback about the report comment? Let us know in this issue.

@incendial
Copy link
Contributor Author

There are likely false positives in the report as well just because if the SDK itself doesn't use eg a ctor, it does not mean that users don't in their code, so before going ahead and removing everything, it has to be case by case but besides that, all in for PRs like this :)

The command should not report anything that is exported directly or indirectly, so if you see anything publicly available - please let me know.

@incendial
Copy link
Contributor Author

so before going ahead and removing everything, it has to be case by case

Can someone from the team take a closer look?

@marandaneto
Copy link
Contributor

so before going ahead and removing everything, it has to be case by case

Can someone from the team take a closer look?

The current removal makes sense the way how it is, I'd approve if it's only that.
What I meant is about some other warnings.

Eg

flutter/lib/src/jvm/jvm_exception.dart:
โš  unused method tryParse
at /Users/dimannich/Desktop/code/sentry-dart/flutter/lib/src/jvm/jvm_exception.dart:22:3

This one makes sense and could be removed, I dont expect that to be called externally.

flutter/test/mocks.dart:
โš  unused constructor MockPlatform.fuchsia
at /Users/dimannich/Desktop/code/sentry-dart/flutter/test/mocks.dart:77:3

Will likely be used in the future once 1st class Fuchsia support lands.

Copy link
Contributor

@marandaneto marandaneto left a comment

Choose a reason for hiding this comment

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

Linter is complaining besides that LGTM.

@incendial
Copy link
Contributor Author

Linter is complaining besides that LGTM.

I'll fix that and remove the mentioned tryParse ๐Ÿ‘ .

The current removal makes sense the way how it is, I'd approve if it's only that.

Sure ๐Ÿ‘ , but now I'm curious about NoOpSentryClient - it's not referenced and not exported (or I don't see it), how you / your users use it? ๐Ÿ™‚

@marandaneto
Copy link
Contributor

Linter is complaining besides that LGTM.

I'll fix that and remove the mentioned tryParse ๐Ÿ‘ .

The current removal makes sense the way how it is, I'd approve if it's only that.

Sure ๐Ÿ‘ , but now I'm curious about NoOpSentryClient - it's not referenced and not exported (or I don't see it), how you / your users use it? ๐Ÿ™‚

That was before the sound null safety, now that Dart is fully sound null safety on v3, we can likely refactor all of that, but I'd rather do that on the next major version, some public APIs would return nullable values most likely, good observation.

@incendial
Copy link
Contributor Author

incendial commented Jan 30, 2023

Hm, why are you mentioning nullsafety, when the report is about unused code?

It's not about nullable parameters as you commented here #949 (comment). This one is another command.

@marandaneto
Copy link
Contributor

NoOpSentryClient

I was just answering your question about NoOpSentryClient, why it even exists in the source code, and it's historical reasons, that's why its not used and detected by the analyzer.

@incendial
Copy link
Contributor Author

Ah, I see, thank you! I've updated the PR.

Copy link
Contributor

@marandaneto marandaneto left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM

@marandaneto marandaneto enabled auto-merge (squash) February 6, 2023 13:27
@marandaneto marandaneto merged commit 3637a22 into getsentry:main Feb 6, 2023
@incendial incendial deleted the remove-unused-code branch February 6, 2023 14:05
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.

None yet

2 participants