Skip to content

Coderrob/eslint-config-zero-tolerance

Repository files navigation

ESLint Plugin Zero Tolerance

@coderrob/eslint-plugin-zero-tolerance

60 opinionated ESLint rules for TypeScript teams that refuse to compromise on code quality.

npm version License ESLint TypeScript


Zero tolerance means every rule earns its place. No warnings you learn to ignore. No exceptions you forget about. Every violation is a conversation about quality — and quality always wins.

Why Zero Tolerance?

Most linting setups start strict and erode over time. A scattered eslint-disable here, an any cast there, and before long the rules exist in name only.

This plugin takes the opposite approach:

  • No eslint-disable comments — fix the root cause, don't silence the symptom.
  • No any smuggling — type assertions and non-null assertions are flagged.
  • No magic values — every number and string earns a name.
  • No leaky tests — persistent mocks, imprecise matchers, and timer abuse are caught.
  • No complexity hiding — functions stay short, parameters stay few, imports stay clean.

The result is a codebase where the rules are the culture and the culture is visible in every file.


Documentation

Hosted docs https://coderrob.github.io/eslint-config-zero-tolerance/
Rules reference docs/rules/index.md
Configuration guide docs/configuration.md

Packages

This monorepo publishes two packages:

Package Description
@coderrob/eslint-plugin-zero-tolerance The ESLint plugin — 60 custom rules
@coderrob/eslint-config-zero-tolerance Pre-built recommended and strict config presets

Requirements

  • ESLint 8.57.0+, 9.x, or 10.x
  • TypeScript-ESLint 8.x
  • TypeScript 5.x

Installation

npm install --save-dev @coderrob/eslint-plugin-zero-tolerance @typescript-eslint/parser

Usage

ESLint 9+ (Flat Config)

Using the recommended preset:

// eslint.config.js
import zeroTolerance from '@coderrob/eslint-plugin-zero-tolerance';

export default [
  zeroTolerance.configs.recommended,
  // your other configs...
];

Using the strict preset:

// eslint.config.js
import zeroTolerance from '@coderrob/eslint-plugin-zero-tolerance';

export default [
  zeroTolerance.configs.strict,
  // your other configs...
];

Alternative: Import presets directly from the config package:

// eslint.config.js
import recommended from '@coderrob/eslint-config-zero-tolerance/recommended';
// or
import strict from '@coderrob/eslint-config-zero-tolerance/strict';

export default [
  recommended, // or strict
  // your other configs...
];

Custom configuration:

// eslint.config.js
import zeroTolerance from '@coderrob/eslint-plugin-zero-tolerance';

export default [
  {
    plugins: {
      'zero-tolerance': zeroTolerance,
    },
    rules: {
      'zero-tolerance/require-interface-prefix': 'error',
      'zero-tolerance/no-throw-literal': 'error',
      'zero-tolerance/max-function-lines': ['warn', { max: 40 }],
      // ... other rules
    },
  },
];

ESLint 8.x (Legacy Config)

Using .eslintrc.js:

module.exports = {
  plugins: ['zero-tolerance'],
  extends: ['plugin:zero-tolerance/legacy-recommended'],
  // or for strict mode:
  // extends: ['plugin:zero-tolerance/legacy-strict'],
};

Rules

All 60 rules are organized into eight categories. Nearly all are included in both the recommended (warn) and strict (error) presets. A handful are opt-in only — see the Configuration guide for the full preset table.

Naming Conventions

Rule Description
require-interface-prefix Enforce that TypeScript interface names start with I followed by an uppercase letter

Documentation

Rule Description
require-bdd-spec Enforce that every TypeScript source file has a valid sibling .ts.bdd.json BDD spec
require-jsdoc-anonymous-functions Require JSDoc comments on anonymous function-like constructs except test files and known test callbacks
require-jsdoc-functions Require JSDoc comments on named functions (except test files)
require-optional-chaining Require optional chaining instead of repeated guard access
require-readonly-props Require JSX component props to be typed as readonly

Testing

Rule Description
require-test-description-style Enforce that test descriptions start with should
no-jest-have-been-called Prohibit imprecise call-assertion matchers; use toHaveBeenCalledTimes and toHaveBeenNthCalledWith instead
no-mock-implementation Prohibit persistent mock methods; use Once variants to prevent test bleeds
no-set-timeout-in-tests Disallow setTimeout usage in test files
no-set-interval-in-tests Disallow setInterval usage in test files
no-fetch-in-tests Disallow fetch usage in test files
no-restricted-imports-in-tests Disallow configured dependency imports in test files
no-test-interface-declaration Disallow interface declarations in test files; import production types instead

Type Safety

Rule Description
no-type-assertion Prevent use of TypeScript as and angle-bracket assertions
no-non-null-assertion Disallow non-null assertions using the ! postfix operator
no-literal-unions Ban literal union types in favour of enums
no-literal-property-unions Require property literal unions to use named domain types
require-union-type-alias Require inline union types with multiple type references to use named type aliases
no-banned-types Ban ReturnType and indexed access types
no-inline-type-import Disallow inline import("...").Type annotations
no-destructured-parameter-type-literal Disallow inline object type literals on destructured parameters
require-exported-object-type Require exported object constants to declare an explicit type annotation

