DEV Community

Cover image for Validate Your Env at Build Time — with Custom Rules Powered by Amazon Q Developer
Samuel Fontebasso
Samuel Fontebasso

Posted on

Validate Your Env at Build Time — with Custom Rules Powered by Amazon Q Developer

This is a submission for the Amazon Q Developer "Quack The Code" Challenge: Crushing the Command Line

What I Built

I created envguardr, a CLI tool that validates environment variables at build time. It’s useful for projects where .env files or runtime checks aren't enough. It handles types, required fields, and default values, but I felt it needed more flexibility.

To address that, I enhanced the underlying validation package valitype by adding support for custom validators. This was one of the ideas suggested by Amazon Q Developer during the challenge. That single improvement unlocked a range of advanced use cases.

Demo

Step-by-step

Install envguardr globally:

$ npm install -g envguardr
Enter fullscreen mode Exit fullscreen mode

Create an env.schema.js file with custom validation logic:

module.exports = {
  API_KEY: {
    type: 'custom',
    validator: (v) => /^[a-z0-9]{16}$/.test(v || ''),
    errorMessage: 'API_KEY must be 16 alphanumeric characters',
    required: true
  }
}
Enter fullscreen mode Exit fullscreen mode

Then run:

$ envguardr validate env.schema.js
Enter fullscreen mode Exit fullscreen mode

Terminal demo: running envguardr with a custom schema validation for API_KEY:

Terminal demo: running envguardr with a custom schema validation for API_KEY

Code Repository

https://github.com/fontebasso/valitype

https://github.com/fontebasso/envguardr

How I Used Amazon Q Developer

This challenge was my first experience with Amazon Q Developer, and I was genuinely impressed. It’s exactly the kind of tool I always felt was missing for developers working with AI.

Amazon Q Developer was able to read my codebase, understand its context, and assist in meaningful ways. It helped me improve typing, write better tests, fix subtle lint issues, and explore useful new features.

From the several improvements it suggested for valitype, I chose to implement custom validators. That feature alone made envguardr much more powerful, giving it the flexibility needed for advanced configuration validation.

Top comments (0)