Streamlining Development: Fixing Supabase Scripts and ESLint Rules

Building robust APIs requires attention to detail, from seamless database interactions to consistent code quality. In the ims-api project, part of the larger ims-platform, recent efforts focused on enhancing the developer experience by tackling common pain points related to script execution and linting configurations. This post details how we addressed these challenges, making the development workflow smoother and more reliable.

The Challenge: Inconsistent Scripts and Strict Linting

Developers often face hurdles when setting up new environments or ensuring that shared scripts work identically across different machines. A common issue arises when CLI tools aren't globally installed or their paths aren't correctly configured, leading to command not found errors. Similarly, while ESLint is invaluable for maintaining code quality, overly strict or conflicting rules can sometimes halt development, especially during rapid prototyping or when integrating new libraries.

In the ims-api project, we encountered both scenarios. Our Supabase-related scripts weren't always executing reliably, and certain ESLint rules were creating unnecessary friction, slowing down progress.

The Fix: Robust Supabase Scripts with npx

The supabase CLI is a powerful tool for interacting with Supabase projects. To ensure its commands execute consistently within package.json scripts, regardless of whether supabase is globally installed, we adopted npx. npx allows you to execute Node.js package binaries, automatically installing them if they aren't found in the local node_modules.

By prefixing our supabase commands with npx, we made our scripts more robust and portable. This change guarantees that the correct version of the supabase CLI (as defined in package.json's devDependencies) is always used, removing environment-specific execution headaches.

Consider this example of how npx enhances script reliability:

{
  "name": "ims-api",
  "version": "1.0.0",
  "scripts": {
    "db:start": "npx supabase start",
    "db:push": "npx supabase db push",
    "db:pull": "npx supabase db pull"
  },
  "devDependencies": {
    "supabase": "^1.15.0"
  }
}

This small but significant change means that any developer running npm run db:start will have the Supabase CLI executed correctly, even if it's not in their global path.

The Fix: Commenting Out ESLint Rules

ESLint plays a critical role in enforcing coding standards and catching potential errors early. However, there are times when certain rules might be overly restrictive or temporarily impede progress, especially in evolving codebases or during specific development phases.

To unblock development and reduce friction, a decision was made to comment out a few ESLint rules that were proving particularly cumbersome. This isn't a permanent abandonment of code quality but rather a pragmatic adjustment to allow for smoother iteration. It's a temporary measure that can be revisited once the immediate development hurdles are overcome, or when a more nuanced rule configuration can be established.

Here’s an illustrative example of how rules might be temporarily disabled in an .eslintrc.json file:

{
  "env": {
    "node": true,
    "es2021": true
  },
  "extends": [
    "eslint:recommended"
  ],
  "parserOptions": {
    "ecmaVersion": "latest",
    "sourceType": "module"
  },
  "rules": {
    // Temporarily commented out to ease development flow
    // "no-unused-vars": "warn",
    // "no-console": "off",
    "indent": ["error", 2],
    "linebreak-style": ["error", "unix"]
  }
}

Commenting out rules like no-unused-vars (which flags variables declared but not used) or no-console (which disallows console.log) can be useful during debugging or feature implementation, allowing developers to focus on functionality before polishing the code to strict linting standards.

The Lesson: Balancing Utility with Practicality

These adjustments highlight an important lesson in software development: the need to balance ideal practices (like strict linting and globally available tools) with practical considerations for developer productivity. Ensuring that development tools work seamlessly, and that linting rules support rather than hinder progress, is crucial for maintaining momentum in a fast-paced project like ims-api.

While code quality is paramount, the ability to adapt tooling configurations to fit current project needs can significantly improve the developer experience and accelerate delivery without sacrificing long-term maintainability. Periodically reviewing and adjusting these configurations is a healthy practice for any evolving project.


Generated with Gitvlg.com

Streamlining Development: Fixing Supabase Scripts and ESLint Rules
SOFIA DESIREE BARTOLI

SOFIA DESIREE BARTOLI

Author

Share: