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 🙏

© 2026 – Pkg Stats / Ryan Hefner

eslint-plugin-performance-rules

v1.1.3

Published

ESLint plugin to detect performance anti-patterns

Readme

eslint-plugin-performance-rules

ESLint plugin to detect performance anti-patterns in JavaScript and TypeScript codebases. Identifies code patterns that cause runtime performance degradation through static AST analysis.

Features

  • 🔍 Detects quadratic loop complexity (O(n²) patterns)
  • 🚫 Identifies synchronous blocking calls in loops
  • ⚡ Catches expensive JSON parsing in loops
  • ⚛️ Finds React inline object creation causing re-renders
  • 🎯 Detects unnecessary array cloning
  • ⏳ Detects await inside loops (use Promise.all instead)
  • 🔤 Catches regex compilation inside loops
  • 🌐 Detects DOM queries inside loops
  • 🗺️ Flags O(n) array lookups inside loops (prefer Map/Set)
  • 📦 Detects object spread inside loops
  • 🖥️ Disallows console calls in production code
  • 🔧 Works with JavaScript and TypeScript
  • ✅ Zero runtime dependencies

Installation

npm install eslint-plugin-performance-rules --save-dev

Configuration

ESLint v9+ (Flat Config — eslint.config.js)

const perfPlugin = require('eslint-plugin-performance-rules');

module.exports = [
  perfPlugin.configs.recommended,
];

Or configure rules individually:

const perfPlugin = require('eslint-plugin-performance-rules');

module.exports = [
  {
    plugins: { 'performance-rules': perfPlugin },
    rules: {
      'performance-rules/no-quadratic-loops': 'warn',
      'performance-rules/no-await-in-loop': 'warn',
      'performance-rules/no-regex-in-loop': 'warn',
      'performance-rules/no-console-in-production': 'warn',
      // ...add more as needed
    },
  },
];

ESLint v7/v8 (Legacy Config — .eslintrc.js)

module.exports = {
  plugins: ['performance-rules'],
  extends: ['plugin:performance-rules/recommended-legacy'],
};

Or configure rules individually:

module.exports = {
  plugins: ['performance-rules'],
  rules: {
    'performance-rules/no-quadratic-loops': 'warn',
    'performance-rules/no-await-in-loop': 'warn',
    'performance-rules/no-regex-in-loop': 'warn',
    'performance-rules/no-console-in-production': 'warn',
  },
};

TypeScript Projects

// eslint.config.js
const perfPlugin = require('eslint-plugin-performance-rules');
const tsParser = require('@typescript-eslint/parser');

module.exports = [
  {
    files: ['**/*.ts', '**/*.tsx'],
    languageOptions: {
      parser: tsParser,
      parserOptions: { ecmaVersion: 2020, sourceType: 'module' },
    },
    ...perfPlugin.configs.recommended,
  },
];

Rules

| Rule | Description | Default | |------|-------------|---------| | no-quadratic-loops | Detects nested loops over the same array — O(n²) complexity | warn | | no-sync-in-loop | Detects fs.*Sync / child_process.*Sync calls inside loops | warn | | no-large-json-parse-in-loop | Detects JSON.parse() and JSON.stringify() inside loops | warn | | react-no-inline-object-creation | Detects inline objects/arrays/functions in JSX props | warn | | no-unnecessary-array-clone | Detects array clones that are never mutated | warn | | no-await-in-loop | Detects await inside loops — use Promise.all() instead | warn | | no-regex-in-loop | Detects regex literals / new RegExp() inside loops | warn | | no-dom-query-in-loop | Detects document.querySelector and friends inside loops | warn | | no-linear-search-in-loop | Flags O(n) array lookups (find/filter/includes/indexOf/findIndex) inside loops | warn | | no-object-spread-in-loop | Detects {...obj} / Object.assign({}, ...) inside loops | warn | | no-console-in-production | Disallows console.* calls (except error/warn by default) | warn |

Rule Details

no-quadratic-loops

// Bad
for (const a of arr) {
  for (const b of arr) { } // O(n²)
}

// Good
const set = new Set(arr);
for (const a of arr) { set.has(a); }

no-await-in-loop

// Bad
for (const url of urls) {
  await fetch(url); // sequential
}

// Good
await Promise.all(urls.map(url => fetch(url)));

no-regex-in-loop

// Bad
for (const s of strings) {
  /foo/.test(s); // recompiled every iteration
}

// Good
const re = /foo/;
for (const s of strings) { re.test(s); }

no-dom-query-in-loop

// Bad
for (const item of items) {
  document.querySelector('.list').appendChild(item);
}

// Good
const list = document.querySelector('.list');
for (const item of items) { list.appendChild(item); }

no-linear-search-in-loop

// Bad — O(n²): find/filter/includes/indexOf/findIndex inside a loop
for (const id of ids) {
  users.find(u => u.id === id);
}

// Good — O(1) lookup with a Map built once outside the loop
const userMap = new Map(users.map(u => [u.id, u]));
for (const id of ids) { userMap.get(id); }

no-object-spread-in-loop

// Bad — new object every iteration
for (const item of arr) {
  const copy = { ...item };
}

// Good
const target = {};
for (const item of arr) { Object.assign(target, item); }

no-console-in-production

// Bad
console.log('debug value:', x);

// Good
console.error('something broke'); // error/warn allowed by default

Configure allowed methods:

// eslint.config.js
rules: {
  'performance-rules/no-console-in-production': ['warn', { allow: ['error', 'warn', 'info'] }]
}

Usage

# Run ESLint
npx eslint .

# With performance formatter
npx eslint . --format ./node_modules/eslint-plugin-performance-rules/src/lib/formatters/performance.js

License

MIT