elixir-antipatterns

Identifies and corrects Elixir and Phoenix anti-patterns in error handling, code architecture, Ecto queries, and testing.

2|Updated Jun 11, 2024
One-click install
npx skills add https://github.com/gutierrezp22/administracion-departamentos --skill elixir-antipatterns-gutierrezp22
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: elixir-antipatterns
Source: https://github.com/gutierrezp22/administracion-departamentos/tree/main/.cursor/skills/elixir-antipatterns
Command: npx skills add https://github.com/gutierrezp22/administracion-departamentos --skill elixir-antipatterns-gutierrezp22

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps developers identify and correct common anti-patterns in Elixir and Phoenix development, leading to more maintainable, robust, and performant code.

Core Features & Use Cases

  • Error Handling: Enforces the use of tagged tuples ({:ok, value} | {:error, reason}) over exceptions for business errors.
  • Code Structure: Guides on separating concerns, especially keeping business logic out of LiveViews and within contexts.
  • Performance: Highlights Ecto query optimizations like preloading to prevent N+1 query issues and advises on database indexing.
  • Testing: Emphasizes writing effective tests with clear assertions.
  • Use Case: During a code review of a new Phoenix feature, this Skill can flag instances where business logic is incorrectly placed in a LiveView component or where Ecto queries might lead to performance bottlenecks.

Quick Start

Review the provided Elixir code for common anti-patterns related to error handling and Ecto queries.

Frequently Asked Questions about elixir-antipatterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix Ecto N+1 query issues in Phoenix LiveView?

Fix Ecto N+1 query issues by applying Repo.preload to optimize database queries and separating business logic out of Phoenix LiveView components into dedicated contexts.

What is the best way to handle business errors in Elixir?

The best way to handle business errors in Elixir is to return tagged tuples like {:ok, value} or {:error, reason} instead of raising exceptions, which ensures more robust and maintainable code.

How do I structure a Phoenix code review for Elixir anti-patterns?

Structure a Phoenix code review by checking for Elixir anti-patterns such as business logic inside LiveViews, missing Ecto query preloads, and ineffective ExUnit test assertions.

Does this Elixir code review guidance cover Ecto query performance?

Yes, this Elixir code review guidance covers Ecto query performance by highlighting query optimizations like preloading associations and advising on appropriate database indexing to prevent bottlenecks.

When should I move business logic out of Phoenix LiveView?

You should move business logic out of Phoenix LiveView whenever it handles core domain operations, ensuring proper context separation to maintain clean architecture and improve Elixir code maintainability.

How do I write effective ExUnit tests for Phoenix contexts?

Write effective ExUnit tests for Phoenix contexts by focusing on clear assertion-based testing practices that validate the isolated business logic without relying on LiveView component rendering.