npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

eslint-plugin-default

v1.1.0

Published

ESLint plugin that enforces proper defaults by disallowing hardcoded values in the codebase

Readme

eslint-plugin-default

ESLint plugin that enforces proper defaults by disallowing hardcoded values in your codebase. Promotes flexible, maintainable code by encouraging configurable defaults instead of magic constants.

Philosophy

This plugin prevents hardcoded values that should be configurable defaults. It encourages proper abstraction of configuration, constants, and URLs, making your codebase more:

  • Maintainable: Easy to update values without hunting through code
  • Testable: Different values for different test scenarios
  • Flexible: Configurable for different environments, users, or deployments
  • Readable: Clear separation between logic and configuration

Installation

npm install --save-dev eslint-plugin-default
# or
pnpm add -D eslint-plugin-default
# or
yarn add --dev eslint-plugin-default

Usage

ESLint 9+ (Flat Config)

import defaultPlugin from 'eslint-plugin-default';

export default [
  {
    plugins: {
      default: defaultPlugin
    },
    rules: {
      'default/no-localhost': 'error',
      'default/no-hardcoded-urls': 'error'
    }
  }
];

Using Predefined Configurations

Recommended Configuration

import defaultPlugin from 'eslint-plugin-default';

export default [
  defaultPlugin.configs.recommended
];

Strict Configuration

import defaultPlugin from 'eslint-plugin-default';

export default [
  defaultPlugin.configs.strict
];

Rules

  • no-localhost - Disallow hardcoded "localhost" usage to encourage configurable defaults
  • no-hardcoded-urls - Disallow any hardcoded URLs to enforce proper configuration abstraction
  • require-param-defaults - Enforce default values for function parameters to prevent runtime errors
  • no-default-params - Disallow default parameters to enforce explicit default value handling

Why These Rules?

Hardcoded values in your codebase can lead to:

  • Maintenance burden: Searching and replacing values across the codebase
  • Testing difficulties: Unable to easily mock or override values for tests
  • Configuration rigidity: Inability to customize behavior without code changes
  • Deployment complexity: Different values needed for different environments
  • Team collaboration issues: Conflicting hardcoded values between developers
  • Code coupling: Business logic mixed with configuration data

Default Management Patterns

✅ Constants Files

// constants/urls.js
export const API_ENDPOINTS = {
  USERS: 'https://api.example.com/users',
  POSTS: 'https://api.example.com/posts'
};

// constants/config.js
export const DEFAULT_CONFIG = {
  timeout: 5000,
  retries: 3,
  host: 'localhost'
};

✅ Configuration Objects

// config/index.js
const config = {
  development: {
    apiUrl: 'http://localhost:3000',
    debug: true
  },
  production: {
    apiUrl: process.env.API_URL,
    debug: false
  }
};

export default config[process.env.NODE_ENV || 'development'];

✅ Default Parameters with Overrides

class ApiClient {
  constructor(options = {}) {
    this.config = {
      baseUrl: 'https://api.example.com',
      timeout: 5000,
      retries: 3,
      ...options
    };
  }
}

// Usage with overrides
const client = new ApiClient({
  baseUrl: process.env.API_URL,
  timeout: 10000
});

✅ Environment Variables with Defaults

const config = {
  apiUrl: process.env.API_URL || 'http://localhost:3000',
  dbUrl: process.env.DATABASE_URL || 'sqlite://memory',
  port: parseInt(process.env.PORT || '3000', 10)
};

Configurations

Both recommended and strict configurations enable all rules as errors, promoting strict adherence to proper default management.

Use Cases

This plugin is particularly useful for:

  • Large codebases: Maintaining consistency in configuration management
  • Team projects: Preventing conflicting hardcoded values between developers
  • Library development: Ensuring configurable defaults for consumers
  • Multi-environment apps: Supporting dev, staging, production configurations
  • Testing: Making values easily mockable and overridable
  • Maintenance: Centralizing configuration changes instead of scattered updates

Development

# Install dependencies
pnpm install

# Run tests
pnpm test

# Run tests with coverage
pnpm test:coverage

# Lint the code
pnpm lint

# Fix linting issues
pnpm lint:fix

# Release (maintainers only)
pnpm release

License

MIT

Changelog

See CHANGELOG.md for details about changes in each version.