Skip to content

chore: add uneccessary_* lints #115

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

Merged
merged 3 commits into from
Aug 30, 2023
Merged

chore: add uneccessary_* lints #115

merged 3 commits into from
Aug 30, 2023

Conversation

eseidel
Copy link
Contributor

@eseidel eseidel commented Aug 18, 2023

Adding:

  • unnecessary_null_checks
  • unnecessary_parenthesis
  • unnecessary_raw_strings Each of these found real cases where fixing with the lint improved readability (one could argue about the raw strings).

@eseidel
Copy link
Contributor Author

eseidel commented Aug 18, 2023

Huh. Will figure out what I broke and upload again, sorry.

@eseidel eseidel marked this pull request as draft August 18, 2023 05:01
@@ -351,7 +351,7 @@ class PostgreSQLFormatIdentifier {

final dataTypeString = variableComponents.last;
try {
type = typeStringToCodeMap[dataTypeString]!;
type = typeStringToCodeMap[dataTypeString];
Copy link
Contributor

@osaxma osaxma Aug 18, 2023

Choose a reason for hiding this comment

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

The test that is failing is due to this line of code.

Apparently, the code was throwing an exception whenever type is null by relying on the removed null check -- that is, when the null check fails, it throws a format exception.

I think a proper way to handle this is to replace the try/catch statement with if/throw such as:

      type = typeStringToCodeMap[dataTypeString];
      if (type == null) {
        throw FormatException(
            "Invalid type code in substitution variable '$t'");
      }

Copy link
Owner

Choose a reason for hiding this comment

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

This looks good to me. @eseidel could you please rebase the PR and also fix this code?

Adding:
  - unnecessary_null_checks
  - unnecessary_parenthesis
  - unnecessary_raw_strings
Each of these found real cases where fixing with the lint
improved readability (one could argue about the raw strings).
@eseidel eseidel marked this pull request as ready for review August 22, 2023 04:17
@eseidel
Copy link
Contributor Author

eseidel commented Aug 22, 2023

Sorry for the delay, I believe this is ready now and should pass CI. 🤞

@codecov-commenter
Copy link

codecov-commenter commented Aug 22, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.01% 🎉

Comparison is base (46c3ff8) 86.71% compared to head (0a67e7f) 86.72%.
Report is 1 commits behind head on master.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #115      +/-   ##
==========================================
+ Coverage   86.71%   86.72%   +0.01%     
==========================================
  Files          29       29              
  Lines        2453     2455       +2     
==========================================
+ Hits         2127     2129       +2     
  Misses        326      326              
Files Changed Coverage Δ
lib/src/binary_codec.dart 96.98% <100.00%> (ø)
lib/src/exceptions.dart 88.09% <100.00%> (ø)
lib/src/query.dart 95.48% <100.00%> (ø)
lib/src/text_codec.dart 80.70% <100.00%> (ø)
lib/src/v3/types.dart 77.41% <100.00%> (ø)

... and 2 files with indirect coverage changes

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

Comment on lines 353 to 361
try {
type = typeStringToCodeMap[dataTypeString]!;
type = typeStringToCodeMap[dataTypeString];
if (type == null) {
throw FormatException(
"Invalid type code in substitution variable '$t'");
}
} catch (e) {
throw FormatException(
"Invalid type code in substitution variable '$t'");
Copy link
Contributor

Choose a reason for hiding this comment

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

The try/catch encapsulating if/throw is redundant and could be removed.

@eseidel
Copy link
Contributor Author

eseidel commented Aug 30, 2023

Thanks. Apologies again. Got distracted with non-hacking matters. :)

@isoos isoos merged commit 81aa780 into isoos:master Aug 30, 2023
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.

4 participants