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

Added more lint checks and fixed some warnings. #2610

Merged
merged 5 commits into from
May 22, 2024

Conversation

cmaglie
Copy link
Member

@cmaglie cmaglie commented May 21, 2024

Please check if the PR fulfills these requirements

See how to contribute

  • The PR has no duplicates (please search among the Pull Requests
    before creating one)
  • The PR follows
    our contributing guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • UPGRADING.md has been updated with a migration guide (for breaking changes)
  • configuration.schema.json updated if new parameters are added.

What kind of change does this PR introduce?

  • The biggest part of this PR is fixing small Printf-style formatting errors in the translations, previously those imperfections were very subtle to detect because they are tricky to do right and the linter was silenced.
  • Eliminated an unreachable block of code
  • Enabled a lot of other minor lint checks

What is the current behavior?

No change

What is the new behavior?

Does this PR introduce a breaking change, and is titled accordingly?

No

Other information

internal/arduino/sketch/sketch.go:108:14: nilness: impossible condition: non-nil == nil (govet)
        if mainFile == nil {
                    ^
This allows a deeper lint-check of printf style functions, like:

  commands/instances.go:344:46: printf: github.com/arduino/arduino-cli/internal/i18n.Tr format %v reads arg #1, but call has 0 args (govet)
		s := status.Newf(codes.FailedPrecondition, i18n.Tr("Loading index file: %v"), err)
This commit fixes invalid calls to i18n.Tr.

1. Missing positional arguments, for example:

  return fmt.Errorf(i18n.Tr("installing %[1]s tool: %[2]s"), tool, err)

in the above case the positional arguments must be part of the Tr call:

-    return fmt.Errorf(i18n.Tr("installing %[1]s tool: %[2]s"), tool, err)
+    return fmt.Errorf(i18n.Tr("installing %[1]s tool: %[2]s", tool, err))

2. This also makes the fmt.Errorf call useless and it could be replaced by
the less expensive errors.New:

-    return fmt.Errorf(i18n.Tr("installing %[1]s tool: %[2]s", tool, err))
+    return errors.New(i18n.Tr("installing %[1]s tool: %[2]s", tool, err))

but we have cases of useless calls even when the string is a constant,
for example:

-    err := fmt.Errorf(i18n.Tr("no instance specified"))
+    err := errors.New(i18n.Tr("no instance specified"))

Unfortunately, this imperfection is not detected by the linter.

3. The "%w" directive is not supported directly in i18n.Tr, so we have
   to wrap it around another fmt.Errorf:

-    return nil, fmt.Errorf(i18n.Tr("reading library headers: %w"), err)
+    return nil, fmt.Errorf("%s: %w", i18n.Tr("reading library headers"), err)
@cmaglie cmaglie added topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project labels May 21, 2024
@cmaglie cmaglie self-assigned this May 21, 2024
Copy link

codecov bot commented May 21, 2024

Codecov Report

Attention: Patch coverage is 53.13433% with 471 lines in your changes are missing coverage. Please review.

Project coverage is 70.26%. Comparing base (ba19a2d) to head (7a20b71).
Report is 1 commits behind head on master.

Files Patch % Lines
internal/arduino/cores/packagemanager/loader.go 3.84% 25 Missing ⚠️
.../arduino/cores/packagemanager/install_uninstall.go 42.85% 24 Missing ⚠️
commands/cmderrors/cmderrors.go 42.10% 22 Missing ⚠️
commands/instances.go 18.51% 22 Missing ⚠️
internal/arduino/builder/sizer.go 15.00% 17 Missing ⚠️
internal/cli/lib/search.go 45.16% 17 Missing ⚠️
internal/arduino/cores/packagemanager/profiles.go 20.00% 16 Missing ⚠️
commands/service_upload.go 48.00% 13 Missing ⚠️
...al/arduino/cores/packagemanager/package_manager.go 40.00% 12 Missing ⚠️
internal/arduino/cores/status.go 0.00% 12 Missing ⚠️
... and 93 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2610      +/-   ##
==========================================
- Coverage   70.30%   70.26%   -0.04%     
==========================================
  Files         222      222              
  Lines       21262    21262              
==========================================
- Hits        14948    14940       -8     
- Misses       5131     5147      +16     
+ Partials     1183     1175       -8     
Flag Coverage Δ
unit 70.26% <53.13%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

Copy link
Contributor

@alessio-perugini alessio-perugini left a comment

Choose a reason for hiding this comment

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

🚀

@cmaglie cmaglie merged commit dc13ef6 into arduino:master May 22, 2024
99 checks passed
@cmaglie cmaglie deleted the lint-checks branch May 22, 2024 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants