@coderrob/eslint-plugin-zero-tolerance

中文文档
1.2.9发布于 2026/11/06Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 4437

Strict, opinionated ESLint rules for TypeScript — enforcing type safety, code quality, testing standards, and maintainable patterns with zero exceptions.

原始使用文档
文档目录20 节
  1. Features
  2. Requirements
  3. Installation
  4. Quick Start
  5. ESLint 9+ (Flat Config)
  6. ESLint 8.x (Legacy Config)
  7. Custom Rule Selection
  8. Presets
  9. Rules
  10. Naming Conventions
  11. Documentation
  12. Testing
  13. Type Safety
  14. Code Quality
  15. Error Handling
  16. Imports
  17. Bug Prevention
  18. Documentation
  19. Choose checks
  20. License

@coderrob/eslint-plugin-zero-tolerance

no-magic-numbers allows arithmetic in named constants, such as const SOMETHING = 10 * 100;.

Behavioral safety contracts document positive and negative inputs, parameter boundaries, state isolation, and cases that require manual migration.

Rule suites require nonempty valid and invalid fixtures, named should cases, explicit diagnostics, and concrete autofix outputs. All 83 rules also run against shared TypeScript, JSX, optional-access, and Jest-chain parsing fixtures. See the contributor guide for validation requirements.

Strict, opinionated ESLint plugin for TypeScript that enforces type safety, code quality, testing standards, and maintainable patterns — with zero exceptions.

npm version License

Features

  • 83 custom ESLint rules across eight categories: type safety, code quality, testing, imports, error handling, bug prevention, naming conventions, and documentation
  • Two presets — recommended generally uses warning severity for gradual adoption, while strict generally uses error severity; strict-only and opt-in exceptions are identified below
  • ESLint 8.57+, 9.x, and 10.x — flat config and legacy .eslintrc both supported
  • 99%+ test coverage — every rule is thoroughly tested with both valid and invalid cases
  • Built with @typescript-eslint/utils for full TypeScript AST support

Requirements

  • Node.js
    • 18.18.0+ when using ESLint 8.57.0+ or 9.x
    • 20.19.0+, 22.13.0+, or 24.0.0+ when using ESLint 10.x
    • CI-tested LTS releases: 18.20.8, 20.20.2, 22.23.4, 24.22.2, and 26.13.0
  • ESLint 8.57.0+, 9.x, or 10.x
    • CI-tested major releases: 8.57.1, 9.39.5, and 10.14.0
  • @typescript-eslint/parser 8.x
  • TypeScript 5.x

Installation

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

Quick Start

ESLint 9+ (Flat Config)

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

export default [zeroTolerance.configs.recommended];

ESLint 8.x (Legacy Config)

// .eslintrc.js
module.exports = {
  plugins: ['@coderrob/zero-tolerance'],
  extends: ['plugin:@coderrob/zero-tolerance/legacy-recommended'],
};

Legacy ESLint resolves the scoped package through the @coderrob/zero-tolerance shorthand, so manually selected legacy rule IDs use @coderrob/zero-tolerance/<rule-name>. Flat configs continue to use the zero-tolerance namespace shown below.

Custom Rule Selection

// 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 }],
    },
  },
];

Presets

PresetSeverityConfig Key
Recommendedwarnconfigs.recommended
Stricterrorconfigs.strict
Legacy Recommendedwarnlegacy-recommended
Legacy Stricterrorlegacy-strict

Preset severities describe the default for enabled rules. prefer-result-return is strict-only, while require-bdd-spec, require-jsdoc-anonymous-functions, no-fetch-in-tests, no-parent-internal-access, and no-restricted-imports-in-tests remain opt-in in both presets. See the full rule documentation for each rule's preset status.

Rules

Naming Conventions

RuleDescription
require-interface-prefixEnforce that TypeScript interface names start with I followed by an uppercase letter

Documentation

RuleDescription
require-bdd-specEnforce that every TypeScript source file has a valid sibling .ts.bdd.json BDD spec
require-jsdoc-anonymous-functionsRequire JSDoc comments on anonymous function-like constructs except test files and known test callbacks
require-jsdoc-functionsRequire JSDoc comments on named functions (except test files)
require-optional-chainingReport repeated logical guard access for manual review
require-readonly-propsRequire JSX component props to be typed as readonly

Testing

RuleDescription
require-test-description-styleEnforce that test descriptions start with should
no-chai-imprecise-spy-assertionsRequire exact Chai-style spy call counts and invocation arguments
no-conditional-test-assertionDisallow assertions in test branches that may not execute
no-jest-have-been-calledRequire exact call counts and invocation indices in Jest assertions; allow negated zero-call checks
no-mock-implementationProhibit persistent mock methods; use Once variants to prevent test bleeds
no-sinon-imprecise-spy-assertionsRequire exact Sinon spy call counts and invocation arguments
no-set-timeout-in-testsDisallow setTimeout usage in test files
no-set-interval-in-testsDisallow setInterval usage in test files
no-fetch-in-testsDisallow fetch usage in test files
no-restricted-imports-in-testsDisallow configured dependency imports in test files
no-test-interface-declarationDisallow interface declarations in test files; import production types instead
no-unawaited-async-assertionRequire asynchronous test assertions to be awaited or returned
no-vitest-imprecise-spy-assertionsRequire exact Vitest spy call counts and invocation indices

Type Safety

RuleDescription
no-type-assertionPrevent use of TypeScript as and angle-bracket assertions
no-non-null-assertionDisallow non-null assertions using the ! postfix operator
no-explicit-anyDisallow explicit any; require precise modeling or explicit narrowing
no-indexed-access-typesDisallow TypeScript indexed access types
no-literal-unionsReport literal unions for manual migration to enums
no-literal-property-unionsRequire property literal unions to use named domain types
require-union-type-aliasRequire inline union types with multiple type references to use named type aliases
no-inline-type-importDisallow inline import("...").Type annotations
no-return-typeDisallow TypeScript ReturnType utility usage
no-destructured-parameter-type-literalDisallow inline object type literals on destructured parameters
require-exported-object-typeRequire exported object constants to declare an explicit type annotation
no-unsafe-json-parseDisallow treating JSON.parse results as typed data without validation

Code Quality

RuleDescription
max-function-linesEnforce a maximum number of lines per function body
max-paramsEnforce a maximum number of function parameters
no-array-mutationDisallow mutating array methods
no-date-nowDisallow Date.now() and no-arg new Date() usage
no-placeholder-implementationDisallow placeholder, stub, TODO, and not implemented production code
no-magic-numbersDisallow magic numbers; use named constants instead
no-magic-stringsDisallow magic strings in comparisons and switch cases
no-map-set-mutationDisallow direct Map and Set mutation methods
no-object-mutationDisallow direct object-property mutation
sort-importsReport import ordering while preserving runtime dependency order
sort-functionsRequire top-level functions and const function expressions to be sorted alphabetically
prefer-nullish-coalescingPrefer nullish coalescing for locally bound identifier guard ternaries
prefer-object-spreadReport empty-target Object.assign calls for manual review before using object spread
prefer-readonly-parametersPrefer readonly typing for object and array-like parameters
prefer-string-rawPrefer native String.raw when the constructor is not shadowed
prefer-structured-cloneReview JSON.parse(JSON.stringify(...)) before considering structuredClone(...)

Error Handling

RuleDescription
no-empty-catchDisallow empty catch blocks that silently swallow errors
no-throw-literalDisallow throwing literals, objects, or templates; always throw a new Error instance
prefer-result-returnPrefer returning Result-style values instead of throwing

Imports

no-parent-internal-access remains opt-in and only matches the first concrete directory reached after .. traversal, such as ../src/foo.

RuleDescription
require-clean-barrelRequire barrel files (index.*) to contain only module re-exports
require-barrel-relative-exportsRequire barrel re-exports to use ./ descendant paths
no-barrel-parent-importsDisallow parent-directory traversal in barrel-file import paths
no-parent-internal-accessDisallow parent-relative access into protected internal directories such as src
no-dynamic-importBan dynamic import() and require() outside test files
no-export-aliasPrevent use of aliases in export statements
no-hardcoded-secretsDisallow hardcoded secrets, credentials, tokens, and secret env defaults
no-raw-sql-interpolationDisallow interpolated raw SQL and unsafe raw query helpers
no-re-exportDisallow direct or pass-through re-exports from parent/grandparent modules
no-shell-command-constructionDisallow shell command construction through subprocess APIs
no-unsafe-code-generationDisallow eval, Function constructors, string timers, and vm execution APIs
require-node-protocolRequire Node.js built-in module imports to use the node: protocol prefix

Bug Prevention

RuleDescription
no-identical-expressionsDisallow identical expressions on both sides of a binary or logical operator
no-identical-branchesDisallow identical conditional branches
no-boolean-return-trapDisallow ambiguous boolean-return APIs outside predicate naming
no-redundant-booleanSimplify comparisons only when the operand is known to be boolean
no-for-inDisallow for..in loops without rewriting inherited-key behavior
no-labelsDisallow labeled statements
no-withDisallow with statements
no-await-in-loopDisallow await inside loops; use Promise.all() instead
no-floating-promisesCheck explicit, local async, and type-resolved promises
no-math-randomDisallow Math.random(); inject a random source instead
no-eslint-disablePrevent use of eslint-disable comments
no-parameter-reassignDisallow reassigning function parameters
no-process-env-outside-configDisallow process.env reads outside configuration modules
no-flag-argumentDisallow boolean flag parameters in function signatures
prefer-guard-clausesPrefer guard clauses by removing else blocks after terminating if branches
prefer-shortcut-returnSimplify boolean returns while retaining comments
no-query-side-effectsDisallow side effects in query-style functions
require-timeout-for-ioRequire timeout or cancellation options for external IO calls
require-exhaustive-switchRequire exhaustive switch statements over finite discriminant types

Documentation

Full rule documentation with examples is available at:

https://coderrob.github.io/eslint-config-zero-tolerance/

Choose checks

Use the rule reference to choose checks and review examples, options, and limits. Enable require-error-cause individually to preserve original exceptions.

For promise handling, unsafe types, callback returns, and branching limits, see additional code-quality checks.

License

Apache 2.0 Copyright Robert Lindley

版本与发布记录

@coderrob/eslint-plugin-zero-tolerance 共发布 20 个版本,首次发布于 2026/03/06;过去 12 个月发布了 20 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.2.9latest2026/11/064 天前
1.2.82026/11/046 天前
1.2.72026/11/037 天前
1.2.62026/08/073 个月前
1.2.52026/07/233 个月前
1.2.42026/04/296 个月前

关于 @coderrob/eslint-plugin-zero-tolerance 的常见问题

@coderrob/eslint-plugin-zero-tolerance 是什么?

Strict, opinionated ESLint rules for TypeScript — enforcing type safety, code quality, testing standards, and maintainable patterns with zero exceptions.

如何安装 @coderrob/eslint-plugin-zero-tolerance?

在项目目录运行 npm install @coderrob/eslint-plugin-zero-tolerance,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:eslint(^8.57.0 || ^9.0.0 || ^10.0.0)、typescript(^5.0.0)、@typescript-eslint/parser(^8.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@coderrob/eslint-plugin-zero-tolerance 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@coderrob/eslint-plugin-zero-tolerance 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@coderrob/eslint-plugin-zero-tolerance 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18.18.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@coderrob/eslint-plugin-zero-tolerance 可以商用吗?

@coderrob/eslint-plugin-zero-tolerance 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@coderrob/eslint-plugin-zero-tolerance 的下载量有多少?

根据 npm 官方下载统计,@coderrob/eslint-plugin-zero-tolerance 在 2026/10/10 – 2026/11/08 这 30 天内被下载 4,437 次,日均约 148 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@coderrob/eslint-plugin-zero-tolerance 还在维护吗?

最新版本 1.2.9 发布于 2026/11/06(4 天前);至今共发布 20 个版本,其中过去 12 个月发布了 20 个;首次发布于 2026/03/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。