Code Quality

Rule Description
max-function-lines Enforce a maximum number of lines per function body
max-params Enforce a maximum number of function parameters
no-array-mutation Disallow mutating array methods
no-date-now Disallow Date.now() and no-arg new Date() usage
no-magic-numbers Disallow magic numbers; use named constants instead
no-magic-strings Disallow magic strings in comparisons and switch cases
no-object-mutation Disallow direct object-property mutation
sort-imports Require import declarations to be grouped and alphabetized
sort-functions Require top-level functions to be sorted alphabetically
prefer-nullish-coalescing Prefer nullish coalescing instead of repeated nullish guard ternaries
prefer-readonly-parameters Prefer readonly typing for object and array-like parameters
prefer-string-raw Prefer String.raw for strings containing escaped backslashes

Error Handling

Rule Description
no-empty-catch Disallow empty catch blocks that silently swallow errors
no-throw-literal Disallow throwing literals, objects, or templates; always throw a new Error instance
prefer-result-return Prefer returning Result-style values instead of throwing

Imports

Rule Description
require-clean-barrel Require barrel files (index.*) to contain only module re-exports
no-barrel-parent-imports Ban .. and ../* parent-directory import traversal in barrel files
no-parent-internal-access Ban parent-relative access into protected internal directories such as src
no-dynamic-import Ban dynamic import() and require() outside test files
no-export-alias Prevent use of aliases in export statements
no-re-export Disallow direct or pass-through re-export statements from parent/grandparent modules
require-node-protocol Require Node.js built-in module imports to use the node: protocol prefix

Bug Prevention

Rule Description
no-identical-expressions Disallow identical expressions on both sides of a binary or logical operator
no-identical-branches Disallow identical branches in if/else and ternary conditionals
no-boolean-return-trap Disallow ambiguous boolean-return APIs outside predicate naming
no-redundant-boolean Disallow redundant comparisons to boolean literals
no-for-in Disallow for..in loops
no-labels Disallow labeled statements
no-with Disallow with statements
no-await-in-loop Disallow await inside loops; use Promise.all() instead
no-floating-promises Disallow unhandled promise expressions; require explicit handling
no-eslint-disable Prevent use of eslint-disable comments
no-parameter-reassign Disallow reassigning function parameters
no-flag-argument Disallow boolean flag parameters in function signatures
prefer-guard-clauses Prefer guard clauses by removing else blocks after terminating if branches
prefer-shortcut-return Prefer shortcut boolean returns over if branches that return true/false
no-query-side-effects Disallow side effects in query-style functions

Development

This repository itself is a pnpm workspace and dogfoods its own rules through eslint.config.mjs. Every source file in the plugin must pass the same rules it enforces on consumers.

Setup

pnpm install

Building

pnpm build

Testing

pnpm test

Coverage gates are enforced per-file at 95% minimum across statements, branches, functions, and lines. The test command also refreshes the coverage badge automatically.

Type Checking

pnpm --filter @coderrob/eslint-plugin-zero-tolerance exec tsc -p tsconfig.json --noEmit
pnpm --filter @coderrob/eslint-config-zero-tolerance exec tsc -p tsconfig.json --noEmit

Dependency Graph

pnpm deps:graph
pnpm deps:circular

Publishing

This monorepo provides automated scripts to handle versioned releases.

Quick release (single command):

pnpm release:prepare --release patch --commit --tag --publish

This will:

  • bump the root, plugin, and config package versions
  • replace workspace:* with a versioned peer dependency in packages/config
  • run pnpm build and pnpm test
  • create a release commit and annotated git tag
  • publish both packages to npm

If you want to restore workspace:* after publishing for local development, run:

pnpm release:restore-workspace

Or include --restore-workspace and commit that restoration separately.

Manual/stepwise release flow:

# 1. Build all packages
pnpm build

# 2. Run tests to ensure everything works
pnpm test

# 3. Prepare packages for publishing (converts workspace:* to versioned dependency)
pnpm release:prepare

# 4. Publish the plugin package
cd packages/plugin
npm publish

# 5. Publish the config package
cd ../config
npm publish

# 6. Restore workspace:* for local development
cd ../..
pnpm release:restore-workspace

Additional release:prepare options:

# Bump versions and prepare manifests without publishing
pnpm release:prepare --release minor

# Skip build/test if already run in CI or a previous step
pnpm release:prepare --release 1.2.0 --skip-build --skip-test --commit --tag --publish

# Dry run the full flow
pnpm release:prepare --release patch --commit --tag --publish --dry-run

License

Apache 2.0 Copyright Robert Lindley

About

Zero-tolerance ESLint plugin and config for enforcing strict code quality standards.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors