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-no-in-array

v1.2.1

Published

ESLint rule to disallow using the 'in' operator with arrays (type-aware)

Readme

eslint-plugin-no-in-array

npm version GitHub

ESLint rule to disallow using the in operator with arrays. This is a type-aware rule that uses TypeScript's type checker to detect arrays, including those stored in variables.

Why?

The in operator checks for property keys, not values. This is a common source of bugs:

const arr = ["a", "b", "c"];

// WRONG - checks if "a" is a property key (index), not a value
"a" in arr; // false (indices are "0", "1", "2")

// CORRECT
arr.includes("a"); // true

Installation & Setup

This rule requires type-checked linting. Choose the setup that matches your project:

[!NOTE] Both setups require type-aware linting via projectService (recommended) or parserOptions.project. Without this, ESLint cannot access TypeScript's type checker and the rule will fail to load.

Pure TypeScript Projects

npm install -D eslint-plugin-no-in-array typescript-eslint
# or
pnpm add -D eslint-plugin-no-in-array typescript-eslint

Using the recommended config (simplest):

import eslint from "@eslint/js";
import { defineConfig } from "eslint/config";
import tseslint from "typescript-eslint";
import noInArray from "eslint-plugin-no-in-array";

export default defineConfig(
  eslint.configs.recommended,
  {
    files: ["**/*.ts", "**/*.tsx"],
    extends: [
      tseslint.configs.recommended,
      tseslint.configs.recommendedTypeChecked,
      noInArray.configs.recommended,
    ],
    languageOptions: {
      parserOptions: {
        projectService: true,
      },
    },
  },
);

Manual configuration:

import eslint from "@eslint/js";
import { defineConfig } from "eslint/config";
import tseslint from "typescript-eslint";
import noInArray from "eslint-plugin-no-in-array";

export default defineConfig(
  eslint.configs.recommended,
  {
    files: ["**/*.ts", "**/*.tsx"],
    extends: [
      tseslint.configs.recommended,
      tseslint.configs.recommendedTypeChecked,
    ],
    plugins: {
      "no-in-array": noInArray,
    },
    languageOptions: {
      parserOptions: {
        projectService: true,
      },
    },
    rules: {
      "no-in-array/check": "warn",
    },
  },
);

Next.js 16+

eslint-config-next already includes typescript-eslint, so you don't need to install it separately.

npm install -D eslint-plugin-no-in-array
# or
pnpm add -D eslint-plugin-no-in-array
import { dirname } from "path";
import { fileURLToPath } from "url";
import { defineConfig, globalIgnores } from "eslint/config";
import nextVitals from "eslint-config-next/core-web-vitals";
import nextTs from "eslint-config-next/typescript";
import noInArray from "eslint-plugin-no-in-array";

// Node 20.11+: use import.meta.dirname instead
const __dirname = dirname(fileURLToPath(import.meta.url));

export default defineConfig([
  ...nextVitals,
  ...nextTs,
  {
    files: ["**/*.ts", "**/*.tsx"],
    extends: [noInArray.configs.recommended],
    languageOptions: {
      parserOptions: {
        project: "./tsconfig.json",
        tsconfigRootDir: __dirname,
      },
    },
  },
  globalIgnores([".next/**", "node_modules/**"]),
]);

Or configure manually as outlined in Pure TypeScript Projects.

What it catches

const arr = ["a", "b", "c"];
const tuple: [string, number] = ["hello", 42];
const readonlyArr: readonly string[] = ["x", "y"];

// All of these will warn:
"a" in arr;
"hello" in tuple;
"x" in readonlyArr;
"foo" in ["inline", "array"];

// This will NOT warn (object, not array):
const obj = { a: 1, b: 2 };
"a" in obj; // OK - this is valid usage

Benchmarks

| Test | v1.0.0 | v1.1.0 | Change | | ------------ | ------ | ------ | ------ | | 100 objects | 493 hz | 589 hz | +19% | | 100 mixed | 925 hz | 989 hz | +7% | | 150 union | 446 hz | 474 hz | +6% | | 100 array in | 388 hz | 403 hz | +4% |

v1.1.0 optimizations: memoization, early primitive exit, union depth limit.

License

MIT