Skip to content

Conversation

@taras-tyshko
Copy link
Contributor

@taras-tyshko taras-tyshko commented Aug 7, 2025

🎯 Objective

Improve code quality and enforce coding standards by making Credo checks mandatory in CI, while resolving all existing code quality issues.

🔧 Changes

Enforced Credo in CI

#2258 (comment)

🐛 Credo Issues Fixed

Software Design Issues (21 files)

  • Nested modules aliasing: Added proper alias statements for nested modules like X509.Certificate.Extension, Phoenix.Channel.Server, NervesHub.Telemetry.Customizations
  • Examples: lib/nerves_hub/certificate.ex, lib/nerves_hub_web/plugs/configure_uploads.ex, lib/nerves_hub/extensions/health.ex

Readability Issues (6 files)

  • Alias ordering: Fixed alphabetical ordering of alias statements
  • Explicit try blocks: Converted to implicit try blocks in lib/nerves_hub/firmwares/update_tool/fwup.ex
  • Zero-arity functions: Added parentheses to functions like def spec() in lib/nerves_hub_web/api_spec.ex
  • Large numbers: Formatted with underscores (e.g., 578088578_088)
  • String literals: Replaced multi-quote strings with sigils in tests

Refactoring Opportunities (3 files)

  • Cyclomatic complexity: Refactored friendly_blocked_until/1 in lib/nerves_hub_web/components/device_update_status.ex using pattern matching
  • Complex macros: Split updated_live_view/0 and hooked_component/1 into smaller, focused functions
  • Enum optimizations: Replaced Enum.map |> Enum.join with Enum.map_join in tests

Configuration Updates

  • Disabled checks: Made TODO comments and @moduledoc tags optional in .credo.exs
  • Why: TODO comments are acceptable in our codebase for tracking technical debt, and @moduledoc requirements would be too disruptive for existing modules

✅ Results

  • 0 Credo warnings across 385 source files
  • Improved readability and maintainability of complex macros
  • Ensured code quality enforcement for future PRs via CI

@taras-tyshko taras-tyshko changed the title Feature/enforce credo code quality Refactor complex macros and enforce Credo in CI Aug 7, 2025
Copy link
Collaborator

@joshk joshk left a comment

Choose a reason for hiding this comment

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

Hi @taras-tyshko

Thank you for your recent PRs.

I like where this is going.

I think it might be going a little far in some cases. Credo is a good guide, as long as it does impact code clarity. I think there are a bunch of alias changes we can skip, and maybe instead ignore the credo warnings of.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Moving these to disabled means we won't see any output for them.

I would like to see the output but not have them fail credo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

GitHub Actions workflow update:

# Before
- name: Run Credo
  run: mix credo

# After  
- name: Run Credo
  run: mix credo --min-priority low

Ignored Priority Checks - Excluded from CI

📝 Design.TagTODO

# TODO comments are acceptable in our codebase, but we want to see them locally
{Credo.Check.Design.TagTODO, [priority: :ignore]},

📚 Readability.ModuleDoc

Missing @moduledoc tags

# ModuleDoc is not required in our codebase, but we want to see them locally  
{Credo.Check.Readability.ModuleDoc, [priority: :ignore]},

Key Change: Using priority: :ignore ensures these checks don't block CI but remain visible for local development feedback.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@joshk I think the priority: :ignore can help as to resolve that issue together with mix credo --min-priority low

@taras-tyshko taras-tyshko force-pushed the feature/enforce-credo-code-quality branch from e846469 to 78297ea Compare August 8, 2025 11:04
@taras-tyshko
Copy link
Contributor Author

@joshk, first of all, thanks for the feedback. I tried to resolve all your comments at PR. I would say I'm ready for a second round of review.

@taras-tyshko taras-tyshko marked this pull request as ready for review August 10, 2025 18:42
@taras-tyshko taras-tyshko force-pushed the feature/enforce-credo-code-quality branch from 5b9c493 to 11b7d48 Compare August 11, 2025 08:05
@taras-tyshko taras-tyshko requested a review from joshk August 11, 2025 10:54
@nshoes nshoes self-requested a review August 11, 2025 14:08
@kybishop
Copy link
Contributor

Just wanted to put Quokka out there as an option. It will automatically keep your codebase in line with your credo configuration so that you don't have to manually fix things 🎉

@taras-tyshko
Copy link
Contributor Author

Just wanted to put Quokka out there as an option. It will automatically keep your codebase in line with your credo configuration so that you don't have to manually fix things 🎉

@taras-tyshko
Copy link
Contributor Author

Just wanted to put Quokka out there as an option. It will automatically keep your codebase in line with your credo configuration so that you don't have to manually fix things 🎉

@kybishop Sounds interesting. I didn't use it before. How about creating a new task and implement it later?

Copy link
Collaborator

@joshk joshk left a comment

Choose a reason for hiding this comment

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

Thanks for your work on this, and sorry for the delay in reviewing the PR.

@taras-tyshko taras-tyshko force-pushed the feature/enforce-credo-code-quality branch from 54ede78 to 911fd2d Compare August 20, 2025 11:24
@taras-tyshko
Copy link
Contributor Author

Update:
1. Big thanks to @joshk for the review.
2. We’ve split the macros changes into a separate PR: #2298
3. In general, we’re waiting for the Macros PR to be merged, and then we can return to this one.

@joshk joshk self-assigned this Aug 22, 2025
@joshk
Copy link
Collaborator

joshk commented Aug 31, 2025

Sorry for the delay in merging in the Macros PR.

Ping me when your ready for me to review this again.

@taras-tyshko taras-tyshko force-pushed the feature/enforce-credo-code-quality branch from cc4a3b4 to 4a13fe5 Compare September 1, 2025 09:43
@taras-tyshko taras-tyshko changed the title Refactor complex macros and enforce Credo in CI Resolve Credo issues and enforce it in CI Sep 1, 2025
@taras-tyshko taras-tyshko requested a review from joshk September 1, 2025 09:49
Copy link
Contributor Author

@taras-tyshko taras-tyshko left a comment

Choose a reason for hiding this comment

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

@joshk thanks for all you work, that's awesome to see the support from your side.
I did a rebase and you can review PR again. Thanks

@kybishop kybishop mentioned this pull request Sep 3, 2025
@taras-tyshko taras-tyshko force-pushed the feature/enforce-credo-code-quality branch from 9aeb142 to b3dba5c Compare September 11, 2025 12:40
@taras-tyshko
Copy link
Contributor Author

@joshk I’ve updated the branch with the latest changes. Could you please take another look at the PR when you have a chance? Thanks!

@taras-tyshko taras-tyshko force-pushed the feature/enforce-credo-code-quality branch from b3dba5c to 63461e7 Compare September 12, 2025 08:06
@@ -1,20 +1,20 @@
defmodule NervesHubWeb.API.ErrorJSONTest do
@moduledoc false
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this really needed for a test file? Do other tests no need this? 🤔

@nshoes nshoes self-requested a review September 16, 2025 18:31
Copy link
Contributor

@nshoes nshoes left a comment

Choose a reason for hiding this comment

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

This LGTM! @joshk do you have any other thoughts before we merge?

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