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-predictable

v1.0.1

Published

An ESLint plugin that enforces code patterns for more predictable, maintainable JavaScript. This plugin promotes functional programming principles to create codebases that are easier to reason about, test, and maintain.

Readme

eslint-plugin-predictable

An ESLint plugin that enforces code patterns for more predictable, maintainable JavaScript. This plugin promotes functional programming principles to create codebases that are easier to reason about, test, and maintain.

Core Principles

  1. Pure Function Calls: By disallowing conditional expressions in function arguments, execution paths become more traceable and deterministic. This makes debugging more straightforward and allows for more reliable state extraction during error scenarios, as execution flow isn't obscured by hidden decision points.

  2. Explicit Control Flow: Enforces separation between decision-making and action execution by ensuring if statements contain explicit flow control (returns, throws, breaks). This pushes decision points into visible control flow, making program behavior transparent and creating clearer boundaries between branching logic and business operations.

  3. Limited Nesting: Restricts conditional nesting depth to encourage function composition over deep nesting. This promotes breaking complex logic into smaller, reusable functions that can be composed together, resulting in code that's more modular, testable, and follows the single responsibility principle.

  4. Focused Objects: Enforces concise object property implementations, making it easier to understand the shape and purpose of objects at a glance. This encourages better domain modeling with objects that have clear, focused responsibilities rather than serving as catchalls for related functionality.

Installation

npm install eslint-plugin-predictable --save-dev

Or using yarn:

yarn add -D eslint-plugin-predictable

Or using pnpm:

pnpm add -D eslint-plugin-predictable

Usage

Add predictable to the plugins section of your .eslintrc configuration file:

{
  "plugins": ["predictable"]
}

Then configure the rules you want to use under the rules section:

{
  "rules": {
    "predictable/complex-objects": "warn",
    "predictable/if-for-flow-control": "error",
    "predictable/max-conditional-depth": ["error", 3],
    "predictable/no-unconditional-function-calls": "warn"
  }
}

Rules

complex-objects

Enforces that object properties should not be longer than 5 lines. This encourages breaking down complex objects into smaller, more manageable pieces.

// ❌ Bad
const config = {
  options: {
    // ... more than 5 lines of code
  }
};

// ✅ Good
const options = {
  // ... code under 5 lines
};

const config = {
  options
};

This rule is auto-fixable. It will extract long object properties into separate constants.

if-for-flow-control

Ensures that if statements are only used for flow control by requiring them to end with a flow control statement (return, throw, break, or continue).

// ❌ Bad
if (condition) {
  doSomething();
}

// ✅ Good
if (condition) {
  doSomething();
  return;
}

This pattern encourages early returns and prevents deeply nested code.

max-conditional-depth

Limits the maximum depth of nested conditional statements. The default maximum is 4, but this can be configured.

// ❌ Bad (with max depth of 3)
if (condition1) {
  if (condition2) {
    if (condition3) {
      if (condition4) {
        // This is too deep
      }
    }
  }
}

// ✅ Good
if (condition1) {
  if (condition2) {
    if (condition3) {
      // This is within the limit
    }
  }
}

The rule ignores conditional rethrows in catch blocks when calculating depth.

You can configure the maximum depth like so:

{
  "rules": {
    "predictable/max-conditional-depth": ["error", { "maximum": 3 }]
  }
}

no-unconditional-function-calls

Prevents conditional expressions within function arguments to make code execution paths more predictable and easier to reason about.

// ❌ Bad
function process() {
  doSomething(condition ? 'yes' : 'no');
}

// ✅ Good
function process() {
  const value = condition ? 'yes' : 'no';
  doSomething(value);
}

// ❌ Bad
function renderTemplate(data) {
  return template(`Value: ${condition ? 'enabled' : 'disabled'}`);
}

// ✅ Good
function renderTemplate(data) {
  const status = condition ? 'enabled' : 'disabled';
  return template(`Value: ${status}`);
}

This rule improves code traceability by making conditional logic explicit and separating decision points from function calls. It catches ternary operators (? :), logical operators (||, &&, ??), and other conditional expressions within function arguments.

Development

Setup

pnpm install

Testing

pnpm test

License

MIT